Merge pull request #284 from prometheus/refactor/storage/notify-when-available
Ensure database access waits until it is started.
This commit is contained in:
commit
52a1e50dda
5
main.go
5
main.go
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue