Skip to content

Commit

Permalink
HBASE-28482 Reverse scan with tags throws ArrayIndexOutOfBoundsExcept…
Browse files Browse the repository at this point in the history
…ion with DBE in setCurrentBlock flow (#5792)

Signed-off-by: Pankaj Kumar <pankajkumar@apache.org>
Signed-off-by: Bryan Beaudreault <bbeaudreault@apache.org>
  • Loading branch information
vineet4008 authored and bbeaudreault committed Apr 28, 2024
1 parent 1994b26 commit 1e4902c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,13 @@ public int compareKey(CellComparator comparator, Cell key) {
public void setCurrentBuffer(ByteBuff buffer) {
if (this.tagCompressionContext != null) {
this.tagCompressionContext.clear();

// Prior seekToKeyInBlock may have reset this to false if we fell back to previous
// seeker state. This is an optimization so we don't have to uncompress tags again when
// reading last state.
// In seekBefore flow, if block change happens then rewind is not called and
// setCurrentBuffer is called, so need to uncompress any tags we see.
current.uncompressTags = true;
}
currentBuffer = buffer;
current.currentBuffer = currentBuffer;
Expand Down Expand Up @@ -873,9 +880,6 @@ public void rewind() {
// reading last state.
// In case of rewind, we are starting from the beginning of the buffer, so we need
// to uncompress any tags we see.
// It may make sense to reset this in setCurrentBuffer as well, but we seem to only call
// setCurrentBuffer after StoreFileScanner.seekAtOrAfter which calls next to consume the
// seeker state. Rewind is called by seekBefore, which doesn't and leaves us in this state.
current.uncompressTags = true;
}
decodeFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,46 @@ public void testReverseScanWithDBE() throws IOException {

try (Connection connection = ConnectionFactory.createConnection(conf)) {
for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
testReverseScanWithDBE(connection, encoding, family);
testReverseScanWithDBE(connection, encoding, family, HConstants.DEFAULT_BLOCKSIZE, 10);
}
}
}

private void testReverseScanWithDBE(Connection conn, DataBlockEncoding encoding, byte[] family)
throws IOException {
/**
* Test that we can do reverse scans when writing tags and using DataBlockEncoding. Fails with an
* exception for PREFIX, DIFF, and FAST_DIFF
*/
@Test
public void testReverseScanWithDBEWhenCurrentBlockUpdates() throws IOException {
byte[] family = Bytes.toBytes("0");

Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);

try (Connection connection = ConnectionFactory.createConnection(conf)) {
for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
testReverseScanWithDBE(connection, encoding, family, 1024, 30000);
}
}
}

private void testReverseScanWithDBE(Connection conn, DataBlockEncoding encoding, byte[] family,
int blockSize, int maxRows) throws IOException {
LOG.info("Running test with DBE={}", encoding);
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName() + "-" + encoding);
TEST_UTIL.createTable(TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(
ColumnFamilyDescriptorBuilder.newBuilder(family).setDataBlockEncoding(encoding).build())
.build(), null);
TEST_UTIL.createTable(
TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder
.newBuilder(family).setDataBlockEncoding(encoding).setBlocksize(blockSize).build()).build(),
null);

Table table = conn.getTable(tableName);

int maxRows = 10;
byte[] val1 = new byte[10];
byte[] val2 = new byte[10];
Bytes.random(val1);
Bytes.random(val2);

for (int i = 0; i < maxRows; i++) {
if (i == maxRows / 2) {
TEST_UTIL.flush(tableName);
}
table.put(new Put(Bytes.toBytes(i)).addColumn(family, Bytes.toBytes(1), val1)
.addColumn(family, Bytes.toBytes(2), val2).setTTL(600_000));
}
Expand Down

0 comments on commit 1e4902c

Please sign in to comment.