Ensure database access waits until it is started.

This commit introduces a channel message to ensure serving
state has been reached with the storage stack before anything attempts
to use it.
pull/284/head
Matt T. Proud 12 years ago
parent 115437ad1f
commit 2c3df44af6

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

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

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

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

Loading…
Cancel
Save