simplify locking in importValue

may be a slight perf cost, but the simplicity is well worth it
This commit is contained in:
Matt Jaffee 2019-03-25 14:27:05 -05:00
parent 4420d72196
commit 714f89c65c
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF

View file

@ -1733,12 +1733,15 @@ func (f *fragment) bulkImportMutex(rowIDs, columnIDs []uint64) error {
// importValue bulk imports a set of range-encoded values.
func (f *fragment) importValue(columnIDs, values []uint64, bitDepth uint, clear bool) error {
f.mu.Lock()
defer f.mu.Unlock()
// Verify that there are an equal number of column ids and values.
if len(columnIDs) != len(values) {
return fmt.Errorf("mismatch of column/value len: %d != %d", len(columnIDs), len(values))
}
var toSet, toClear []uint64
f.mu.RLock()
smallWrite := false
if len(columnIDs)*int(bitDepth+1)+f.opN < f.MaxOpN {
smallWrite = true
@ -1751,14 +1754,11 @@ func (f *fragment) importValue(columnIDs, values []uint64, bitDepth uint, clear
toSet = make([]uint64, 0, len(columnIDs)*int(bitDepth+1)*(5/8))
toClear = make([]uint64, 0, len(columnIDs)*int(bitDepth+1)*(5/8))
}
f.mu.RUnlock()
if !smallWrite {
f.mu.Lock()
defer f.mu.Unlock()
f.storage.OpWriter = nil
}
// Process every value.
// If an error occurs then reopen the storage.
if err := func() (err error) {
@ -1785,9 +1785,7 @@ func (f *fragment) importValue(columnIDs, values []uint64, bitDepth uint, clear
for i := uint(0); i < bitDepth+1; i++ {
rowSet[uint64(i)] = struct{}{}
}
f.mu.Lock()
err := f.importPositions(toSet, toClear, rowSet)
f.mu.Unlock()
return errors.Wrap(err, "importing positions")
}
err := f.snapshot()