mirror of
https://github.com/safing/portbase
synced 2025-09-02 02:29:59 +00:00
Fix locking in runtime and hashmap storage
This commit is contained in:
parent
75ab99d681
commit
19f75bb6ca
2 changed files with 14 additions and 22 deletions
|
@ -104,17 +104,16 @@ func (hm *HashMap) queryExecutor(queryIter *iterator.Iterator, q *query.Query, l
|
||||||
|
|
||||||
mapLoop:
|
mapLoop:
|
||||||
for key, record := range hm.db {
|
for key, record := range hm.db {
|
||||||
|
record.Lock()
|
||||||
|
if !q.MatchesKey(key) ||
|
||||||
|
!q.MatchesRecord(record) ||
|
||||||
|
!record.Meta().CheckValidity() ||
|
||||||
|
!record.Meta().CheckPermission(local, internal) {
|
||||||
|
|
||||||
switch {
|
record.Unlock()
|
||||||
case !q.MatchesKey(key):
|
|
||||||
continue
|
|
||||||
case !q.MatchesRecord(record):
|
|
||||||
continue
|
|
||||||
case !record.Meta().CheckValidity():
|
|
||||||
continue
|
|
||||||
case !record.Meta().CheckPermission(local, internal):
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
record.Unlock()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-queryIter.Done:
|
case <-queryIter.Done:
|
||||||
|
|
|
@ -202,23 +202,16 @@ func (r *Registry) Query(q *query.Query, local, internal bool) (*iterator.Iterat
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range records {
|
for _, r := range records {
|
||||||
// TODO(ppacher): do we need to lock r?
|
r.Lock()
|
||||||
// storage/hashmap does not lock the records
|
if q.MatchesKey(r.DatabaseKey()) ||
|
||||||
// before sending them to the iterator but
|
!r.Meta().CheckValidity() ||
|
||||||
// better make sure that's correct.
|
!r.Meta().CheckPermission(local, internal) ||
|
||||||
|
!q.MatchesRecord(r) {
|
||||||
|
|
||||||
if !strings.HasPrefix(r.DatabaseKey(), searchPrefix) {
|
r.Unlock()
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !r.Meta().CheckValidity() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !r.Meta().CheckPermission(local, internal) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !q.MatchesRecord(r) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
r.Unlock()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case iter.Next <- r:
|
case iter.Next <- r:
|
||||||
|
|
Loading…
Add table
Reference in a new issue