-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dbnode] Add additional data snapshotting metrics (#2575)
- Loading branch information
Showing
13 changed files
with
213 additions
and
102 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
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 |
---|---|---|
|
@@ -96,7 +96,7 @@ type databaseBuffer interface { | |
metadata persist.Metadata, | ||
persistFn persist.DataFn, | ||
nsCtx namespace.Context, | ||
) error | ||
) (SnapshotResult, error) | ||
|
||
WarmFlush( | ||
ctx context.Context, | ||
|
@@ -541,24 +541,38 @@ func (b *dbBuffer) Snapshot( | |
metadata persist.Metadata, | ||
persistFn persist.DataFn, | ||
nsCtx namespace.Context, | ||
) error { | ||
) (SnapshotResult, error) { | ||
var ( | ||
start = b.nowFn() | ||
result SnapshotResult | ||
) | ||
|
||
buckets, exists := b.bucketVersionsAt(blockStart) | ||
if !exists { | ||
return nil | ||
return result, nil | ||
} | ||
|
||
// Snapshot must take both cold and warm writes because cold flushes don't | ||
// happen for the current block (since cold flushes can't happen before a | ||
// warm flush has happened). | ||
streams, err := buckets.mergeToStreams(ctx, streamsOptions{filterWriteType: false, nsCtx: nsCtx}) | ||
if err != nil { | ||
return err | ||
return result, err | ||
} | ||
numStreams := len(streams) | ||
|
||
var mergedStream xio.SegmentReader | ||
if numStreams == 1 { | ||
mergedStream = streams[0] | ||
afterMergeByBucket := b.nowFn() | ||
result.Stats.TimeMergeByBucket = afterMergeByBucket.Sub(start) | ||
|
||
var ( | ||
numStreams = len(streams) | ||
mergeAcrossBuckets = numStreams != 1 | ||
segment ts.Segment | ||
) | ||
if !mergeAcrossBuckets { | ||
segment, err = streams[0].Segment() | ||
if err != nil { | ||
return result, err | ||
} | ||
} else { | ||
// We may need to merge again here because the regular merge method does | ||
// not merge warm and cold buckets or buckets that have different versions. | ||
|
@@ -580,34 +594,37 @@ func (b *dbBuffer) Snapshot( | |
for iter.Next() { | ||
dp, unit, annotation := iter.Current() | ||
if err := encoder.Encode(dp, unit, annotation); err != nil { | ||
return err | ||
return result, err | ||
} | ||
} | ||
if err := iter.Err(); err != nil { | ||
return err | ||
return result, err | ||
} | ||
|
||
var ok bool | ||
mergedStream, ok = encoder.Stream(ctx) | ||
if !ok { | ||
// Don't write out series with no data. | ||
return nil | ||
} | ||
segment = encoder.Discard() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
notbdu
Author
Contributor
|
||
} | ||
|
||
segment, err := mergedStream.Segment() | ||
if err != nil { | ||
return err | ||
} | ||
afterMergeAcrossBuckets := b.nowFn() | ||
result.Stats.TimeMergeAcrossBuckets = afterMergeAcrossBuckets.Sub(afterMergeByBucket) | ||
|
||
if segment.Len() == 0 { | ||
// Don't write out series with no data. | ||
return nil | ||
return result, nil | ||
} | ||
|
||
checksum := segment.CalculateChecksum() | ||
|
||
return persistFn(metadata, segment, checksum) | ||
afterChecksum := b.nowFn() | ||
result.Stats.TimeChecksum = afterChecksum.Sub(afterMergeAcrossBuckets) | ||
|
||
if err := persistFn(metadata, segment, checksum); err != nil { | ||
return result, err | ||
} | ||
|
||
result.Stats.TimePersist = b.nowFn().Sub(afterChecksum) | ||
|
||
result.Persist = true | ||
return result, nil | ||
} | ||
|
||
func (b *dbBuffer) WarmFlush( | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
I looked at the docs for this fn, it said it transfers ownership to the caller. What's the reasoning for using this versus
.Stream(ctx)
?