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

feat: support one-click stop format #162

Merged
merged 1 commit into from
Nov 28, 2022
Merged

feat: support one-click stop format #162

merged 1 commit into from
Nov 28, 2022

Conversation

DemoLiang
Copy link
Contributor

@DemoLiang DemoLiang commented Nov 22, 2022

feat: 支持一键停止磁盘格式化,包括:停止容器,删除fstab记录,umount 挂载的磁盘
test:简单测试了:单节点单盘、单节点多盘、多节点多盘

curveadm run result:
image

step1: check node docker,fstab, mountpoint not exist
image
image

step2: curveadm run format ,and check docker,fstab,mountpoint exist
image
image

step3: curveadm stop format ,check docker, fstab,mountpoint delete
image
image

#156

@DemoLiang DemoLiang changed the title feat: #156 support one-click stop format feat: support one-click stop format Nov 22, 2022
@ilixiaocui ilixiaocui requested review from Wine93, ilixiaocui and cw123 and removed request for ilixiaocui and cw123 November 22, 2022 08:55
@@ -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`
Copy link
Collaborator

@Wine93 Wine93 Nov 22, 2022

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.

Copy link
Contributor Author

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

@@ -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")
Copy link
Collaborator

@Wine93 Wine93 Nov 22, 2022

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Collaborator

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

Usage message:

flags.BoolVar(&options.stopFormat, "stop", false, "Stop formatting progress")

not

flags.BoolVar(&options.stopFormat, "stop", false, "stop formatting status")

Copy link
Contributor Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree!

@@ -49,11 +50,16 @@ var (
FORMAT_STATUS_PLAYBOOK_STEPS = []int{
playbook.GET_FORMAT_STATUS,
}
// FORMAT_STOP_PLAYBOOK_STEPS 停止格式化step
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve

@@ -114,6 +114,9 @@ const (
REMOVE_PLAYGROUND
GET_PLAYGROUND_STATUS

// STOP_FORMAT 停止format
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve

}
)

// skipStopFormat 跳过停止format操作,当前不存在format的容器
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve

}
}

// expression 生成要删除或者添加的fstab的sed表达式
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve

}
}

// execute 执行删除fstab记录
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve

})
}

// stopContainer 停止container
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve

@ilixiaocui
Copy link
Collaborator

Thanks you for the pr!

Please post the screenshot of the execution result of curveadm fromat.

return nil
}

// NewStopFormatTask 新建停止stop format任务
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve

}

// execute 执行删除fstab记录
func (s *deleteFSTab) execute(ctx *context.Context) error {
Copy link
Collaborator

@Wine93 Wine93 Nov 22, 2022

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.

Copy link
Contributor Author

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

device := fc.GetDevice()
mountPoint := fc.GetMountPoint()
usagePercent := fc.GetFormatPercent()
subname := fmt.Sprintf("host=%s device=%s mountPoint=%s usage=%d%%",
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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)

Copy link
Contributor Author

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

@@ -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`
Copy link
Collaborator

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.

Copy link
Contributor Author

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{
Copy link
Collaborator

@Wine93 Wine93 Nov 22, 2022

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.

Copy link
Contributor Author

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

@Wine93
Copy link
Collaborator

Wine93 commented Nov 22, 2022

Thank for you contribute @DemoLiang , maybe some improvements can make this feature become better :)

InPlace: true,
ExecOptions: curveadm.ExecOptions(),
})
if s.skipAdd {
Copy link
Collaborator

@Wine93 Wine93 Nov 23, 2022

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?

Copy link
Contributor Author

@DemoLiang DemoLiang Nov 23, 2022

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

Wine93
Wine93 previously approved these changes Nov 23, 2022
Copy link
Collaborator

@Wine93 Wine93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -0,0 +1,133 @@
/*
* Copyright (c) 2021 NetEase Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2022

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update

Comment on lines 81 to +82
flags.BoolVar(&options.showStatus, "status", false, "Show formatting status")
flags.BoolVar(&options.stopFormat, "stop", false, "Stop formatting progress")
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator

@Cyber-SiKu Cyber-SiKu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ilixiaocui ilixiaocui removed their request for review November 28, 2022 02:59
@Wine93 Wine93 merged commit 6a46cc5 into opencurve:master Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants