Search in sources :

Example 1 with SimpleDataPageIO

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);
}
Also used : Arrays(java.util.Arrays) DataPagePayload(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload) LZ4_MAX_LEVEL(org.apache.ignite.internal.processors.compress.CompressionProcessor.LZ4_MAX_LEVEL) ZSTD_MAX_LEVEL(org.apache.ignite.internal.processors.compress.CompressionProcessor.ZSTD_MAX_LEVEL) Random(java.util.Random) Function(java.util.function.Function) LEAF_IO(org.apache.ignite.internal.processors.compress.CompressionProcessorTest.TestLeafIO.LEAF_IO) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) ZSTD(org.apache.ignite.configuration.DiskPageCompression.ZSTD) DiskPageCompression(org.apache.ignite.configuration.DiskPageCompression) GridUnsafe.bufferAddress(org.apache.ignite.internal.util.GridUnsafe.bufferAddress) LZ4(org.apache.ignite.configuration.DiskPageCompression.LZ4) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) BPlusTree(org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree) LZ4_MIN_LEVEL(org.apache.ignite.internal.processors.compress.CompressionProcessor.LZ4_MIN_LEVEL) BPlusLeafIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO) BPlusIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO) GridIntList(org.apache.ignite.internal.util.GridIntList) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) PageIdAllocator(org.apache.ignite.internal.pagemem.PageIdAllocator) UNCOMPRESSED_PAGE(org.apache.ignite.internal.processors.compress.CompressionProcessor.UNCOMPRESSED_PAGE) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridUnsafe(org.apache.ignite.internal.util.GridUnsafe) Test(org.junit.Test) INNER_IO(org.apache.ignite.internal.processors.compress.CompressionProcessorTest.TestInnerIO.INNER_IO) BPlusInnerIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) SKIP_GARBAGE(org.apache.ignite.configuration.DiskPageCompression.SKIP_GARBAGE) List(java.util.List) PageIdUtils(org.apache.ignite.internal.pagemem.PageIdUtils) CompressionProcessorImpl.allocateDirectBuffer(org.apache.ignite.internal.processors.compress.CompressionProcessorImpl.allocateDirectBuffer) SimpleDataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.SimpleDataPageIO) SNAPPY(org.apache.ignite.configuration.DiskPageCompression.SNAPPY) SimpleDataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.SimpleDataPageIO) DataPagePayload(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload) GridIntList(org.apache.ignite.internal.util.GridIntList) ByteBuffer(java.nio.ByteBuffer) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteException(org.apache.ignite.IgniteException) ArrayList(java.util.ArrayList) GridIntList(org.apache.ignite.internal.util.GridIntList) List(java.util.List)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Function (java.util.function.Function)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 DiskPageCompression (org.apache.ignite.configuration.DiskPageCompression)1 LZ4 (org.apache.ignite.configuration.DiskPageCompression.LZ4)1 SKIP_GARBAGE (org.apache.ignite.configuration.DiskPageCompression.SKIP_GARBAGE)1 SNAPPY (org.apache.ignite.configuration.DiskPageCompression.SNAPPY)1 ZSTD (org.apache.ignite.configuration.DiskPageCompression.ZSTD)1 PageIdAllocator (org.apache.ignite.internal.pagemem.PageIdAllocator)1 PageIdUtils (org.apache.ignite.internal.pagemem.PageIdUtils)1 PageUtils (org.apache.ignite.internal.pagemem.PageUtils)1 BPlusTree (org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree)1 BPlusIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO)1 BPlusInnerIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO)1