Skip to content

Commit 5bbc04b

Browse files
authored
Cleanup assert in DownsampleShardIndexer (#124751)
1 parent 5f20493 commit 5bbc04b

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/DownsampleShardIndexer.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -457,24 +457,7 @@ public void collect(int docId, long owningBucketOrd) throws IOException {
457457
);
458458
}
459459

460-
/*
461-
* Sanity checks to ensure that we receive documents in the correct order
462-
* - _tsid must be sorted in ascending order
463-
* - @timestamp must be sorted in descending order within the same _tsid
464-
*/
465-
BytesRef lastTsid = downsampleBucketBuilder.tsid();
466-
assert lastTsid == null || lastTsid.compareTo(tsidHash) <= 0
467-
: "_tsid is not sorted in ascending order: ["
468-
+ DocValueFormat.TIME_SERIES_ID.format(lastTsid)
469-
+ "] -> ["
470-
+ DocValueFormat.TIME_SERIES_ID.format(tsidHash)
471-
+ "]";
472-
assert tsidHash.equals(lastTsid) == false || lastTimestamp >= timestamp
473-
: "@timestamp is not sorted in descending order: ["
474-
+ timestampFormat.format(lastTimestamp)
475-
+ "] -> ["
476-
+ timestampFormat.format(timestamp)
477-
+ "]";
460+
assert assertTsidAndTimestamp(tsidHash, timestamp);
478461
lastTimestamp = timestamp;
479462

480463
if (tsidChanged || downsampleBucketBuilder.timestamp() != lastHistoTimestamp) {
@@ -532,6 +515,28 @@ void leafBulkCollection() throws IOException {
532515
// buffer.clean() also overwrites all slots with zeros
533516
docIdBuffer.elementsCount = 0;
534517
}
518+
519+
/**
520+
* Sanity checks to ensure that we receive documents in the correct order
521+
* - _tsid must be sorted in ascending order
522+
* - @timestamp must be sorted in descending order within the same _tsid
523+
*/
524+
boolean assertTsidAndTimestamp(BytesRef tsidHash, long timestamp) {
525+
BytesRef lastTsid = downsampleBucketBuilder.tsid();
526+
assert lastTsid == null || lastTsid.compareTo(tsidHash) <= 0
527+
: "_tsid is not sorted in ascending order: ["
528+
+ DocValueFormat.TIME_SERIES_ID.format(lastTsid)
529+
+ "] -> ["
530+
+ DocValueFormat.TIME_SERIES_ID.format(tsidHash)
531+
+ "]";
532+
assert tsidHash.equals(lastTsid) == false || lastTimestamp >= timestamp
533+
: "@timestamp is not sorted in descending order: ["
534+
+ timestampFormat.format(lastTimestamp)
535+
+ "] -> ["
536+
+ timestampFormat.format(timestamp)
537+
+ "]";
538+
return true;
539+
}
535540
}
536541

537542
private void indexBucket(XContentBuilder doc) {

0 commit comments

Comments
 (0)