lib/storage: verify whether items are sorted in the end of call to mergeTagToMetricIDsRows

This should prevent from inverted index corruption if bug in mergeTagToMetricIDsRows is discovered.
This commit is contained in:
Aliaksandr Valialkin 2019-09-26 13:12:24 +03:00
parent cf4786f34a
commit c39355921e

View file

@ -2284,9 +2284,23 @@ func mergeTagToMetricIDsRows(data []byte, items [][]byte) ([]byte, [][]byte) {
dstData, dstItems = tmm.flushPendingMetricIDs(dstData, dstItems, mpPrev)
}
putTagToMetricIDsRowsMerger(tmm)
assertItemsSorted(dstItems)
return dstData, dstItems
}
func assertItemsSorted(items [][]byte) {
if len(items) == 0 {
return
}
prevItem := items[0]
for _, currItem := range items[1:] {
if string(prevItem) > string(currItem) {
logger.Panicf("BUG: items aren't sorted: prevItem > currItem\nprevItem=%X\ncurrItem=%X\nitems=%X", prevItem, currItem, items)
}
prevItem = currItem
}
}
// maxMetricIDsPerRow limits the number of metricIDs in tag->metricIDs row.
//
// This reduces overhead on index and metaindex in lib/mergeset.