Mark --snapshot-count as deprecated in v3.6 and will be decommissioned in v3.7

Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
This commit is contained in:
Benjamin Wang
2024-12-03 13:25:31 +00:00
parent b0387393a2
commit 8bc42d9075
4 changed files with 42 additions and 2 deletions

View File

@ -158,6 +158,8 @@ type Config struct {
//revive:disable-next-line:var-naming //revive:disable-next-line:var-naming
WalDir string `json:"wal-dir"` WalDir string `json:"wal-dir"`
// SnapshotCount is deprecated in v3.6 and will be decommissioned in v3.7.
// TODO: remove it in 3.7.
SnapshotCount uint64 `json:"snapshot-count"` SnapshotCount uint64 `json:"snapshot-count"`
// SnapshotCatchUpEntries is the number of entries for a slow follower // SnapshotCatchUpEntries is the number of entries for a slow follower
@ -616,7 +618,7 @@ func (cfg *Config) AddFlags(fs *flag.FlagSet) {
fs.UintVar(&cfg.MaxSnapFiles, "max-snapshots", cfg.MaxSnapFiles, "Maximum number of snapshot files to retain (0 is unlimited).") fs.UintVar(&cfg.MaxSnapFiles, "max-snapshots", cfg.MaxSnapFiles, "Maximum number of snapshot files to retain (0 is unlimited).")
fs.UintVar(&cfg.MaxWalFiles, "max-wals", cfg.MaxWalFiles, "Maximum number of wal files to retain (0 is unlimited).") fs.UintVar(&cfg.MaxWalFiles, "max-wals", cfg.MaxWalFiles, "Maximum number of wal files to retain (0 is unlimited).")
fs.StringVar(&cfg.Name, "name", cfg.Name, "Human-readable name for this member.") fs.StringVar(&cfg.Name, "name", cfg.Name, "Human-readable name for this member.")
fs.Uint64Var(&cfg.SnapshotCount, "snapshot-count", cfg.SnapshotCount, "Number of committed transactions to trigger a snapshot to disk.") fs.Uint64Var(&cfg.SnapshotCount, "snapshot-count", cfg.SnapshotCount, "Number of committed transactions to trigger a snapshot to disk. Deprecated in v3.6 and will be decommissioned in v3.7.")
fs.UintVar(&cfg.TickMs, "heartbeat-interval", cfg.TickMs, "Time (in milliseconds) of a heartbeat interval.") fs.UintVar(&cfg.TickMs, "heartbeat-interval", cfg.TickMs, "Time (in milliseconds) of a heartbeat interval.")
fs.UintVar(&cfg.ElectionMs, "election-timeout", cfg.ElectionMs, "Time (in milliseconds) for an election to timeout.") fs.UintVar(&cfg.ElectionMs, "election-timeout", cfg.ElectionMs, "Time (in milliseconds) for an election to timeout.")
fs.BoolVar(&cfg.InitialElectionTickAdvance, "initial-election-tick-advance", cfg.InitialElectionTickAdvance, "Whether to fast-forward initial election ticks on boot for faster election.") fs.BoolVar(&cfg.InitialElectionTickAdvance, "initial-election-tick-advance", cfg.InitialElectionTickAdvance, "Whether to fast-forward initial election ticks on boot for faster election.")

View File

@ -56,6 +56,11 @@ var (
"test.coverprofile", "test.coverprofile",
"test.outputdir", "test.outputdir",
} }
deprecatedFlags = map[string]string{
// TODO: remove in 3.7.
"snapshot-count": "--snapshot-count is deprecated in 3.6 and will be decommissioned in 3.7.",
}
) )
// config holds the config for a command line invocation of etcd // config holds the config for a command line invocation of etcd
@ -165,6 +170,20 @@ func (cfg *config) parse(arguments []string) error {
return perr return perr
} }
var warningsForDeprecatedFlags []string
cfg.cf.flagSet.Visit(func(f *flag.Flag) {
if msg, ok := deprecatedFlags[f.Name]; ok {
warningsForDeprecatedFlags = append(warningsForDeprecatedFlags, msg)
}
})
if len(warningsForDeprecatedFlags) > 0 {
if lg := cfg.ec.GetLogger(); lg != nil {
for _, msg := range warningsForDeprecatedFlags {
lg.Warn(msg)
}
}
}
// now logger is set up // now logger is set up
return err return err
} }

View File

@ -58,7 +58,7 @@ Member:
--wal-dir '' --wal-dir ''
Path to the dedicated wal directory. Path to the dedicated wal directory.
--snapshot-count '10000' --snapshot-count '10000'
Number of committed transactions to trigger a snapshot to disk. Number of committed transactions to trigger a snapshot to disk. Deprecated in v3.6 and will be decommissioned in v3.7.
--heartbeat-interval '100' --heartbeat-interval '100'
Time (in milliseconds) of a heartbeat interval. Time (in milliseconds) of a heartbeat interval.
--election-timeout '1000' --election-timeout '1000'

View File

@ -661,3 +661,22 @@ func TestEtcdTLSVersion(t *testing.T) {
proc.Wait() // ensure the port has been released proc.Wait() // ensure the port has been released
proc.Close() proc.Close()
} }
// TestEtcdDeprecatedFlags checks that etcd will print warning messages if deprecated flags are set.
func TestEtcdDeprecatedFlags(t *testing.T) {
e2e.SkipInShortMode(t)
proc, err := e2e.SpawnCmd(
[]string{
e2e.BinPath.Etcd,
"--name", "e1",
"--snapshot-count=100",
}, nil,
)
require.NoError(t, err)
require.NoError(t, e2e.WaitReadyExpectProc(context.TODO(), proc, []string{"--snapshot-count is deprecated in 3.6 and will be decommissioned in 3.7"}))
require.NoError(t, proc.Stop())
proc.Wait() // ensure the port has been released
proc.Close()
}