mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
mq: start a new compaction group only after the current one has a file
A first log file larger than the group size left an empty first group, and naming a parquet file after its group's first log then indexed past the end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
05c99a5907
commit
6df93de83b
2 files changed
+20
-1
No files matched your search
@@ -142,7 +142,7 @@ func groupFilesBySize(logFiles []*filer_pb.Entry, maxGroupSize int64) (logFileGr
|
||||
var logFileGroup []*filer_pb.Entry
|
||||
var groupSize int64
|
||||
for _, logFile := range logFiles {
|
||||
if groupSize+int64(logFile.Attributes.FileSize) > maxGroupSize {
|
||||
if len(logFileGroup) > 0 && groupSize+int64(logFile.Attributes.FileSize) > maxGroupSize {
|
||||
logFileGroups = append(logFileGroups, logFileGroup)
|
||||
logFileGroup = nil
|
||||
groupSize = 0
|
||||
|
||||
@@ -57,3 +57,22 @@ func TestCompactionSelectsWindowsBySourceName(t *testing.T) {
|
||||
t.Fatalf("selected %v, want only the window not yet compacted", names)
|
||||
}
|
||||
}
|
||||
|
||||
// A log file larger than a group starts its own group instead of leaving an empty one.
|
||||
func TestGroupFilesBySizeLeavesNoEmptyGroup(t *testing.T) {
|
||||
file := func(name string, size uint64) *filer_pb.Entry {
|
||||
return &filer_pb.Entry{Name: name, Attributes: &filer_pb.FuseAttributes{FileSize: size}}
|
||||
}
|
||||
groups := groupFilesBySize([]*filer_pb.Entry{file("a", 300), file("b", 50), file("c", 60), file("d", 400)}, 100)
|
||||
var names [][]string
|
||||
for _, group := range groups {
|
||||
var groupNames []string
|
||||
for _, f := range group {
|
||||
groupNames = append(groupNames, f.Name)
|
||||
}
|
||||
names = append(names, groupNames)
|
||||
}
|
||||
if len(names) != 4 || len(names[0]) != 1 || names[0][0] != "a" || len(names[1]) != 1 || names[1][0] != "b" || names[2][0] != "c" || names[3][0] != "d" {
|
||||
t.Errorf("groups %v", names)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user