Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/bkctl/bookie/set_readonly_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,20 @@ func setReadonlyStateCmd(vc *cmdutils.VerbCmd) {
desc.ToString(),
desc.ExampleToString())

force := vc.Command.Flags().BoolP("force", "f", false, "force to set readonly state")

vc.SetRunFuncWithNameArg(func() error {
return doSetReadonlyState(vc)
return doSetReadonlyState(vc, *force)
}, "the readonly state is boolean")
}

func doSetReadonlyState(vc *cmdutils.VerbCmd) error {
func doSetReadonlyState(vc *cmdutils.VerbCmd, force bool) error {
admin := cmdutils.NewBookieClient()
readonly, err := strconv.ParseBool(vc.NameArg)
if err != nil {
return err
}
err = admin.Bookie().SetReadonlyState(readonly)
err = admin.Bookie().SetReadonlyState(readonly, force)
if err == nil {
cmdutils.PrintJSON(vc.Command.OutOrStdout(), "Successfully set the readonly state of a bookie")
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/bookkeeper/bookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Bookie interface {
State() (*bkdata.State, error)

// SetReadonlyState sets the readonly state of a bookie
SetReadonlyState(bool) error
SetReadonlyState(bool, bool) error
}

type bookie struct {
Expand All @@ -61,12 +61,16 @@ func (c *bookieClient) Bookie() Bookie {
}
}

func (b *bookie) SetReadonlyState(readonly bool) error {
func (b *bookie) SetReadonlyState(readonly bool, force bool) error {
endpoint := b.bk.endpoint(b.basePath, "/state/readonly")
request := bkdata.ReadonlyState{
ReadOnly: readonly,
}
return b.bk.Client.Put(endpoint, &request)
params := map[string]string{}
if readonly && force {
params["force"] = "true"
}
return b.bk.Client.PutWithQueryParams(endpoint, &request, nil, params)
}

func (b *bookie) LastLogMark() (map[string]string, error) {
Expand Down