lib/storage: move common code to newRawRowsBlock() function

This commit is contained in:
Aliaksandr Valialkin 2022-10-21 14:46:06 +03:00
parent b5674164c6
commit 4128ad71e2
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1

View File

@ -473,8 +473,7 @@ func (rrs *rawRowsShard) addRows(pt *partition, rows []rawRow) {
rrs.mu.Lock()
if cap(rrs.rows) == 0 {
n := getMaxRawRowsPerShard()
rrs.rows = make([]rawRow, 0, n)
rrs.rows = newRawRowsBlock()
}
n := copy(rrs.rows[len(rrs.rows):cap(rrs.rows)], rows)
rrs.rows = rrs.rows[:len(rrs.rows)+n]
@ -484,8 +483,7 @@ func (rrs *rawRowsShard) addRows(pt *partition, rows []rawRow) {
// Convert rrs.rows to rowsToFlush and convert it to a part,
// then try moving the remaining rows to rrs.rows.
rowsToFlush = rrs.rows
n = getMaxRawRowsPerShard()
rrs.rows = make([]rawRow, 0, n)
rrs.rows = newRawRowsBlock()
if len(rows) <= n {
rrs.rows = append(rrs.rows[:0], rows...)
} else {
@ -500,6 +498,11 @@ func (rrs *rawRowsShard) addRows(pt *partition, rows []rawRow) {
pt.flushRowsToParts(rowsToFlush)
}
func newRawRowsBlock() []rawRow {
n := getMaxRawRowsPerShard()
return make([]rawRow, 0, n)
}
func (pt *partition) flushRowsToParts(rows []rawRow) {
maxRows := getMaxRawRowsPerShard()
wg := getWaitGroup()