mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-12 07:41:02 +00:00
Merge pull request #42 from seebs/sqdeadlock
use the right lock for Enqueue
This commit is contained in:
commit
16c3cfa727
1 changed files with 7 additions and 6 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/pilosa/pilosa/v2/logger"
|
||||
|
|
@ -108,8 +109,8 @@ type prioritySnapshotQueue struct {
|
|||
mu sync.RWMutex
|
||||
scanWG, workerWG sync.WaitGroup
|
||||
stats struct {
|
||||
enqueued int64
|
||||
skipped int64
|
||||
enqueued uint64
|
||||
skipped uint64
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,8 +201,8 @@ func (sq *prioritySnapshotQueue) Enqueue(f *fragment) {
|
|||
if f.snapshotPending {
|
||||
return
|
||||
}
|
||||
sq.mu.Lock()
|
||||
defer sq.mu.Unlock()
|
||||
sq.mu.RLock()
|
||||
defer sq.mu.RUnlock()
|
||||
if sq.normal == nil {
|
||||
sq.logger.Printf("requested snapshot after snapshot queue was closed")
|
||||
return
|
||||
|
|
@ -214,10 +215,10 @@ func (sq *prioritySnapshotQueue) Enqueue(f *fragment) {
|
|||
// try to enqueue snapshot
|
||||
select {
|
||||
case sq.normal <- snapshotRequest{frag: f, when: time.Now()}:
|
||||
sq.stats.enqueued++
|
||||
atomic.AddUint64(&sq.stats.enqueued, 1)
|
||||
return
|
||||
default:
|
||||
sq.stats.skipped++
|
||||
atomic.AddUint64(&sq.stats.skipped, 1)
|
||||
f.snapshotPending = false
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue