Skip to content

Commit

Permalink
cluster: refine log_dir handling on clean (part 1) (#981)
Browse files Browse the repository at this point in the history
* cluster: make experimental features more visiblely marked

* cluster: not deleting anythin if data dir is under log dir

Co-authored-by: Ti Prow Robot <[email protected]>
  • Loading branch information
AstroProfundis and ti-chi-bot authored Dec 14, 2020
1 parent 01bf92c commit 32d6f10
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
7 changes: 5 additions & 2 deletions components/cluster/command/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ func newCleanCmd() *cobra.Command {

cmd := &cobra.Command{
Use: "clean <cluster-name>",
Short: "Cleanup a specified cluster",
Long: `Cleanup a specified cluster without destroying it (experimental).
Short: "(EXPERIMENTAL) Cleanup a specified cluster",
Long: `EXPERIMENTAL: This is an experimental feature, things may or may not work,
please backup your data before process.
Cleanup a specified cluster without destroying it.
You can retain some nodes and roles data when cleanup the cluster, eg:
$ tiup cluster clean <cluster-name> --all
$ tiup cluster clean <cluster-name> --log
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func newDeploy() *cobra.Command {
}

cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
cmd.Flags().BoolVarP(&opt.SkipCreateUser, "skip-create-user", "", false, "Skip creating the user specified in topology (experimental).")
cmd.Flags().BoolVarP(&opt.SkipCreateUser, "skip-create-user", "", false, "(EXPERIMENTAL) Skip creating the user specified in topology.")
cmd.Flags().StringVarP(&opt.IdentityFile, "identity_file", "i", opt.IdentityFile, "The path of the SSH identity file. If specified, public key authentication will be used.")
cmd.Flags().BoolVarP(&opt.UsePassword, "password", "p", false, "Use password of target hosts. If specified, password authentication will be used.")
cmd.Flags().BoolVarP(&opt.IgnoreConfigCheck, "ignore-config-check", "", opt.IgnoreConfigCheck, "Ignore the config check result")
Expand Down
4 changes: 2 additions & 2 deletions components/cluster/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func init() {
// start/stop operations is 90s, the default value of this argument is better be longer than that
rootCmd.PersistentFlags().Uint64Var(&gOpt.OptTimeout, "wait-timeout", 120, "Timeout in seconds to wait for an operation to complete, ignored for operations that don't fit.")
rootCmd.PersistentFlags().BoolVarP(&skipConfirm, "yes", "y", false, "Skip all confirmations and assumes 'yes'")
rootCmd.PersistentFlags().BoolVar(&gOpt.NativeSSH, "native-ssh", gOpt.NativeSSH, "Use the native SSH client installed on local system instead of the build-in one (experimental).")
rootCmd.PersistentFlags().StringVar((*string)(&gOpt.SSHType), "ssh", "", "(experimental) The executor type: 'builtin', 'system', 'none'.")
rootCmd.PersistentFlags().BoolVar(&gOpt.NativeSSH, "native-ssh", gOpt.NativeSSH, "(EXPERIMENTAL) Use the native SSH client installed on local system instead of the build-in one.")
rootCmd.PersistentFlags().StringVar((*string)(&gOpt.SSHType), "ssh", "", "(EXPERIMENTAL) The executor type: 'builtin', 'system', 'none'.")
_ = rootCmd.PersistentFlags().MarkHidden("native-ssh")

rootCmd.AddCommand(
Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func newScaleOutCmd() *cobra.Command {
}

cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
cmd.Flags().BoolVarP(&opt.SkipCreateUser, "skip-create-user", "", false, "Skip creating the user specified in topology (experimental).")
cmd.Flags().BoolVarP(&opt.SkipCreateUser, "skip-create-user", "", false, "(EXPERIMENTAL) Skip creating the user specified in topology.")
cmd.Flags().StringVarP(&opt.IdentityFile, "identity_file", "i", opt.IdentityFile, "The path of the SSH identity file. If specified, public key authentication will be used.")
cmd.Flags().BoolVarP(&opt.UsePassword, "password", "p", false, "Use password of target hosts. If specified, password authentication will be used.")
cmd.Flags().BoolVarP(&opt.NoLabels, "no-labels", "", false, "Don't check TiKV labels")
Expand Down
6 changes: 4 additions & 2 deletions components/dm/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ func init() {
}

rootCmd = &cobra.Command{
Use: cliutil.OsArgs0(),
Short: "Deploy a DM cluster (experimental)",
Use: cliutil.OsArgs0(),
Short: "(EXPERIMENTAL) Deploy a DM cluster",
Long: `EXPERIMENTAL: This is an experimental feature, things may or may not work,
please backup your data before process.`,
SilenceUsage: true,
SilenceErrors: true,
Version: version.NewTiUPVersion().String(),
Expand Down
8 changes: 6 additions & 2 deletions pkg/cluster/operation/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,23 @@ func CleanupComponent(getter ExecutorGetter, instances []spec.Instance, cls spec
log.Infof("Cleanup instance %s", ins.GetHost())

delFiles := set.NewStringSet()
dataPaths := set.NewStringSet()
logPaths := set.NewStringSet()

if options.CleanupData && len(ins.DataDir()) > 0 {
for _, dataDir := range strings.Split(ins.DataDir(), ",") {
delFiles.Insert(path.Join(dataDir, "*"))
dataPaths.Insert(path.Join(dataDir, "*"))
}
}

if options.CleanupLog && len(ins.LogDir()) > 0 {
for _, logDir := range strings.Split(ins.LogDir(), ",") {
delFiles.Insert(path.Join(logDir, "*"))
logPaths.Insert(path.Join(logDir, "*.log"))
}
}

delFiles.Join(logPaths).Join(dataPaths)

log.Debugf("Deleting paths on %s: %s", ins.GetHost(), strings.Join(delFiles.Slice(), " "))
c := module.ShellModuleConfig{
Command: fmt.Sprintf("rm -rf %s;", strings.Join(delFiles.Slice(), " ")),
Expand Down
8 changes: 8 additions & 0 deletions pkg/set/string_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func (s StringSet) Insert(val string) {
s[val] = struct{}{}
}

// Join add all elements of `add` to `s`.
func (s StringSet) Join(add StringSet) StringSet {
for elt := range add {
s.Insert(elt)
}
return s
}

// Intersection returns the intersection of two sets
func (s StringSet) Intersection(rhs StringSet) StringSet {
newSet := NewStringSet()
Expand Down

0 comments on commit 32d6f10

Please sign in to comment.