From 1c5163ae51b1eae921b39644d0d2e8ef3d26f562 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 23 Jan 2024 12:56:19 +0200 Subject: [PATCH] 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 --- lib/mergeset/merge.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/mergeset/merge.go b/lib/mergeset/merge.go index 3f443c2f7..df8a7fcd6 100644 --- a/lib/mergeset/merge.go +++ b/lib/mergeset/merge.go @@ -129,8 +129,8 @@ again: if bsr.currItemIdx < len(items) { // 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 - lastItem := items[len(items)-1].Bytes(data) - compareEveryItem = hasNextItem && string(lastItem) > nextItem + lastItem := items[len(items)-1].String(data) + compareEveryItem = hasNextItem && lastItem > nextItem } for bsr.currItemIdx < len(items) { item := items[bsr.currItemIdx].Bytes(data) @@ -183,12 +183,12 @@ func (bsm *blockStreamMerger) flushIB(bsw *blockStreamWriter, ph *partHeader, it } // Consistency checks after prepareBlock call. firstItem := items[0].String(data) - 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) + if firstItem < string(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) - 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) + if lastItem > string(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 // can be expensive check in prod for items with long common prefix.