@ -553,7 +553,7 @@ func validateOpts(opts *Options, rngs []int64) (*Options, []int64) {
return opts , rngs
return opts , rngs
}
}
func open ( dir string , l log . Logger , r prometheus . Registerer , opts * Options , rngs [ ] int64 ) ( db * DB , err error ) {
func open ( dir string , l log . Logger , r prometheus . Registerer , opts * Options , rngs [ ] int64 ) ( db * DB , r eturnedE rr error ) {
if err := os . MkdirAll ( dir , 0777 ) ; err != nil {
if err := os . MkdirAll ( dir , 0777 ) ; err != nil {
return nil , err
return nil , err
}
}
@ -595,6 +595,19 @@ func open(dir string, l log.Logger, r prometheus.Registerer, opts *Options, rngs
chunkPool : chunkenc . NewPool ( ) ,
chunkPool : chunkenc . NewPool ( ) ,
blocksToDelete : opts . BlocksToDelete ,
blocksToDelete : opts . BlocksToDelete ,
}
}
defer func ( ) {
// Close files if startup fails somewhere.
if returnedErr == nil {
return
}
var merr tsdb_errors . MultiError
merr . Add ( returnedErr )
merr . Add ( errors . Wrap ( db . Close ( ) , "close DB after failed startup" ) )
returnedErr = merr . Err ( )
} ( )
if db . blocksToDelete == nil {
if db . blocksToDelete == nil {
db . blocksToDelete = DefaultBlocksToDelete ( db )
db . blocksToDelete = DefaultBlocksToDelete ( db )
}
}
@ -612,10 +625,10 @@ func open(dir string, l log.Logger, r prometheus.Registerer, opts *Options, rngs
}
}
ctx , cancel := context . WithCancel ( context . Background ( ) )
ctx , cancel := context . WithCancel ( context . Background ( ) )
db . compactor , err = NewLeveledCompactor ( ctx , r , l , rngs , db . chunkPool )
db . compactor , r eturnedE rr = NewLeveledCompactor ( ctx , r , l , rngs , db . chunkPool )
if err != nil {
if r eturnedE rr != nil {
cancel ( )
cancel ( )
return nil , errors . Wrap ( err , "create leveled compactor" )
return nil , errors . Wrap ( r eturnedE rr, "create leveled compactor" )
}
}
db . compactCancel = cancel
db . compactCancel = cancel
@ -627,15 +640,15 @@ func open(dir string, l log.Logger, r prometheus.Registerer, opts *Options, rngs
if opts . WALSegmentSize > 0 {
if opts . WALSegmentSize > 0 {
segmentSize = opts . WALSegmentSize
segmentSize = opts . WALSegmentSize
}
}
wlog , err = wal . NewSize ( l , r , walDir , segmentSize , opts . WALCompression )
wlog , r eturnedE rr = wal . NewSize ( l , r , walDir , segmentSize , opts . WALCompression )
if err != nil {
if r eturnedE rr != nil {
return nil , err
return nil , r eturnedE rr
}
}
}
}
db . head , err = NewHead ( r , l , wlog , rngs [ 0 ] , dir , db . chunkPool , opts . StripeSize , opts . SeriesLifecycleCallback )
db . head , r eturnedE rr = NewHead ( r , l , wlog , rngs [ 0 ] , dir , db . chunkPool , opts . StripeSize , opts . SeriesLifecycleCallback )
if err != nil {
if r eturnedE rr != nil {
return nil , err
return nil , r eturnedE rr
}
}
// Register metrics after assigning the head block.
// Register metrics after assigning the head block.
@ -1333,7 +1346,9 @@ func (db *DB) Close() error {
if db . lockf != nil {
if db . lockf != nil {
merr . Add ( db . lockf . Release ( ) )
merr . Add ( db . lockf . Release ( ) )
}
}
if db . head != nil {
merr . Add ( db . head . Close ( ) )
merr . Add ( db . head . Close ( ) )
}
return merr . Err ( )
return merr . Err ( )
}
}