-
Notifications
You must be signed in to change notification settings - Fork 72
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
feat: support one-click stop format #162
Conversation
cli/command/format.go
Outdated
@@ -38,7 +38,8 @@ import ( | |||
const ( | |||
FORMAT_EXAMPLE = `Examples: | |||
$ curveadm format -f /path/to/format.yaml # Format chunkfile pool with specified configure file | |||
$ curveadm format --status -f /path/to/format.yaml # Display formatting status` | |||
$ curveadm format --status -f /path/to/format.yaml # Display formatting status | |||
$ curveadm format --stop -f /path/to/format.yaml # stop formatting` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should align the comment of command examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should align the comment of command examples.
resolve
cli/command/format.go
Outdated
@@ -73,6 +79,7 @@ func NewFormatCommand(curveadm *cli.CurveAdm) *cobra.Command { | |||
flags := cmd.Flags() | |||
flags.StringVarP(&options.filename, "formatting", "f", "format.yaml", "Specify the configure file for formatting chunkfile pool") | |||
flags.BoolVar(&options.showStatus, "status", false, "Show formatting status") | |||
flags.BoolVar(&options.stopFormat, "stop", false, "stop formatting status") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage message of stop
option should be Stop formatting progress
.
BTW: i think we shoud use subcommands to instead of all options, like:
curveadm format start
curveadm format status
curveadm format stop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve
current subcommands not support in format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I keep the same write as status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I real forget why we use option instead of subcommands, but you can change it if you interested it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage message of
stop
option should beStop formatting progress
.BTW: i think we shoud use subcommands to instead of all options, like:
curveadm format start curveadm format status curveadm format stop
Usage message:
flags.BoolVar(&options.stopFormat, "stop", false, "Stop formatting progress")
not
flags.BoolVar(&options.stopFormat, "stop", false, "stop formatting status")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resove the usage
i think we should keep the option with pre version ,stop and status
subcommands can rewrite in next version for status , stop and others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree!
cli/command/format.go
Outdated
@@ -49,11 +50,16 @@ var ( | |||
FORMAT_STATUS_PLAYBOOK_STEPS = []int{ | |||
playbook.GET_FORMAT_STATUS, | |||
} | |||
// FORMAT_STOP_PLAYBOOK_STEPS 停止格式化step |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use english comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve
internal/playbook/factory.go
Outdated
@@ -114,6 +114,9 @@ const ( | |||
REMOVE_PLAYGROUND | |||
GET_PLAYGROUND_STATUS | |||
|
|||
// STOP_FORMAT 停止format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve
internal/task/task/bs/format_stop.go
Outdated
} | ||
) | ||
|
||
// skipStopFormat 跳过停止format操作,当前不存在format的容器 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve
internal/task/task/bs/format_stop.go
Outdated
} | ||
} | ||
|
||
// expression 生成要删除或者添加的fstab的sed表达式 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve
internal/task/task/bs/format_stop.go
Outdated
} | ||
} | ||
|
||
// execute 执行删除fstab记录 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve
internal/task/task/bs/format_stop.go
Outdated
}) | ||
} | ||
|
||
// stopContainer 停止container |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve
Thanks you for the pr! Please post the screenshot of the execution result of curveadm fromat. |
internal/task/task/bs/format_stop.go
Outdated
return nil | ||
} | ||
|
||
// NewStopFormatTask 新建停止stop format任务 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve
internal/task/task/bs/format_stop.go
Outdated
} | ||
|
||
// execute 执行删除fstab记录 | ||
func (s *deleteFSTab) execute(ctx *context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The step deleteFSTab
is similar to step step2EditFSTab
, you can union them into one, and provide one parameter to determine whether to add record into fstab.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve this issue ,remove deleteFsTabe
add skipAdd for edit fstab to skip add record for delete
internal/task/task/bs/format_stop.go
Outdated
device := fc.GetDevice() | ||
mountPoint := fc.GetMountPoint() | ||
usagePercent := fc.GetFormatPercent() | ||
subname := fmt.Sprintf("host=%s device=%s mountPoint=%s usage=%d%%", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the container id (or name) is more useful than the usage percent in stop task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we can't get containerid ,if task step not run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we can't get containerid ,if task step not run?
There is a fixed method to generate container name for format task:
containerName := device2ContainerName(device)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modify it ,replace the usagePercent with containerName
cli/command/format.go
Outdated
@@ -38,7 +38,8 @@ import ( | |||
const ( | |||
FORMAT_EXAMPLE = `Examples: | |||
$ curveadm format -f /path/to/format.yaml # Format chunkfile pool with specified configure file | |||
$ curveadm format --status -f /path/to/format.yaml # Display formatting status` | |||
$ curveadm format --status -f /path/to/format.yaml # Display formatting status | |||
$ curveadm format --stop -f /path/to/format.yaml # stop formatting` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use gofmt or ide auto format the code style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve ,format it
gofmt not support strings usage format ,
}) | ||
|
||
// 2: stop container | ||
t.AddStep(&stopContainer{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we shoud place the step stopContainer
to the after of step deleteFSTab
, because we will skip this task if container not exist even if the record in fstab is not deleted, and the last stop task which abort after stop container will make this problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeh ,we have place the step of stopContainer and deleteFSTab
first delete fstab record
next stop container
Thank for you contribute @DemoLiang , maybe some improvements can make this feature become better :) |
internal/task/task/bs/format.go
Outdated
InPlace: true, | ||
ExecOptions: curveadm.ExecOptions(), | ||
}) | ||
if s.skipAdd { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong judge, i think you want to express is that the step will not add new record if the parameter skipAdd
is true, is it right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeh ,Thanks you review it
we have two curveadm project for backup
and test is deleteFSTab
,so I did not find the error
I've resolve it and retested uploading tested pass images
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
internal/task/task/bs/format_stop.go
Outdated
@@ -0,0 +1,133 @@ | |||
/* | |||
* Copyright (c) 2021 NetEase Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update
flags.BoolVar(&options.showStatus, "status", false, "Show formatting status") | ||
flags.BoolVar(&options.stopFormat, "stop", false, "Stop formatting progress") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the flag stop
and status
mutually exclusive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check the option ,If both option is true, report an error config and return
Signed-off-by: DemoLiang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
feat: 支持一键停止磁盘格式化,包括:停止容器,删除fstab记录,umount 挂载的磁盘
test:简单测试了:单节点单盘、单节点多盘、多节点多盘
curveadm run result:
step1: check node docker,fstab, mountpoint not exist
step2: curveadm run format ,and check docker,fstab,mountpoint exist
step3: curveadm stop format ,check docker, fstab,mountpoint delete
#156