From d43738a49b189f62c1a07ba5e3e9a9e3b817a364 Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Wed, 27 Mar 2024 10:12:42 -0700 Subject: [PATCH] server/storage: address golangci var-naming issues Signed-off-by: Ivan Valdes --- etcdutl/etcdutl/migrate_command.go | 2 +- etcdutl/etcdutl/snapshot_command.go | 2 +- server/config/config.go | 2 +- server/etcdserver/bootstrap.go | 2 +- server/etcdserver/bootstrap_test.go | 2 +- server/etcdserver/raft_test.go | 2 +- server/storage/datadir/datadir.go | 8 ++++++++ server/storage/datadir/datadir_test.go | 8 ++++---- server/storage/util.go | 13 +++++++++++-- server/verify/verify.go | 2 +- 10 files changed, 30 insertions(+), 13 deletions(-) diff --git a/etcdutl/etcdutl/migrate_command.go b/etcdutl/etcdutl/migrate_command.go index 521cf8ba80c..154ba466a35 100644 --- a/etcdutl/etcdutl/migrate_command.go +++ b/etcdutl/etcdutl/migrate_command.go @@ -94,7 +94,7 @@ func (o *migrateOptions) Config() (*migrateConfig, error) { dbPath := datadir.ToBackendFileName(o.dataDir) c.be = backend.NewDefaultBackend(GetLogger(), dbPath) - walPath := datadir.ToWalDir(o.dataDir) + walPath := datadir.ToWALDir(o.dataDir) w, err := wal.OpenForRead(c.lg, walPath, walpb.Snapshot{}) if err != nil { return nil, fmt.Errorf(`failed to open wal: %v`, err) diff --git a/etcdutl/etcdutl/snapshot_command.go b/etcdutl/etcdutl/snapshot_command.go index eeffb93bbd8..8fa89fba02a 100644 --- a/etcdutl/etcdutl/snapshot_command.go +++ b/etcdutl/etcdutl/snapshot_command.go @@ -138,7 +138,7 @@ func SnapshotRestoreCommandFunc(restoreCluster string, walDir := restoreWalDir if walDir == "" { - walDir = datadir.ToWalDir(dataDir) + walDir = datadir.ToWALDir(dataDir) } lg := GetLogger() diff --git a/server/config/config.go b/server/config/config.go index af8604a621a..14e8fa3df98 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -307,7 +307,7 @@ func (c *ServerConfig) WALDir() string { if c.DedicatedWALDir != "" { return c.DedicatedWALDir } - return datadir.ToWalDir(c.DataDir) + return datadir.ToWALDir(c.DataDir) } func (c *ServerConfig) SnapDir() string { return filepath.Join(c.MemberDir(), "snap") } diff --git a/server/etcdserver/bootstrap.go b/server/etcdserver/bootstrap.go index 7a0c09cc2f9..e4dd7ec4a52 100644 --- a/server/etcdserver/bootstrap.go +++ b/server/etcdserver/bootstrap.go @@ -694,7 +694,7 @@ func (wal *bootstrappedWAL) CommitedEntries() []raftpb.Entry { func (wal *bootstrappedWAL) NewConfigChangeEntries() []raftpb.Entry { return serverstorage.CreateConfigChangeEnts( wal.lg, - serverstorage.GetEffectiveNodeIDsFromWalEntries(wal.lg, wal.snapshot, wal.ents), + serverstorage.GetEffectiveNodeIDsFromWALEntries(wal.lg, wal.snapshot, wal.ents), uint64(wal.meta.nodeID), wal.st.Term, wal.st.Commit, diff --git a/server/etcdserver/bootstrap_test.go b/server/etcdserver/bootstrap_test.go index 724a1df6a0d..83d28e3a1fa 100644 --- a/server/etcdserver/bootstrap_test.go +++ b/server/etcdserver/bootstrap_test.go @@ -230,7 +230,7 @@ func createDataDir(t *testing.T) (string, error) { } // create ${dataDir}/member/wal - err = os.MkdirAll(datadir.ToWalDir(dataDir), 0700) + err = os.MkdirAll(datadir.ToWALDir(dataDir), 0700) if err != nil { return "", err } diff --git a/server/etcdserver/raft_test.go b/server/etcdserver/raft_test.go index 7845d24baa4..cce1ac872b1 100644 --- a/server/etcdserver/raft_test.go +++ b/server/etcdserver/raft_test.go @@ -69,7 +69,7 @@ func TestGetIDs(t *testing.T) { if tt.confState != nil { snap.Metadata.ConfState = *tt.confState } - idSet := serverstorage.GetEffectiveNodeIDsFromWalEntries(lg, &snap, tt.ents) + idSet := serverstorage.GetEffectiveNodeIDsFromWALEntries(lg, &snap, tt.ents) if !reflect.DeepEqual(idSet, tt.widSet) { t.Errorf("#%d: idset = %#v, want %#v", i, idSet, tt.widSet) } diff --git a/server/storage/datadir/datadir.go b/server/storage/datadir/datadir.go index fa4c51ad1a2..6749bd398c6 100644 --- a/server/storage/datadir/datadir.go +++ b/server/storage/datadir/datadir.go @@ -31,7 +31,15 @@ func ToSnapDir(dataDir string) string { return filepath.Join(ToMemberDir(dataDir), snapDirSegment) } +// ToWalDir returns the directory path for the member's WAL. +// Deprecated: use ToWALDir instead. +// +//revive:disable-next-line:var-naming func ToWalDir(dataDir string) string { + return ToWALDir(dataDir) +} + +func ToWALDir(dataDir string) string { return filepath.Join(ToMemberDir(dataDir), walDirSegment) } diff --git a/server/storage/datadir/datadir_test.go b/server/storage/datadir/datadir_test.go index 03e14758799..5b8abeeb6f6 100644 --- a/server/storage/datadir/datadir_test.go +++ b/server/storage/datadir/datadir_test.go @@ -37,12 +37,12 @@ func TestToSnapDir(t *testing.T) { assert.Equal(t, "/dir/data-dir/member/snap", result) } -func TestToWalDir(t *testing.T) { - result := datadir.ToWalDir("/dir/data-dir") +func TestToWALDir(t *testing.T) { + result := datadir.ToWALDir("/dir/data-dir") assert.Equal(t, "/dir/data-dir/member/wal", result) } -func TestToWalDirSlash(t *testing.T) { - result := datadir.ToWalDir("/dir/data-dir/") +func TestToWALDirSlash(t *testing.T) { + result := datadir.ToWALDir("/dir/data-dir/") assert.Equal(t, "/dir/data-dir/member/wal", result) } diff --git a/server/storage/util.go b/server/storage/util.go index e1996cfe581..6e104ccbf58 100644 --- a/server/storage/util.go +++ b/server/storage/util.go @@ -109,13 +109,22 @@ func CreateConfigChangeEnts(lg *zap.Logger, ids []uint64, self uint64, term, ind return ents } -// GetEffectiveNodeIDsFromWalEntries returns an ordered set of IDs included in the given snapshot and +// GetEffectiveNodeIdsFromWalEntries returns an ordered set of IDs included in the given snapshot and +// the entries. +// Deprecated: use GetEffectiveNodeIDsFromWALEntries instead. +// +//revive:disable-next-line:var-naming +func GetEffectiveNodeIdsFromWalEntries(lg *zap.Logger, snap *raftpb.Snapshot, ents []raftpb.Entry) []uint64 { + return GetEffectiveNodeIDsFromWALEntries(lg, snap, ents) +} + +// GetEffectiveNodeIDsFromWALEntries returns an ordered set of IDs included in the given snapshot and // the entries. The given snapshot/entries can contain three kinds of // ID-related entry: // - ConfChangeAddNode, in which case the contained ID will Be added into the set. // - ConfChangeRemoveNode, in which case the contained ID will Be removed from the set. // - ConfChangeAddLearnerNode, in which the contained ID will Be added into the set. -func GetEffectiveNodeIDsFromWalEntries(lg *zap.Logger, snap *raftpb.Snapshot, ents []raftpb.Entry) []uint64 { +func GetEffectiveNodeIDsFromWALEntries(lg *zap.Logger, snap *raftpb.Snapshot, ents []raftpb.Entry) []uint64 { ids := make(map[uint64]bool) if snap != nil { for _, id := range snap.Metadata.ConfState.Voters { diff --git a/server/verify/verify.go b/server/verify/verify.go index 5fce8b28a07..0dc99afc819 100644 --- a/server/verify/verify.go +++ b/server/verify/verify.go @@ -132,7 +132,7 @@ func validateConsistentIndex(cfg Config, hardstate *raftpb.HardState, snapshot * } func validateWAL(cfg Config) (*walpb.Snapshot, *raftpb.HardState, error) { - walDir := datadir.ToWalDir(cfg.DataDir) + walDir := datadir.ToWALDir(cfg.DataDir) walSnaps, err := wal2.ValidSnapshotEntries(cfg.Logger, walDir) if err != nil {