Skip to content

Commit

Permalink
Merge pull request #17660 from ivanvc/address-server-storage-var-nami…
Browse files Browse the repository at this point in the history
…ng-lint-rule

server/storage: address golangci var-naming issues
  • Loading branch information
serathius authored Mar 29, 2024
2 parents 76f21a1 + d43738a commit a25497e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion etcdutl/etcdutl/migrate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion etcdutl/etcdutl/snapshot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func SnapshotRestoreCommandFunc(restoreCluster string,

walDir := restoreWalDir
if walDir == "" {
walDir = datadir.ToWalDir(dataDir)
walDir = datadir.ToWALDir(dataDir)
}

lg := GetLogger()
Expand Down
2 changes: 1 addition & 1 deletion server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions server/storage/datadir/datadir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions server/storage/datadir/datadir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 11 additions & 2 deletions server/storage/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a25497e

Please sign in to comment.