lib/mergeset: make sure that the first and the last items are in the original range after prepareBlock()

Previously the checks were to strict by requiring to leave the same first and last items by prepareBlock()

Thanks to @ahfuzhang for the suggestion at https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5655
This commit is contained in:
Aliaksandr Valialkin 2024-01-23 12:56:19 +02:00
parent 7b1325c3a3
commit c2927053ee
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB

View File

@ -129,8 +129,8 @@ again:
if bsr.currItemIdx < len(items) { if bsr.currItemIdx < len(items) {
// An optimization, which allows skipping costly comparison for every merged item in the loop below. // An optimization, which allows skipping costly comparison for every merged item in the loop below.
// Thanks to @ahfuzhang for the suggestion at https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5651 // Thanks to @ahfuzhang for the suggestion at https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5651
lastItem := items[len(items)-1].Bytes(data) lastItem := items[len(items)-1].String(data)
compareEveryItem = hasNextItem && string(lastItem) > nextItem compareEveryItem = hasNextItem && lastItem > nextItem
} }
for bsr.currItemIdx < len(items) { for bsr.currItemIdx < len(items) {
item := items[bsr.currItemIdx].Bytes(data) item := items[bsr.currItemIdx].Bytes(data)
@ -183,12 +183,12 @@ func (bsm *blockStreamMerger) flushIB(bsw *blockStreamWriter, ph *partHeader, it
} }
// Consistency checks after prepareBlock call. // Consistency checks after prepareBlock call.
firstItem := items[0].String(data) firstItem := items[0].String(data)
if firstItem != string(bsm.firstItem) { if firstItem < string(bsm.firstItem) {
logger.Panicf("BUG: prepareBlock must return first item equal to the original first item;\ngot\n%X\nwant\n%X", firstItem, bsm.firstItem) logger.Panicf("BUG: prepareBlock must return the first item bigger or equal to the original first item;\ngot\n%X\nwant\n%X", firstItem, bsm.firstItem)
} }
lastItem := items[len(items)-1].String(data) lastItem := items[len(items)-1].String(data)
if lastItem != string(bsm.lastItem) { if lastItem > string(bsm.lastItem) {
logger.Panicf("BUG: prepareBlock must return last item equal to the original last item;\ngot\n%X\nwant\n%X", lastItem, bsm.lastItem) logger.Panicf("BUG: prepareBlock must return the last item smaller or equal to the original last item;\ngot\n%X\nwant\n%X", lastItem, bsm.lastItem)
} }
// Verify whether the bsm.ib.items are sorted only in tests, since this // Verify whether the bsm.ib.items are sorted only in tests, since this
// can be expensive check in prod for items with long common prefix. // can be expensive check in prod for items with long common prefix.