Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force readonly #1259

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
Loading