prometheus/storage/metric
Julius Volz 1b29975865 Fix RWLock memory storage deadlock.
This fixes https://github.com/prometheus/prometheus/issues/390

The cause for the deadlock was a lock semantic in Go that wasn't
obvious to me when introducing this bug:

http://golang.org/pkg/sync/#RWMutex.Lock

Key phrase: "To ensure that the lock eventually becomes available, a
blocked Lock call excludes new readers from acquiring the lock."

In the memory series storage, we have one function
(GetFingerprintsForLabelMatchers) acquiring an RLock(), which calls
another function also acquiring the same RLock()
(GetLabelValuesForLabelName). That normally doesn't deadlock, unless a
Lock() call from another goroutine happens right in between the two
RLock() calls, blocking both the Lock() and the second RLock() call from
ever completing.

  GoRoutine 1          GoRoutine 2
  ======================================
  RLock()
  ...                  Lock() [DEADLOCK]
  RLock() [DEADLOCK]   Unlock()
  RUnlock()
  RUnlock()

Testing deadlocks is tricky, but the regression test I added does
reliably detect the deadlock in the original code on my machine within a
normal concurrent reader/writer run duration of 250ms.

Change-Id: Ib34c2bb8df1a80af44550cc2bf5007055cdef413
2014-04-17 13:43:13 +02:00
..
tiered Fix RWLock memory storage deadlock. 2014-04-17 13:43:13 +02:00
interface.go Separate storage implementation from interfaces. 2014-04-16 13:30:19 +02:00
labelpair.go Major code cleanup in storage. 2014-02-27 15:22:37 +01:00
labelpair_test.go WIP - Snapshot of Moving to Client Model. 2013-06-25 15:52:42 +02:00
matcher.go Separate storage implementation from interfaces. 2014-04-16 13:30:19 +02:00
sample.go Separate storage implementation from interfaces. 2014-04-16 13:30:19 +02:00