Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -457,24 +457,7 @@ public void collect(int docId, long owningBucketOrd) throws IOException {
);
}

/*
* Sanity checks to ensure that we receive documents in the correct order
* - _tsid must be sorted in ascending order
* - @timestamp must be sorted in descending order within the same _tsid
*/
BytesRef lastTsid = downsampleBucketBuilder.tsid();
assert lastTsid == null || lastTsid.compareTo(tsidHash) <= 0
: "_tsid is not sorted in ascending order: ["
+ DocValueFormat.TIME_SERIES_ID.format(lastTsid)
+ "] -> ["
+ DocValueFormat.TIME_SERIES_ID.format(tsidHash)
+ "]";
assert tsidHash.equals(lastTsid) == false || lastTimestamp >= timestamp
: "@timestamp is not sorted in descending order: ["
+ timestampFormat.format(lastTimestamp)
+ "] -> ["
+ timestampFormat.format(timestamp)
+ "]";
assert assertTsidAndTimestamp(tsidHash, timestamp);
lastTimestamp = timestamp;

if (tsidChanged || downsampleBucketBuilder.timestamp() != lastHistoTimestamp) {
Expand Down Expand Up @@ -532,6 +515,28 @@ void leafBulkCollection() throws IOException {
// buffer.clean() also overwrites all slots with zeros
docIdBuffer.elementsCount = 0;
}

/**
* Sanity checks to ensure that we receive documents in the correct order
* - _tsid must be sorted in ascending order
* - @timestamp must be sorted in descending order within the same _tsid
*/
boolean assertTsidAndTimestamp(BytesRef tsidHash, long timestamp) {
BytesRef lastTsid = downsampleBucketBuilder.tsid();
assert lastTsid == null || lastTsid.compareTo(tsidHash) <= 0
: "_tsid is not sorted in ascending order: ["
+ DocValueFormat.TIME_SERIES_ID.format(lastTsid)
+ "] -> ["
+ DocValueFormat.TIME_SERIES_ID.format(tsidHash)
+ "]";
assert tsidHash.equals(lastTsid) == false || lastTimestamp >= timestamp
: "@timestamp is not sorted in descending order: ["
+ timestampFormat.format(lastTimestamp)
+ "] -> ["
+ timestampFormat.format(timestamp)
+ "]";
return true;
}
}

private void indexBucket(XContentBuilder doc) {
Expand Down