Skip to content

Commit

Permalink
fixing possible race.
Browse files Browse the repository at this point in the history
  • Loading branch information
soundvibe committed Mar 9, 2021
1 parent 05bec35 commit 629efb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/dbnode/storage/bootstrap/bootstrapper/commitlog/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ type readSeriesBlocksWorker struct {
}

func (w *readSeriesBlocksWorker) readSeriesBlocks() error {
defer close(w.dataCh)
for {
id, tags, data, expectedChecksum, err := w.reader.Read()
if err != nil && !errors.Is(err, io.EOF) {
Expand Down Expand Up @@ -940,12 +939,23 @@ func (s *commitLogSource) bootstrapShardBlockSnapshot(
}

go func() {
if workerErr = worker.readSeriesBlocks(); workerErr != nil {
s.log.Error("series read blocks error", zap.Error(workerErr))
if err := worker.readSeriesBlocks(); err != nil {
s.log.Error("series read blocks error", zap.Error(err))
workerErr = err
}
close(worker.dataCh)
}()

for seriesBlock := range worker.dataCh {
if err := s.loadBlocks(worker.dataCh, writeType); err != nil {
close(worker.dataCh)
return err
}

return workerErr
}

func (s *commitLogSource) loadBlocks(dataCh <-chan seriesBlock, writeType series.WriteType) error {
for seriesBlock := range dataCh {
// Load into series.
seriesRef, err := seriesBlock.resolver.SeriesRef()
if err != nil {
Expand All @@ -956,8 +966,7 @@ func (s *commitLogSource) bootstrapShardBlockSnapshot(
return err
}
}

return workerErr
return nil
}

func (s *commitLogSource) mostRecentSnapshotByBlockShard(
Expand Down
2 changes: 1 addition & 1 deletion src/dbnode/storage/bootstrap/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ type NamespaceDataAccumulator interface {

// CheckoutSeriesResult is the result of a checkout series operation.
type CheckoutSeriesResult struct {
// Resolver is the series for the checkout operation.
// Resolver is the series read write ref resolver.
Resolver SeriesRefResolver
// Shard is the shard for the series.
Shard uint32
Expand Down

0 comments on commit 629efb9

Please sign in to comment.