diff --git a/processing/src/main/java/org/apache/druid/segment/data/CompressionFactory.java b/processing/src/main/java/org/apache/druid/segment/data/CompressionFactory.java index 0b45cdb8d5c..10943316b70 100644 --- a/processing/src/main/java/org/apache/druid/segment/data/CompressionFactory.java +++ b/processing/src/main/java/org/apache/druid/segment/data/CompressionFactory.java @@ -287,6 +287,11 @@ public class CompressionFactory int read(long[] out, int outPosition, int[] indexes, int length, int indexOffset, int limit); + /** + * Duplicates this reader, creating a new reader that does not share any state. Important to achieve thread-safety, + * because a common pattern is to duplicate a reader multiple times and then call {@link #setBuffer} on the + * various duplicates. + */ LongEncodingReader duplicate(); } diff --git a/processing/src/main/java/org/apache/druid/segment/data/LongsLongEncodingReader.java b/processing/src/main/java/org/apache/druid/segment/data/LongsLongEncodingReader.java index 7fd1aef58b4..2ed0459121a 100644 --- a/processing/src/main/java/org/apache/druid/segment/data/LongsLongEncodingReader.java +++ b/processing/src/main/java/org/apache/druid/segment/data/LongsLongEncodingReader.java @@ -69,6 +69,6 @@ public class LongsLongEncodingReader implements CompressionFactory.LongEncodingR @Override public CompressionFactory.LongEncodingReader duplicate() { - return this; + return new LongsLongEncodingReader(buffer.getByteBuffer(), buffer.getTypeByteOrder()); } }