Skip to content

Commit

Permalink
fix thread-safe zerolog usage, details rs/zerolog#242 and https://git…
Browse files Browse the repository at this point in the history
  • Loading branch information
Slach authored and mskwon committed Jun 14, 2023
1 parent c2160c5 commit 50bce08
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/backup/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ func (b *Backuper) downloadTableMetadata(ctx context.Context, backupName string,
b.resumableState.AppendToState(localMetadataFile, written)
}
}
logger = logger.With().Logger()
logger.Info().
Str("duration", utils.HumanizeDuration(time.Since(start))).
Str("size", utils.FormatBytes(size)).
Expand Down
5 changes: 3 additions & 2 deletions pkg/resumable/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ func (s *State) IsAlreadyProcessed(path string) (bool, int64) {
res := strings.Index(s.currentState, path+":")
if res >= 0 {
// s.logger is non thread-safe https://github.com/rs/zerolog/issues/242
s.logger.Info().Msgf("%s already processed", path)
logger := s.logger.With().Logger()
logger.Info().Msgf("%s already processed", path)
sSize := s.currentState[res : res+strings.Index(s.currentState[res:], "\n")]
sSize = sSize[strings.Index(sSize, ":")+1:]
size, err = strconv.ParseInt(sSize, 10, 64)
if err != nil {
s.logger.Warn().Msgf("invalid size %s in upload state: %v", sSize, err)
logger.Warn().Msgf("invalid size %s in upload state: %v", sSize, err)
}
}
s.mx.RUnlock()
Expand Down

0 comments on commit 50bce08

Please sign in to comment.