Skip to content

Commit

Permalink
Additional hardening against division by 0
Browse files Browse the repository at this point in the history
  • Loading branch information
linasm committed Dec 2, 2020
1 parent 651cc8f commit 007e6a5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/dbnode/persist/fs/streaming_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ type StreamingWriter interface {

// StreamingWriterOpenOptions in the options for the StreamingWriter.
type StreamingWriterOpenOptions struct {
NamespaceID ident.ID
ShardID uint32
BlockStart time.Time
BlockSize time.Duration
VolumeIndex int
NamespaceID ident.ID
ShardID uint32
BlockStart time.Time
BlockSize time.Duration
VolumeIndex int

// PlannedRecordsCount is an estimate of the number of series to be written.
// Must be greater than 0.
PlannedRecordsCount uint
}

Expand Down Expand Up @@ -188,7 +191,8 @@ func (w *streamingWriter) writeIndexRelated(
// time window
w.bloomFilter.Add(id)

if entry.index%w.summaryEvery == 0 {
writeSummary := w.summaryEvery == 0 || entry.index%w.summaryEvery == 0
if writeSummary {
// Capture the offset for when we write this summary back, only capture
// for every summary we'll actually write to avoid a few memcopies
entry.indexFileOffset = w.indexOffset
Expand All @@ -200,7 +204,7 @@ func (w *streamingWriter) writeIndexRelated(
}
w.indexOffset += length

if entry.index%w.summaryEvery == 0 {
if writeSummary {
err = w.writer.writeSummariesEntry(id, entry)
if err != nil {
return err
Expand Down

0 comments on commit 007e6a5

Please sign in to comment.