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 2b8358726f
commit 95e3d648cb

View file

@ -2355,9 +2355,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.