Search in sources :

Example 1 with RecordedShard

use of io.trino.plugin.raptor.legacy.storage.InMemoryShardRecorder.RecordedShard in project trino by trinodb.

the class TestRaptorStorageManager method testWriter.

@Test
public void testWriter() throws Exception {
    RaptorStorageManager manager = createRaptorStorageManager();
    List<Long> columnIds = ImmutableList.of(3L, 7L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10));
    StoragePageSink sink = createStoragePageSink(manager, columnIds, columnTypes);
    List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello").row(456L, "bye").build();
    sink.appendPages(pages);
    // shard is not recorded until flush
    assertEquals(shardRecorder.getShards().size(), 0);
    sink.flush();
    // shard is recorded after flush
    List<RecordedShard> recordedShards = shardRecorder.getShards();
    assertEquals(recordedShards.size(), 1);
    List<ShardInfo> shards = getFutureValue(sink.commit());
    assertEquals(shards.size(), 1);
    ShardInfo shardInfo = Iterables.getOnlyElement(shards);
    UUID shardUuid = shardInfo.getShardUuid();
    File file = storageService.getStorageFile(shardUuid);
    File backupFile = fileBackupStore.getBackupFile(shardUuid);
    assertEquals(recordedShards.get(0).getTransactionId(), TRANSACTION_ID);
    assertEquals(recordedShards.get(0).getShardUuid(), shardUuid);
    assertEquals(shardInfo.getRowCount(), 2);
    assertEquals(shardInfo.getCompressedSize(), file.length());
    assertEquals(shardInfo.getXxhash64(), xxhash64(file));
    // verify primary and backup shard exist
    assertFile(file, "primary shard");
    assertFile(backupFile, "backup shard");
    assertFileEquals(file, backupFile);
    // remove primary shard to force recovery from backup
    assertTrue(file.delete());
    assertTrue(file.getParentFile().delete());
    assertFalse(file.exists());
    recoveryManager.restoreFromBackup(shardUuid, shardInfo.getCompressedSize(), OptionalLong.of(shardInfo.getXxhash64()));
    try (OrcDataSource dataSource = manager.openShard(shardUuid, READER_OPTIONS)) {
        OrcRecordReader reader = createReader(dataSource, columnIds, columnTypes);
        Page page = reader.nextPage();
        assertEquals(page.getPositionCount(), 2);
        Block column0 = page.getBlock(0);
        assertEquals(column0.isNull(0), false);
        assertEquals(column0.isNull(1), false);
        assertEquals(BIGINT.getLong(column0, 0), 123L);
        assertEquals(BIGINT.getLong(column0, 1), 456L);
        Block column1 = page.getBlock(1);
        assertEquals(createVarcharType(10).getSlice(column1, 0), utf8Slice("hello"));
        assertEquals(createVarcharType(10).getSlice(column1, 1), utf8Slice("bye"));
        assertNull(reader.nextPage());
    }
}
Also used : OrcDataSource(io.trino.orc.OrcDataSource) Page(io.trino.spi.Page) RecordedShard(io.trino.plugin.raptor.legacy.storage.InMemoryShardRecorder.RecordedShard) OrcRecordReader(io.trino.orc.OrcRecordReader) Type(io.trino.spi.type.Type) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) OptionalLong(java.util.OptionalLong) Block(io.trino.spi.block.Block) UUID(java.util.UUID) FileAssert.assertFile(org.testng.FileAssert.assertFile) File(java.io.File) ShardInfo(io.trino.plugin.raptor.legacy.metadata.ShardInfo) Test(org.testng.annotations.Test)

Example 2 with RecordedShard

use of io.trino.plugin.raptor.legacy.storage.InMemoryShardRecorder.RecordedShard in project trino by trinodb.

the class TestRaptorStorageManager method testRewriter.

@Test
public void testRewriter() throws Exception {
    RaptorStorageManager manager = createRaptorStorageManager();
    long transactionId = TRANSACTION_ID;
    List<Long> columnIds = ImmutableList.of(3L, 7L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10));
    // create file with 2 rows
    StoragePageSink sink = createStoragePageSink(manager, columnIds, columnTypes);
    List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello").row(456L, "bye").build();
    sink.appendPages(pages);
    List<ShardInfo> shards = getFutureValue(sink.commit());
    assertEquals(shardRecorder.getShards().size(), 1);
    // delete one row
    BitSet rowsToDelete = new BitSet();
    rowsToDelete.set(0);
    Collection<Slice> fragments = manager.rewriteShard(transactionId, OptionalInt.empty(), shards.get(0).getShardUuid(), rowsToDelete);
    Slice shardDelta = Iterables.getOnlyElement(fragments);
    ShardDelta shardDeltas = jsonCodec(ShardDelta.class).fromJson(shardDelta.getBytes());
    ShardInfo shardInfo = Iterables.getOnlyElement(shardDeltas.getNewShards());
    // check that output file has one row
    assertEquals(shardInfo.getRowCount(), 1);
    // check that storage file is same as backup file
    File storageFile = storageService.getStorageFile(shardInfo.getShardUuid());
    File backupFile = fileBackupStore.getBackupFile(shardInfo.getShardUuid());
    assertFileEquals(storageFile, backupFile);
    // verify recorded shard
    List<RecordedShard> recordedShards = shardRecorder.getShards();
    assertEquals(recordedShards.size(), 2);
    assertEquals(recordedShards.get(1).getTransactionId(), TRANSACTION_ID);
    assertEquals(recordedShards.get(1).getShardUuid(), shardInfo.getShardUuid());
}
Also used : BitSet(java.util.BitSet) Page(io.trino.spi.Page) RecordedShard(io.trino.plugin.raptor.legacy.storage.InMemoryShardRecorder.RecordedShard) Type(io.trino.spi.type.Type) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) OptionalLong(java.util.OptionalLong) ShardDelta(io.trino.plugin.raptor.legacy.metadata.ShardDelta) FileAssert.assertFile(org.testng.FileAssert.assertFile) File(java.io.File) ShardInfo(io.trino.plugin.raptor.legacy.metadata.ShardInfo) Test(org.testng.annotations.Test)

Aggregations

ShardInfo (io.trino.plugin.raptor.legacy.metadata.ShardInfo)2 RecordedShard (io.trino.plugin.raptor.legacy.storage.InMemoryShardRecorder.RecordedShard)2 Page (io.trino.spi.Page)2 Type (io.trino.spi.type.Type)2 VarcharType.createVarcharType (io.trino.spi.type.VarcharType.createVarcharType)2 File (java.io.File)2 OptionalLong (java.util.OptionalLong)2 FileAssert.assertFile (org.testng.FileAssert.assertFile)2 Test (org.testng.annotations.Test)2 Slice (io.airlift.slice.Slice)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 OrcDataSource (io.trino.orc.OrcDataSource)1 OrcRecordReader (io.trino.orc.OrcRecordReader)1 ShardDelta (io.trino.plugin.raptor.legacy.metadata.ShardDelta)1 Block (io.trino.spi.block.Block)1 BitSet (java.util.BitSet)1 UUID (java.util.UUID)1