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

support incremental formatting #288

Merged
merged 1 commit into from
Oct 12, 2023
Merged
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
73 changes: 57 additions & 16 deletions cli/command/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ package command

import (
"fmt"

"github.com/opencurve/curveadm/cli/cli"
comm "github.com/opencurve/curveadm/internal/common"
"github.com/opencurve/curveadm/internal/configure"
"github.com/opencurve/curveadm/internal/configure/topology"
"github.com/opencurve/curveadm/internal/errno"
"github.com/opencurve/curveadm/internal/playbook"
"github.com/opencurve/curveadm/internal/task/task/bs"
Expand All @@ -39,11 +39,12 @@ 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 --stop -f /path/to/format.yaml # Stop formatting progress
$ curveadm format --debug -f /path/to/format.yaml # Format chunkfile with debug mode
$ curveadm format --clean -f /path/to/format.yaml # clean the container left by debug mode`
$ curveadm format -f /path/to/format.yaml # Format chunkfile pool with specified configure file
$ curveadm format -f /path/to/format.yaml --increment # Incremental Format chunkfile pool with specified configure file
$ curveadm format --status -f /path/to/format.yaml # Display formatting status
$ curveadm format --stop -f /path/to/format.yaml # Stop formatting progress
$ curveadm format --debug -f /path/to/format.yaml # Format chunkfile with debug mode
$ curveadm format --clean -f /path/to/format.yaml # clean the container left by debug mode`
)

