Skip to content

Commit

Permalink
refactor: remove redundant FindLogStream function
Browse files Browse the repository at this point in the history
The FindLogStream function in proto/snpb/metadata.go was removed as it was
redundant and no longer needed. The functionality is already covered by the
GetLogStream method.
  • Loading branch information
ijsong committed Nov 23, 2024
1 parent 099dbf1 commit a0af1e1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ func (adm *Admin) hasSealedReplica(ctx context.Context, lsdesc *varlogpb.LogStre
continue
}

lsmeta, ok := meta.FindLogStream(lsdesc.LogStreamID)
lsmeta, ok := meta.GetLogStream(lsdesc.LogStreamID)
if !ok {
continue
}
Expand Down
9 changes: 0 additions & 9 deletions proto/snpb/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ func (snmd *StorageNodeMetadataDescriptor) GetLogStream(logStreamID types.LogStr
return LogStreamReplicaMetadataDescriptor{}, false
}

func (snmd StorageNodeMetadataDescriptor) FindLogStream(logStreamID types.LogStreamID) (LogStreamReplicaMetadataDescriptor, bool) {
for _, lsmeta := range snmd.GetLogStreamReplicas() {
if lsmeta.GetLogStreamID() == logStreamID {
return lsmeta, true
}
}
return LogStreamReplicaMetadataDescriptor{}, false
}

func (lsrmd *LogStreamReplicaMetadataDescriptor) Head() varlogpb.LogEntryMeta {
if lsrmd == nil {
return varlogpb.LogEntryMeta{}
Expand Down
9 changes: 4 additions & 5 deletions tests/it/management/management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func TestSyncLogStream(t *testing.T) {
if err != nil {
return false
}
lsmd, exist := snmd.FindLogStream(lsID)
lsmd, exist := snmd.GetLogStream(lsID)
if !exist {
return false
}
Expand Down Expand Up @@ -544,7 +544,6 @@ func TestSyncLogStreamWithAutoUnseal(t *testing.T) {
assert.True(t, ok)
return lsrmd.LocalHighWatermark.GLSN == types.GLSN(numLogs) &&
lsrmd.Status == varlogpb.LogStreamStatusRunning

}, 5*time.Second, 100*time.Millisecond)
}

Expand Down Expand Up @@ -706,23 +705,23 @@ func TestGCZombieLogStream(t *testing.T) {
meta, err = snMCL.GetMetadata(context.TODO())
So(err, ShouldBeNil)

_, exist := meta.FindLogStream(lsID)
_, exist := meta.GetLogStream(lsID)
So(exist, ShouldBeTrue)

Convey("Then the LogStream should removed after GCTimeout", func(ctx C) {
time.Sleep(gcTimeout / 2)
meta, err := snMCL.GetMetadata(context.TODO())
So(err, ShouldBeNil)

_, exist := meta.FindLogStream(lsID)
_, exist := meta.GetLogStream(lsID)
So(exist, ShouldBeTrue)

So(testutil.CompareWait(func() bool {
meta, err := snMCL.GetMetadata(context.TODO())
if err != nil {
return false
}
_, exist := meta.FindLogStream(lsID)
_, exist := meta.GetLogStream(lsID)
return !exist
}, gcTimeout), ShouldBeTrue)
})
Expand Down

0 comments on commit a0af1e1

Please sign in to comment.