LongsLongEncodingReader: Implement "duplicate", fixing concurrency bug. (#11098)

Regression introduced in #11004 due to overzealous optimization. Even though
we replaced stateful usage of ByteBuffer with stateless usage of Memory, we
still need to create a new object on "duplicate" due to semantics of setBuffer.
This commit is contained in:
Gian Merlino 2021-04-13 08:01:01 -07:00 committed by GitHub
parent f60d8ea1c3
commit c8e394015d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -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();
}

View File

@ -69,6 +69,6 @@ public class LongsLongEncodingReader implements CompressionFactory.LongEncodingR
@Override
public CompressionFactory.LongEncodingReader duplicate()
{
return this;
return new LongsLongEncodingReader(buffer.getByteBuffer(), buffer.getTypeByteOrder());
}
}