From fe518fdb28659dbfaf8c151e16c6414324b28325 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Fri, 13 Feb 2015 12:12:07 +0100 Subject: [PATCH] Simplify AppendSamples by allowing it to be goroutine-unsafe. --- storage/local/interface.go | 4 ++-- storage/local/storage.go | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/storage/local/interface.go b/storage/local/interface.go index c351ab36b8..bdfa5698d3 100644 --- a/storage/local/interface.go +++ b/storage/local/interface.go @@ -24,7 +24,7 @@ import ( ) // Storage ingests and manages samples, along with various indexes. All methods -// are goroutine-safe. +// except AppendSamples are goroutine-safe. type Storage interface { prometheus.Collector // AppendSamples stores a group of new samples. Multiple samples for the @@ -32,7 +32,7 @@ type Storage interface { // oldest to newest (both in the same call to AppendSamples and across // multiple calls). When AppendSamples has returned, the appended // samples might not be queryable immediately. (Use WaitForIndexing to - // wait for complete processing.) + // wait for complete processing.) This method is not goroutine-safe. AppendSamples(clientmodel.Samples) // NewPreloader returns a new Preloader which allows preloading and pinning // series data into memory for use within a query. diff --git a/storage/local/storage.go b/storage/local/storage.go index a3821e718c..93da63e403 100644 --- a/storage/local/storage.go +++ b/storage/local/storage.go @@ -73,7 +73,6 @@ type memorySeriesStorage struct { lastTimestampAppended clientmodel.Timestamp // Wait group for goroutines appending samples with the same timestamp. appendWaitGroup sync.WaitGroup - appendMtx sync.Mutex persistQueue chan persistRequest persistStopped chan struct{} @@ -371,13 +370,6 @@ func (s *memorySeriesStorage) GetMetricForFingerprint(fp clientmodel.Fingerprint // AppendSamples implements Storage. func (s *memorySeriesStorage) AppendSamples(samples clientmodel.Samples) { - if len(samples) == 0 { - return - } - - s.appendMtx.Lock() - defer s.appendMtx.Unlock() - for _, sample := range samples { if sample.Timestamp != s.lastTimestampAppended { // Timestamp has changed. We have to wait for all @@ -392,7 +384,6 @@ func (s *memorySeriesStorage) AppendSamples(samples clientmodel.Samples) { s.appendWaitGroup.Done() }(sample) } - } func (s *memorySeriesStorage) appendSample(sample *clientmodel.Sample) {