From dcbc22552f0dcfa3075982eabeda44b0a28fd428 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 17 Jun 2021 14:27:14 +0300 Subject: [PATCH] lib/storage: fix infinite loop introduced in aa9b56a046b6ae8083fa659df35dd5e994bf9115 --- lib/storage/partition.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/storage/partition.go b/lib/storage/partition.go index 11d62c980..3b6213d9c 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -485,14 +485,11 @@ func (rrs *rawRowsShard) addRows(pt *partition, rows []rawRow) { rrs.rows = make([]rawRow, 0, n) } maxRowsCount := cap(rrs.rows) - for { - capacity := maxRowsCount - len(rrs.rows) - if capacity >= len(rows) { - // Fast path - rows fit capacity. - rrs.rows = append(rrs.rows, rows...) - break - } - + capacity := maxRowsCount - len(rrs.rows) + if capacity >= len(rows) { + // Fast path - rows fit capacity. + rrs.rows = append(rrs.rows, rows...) + } else { // Slow path - rows don't fit capacity. // Put rrs.rows and rows to rowsToFlush and convert it to a part. rowsToFlush = append(rowsToFlush, rrs.rows...)