use of io.trino.plugin.raptor.legacy.metadata.ShardInfo in project trino by trinodb.
the class RaptorStorageManager method shardDelta.
private static Collection<Slice> shardDelta(UUID oldShardUuid, Optional<ShardInfo> shardInfo) {
List<ShardInfo> newShards = shardInfo.map(ImmutableList::of).orElse(ImmutableList.of());
ShardDelta delta = new ShardDelta(ImmutableList.of(oldShardUuid), newShards);
return ImmutableList.of(Slices.wrappedBuffer(SHARD_DELTA_CODEC.toJsonBytes(delta)));
}
use of io.trino.plugin.raptor.legacy.metadata.ShardInfo in project trino by trinodb.
the class OrganizationJob method runJob.
private void runJob(long transactionId, OptionalInt bucketNumber, long tableId, Set<UUID> shardUuids) throws IOException {
TableMetadata metadata = getTableMetadata(tableId);
List<ShardInfo> newShards = performCompaction(transactionId, bucketNumber, shardUuids, metadata);
log.info("Compacted shards %s into %s", shardUuids, newShards.stream().map(ShardInfo::getShardUuid).collect(toList()));
shardManager.replaceShardUuids(transactionId, tableId, metadata.getColumns(), shardUuids, newShards, OptionalLong.empty());
}
use of io.trino.plugin.raptor.legacy.metadata.ShardInfo in project trino by trinodb.
the class ShardCompactor method compact.
public List<ShardInfo> compact(long transactionId, OptionalInt bucketNumber, Set<UUID> uuids, List<ColumnInfo> columns) throws IOException {
long start = System.nanoTime();
List<Long> columnIds = columns.stream().map(ColumnInfo::getColumnId).collect(toList());
List<Type> columnTypes = columns.stream().map(ColumnInfo::getType).collect(toList());
StoragePageSink storagePageSink = storageManager.createStoragePageSink(transactionId, bucketNumber, columnIds, columnTypes, false);
List<ShardInfo> shardInfos;
try {
shardInfos = compact(storagePageSink, bucketNumber, uuids, columnIds, columnTypes);
} catch (IOException | RuntimeException e) {
storagePageSink.rollback();
throw e;
}
updateStats(uuids.size(), shardInfos.size(), nanosSince(start).toMillis());
return shardInfos;
}
use of io.trino.plugin.raptor.legacy.metadata.ShardInfo in project trino by trinodb.
the class ShardCompactor method compactSorted.
public List<ShardInfo> compactSorted(long transactionId, OptionalInt bucketNumber, Set<UUID> uuids, List<ColumnInfo> columns, List<Long> sortColumnIds, List<SortOrder> sortOrders) throws IOException {
checkArgument(sortColumnIds.size() == sortOrders.size(), "sortColumnIds and sortOrders must be of the same size");
long start = System.nanoTime();
List<Long> columnIds = columns.stream().map(ColumnInfo::getColumnId).collect(toList());
List<Type> columnTypes = columns.stream().map(ColumnInfo::getType).collect(toList());
checkArgument(columnIds.containsAll(sortColumnIds), "sortColumnIds must be a subset of columnIds");
List<Integer> sortIndexes = sortColumnIds.stream().map(columnIds::indexOf).collect(toList());
Queue<SortedRowSource> rowSources = new PriorityQueue<>();
StoragePageSink outputPageSink = storageManager.createStoragePageSink(transactionId, bucketNumber, columnIds, columnTypes, false);
try {
for (UUID uuid : uuids) {
ConnectorPageSource pageSource = storageManager.getPageSource(uuid, bucketNumber, columnIds, columnTypes, TupleDomain.all(), orcReaderOptions);
SortedRowSource rowSource = new SortedRowSource(pageSource, columnTypes, sortIndexes, sortOrders, typeOperators);
rowSources.add(rowSource);
}
while (!rowSources.isEmpty()) {
SortedRowSource rowSource = rowSources.poll();
if (!rowSource.hasNext()) {
// rowSource is empty, close it
rowSource.close();
continue;
}
outputPageSink.appendRow(rowSource.next());
if (outputPageSink.isFull()) {
outputPageSink.flush();
}
rowSources.add(rowSource);
}
outputPageSink.flush();
List<ShardInfo> shardInfos = getFutureValue(outputPageSink.commit());
updateStats(uuids.size(), shardInfos.size(), nanosSince(start).toMillis());
return shardInfos;
} catch (IOException | RuntimeException e) {
outputPageSink.rollback();
throw e;
} finally {
rowSources.forEach(SortedRowSource::closeQuietly);
}
}
use of io.trino.plugin.raptor.legacy.metadata.ShardInfo 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());
}
}
Aggregations