Fix locking in runtime and hashmap storage

This commit is contained in:
Patrick Pacher 2020-09-18 12:11:05 +02:00
parent 75ab99d681
commit 19f75bb6ca
No known key found for this signature in database
GPG key ID: E8CD2DA160925A6D
2 changed files with 14 additions and 22 deletions

View file

@ -104,17 +104,16 @@ func (hm *HashMap) queryExecutor(queryIter *iterator.Iterator, q *query.Query, l
mapLoop:
for key, record := range hm.db {
record.Lock()
if !q.MatchesKey(key) ||
!q.MatchesRecord(record) ||
!record.Meta().CheckValidity() ||
!record.Meta().CheckPermission(local, internal) {
switch {
case !q.MatchesKey(key):
continue
case !q.MatchesRecord(record):
continue
case !record.Meta().CheckValidity():
continue
case !record.Meta().CheckPermission(local, internal):
record.Unlock()
continue
}
record.Unlock()
select {
case <-queryIter.Done:

View file

@ -202,23 +202,16 @@ func (r *Registry) Query(q *query.Query, local, internal bool) (*iterator.Iterat
}
for _, r := range records {
// TODO(ppacher): do we need to lock r?
// storage/hashmap does not lock the records
// before sending them to the iterator but
// better make sure that's correct.
r.Lock()
if q.MatchesKey(r.DatabaseKey()) ||
!r.Meta().CheckValidity() ||
!r.Meta().CheckPermission(local, internal) ||
!q.MatchesRecord(r) {
if !strings.HasPrefix(r.DatabaseKey(), searchPrefix) {
continue
}
if !r.Meta().CheckValidity() {
continue
}
if !r.Meta().CheckPermission(local, internal) {
continue
}
if !q.MatchesRecord(r) {
r.Unlock()
continue
}
r.Unlock()
select {
case iter.Next <- r: