Add PutMany, currently only for bbolt and hashmap storage backends

This commit is contained in:
Daniel 2020-04-09 14:22:22 +02:00
parent 35ab2be6a0
commit e0f96d5188
10 changed files with 246 additions and 12 deletions

View file

@ -52,6 +52,33 @@ func (hm *HashMap) Put(r record.Record) error {
return nil
}
// PutMany stores many records in the database.
func (hm *HashMap) PutMany() (batch chan record.Record, err chan error) {
hm.dbLock.Lock()
defer hm.dbLock.Unlock()
// we could lock for every record, but we want to have the same behaviour
// as the other storage backends, especially for testing.
batch = make(chan record.Record, 100)
err = make(chan error, 1)
// start handler
go func() {
for {
r := <-batch
// finished?
if r == nil {
err <- nil
return
}
// put
hm.db[r.DatabaseKey()] = r
}
}()
return
}
// Delete deletes a record from the database.
func (hm *HashMap) Delete(key string) error {
hm.dbLock.Lock()