diff --git a/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/DownsampleShardIndexer.java b/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/DownsampleShardIndexer.java index b5ad69777bc80..65174680c01d4 100644 --- a/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/DownsampleShardIndexer.java +++ b/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/DownsampleShardIndexer.java @@ -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) { @@ -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) {