@@ -465,59 +465,57 @@ func (i *Ingester) closeAllTSDB() {
465
465
// openExistingTSDB walks the user tsdb dir, and opens a tsdb for each user. This may start a WAL replay, so we limit the number of
466
466
// concurrently opening TSDB.
467
467
func (i * Ingester ) openExistingTSDB (ctx context.Context ) error {
468
+ level .Info (util .Logger ).Log ("msg" , "opening existing TSDBs" )
468
469
wg := & sync.WaitGroup {}
469
- openGate := gate .New (i .cfg .TSDBConfig .MaxOpeningTSDBOnStartup )
470
+ openGate := gate .New (i .cfg .TSDBConfig .MaxTSDBOpeningConcurrencyOnStartup )
470
471
471
472
err := filepath .Walk (i .cfg .TSDBConfig .Dir , func (path string , info os.FileInfo , err error ) error {
472
- if path == i .cfg .TSDBConfig .Dir { // Nothing to do for root
473
+
474
+ // Skip root dir and all other files
475
+ if path == i .cfg .TSDBConfig .Dir || ! info .IsDir () {
473
476
return nil
474
477
}
475
478
476
479
// Top level directories are assumed to be user TSDBs
477
- if info .IsDir () {
480
+ userID := info .Name ()
481
+ f , err := os .Open (path )
482
+ if err != nil {
483
+ level .Error (util .Logger ).Log ("msg" , "unable to open user TSDB dir" , "err" , err , "user" , userID , "path" , path )
484
+ return filepath .SkipDir
485
+ }
486
+ defer f .Close ()
478
487
479
- userID := info . Name ()
480
- f , err := os . Open ( path )
481
- if err != nil {
482
- level .Error (util .Logger ).Log ("msg" , "unable to open user TSDB dir" , "err" , err , "user" , userID )
488
+ // If the dir is empty skip it
489
+ if _ , err := f . Readdirnames ( 1 ); err != nil {
490
+ if err != io . EOF {
491
+ level .Error (util .Logger ).Log ("msg" , "unable to read TSDB dir" , "err" , err , "user" , userID , "path" , path )
483
492
return filepath .SkipDir
484
493
}
485
- defer f .Close ()
486
494
487
- // If the dir is empty skip it
488
- if _ , err := f .Readdirnames (1 ); err != nil {
489
- if err != io .EOF {
490
- level .Error (util .Logger ).Log ("msg" , "unable to read TSDB dir" , "err" , err , "user" , userID )
491
- return filepath .SkipDir
492
- }
495
+ // Empty dir
496
+ return filepath .SkipDir
497
+ }
493
498
494
- // Empty dir
495
- return filepath .SkipDir
496
- }
499
+ // Limit the number of TSDB's opening concurrently. Start blocks until there's a free spot available or the context is cancelled.
500
+ if err := openGate .Start (ctx ); err != nil {
501
+ return err
502
+ }
497
503
498
- // Limit the number of TSDB's opening concurrently
499
- if err := openGate .Start (ctx ); err != nil {
500
- return err
504
+ wg .Add (1 )
505
+ go func (userID string ) {
506
+ defer wg .Done ()
507
+ defer openGate .Done ()
508
+ _ , err := i .getOrCreateTSDB (userID , true ) // force create the TSDB due to the lifecycler not having started yet
509
+ if err != nil {
510
+ level .Error (util .Logger ).Log ("msg" , "unable to open user TSDB" , "err" , err , "user" , userID )
501
511
}
512
+ }(userID )
502
513
503
- wg .Add (1 )
504
- go func (userID string ) {
505
- defer wg .Done ()
506
- defer openGate .Done ()
507
- _ , err := i .getOrCreateTSDB (userID , true ) // force create the TSDB due to the lifecycler not having started yet
508
- if err != nil {
509
- level .Error (util .Logger ).Log ("msg" , "unable to open user TSDB" , "err" , err , "user" , userID )
510
- }
511
- }(userID )
512
-
513
- return filepath .SkipDir // Don't descend into directories
514
- }
515
-
516
- // Skip all other files
517
- return nil
514
+ return filepath .SkipDir // Don't descend into directories
518
515
})
519
516
520
517
// Wait for all opening routines to finish
521
518
wg .Wait ()
519
+ level .Info (util .Logger ).Log ("msg" , "completed opening existing TSDBs" )
522
520
return err
523
521
}
0 commit comments