mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
Merge pull request #1660 from molecula/client-batch-race
Fix data race in batch import client by adding locking around rowCache
This commit is contained in:
commit
e450099579
1 changed files with 5 additions and 0 deletions
|
|
@ -15,6 +15,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/molecula/featurebase/v2/client/egpool"
|
||||
|
|
@ -916,6 +917,8 @@ func (b *Batch) doTranslation() error {
|
|||
rowCache = make(map[string]agedTranslation)
|
||||
b.rowTranslations[fieldName] = rowCache
|
||||
}
|
||||
// create a lock since we're updating this concurrently below
|
||||
rowCacheLock := &sync.Mutex{}
|
||||
|
||||
fieldName, tt := fieldName, tt
|
||||
eg.Go(func() error {
|
||||
|
|
@ -934,12 +937,14 @@ func (b *Batch) doTranslation() error {
|
|||
b.log.Debugf("translating %d field keys for %s took %v", len(trans), fieldName, time.Since(start))
|
||||
|
||||
// Apply keys to translation cache.
|
||||
rowCacheLock.Lock()
|
||||
for key, id := range trans {
|
||||
rowCache[key] = agedTranslation{
|
||||
id: id,
|
||||
lastUsed: b.cycle,
|
||||
}
|
||||
}
|
||||
rowCacheLock.Unlock()
|
||||
|
||||
// Fill out missing IDs in local batch records with translated IDs.
|
||||
rowIDSets := b.rowIDSets[fieldName]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue