Skip to content

Commit

Permalink
try setting writeset concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
udpatil committed Nov 16, 2023
1 parent 4876150 commit 10a0106
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions store/multiversion/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,24 @@ func (s *Store) SetWriteset(index int, incarnation int, writeset WriteSet) {
s.removeOldWriteset(index, writeset)

writeSetKeys := make([]string, 0, len(writeset))
wg := sync.WaitGroup{}
for key, value := range writeset {
writeSetKeys = append(writeSetKeys, key)
loadVal, _ := s.multiVersionMap.LoadOrStore(key, NewMultiVersionItem()) // init if necessary
mvVal := loadVal.(MultiVersionValue)
if value == nil {
// delete if nil value
// TODO: sync map
mvVal.Delete(index, incarnation)
} else {
mvVal.Set(index, incarnation, value)
}
wg.Add(1)
go func(k string, v []byte) {
defer wg.Done()
loadVal, _ := s.multiVersionMap.LoadOrStore(k, NewMultiVersionItem()) // init if necessary
mvVal := loadVal.(MultiVersionValue)
if v == nil {
// delete if nil value
// TODO: sync map
mvVal.Delete(index, incarnation)
} else {
mvVal.Set(index, incarnation, v)
}
}(key, value)
}
wg.Wait()
sort.Strings(writeSetKeys) // TODO: if we're sorting here anyways, maybe we just put it into a btree instead of a slice
s.txWritesetKeys.Store(index, writeSetKeys)
}
Expand Down

0 comments on commit 10a0106

Please sign in to comment.