//Setting up region
String method = "testIndexedScanWithDeletedRows";
initIdxRegion(tableName, method, new HBaseConfiguration(), Pair.of(family,
new IdxIndexDescriptor[]{indexDescriptor1, indexDescriptor2}));
for (long i = 0; i < numRows; i++) {
Put put = new Put(Bytes.toBytes(random.nextLong() + "." + i));
long value = i % 10;
put.add(family, qualLong, timestamp, Bytes.toBytes(value));
put.add(family, qualDouble, timestamp, Bytes.toBytes((double) i));
region.put(put);
}
checkIndexedScanWithDeletedRows(family, false, 7L, numRows / 5);
checkIndexedScanWithDeletedRows(family, false, 6L, 8L, 3 * numRows / 5);
timestamp++;
// delete some rows
random = new Random(10121986L); // pseudo random order of row insertions
for (long i = 0; i < numRows; i++) {
byte[] rowId = Bytes.toBytes(random.nextLong() + "." + i);
if (i % 10 == 7) {
Delete delete = new Delete(rowId, timestamp, null);
region.delete(delete, null, true);
}
}
checkIndexedScanWithDeletedRows(family, false, 7L, 0);
checkIndexedScanWithDeletedRows(family, false, 6L, 8L, 2 * numRows / 5);
/**
* Flush and verify
*/
region.flushcache();
checkIndexedScanWithDeletedRows(family, true, 7L, 0);
checkIndexedScanWithDeletedRows(family, true, 6L, 8L, 2 * numRows / 5);
/**
* New check - now the index should find the 4's and the memstore
* should only contains deleted rows - override the index's findings
*/
checkIndexedScanWithDeletedRows(family, true, 4L, numRows / 5);
checkIndexedScanWithDeletedRows(family, true, 3L, 8L, numRows);
timestamp++;
random = new Random(10121986L); // pseudo random order of row insertions
for (long i = 0; i < numRows; i++) {
byte[] rowId = Bytes.toBytes(random.nextLong() + "." + i);
if (i % 10 == 4) {
Delete delete = new Delete(rowId, timestamp, null);
region.delete(delete, null, true);
}
}
checkIndexedScanWithDeletedRows(family, false, 4L, 0);
checkIndexedScanWithDeletedRows(family, false, 3L, 8L, 4 * numRows / 5);
region.flushcache();
checkIndexedScanWithDeletedRows(family, true, 4L, 0);
checkIndexedScanWithDeletedRows(family, true, 3L, 8L, 4 * numRows / 5);
timestamp++;
/**
* New check - put some records back and verify
*/
for (long i = 0; i < numRows / 10; i++) {
Put put = new Put(Bytes.toBytes(random.nextLong() + "." + i));
long value = 7L;
put.add(family, qualLong, timestamp, Bytes.toBytes(value));
put.add(family, qualDouble, timestamp, Bytes.toBytes((double) i));
region.put(put);
}
checkIndexedScanWithDeletedRows(family, false, 7L, numRows / 5);
checkIndexedScanWithDeletedRows(family, false, 4L, 0);