Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSDB: downsampling cache histoTimestamp to reduce rounding cost #88420

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
cache histoTimestamp to reduce rounding.round cost
  • Loading branch information
weizijun committed Jul 11, 2022
commit 63b13d4c0c3ac365579b1144c73ca624147830dc
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ private class TimeSeriesBucketCollector extends BucketCollector {
private long bucketsCreated;
private final RollupBucketBuilder rollupBucketBuilder = new RollupBucketBuilder();
long lastTimestamp = Long.MAX_VALUE;
long lastHistoTimestamp = Long.MAX_VALUE;
BytesRef lastTsid = null;

TimeSeriesBucketCollector(BulkProcessor bulkProcessor) {
Expand All @@ -232,14 +233,18 @@ public void collect(int docId, long owningBucketOrd) throws IOException {
final BytesRef tsid = aggCtx.getTsid();
assert tsid != null : "Document without [" + TimeSeriesIdFieldMapper.NAME + "] field was found.";
final long timestamp = aggCtx.getTimestamp();
final long histoTimestamp = rounding.round(timestamp);

boolean tsidChanged = tsid.equals(rollupBucketBuilder.tsid()) == false;
if (tsidChanged || timestamp < lastHistoTimestamp) {
lastHistoTimestamp = rounding.round(timestamp);
}

logger.trace(
"Doc: [{}] - _tsid: [{}], @timestamp: [{}}] -> rollup bucket ts: [{}]",
docId,
DocValueFormat.TIME_SERIES_ID.format(tsid),
timestampFormat.format(timestamp),
timestampFormat.format(histoTimestamp)
timestampFormat.format(lastHistoTimestamp)
);

/*
Expand All @@ -262,15 +267,15 @@ public void collect(int docId, long owningBucketOrd) throws IOException {
lastTsid = BytesRef.deepCopyOf(tsid);
lastTimestamp = timestamp;

if (tsid.equals(rollupBucketBuilder.tsid()) == false || rollupBucketBuilder.timestamp() != histoTimestamp) {
if (tsidChanged || rollupBucketBuilder.timestamp() != lastHistoTimestamp) {
// Flush rollup doc if not empty
if (rollupBucketBuilder.isEmpty() == false) {
Map<String, Object> doc = rollupBucketBuilder.buildRollupDocument();
indexBucket(doc);
}

// Create new rollup bucket
rollupBucketBuilder.init(tsid, histoTimestamp);
rollupBucketBuilder.init(tsid, lastHistoTimestamp);
bucketsCreated++;
}

Expand Down