test: fix DiskSizeBytes flakiness (#22639)

pull/22650/head
Sam Arnold 2021-10-08 09:46:58 -04:00 committed by GitHub
parent 708e808d00
commit 2ecbb68fc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View File

@ -20,7 +20,7 @@ func (i *Index) LogDiskSize(t *testing.T) {
// Get MANIFEST sizes from each partition.
for count, p := range i.partitions {
sz := p.manifestSize
t.Logf("Parition %d has size %d", count, sz)
t.Logf("Partition %d has size %d", count, sz)
size += sz
}
for _, f := range fs.files {

View File

@ -226,7 +226,7 @@ func TestIndex_Open(t *testing.T) {
for i := 0; i < int(idx.PartitionN); i++ {
p := idx.PartitionAt(i)
if got, exp := p.NeedsCompaction(), false; got != exp {
if got, exp := p.NeedsCompaction(false), false; got != exp {
t.Fatalf("got needs compaction %v, expected %v", got, exp)
}
}
@ -594,7 +594,7 @@ func (idx *Index) RunStateAware(t *testing.T, fn func(t *testing.T, state int))
for {
needsCompaction := false
for i := 0; i < int(idx.PartitionN); i++ {
needsCompaction = needsCompaction || idx.PartitionAt(i).NeedsCompaction()
needsCompaction = needsCompaction || idx.PartitionAt(i).NeedsCompaction(false)
}
if !needsCompaction {
break

View File

@ -912,7 +912,7 @@ func (p *Partition) runPeriodicCompaction() {
case <-closing:
return
case <-t.C:
if p.NeedsCompaction() {
if p.NeedsCompaction(true) {
p.Compact()
}
}
@ -920,8 +920,11 @@ func (p *Partition) runPeriodicCompaction() {
}
// NeedsCompaction only requires a read lock and checks if there are files that could be compacted.
// If compact is updated we should also update NeedsCompaction.
func (p *Partition) NeedsCompaction() bool {
//
// If compact() is updated we should also update needsCompaction
// If checkRunning = true, only count as needing a compaction if there is not a compaction already
// in progress for the level that would be compacted
func (p *Partition) NeedsCompaction(checkRunning bool) bool {
p.mu.RLock()
defer p.mu.RUnlock()
if p.needsLogCompaction() {
@ -933,7 +936,7 @@ func (p *Partition) NeedsCompaction() bool {
for _, f := range p.fileSet.files {
level := f.Level()
levelCount[level]++
if level <= maxLevel && levelCount[level] > 1 && !p.levelCompacting[level] {
if level <= maxLevel && levelCount[level] > 1 && !(checkRunning && p.levelCompacting[level]) {
return true
}
}