Skip to content

Commit

Permalink
when scanning store files, find old partial files with a traceID and …
Browse files Browse the repository at this point in the history
…delete them on sight (they are leftovers, possibly slowing down next runs)
  • Loading branch information
sduchesneau committed Mar 22, 2024
1 parent ad0c197 commit 8336074
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
7 changes: 7 additions & 0 deletions storage/store/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ func (c *Config) ListSnapshotFiles(ctx context.Context, below uint64) (files []*
return nil
}

if fileInfo.WithTraceID {
if err := c.objStore.DeleteObject(ctx, filename); err != nil { // clean up all old files with traceID in them, they will only slow every next run
logger.Warn("cannot delete old partial file with trace_id", zap.String("filename", filename), zap.Error(err))
}
return nil
}

if fileInfo.Range.StartBlock >= below {
return dstore.StopIteration
}
Expand Down
18 changes: 10 additions & 8 deletions storage/store/filename.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ func (f FileInfos) String() string {
}

type FileInfo struct {
ModuleName string
Filename string
Range *block.Range
Partial bool
ModuleName string
Filename string
Range *block.Range
Partial bool
WithTraceID bool
}

func NewCompleteFileInfo(moduleName string, moduleInitialBlock uint64, exclusiveEndBlock uint64) *FileInfo {
Expand Down Expand Up @@ -70,10 +71,11 @@ func parseFileName(moduleName, filename string) (*FileInfo, bool) {
}

return &FileInfo{
ModuleName: moduleName,
Filename: filename,
Range: block.NewRange(uint64(mustAtoi(res[0][2])), uint64(mustAtoi(res[0][1]))),
Partial: res[0][4] == "partial",
ModuleName: moduleName,
Filename: filename,
Range: block.NewRange(uint64(mustAtoi(res[0][2])), uint64(mustAtoi(res[0][1]))),
Partial: res[0][4] == "partial",
WithTraceID: res[0][3] != "",
}, true
}

Expand Down
6 changes: 6 additions & 0 deletions storage/store/filename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func Test_parseFileName(t *testing.T) {
&FileInfo{ModuleName: "test", Filename: "0000000100-0000000000.kv", Range: block.NewRange(0, 100), Partial: false},
true,
},
{
"old-partial-with-trace-id",
fmt.Sprintf("%010d-%010d.deadbeefdeadbeefdeadbeefdeadbeef.partial", 100, 0),
&FileInfo{ModuleName: "test", Filename: "0000000100-0000000000.deadbeefdeadbeefdeadbeefdeadbeef.partial", Range: block.NewRange(0, 100), Partial: true, WithTraceID: true},
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 8336074

Please sign in to comment.