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