Merge pull request #284 from prometheus/refactor/storage/notify-when-available

Ensure database access waits until it is started.
This commit is contained in:
Matt T. Proud 2013-06-06 02:33:27 -07:00
commit 52a1e50dda
4 changed files with 14 additions and 5 deletions

View File

@ -266,7 +266,10 @@ func main() {
} }
defer prometheus.close() defer prometheus.close()
go ts.Serve() storageStarted := make(chan bool)
go ts.Serve(storageStarted)
<-storageStarted
go prometheus.interruptHandler() go prometheus.interruptHandler()
go prometheus.reportDatabaseState() go prometheus.reportDatabaseState()

View File

@ -79,8 +79,9 @@ func NewTestTieredStorage(t test.Tester) (storage *metric.TieredStorage, closer
directory.Close() directory.Close()
t.Fatalf("storage == nil") t.Fatalf("storage == nil")
} }
started := make(chan bool)
go storage.Serve() go storage.Serve(started)
<-started
closer = &testTieredStorageCloser{ closer = &testTieredStorageCloser{
storage: storage, storage: storage,
directory: directory, directory: directory,

View File

@ -101,7 +101,10 @@ func NewTestTieredStorage(t test.Tester) (storage *TieredStorage, closer test.Cl
t.Fatalf("storage == nil") t.Fatalf("storage == nil")
} }
go storage.Serve() started := make(chan bool)
go storage.Serve(started)
<-started
closer = &testTieredStorageCloser{ closer = &testTieredStorageCloser{
storage: storage, storage: storage,
directory: directory, directory: directory,

View File

@ -156,7 +156,7 @@ func (t *TieredStorage) MakeView(builder ViewRequestBuilder, deadline time.Durat
} }
// Starts serving requests. // Starts serving requests.
func (t *TieredStorage) Serve() { func (t *TieredStorage) Serve(started chan<- bool) {
flushMemoryTicker := time.NewTicker(t.flushMemoryInterval) flushMemoryTicker := time.NewTicker(t.flushMemoryInterval)
defer flushMemoryTicker.Stop() defer flushMemoryTicker.Stop()
queueReportTicker := time.NewTicker(time.Second) queueReportTicker := time.NewTicker(time.Second)
@ -168,6 +168,8 @@ func (t *TieredStorage) Serve() {
} }
}() }()
started <- true
for { for {
select { select {
case <-flushMemoryTicker.C: case <-flushMemoryTicker.C: