Skip to content

Commit 9d1f319

Browse files
committed
sstable: fix i.synthetic.atSyntheticKey check in Next
we should check if key is synthetic before invalidation check
1 parent fd959dd commit 9d1f319

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

sstable/reader_iter_single_lvl.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,17 +1344,6 @@ func (i *singleLevelIterator[I, PI, D, PD]) lastInternal() *base.InternalKV {
13441344
// Note: compactionIterator.Next mirrors the implementation of Iterator.Next
13451345
// due to performance. Keep the two in sync.
13461346
func (i *singleLevelIterator[I, PI, D, PD]) Next() *base.InternalKV {
1347-
if invariants.Enabled && i.lastOpWasSeekPrefixGE.Get() {
1348-
// If the previous operation was SeekPrefixGE that returned nil due to bloom
1349-
// filter miss, the data block should not have been invalidated. This assertion
1350-
// ensures the optimization to preserve loaded blocks is working correctly.
1351-
if PD(&i.data).IsDataInvalidated() {
1352-
panic("pebble: data block was invalidated after SeekPrefixGE returned nil due to bloom filter miss")
1353-
}
1354-
}
1355-
// Clear the tracking flag since this is no longer the next operation after SeekPrefixGE
1356-
i.lastOpWasSeekPrefixGE.Set(false)
1357-
13581347
// The SeekPrefixGE might have returned a synthetic key with latest suffix
13591348
// contained in the sstable. If the caller is calling Next(), that means
13601349
// they want to move past the synthetic key and Next() is responsible for
@@ -1366,6 +1355,17 @@ func (i *singleLevelIterator[I, PI, D, PD]) Next() *base.InternalKV {
13661355
return i.seekPrefixGE(i.reader.Comparer.Split.Prefix(i.synthetic.seekKey), i.synthetic.seekKey, base.SeekGEFlagsNone)
13671356
}
13681357

1358+
if invariants.Enabled && i.lastOpWasSeekPrefixGE.Get() {
1359+
// If the previous operation was SeekPrefixGE that returned nil due to bloom
1360+
// filter miss, the data block should not have been invalidated. This assertion
1361+
// ensures the optimization to preserve loaded blocks is working correctly.
1362+
if PD(&i.data).IsDataInvalidated() {
1363+
panic("pebble: data block was invalidated after SeekPrefixGE returned nil due to bloom filter miss")
1364+
}
1365+
}
1366+
// Clear the tracking flag since this is no longer the next operation after SeekPrefixGE
1367+
i.lastOpWasSeekPrefixGE.Set(false)
1368+
13691369
if i.exhaustedBounds == +1 {
13701370
panic("Next called even though exhausted upper bound")
13711371
}

sstable/reader_iter_two_lvl.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -916,16 +916,6 @@ func (i *twoLevelIterator[I, PI, D, PD]) Last() *base.InternalKV {
916916
// Note: twoLevelCompactionIterator.Next mirrors the implementation of
917917
// twoLevelIterator.Next due to performance. Keep the two in sync.
918918
func (i *twoLevelIterator[I, PI, D, PD]) Next() *base.InternalKV {
919-
if invariants.Enabled && i.lastOpWasSeekPrefixGE.Get() {
920-
// If the previous operation was SeekPrefixGE that returned nil due to bloom
921-
// filter miss, the data block should not have been invalidated. This assertion
922-
// ensures the optimization to preserve loaded blocks is working correctly.
923-
if PD(&i.secondLevel.data).IsDataInvalidated() {
924-
panic("pebble: data block was invalidated after SeekPrefixGE returned nil due to bloom filter miss")
925-
}
926-
}
927-
i.lastOpWasSeekPrefixGE.Set(false)
928-
929919
// The SeekPrefixGE might have returned a synthetic key with latest suffix
930920
// contained in the sstable. If the caller is calling Next(), that means
931921
// they want to move past the synthetic key and Next() is responsible for
@@ -939,6 +929,16 @@ func (i *twoLevelIterator[I, PI, D, PD]) Next() *base.InternalKV {
939929
i.secondLevel.synthetic.seekKey, base.SeekGEFlagsNone)
940930
}
941931

932+
if invariants.Enabled && i.lastOpWasSeekPrefixGE.Get() {
933+
// If the previous operation was SeekPrefixGE that returned nil due to bloom
934+
// filter miss, the data block should not have been invalidated. This assertion
935+
// ensures the optimization to preserve loaded blocks is working correctly.
936+
if PD(&i.secondLevel.data).IsDataInvalidated() {
937+
panic("pebble: data block was invalidated after SeekPrefixGE returned nil due to bloom filter miss")
938+
}
939+
}
940+
i.lastOpWasSeekPrefixGE.Set(false)
941+
942942
// Seek optimization only applies until iterator is first positioned after SetBounds.
943943
i.secondLevel.boundsCmp = 0
944944
if i.secondLevel.err != nil {

0 commit comments

Comments
 (0)