Cleanup assert in DownsampleShardIndexer (#124751)

This commit is contained in:
Martijn van Groningen 2025-03-13 18:07:59 +01:00 committed by GitHub
parent 5f204938f8
commit 5bbc04bc66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -457,24 +457,7 @@ class DownsampleShardIndexer {
); );
} }
/* assert assertTsidAndTimestamp(tsidHash, timestamp);
* 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)
+ "]";
lastTimestamp = timestamp; lastTimestamp = timestamp;
if (tsidChanged || downsampleBucketBuilder.timestamp() != lastHistoTimestamp) { if (tsidChanged || downsampleBucketBuilder.timestamp() != lastHistoTimestamp) {
@ -532,6 +515,28 @@ class DownsampleShardIndexer {
// buffer.clean() also overwrites all slots with zeros // buffer.clean() also overwrites all slots with zeros
docIdBuffer.elementsCount = 0; 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) { private void indexBucket(XContentBuilder doc) {