Cluster *arvados.Cluster
setupOnce sync.Once
- lockMtx sync.Mutex
- lock map[string]*sync.RWMutex
+ lockMtx sync.Mutex
+ lock map[string]*sync.RWMutex
+ lockTidied time.Time
}
var urlPDHDecoder = strings.NewReplacer(" ", "+", "-", "+")
func (h *handler) collectionLock(collectionID string, writing bool) sync.Locker {
h.lockMtx.Lock()
defer h.lockMtx.Unlock()
+ if time.Since(h.lockTidied) > lockTidyInterval {
+ // Periodically delete all locks that aren't in use.
+ h.lockTidied = time.Now()
+ for id, locker := range h.lock {
+ if locker.TryLock() {
+ locker.Unlock()
+ delete(h.lock, id)
+ }
+ }
+ }
locker := h.lock[collectionID]
if locker == nil {
locker = new(sync.RWMutex)
}
func (s *IntegrationSuite) TestConcurrentWrites(c *check.C) {
+ lockTidyInterval = time.Second
client := arvados.NewClientFromEnv()
client.AuthToken = arvadostest.ActiveTokenV2
// Start small, and increase concurrency (2^2, 4^2, ...)