maintain column set in bulkImportMutex to guard against repeats

This commit is contained in:
Matt Jaffee 2019-02-28 14:01:53 -06:00
parent 4082ce655a
commit 9b8a97ccb6
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 13 additions and 6 deletions

View file

@ -1640,12 +1640,15 @@ func (f *fragment) bulkImportMutex(rowIDs, columnIDs []uint64) error {
defer f.mu.Unlock()
rowSet := make(map[uint64]struct{})
// we have to maintain which columns are getting bits set as a map so that
// we don't end up setting multiple bits in the same column if a column is
// repeated within the import.
colSet := make(map[uint64]uint64) // row to column
// Since each imported bit will at most set one bit and clear one bit, we
// can reuse the rowIDs and columnIDs slices as the set and clear slice
// arguments to importPositions. We maintain indexes into them as we loop
// through them since the indexes of set and cleared bits may lag behind the
// current index.
setIdx := 0
clearIdx := 0
for i := range rowIDs {
rowID, columnID := rowIDs[i], columnIDs[i]
@ -1668,11 +1671,15 @@ func (f *fragment) bulkImportMutex(rowIDs, columnIDs []uint64) error {
if err != nil {
return err
}
rowIDs[setIdx] = pos
setIdx++
colSet[columnID] = pos
rowSet[rowID] = struct{}{}
}
toSet := rowIDs[:setIdx]
i := 0
for _, pos := range colSet {
rowIDs[i] = pos
i++
}
toSet := rowIDs[:i]
toClear := columnIDs[:clearIdx]
return errors.Wrap(f.importPositions(toSet, toClear, rowSet), "importing positions")

View file

@ -1700,7 +1700,7 @@ func TestFragment_ImportMutex(t *testing.T) {
for k, v := range test.setExp {
cols := f.row(k).Columns()
if !reflect.DeepEqual(cols, v) {
t.Fatalf("expected: %v, but got: %v", v, cols)
t.Fatalf("row: %d, expected: %v, but got: %v", k, v, cols)
}
}
@ -1714,7 +1714,7 @@ func TestFragment_ImportMutex(t *testing.T) {
for k, v := range test.clearExp {
cols := f.row(k).Columns()
if !reflect.DeepEqual(cols, v) {
t.Fatalf("expected: %v, but got: %v", v, cols)
t.Fatalf("row: %d expected: %v, but got: %v", k, v, cols)
}
}
})