mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-19 04:24:28 +02:00
filer: avoid possible timeouts for updates and deletions
This commit is contained in:
1 parent
45156cc2fe
commit
621cdbdf58
4 files changed
+95
-27
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package util
|
||||
|
||||
import "sync"
|
||||
|
||||
type UnboundedQueue struct {
|
||||
outbound []string
|
||||
outboundLock sync.RWMutex
|
||||
inbound []string
|
||||
inboundLock sync.RWMutex
|
||||
}
|
||||
|
||||
func NewUnboundedQueue() *UnboundedQueue {
|
||||
q := &UnboundedQueue{}
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *UnboundedQueue) EnQueue(items ...string) {
|
||||
q.inboundLock.Lock()
|
||||
defer q.inboundLock.Unlock()
|
||||
|
||||
q.outbound = append(q.outbound, items...)
|
||||
|
||||
}
|
||||
|
||||
func (q *UnboundedQueue) Consume(fn func([]string)) {
|
||||
q.outboundLock.Lock()
|
||||
defer q.outboundLock.Unlock()
|
||||
|
||||
if len(q.outbound) == 0 {
|
||||
q.inboundLock.Lock()
|
||||
inbountLen := len(q.inbound)
|
||||
if inbountLen > 0 {
|
||||
t := q.outbound
|
||||
q.outbound = q.inbound
|
||||
q.inbound = t
|
||||
}
|
||||
q.inboundLock.Unlock()
|
||||
}
|
||||
|
||||
if len(q.outbound) > 0 {
|
||||
fn(q.outbound)
|
||||
q.outbound = q.outbound[:0]
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user