var (
Expand All @@ -62,6 +63,11 @@ var (
FORMAT_CLEAN_PLAYBOOK_STEPS = []int{
playbook.CLEAN_FORMAT,
}

FORMAT_INCREMENT_PLAYBOOK_STEPS = []int{
playbook.STOP_SERVICE,
playbook.FORMAT_CHUNKFILE_POOL,
}
)

type formatOptions struct {
Expand All @@ -70,6 +76,7 @@ type formatOptions struct {
stopFormat bool
debug bool
clean bool
increment bool
}

func checkFormatOptions(options formatOptions) error {
Expand Down Expand Up @@ -116,6 +123,7 @@ func NewFormatCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags.BoolVar(&options.stopFormat, "stop", false, "Stop formatting progress")
flags.BoolVar(&options.debug, "debug", false, "Debug formatting progress")
flags.BoolVar(&options.clean, "clean", false, "Clean the Container")
flags.BoolVar(&options.increment, "increment", false, "Incremental formatting")

return cmd
}
Expand All @@ -131,6 +139,7 @@ func genFormatPlaybook(curveadm *cli.CurveAdm,
stopFormat := options.stopFormat
debug := options.debug
clean := options.clean
increment := options.increment

steps := FORMAT_PLAYBOOK_STEPS
if showStatus {
Copy link
Contributor

Choose a reason for hiding this comment

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

may be we can use playbook playbook.STOP_SERVICE.
for example:

 FORMAT_INCREMENT_PLAYBOOK_STEPS := int[]{
  playbook.STOP_SERVICE,
  playbook.FORMAT_CHUNKFILE_POOL,
}

if increment {
  steps = FORMAT_INCREMENT_PLAYBOOK_STEPS
}

stopChunkServercs = curveadm.FilterDeployConfig(dcs, topology.FilterOption{
		Role: "chunkserver",
})
if len(stopChunkServercs) == 0 {
	// no chunkserver
}
if step == playbook.STOP_SERVICE {
     pb.AddStep(&playbook.PlaybookStep{
        ...
        Configs: stopChunkServercs
     } else ...
}

Copy link
Author

Choose a reason for hiding this comment

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

done

Expand All @@ -142,6 +151,9 @@ func genFormatPlaybook(curveadm *cli.CurveAdm,
if clean {
steps = FORMAT_CLEAN_PLAYBOOK_STEPS
}
if increment {
steps = FORMAT_INCREMENT_PLAYBOOK_STEPS
}

pb := playbook.NewPlaybook(curveadm)
for _, step := range steps {
Expand All @@ -150,14 +162,34 @@ func genFormatPlaybook(curveadm *cli.CurveAdm,
if step == playbook.FORMAT_CHUNKFILE_POOL {
options[comm.DEBUG_MODE] = debug
}
pb.AddStep(&playbook.PlaybookStep{
Type: step,
Configs: fcs,
ExecOptions: playbook.ExecOptions{
SilentSubBar: showStatus,
},
Options: options,
})
options[comm.FORMAT_INCREMENTAL] = increment
if step == playbook.STOP_SERVICE {
dcs, err := curveadm.ParseTopology()
if err != nil {
return nil, err
}
stopChunkServercs := curveadm.FilterDeployConfig(dcs, topology.FilterOption{
Id: "*",
Role: "chunkserver",
Host: "*",
})
if len(stopChunkServercs) == 0 {
continue
}
pb.AddStep(&playbook.PlaybookStep{
Type: step,
Configs: stopChunkServercs,
})
} else {
pb.AddStep(&playbook.PlaybookStep{
Type: step,
Configs: fcs,
ExecOptions: playbook.ExecOptions{
SilentSubBar: showStatus,
},
Options: options,
})
}
}
return pb, nil
}
Expand All @@ -179,6 +211,7 @@ func runFormat(curveadm *cli.CurveAdm, options formatOptions) error {
var fcs []*configure.FormatConfig
diskRecords := curveadm.DiskRecords()
debug := options.debug
increment := options.increment
if debug {
curveadm.SetDebugLevel()
}
Expand Down Expand Up @@ -224,13 +257,21 @@ func runFormat(curveadm *cli.CurveAdm, options formatOptions) error {
return err
}

// 3) run playbook
// 3) confirm by user
if increment {
if pass := tuicomm.ConfirmYes(tuicomm.PromptIncrementFormat()); !pass {
curveadm.WriteOut(tuicomm.PromptCancelOpetation("increment format"))
return errno.ERR_CANCEL_OPERATION
}
}

// 4) run playbook
err = pb.Run()
if err != nil {
return err
}

// 4) print status or prompt
// 5) print status or prompt
if options.showStatus {
output := displayFormatStatus(curveadm)
curveadm.WriteOutln("")
Expand Down
1 change: 1 addition & 0 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (

// format
KEY_ALL_FORMAT_STATUS = "ALL_FORMAT_STATUS"
FORMAT_INCREMENTAL = "FORMAT_INCREMENTAL"

// check
KEY_CHECK_WITH_WEAK = "CHECK_WITH_WEAK"
Expand Down
33 changes: 27 additions & 6 deletions internal/task/scripts/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,33 @@ percent=$2
chunkfile_size=$3
chunkfile_pool_dir=$4
chunkfile_pool_meta_path=$5
increment_format=$6

mkdir -p $chunkfile_pool_dir
$binary \
-allocatePercent=$percent \
-fileSize=$chunkfile_size \
-filePoolDir=$chunkfile_pool_dir \
-filePoolMetaPath=$chunkfile_pool_meta_path \
-fileSystemPath=$chunkfile_pool_dir

if [ $increment_format == "true" ]
then
rootdir=$(dirname $chunkfile_pool_dir)
used_percent=$(df $rootdir --output=pcent|tail -n 1|sed 's/%//'|xargs)
let minus=$percent-$used_percent

if [ $minus -gt 0 ]
then
$binary \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it not works, do you have test it?

Copy link
Author

@liuminjian liuminjian Oct 8, 2023

Choose a reason for hiding this comment

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

I have tested it
image
image

-allocatePercent=$minus \
-fileSize=$chunkfile_size \
-filePoolDir=$chunkfile_pool_dir \
-filePoolMetaPath=$chunkfile_pool_meta_path \
-fileSystemPath=$chunkfile_pool_dir
fi
else
$binary \
-allocatePercent=$percent \
-fileSize=$chunkfile_size \
-filePoolDir=$chunkfile_pool_dir \
-filePoolMetaPath=$chunkfile_pool_meta_path \
-fileSystemPath=$chunkfile_pool_dir
fi


Copy link
Contributor

Choose a reason for hiding this comment

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

The parameters of curve_format is incremental precent default and seems to be unnecessary to modify the script.

`
17 changes: 10 additions & 7 deletions internal/task/task/bs/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ package bs

import (
"fmt"
comm "github.com/opencurve/curveadm/internal/common"
"regexp"
"strings"
"time"

"github.com/opencurve/curveadm/cli/cli"
comm "github.com/opencurve/curveadm/internal/common"
"github.com/opencurve/curveadm/internal/configure"
"github.com/opencurve/curveadm/internal/configure/disks"
os "github.com/opencurve/curveadm/internal/configure/os"
Expand Down Expand Up @@ -246,8 +246,9 @@ func NewFormatChunkfilePoolTask(curveadm *cli.CurveAdm, fc *configure.FormatConf
chunkfilePoolRootDir := layout.ChunkfilePoolRootDir
formatScript := scripts.SCRIPT_FORMAT
formatScriptPath := fmt.Sprintf("%s/format.sh", layout.ToolsBinDir)
formatCommand := fmt.Sprintf("%s %s %d %d %s %s", formatScriptPath, layout.FormatBinaryPath,
usagePercent, DEFAULT_CHUNKFILE_SIZE, layout.ChunkfilePoolDir, layout.ChunkfilePoolMetaPath)
increment := curveadm.MemStorage().Get(comm.FORMAT_INCREMENTAL).(bool)
formatCommand := fmt.Sprintf("%s %s %d %d %s %s %t", formatScriptPath, layout.FormatBinaryPath,
usagePercent, DEFAULT_CHUNKFILE_SIZE, layout.ChunkfilePoolDir, layout.ChunkfilePoolMetaPath, increment)
debug := curveadm.MemStorage().Get(comm.DEBUG_MODE).(bool)

// 1: skip if formating container exist
Expand Down Expand Up @@ -279,10 +280,12 @@ func NewFormatChunkfilePoolTask(curveadm *cli.CurveAdm, fc *configure.FormatConf
Paths: []string{mountPoint},
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.CreateFilesystem{ // mkfs.ext4 MOUNT_POINT
Device: device,
ExecOptions: curveadm.ExecOptions(),
})
if !increment {
t.AddStep(&step.CreateFilesystem{ // mkfs.ext4 MOUNT_POINT
Device: device,
ExecOptions: curveadm.ExecOptions(),
})
}
t.AddStep(&step.MountFilesystem{
Source: device,
Directory: mountPoint,
Expand Down
6 changes: 6 additions & 0 deletions internal/tui/common/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ func PromptCollectService() string {
return prompt.Build()
}

func PromptIncrementFormat() string {
prompt := NewPrompt(color.YellowString(PROMPT_WARNING) + DEFAULT_CONFIRM_PROMPT)
prompt.data["warning"] = "WARNING: increment format will stop chunkserver service"
return prompt.Build()
}

func prettyClue(clue string) string {
items := strings.Split(clue, "\n")
for {
Expand Down