-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tsdb): Adds shard opening progress checks to startup
This PR adds a check to see how many shards are remaining vs how many shards are opened as well as the percentage. closes influxdata/feature-requests#476
- Loading branch information
Showing
5 changed files
with
401 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package run | ||
|
||
import ( | ||
"fmt" | ||
"sync/atomic" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
type StartupProgressLogger struct { | ||
shardsCompleted atomic.Uint64 | ||
shardsTotal atomic.Uint64 | ||
logger *zap.Logger | ||
} | ||
|
||
func NewStartupProgressLogger(logger *zap.Logger) *StartupProgressLogger { | ||
return &StartupProgressLogger{ | ||
logger: logger, | ||
} | ||
} | ||
|
||
func (s *StartupProgressLogger) AddShard() { | ||
s.shardsTotal.Add(1) | ||
} | ||
|
||
func (s *StartupProgressLogger) RemoveShardFromCount() { | ||
if s.shardsTotal.Load() > 0 { | ||
old, newUint := s.shardsTotal.Load(), s.shardsTotal.Load()-1 | ||
s.shardsTotal.CompareAndSwap(old, newUint) | ||
} | ||
} | ||
|
||
func (s *StartupProgressLogger) CompletedShard() { | ||
shardsCompleted := s.shardsCompleted.Add(1) | ||
totalShards := s.shardsTotal.Load() | ||
|
||
percentShards := float64(shardsCompleted) / float64(totalShards) * 100 | ||
s.logger.Info(fmt.Sprintf("Finished loading shard, current progress %.1f%% shards (%d / %d).", percentShards, shardsCompleted, totalShards)) | ||
} |
Oops, something went wrong.