use of org.apache.ignite.internal.processors.cache.persistence.tree.io.SimpleDataPageIO in project ignite by apache.
the class CompressionProcessorTest method doTestDataPage.
/**
* @throws IgniteCheckedException If failed.
*/
private void doTestDataPage() throws IgniteCheckedException {
Random rnd = ThreadLocalRandom.current();
final byte[][] rows = new byte[][] { new byte[17], new byte[37], new byte[71] };
for (int i = 0; i < rows.length; i++) rnd.nextBytes(rows[i]);
ByteBuffer page = allocateDirectBuffer(pageSize);
long pageAddr = bufferAddress(page);
SimpleDataPageIO io = SimpleDataPageIO.VERSIONS.latest();
long pageId = PageIdUtils.pageId(PageIdAllocator.MAX_PARTITION_ID, PageIdAllocator.FLAG_DATA, 171717);
io.initNewPage(pageAddr, pageId, pageSize, null);
checkIo(io, page);
Function<ByteBuffer, List<Bytes>> getContents = (buf) -> {
try {
long addr = bufferAddress(buf);
return io.forAllItems(addr, (link) -> {
DataPagePayload payload = io.readPayload(addr, PageIdUtils.itemId(link), pageSize);
return new Bytes(payload.getBytes(addr));
});
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
};
// Empty data page.
checkCompressDecompress(page, getContents, false);
GridIntList itemIds = new GridIntList();
for (; ; ) {
byte[] row = rows[rnd.nextInt(rows.length)];
if (io.getFreeSpace(pageAddr) < row.length)
break;
itemIds.add(io.addRow(pageAddr, row, pageSize));
}
int freeSpace = io.getFreeSpace(pageAddr);
if (freeSpace != 0) {
byte[] lastRow = new byte[freeSpace];
rnd.nextBytes(lastRow);
io.addRowFragment(pageId, pageAddr, lastRow, 777L, pageSize);
assertEquals(0, io.getRealFreeSpace(pageAddr));
}
// Full data page.
checkCompressDecompress(page, getContents, io.getRealFreeSpace(pageAddr) == 0);
for (int i = 0; i < itemIds.size(); i += 2) io.removeRow(pageAddr, itemIds.get(i), pageSize);
// Half-filled data page.
checkCompressDecompress(page, getContents, false);
}
Aggregations