use of com.palantir.common.exception.TableMappingNotFoundException in project atlasdb by palantir.
the class TableRemappingKeyValueService method truncateTables.
@Override
public void truncateTables(Set<TableReference> tableRefs) {
Set<TableReference> tablesToTruncate = new HashSet<>();
for (TableReference tableRef : tableRefs) {
try {
tablesToTruncate.add(tableMapper.getMappedTableName(tableRef));
} catch (TableMappingNotFoundException e) {
throw new IllegalArgumentException(e);
}
}
delegate().truncateTables(tablesToTruncate);
}
use of com.palantir.common.exception.TableMappingNotFoundException in project atlasdb by palantir.
the class OracleTableNameUnmapper method getShortTableNameFromMappingTable.
@SuppressWarnings("checkstyle:NestedTryDepth")
public String getShortTableNameFromMappingTable(ConnectionSupplier connectionSupplier, String tablePrefix, TableReference tableRef) throws TableMappingNotFoundException {
String fullTableName = tablePrefix + DbKvs.internalTableName(tableRef);
try {
return unmappingCache.get(fullTableName, () -> {
SqlConnection conn = connectionSupplier.get();
AgnosticResultSet results = conn.selectResultSetUnregisteredQuery("SELECT short_table_name " + "FROM " + AtlasDbConstants.ORACLE_NAME_MAPPING_TABLE + " WHERE table_name = ?", fullTableName);
if (results.size() == 0) {
throw new TableMappingNotFoundException("The table " + fullTableName + " does not have a mapping." + "This might be because the table does not exist.");
}
return Iterables.getOnlyElement(results.rows()).getString("short_table_name");
});
} catch (ExecutionException e) {
throw new TableMappingNotFoundException(e.getCause());
}
}
use of com.palantir.common.exception.TableMappingNotFoundException in project atlasdb by palantir.
the class KvTableMappingService method getMappedTableRef.
private TableReference getMappedTableRef(TableReference tableRef) throws TableMappingNotFoundException {
TableReference candidate = tableMap.get().get(tableRef);
if (candidate == null) {
updateTableMap();
candidate = tableMap.get().get(tableRef);
if (candidate == null) {
throw new TableMappingNotFoundException("Unable to resolve mapping for table reference " + tableRef);
}
}
return candidate;
}
use of com.palantir.common.exception.TableMappingNotFoundException in project atlasdb by palantir.
the class TableRemappingKeyValueService method checkAndSet.
@Override
public void checkAndSet(CheckAndSetRequest checkAndSetRequest) {
try {
CheckAndSetRequest request = new CheckAndSetRequest.Builder().from(checkAndSetRequest).table(tableMapper.getMappedTableName(checkAndSetRequest.table())).build();
delegate().checkAndSet(request);
} catch (TableMappingNotFoundException e) {
throw new IllegalArgumentException(e);
}
}
use of com.palantir.common.exception.TableMappingNotFoundException in project atlasdb by palantir.
the class TableMigratorTest method testMigrationToDifferentKvs.
// Table/IndexDefinition syntax
@SuppressWarnings({ "checkstyle:Indentation", "checkstyle:RightCurly" })
@Test
public void testMigrationToDifferentKvs() throws TableMappingNotFoundException {
final TableReference tableRef = TableReference.create(Namespace.DEFAULT_NAMESPACE, "table");
final TableReference namespacedTableRef = TableReference.createFromFullyQualifiedName("namespace." + tableRef.getTableName());
TableDefinition definition = new TableDefinition() {
{
rowName();
rowComponent("r", ValueType.BLOB);
columns();
column("c", "c", ValueType.BLOB);
}
};
keyValueService.createTable(tableRef, definition.toTableMetadata().persistToBytes());
keyValueService.createTable(namespacedTableRef, definition.toTableMetadata().persistToBytes());
keyValueService.putMetadataForTable(namespacedTableRef, definition.toTableMetadata().persistToBytes());
final Cell theCell = Cell.create(PtBytes.toBytes("r1"), PtBytes.toBytes("c"));
final byte[] theValue = PtBytes.toBytes("v1");
txManager.runTaskWithRetry((TransactionTask<Void, RuntimeException>) txn -> {
Map<Cell, byte[]> values = ImmutableMap.of(theCell, theValue);
txn.put(tableRef, values);
txn.put(namespacedTableRef, values);
return null;
});
final InMemoryKeyValueService kvs2 = new InMemoryKeyValueService(false);
final ConflictDetectionManager cdm2 = ConflictDetectionManagers.createWithNoConflictDetection();
final SweepStrategyManager ssm2 = SweepStrategyManagers.completelyConservative();
final MetricsManager metricsManager = MetricsManagers.createForTests();
final TestTransactionManagerImpl txManager2 = new TestTransactionManagerImpl(metricsManager, kvs2, inMemoryTimeLockRule.get(), lockService, transactionService, cdm2, ssm2, DefaultTimestampCache.createForTests(), MultiTableSweepQueueWriter.NO_OP, MoreExecutors.newDirectExecutorService());
kvs2.createTable(tableRef, definition.toTableMetadata().persistToBytes());
kvs2.createTable(namespacedTableRef, definition.toTableMetadata().persistToBytes());
TableReference checkpointTable = TableReference.create(Namespace.DEFAULT_NAMESPACE, "checkpoint");
GeneralTaskCheckpointer checkpointer = new GeneralTaskCheckpointer(checkpointTable, kvs2, txManager2);
for (final TableReference name : Lists.newArrayList(tableRef, namespacedTableRef)) {
TransactionRangeMigrator rangeMigrator = new TransactionRangeMigratorBuilder().srcTable(name).readTxManager(txManager).txManager(txManager2).checkpointer(checkpointer).build();
TableMigratorBuilder builder = new TableMigratorBuilder().srcTable(name).partitions(1).executor(PTExecutors.newSingleThreadExecutor()).checkpointer(checkpointer).rangeMigrator(rangeMigrator);
TableMigrator migrator = builder.build();
migrator.migrate();
}
checkpointer.deleteCheckpoints();
final ConflictDetectionManager verifyCdm = ConflictDetectionManagers.createWithNoConflictDetection();
final SweepStrategyManager verifySsm = SweepStrategyManagers.completelyConservative();
final TestTransactionManagerImpl verifyTxManager = new TestTransactionManagerImpl(metricsManager, kvs2, inMemoryTimeLockRule.get(), lockService, transactionService, verifyCdm, verifySsm, DefaultTimestampCache.createForTests(), MultiTableSweepQueueWriter.NO_OP, MoreExecutors.newDirectExecutorService());
final MutableLong count = new MutableLong();
for (final TableReference name : Lists.newArrayList(tableRef, namespacedTableRef)) {
verifyTxManager.runTaskReadOnly((TransactionTask<Void, RuntimeException>) txn -> {
BatchingVisitable<RowResult<byte[]>> bv = txn.getRange(name, RangeRequest.all());
bv.batchAccept(1000, AbortingVisitors.batching(new AbortingVisitor<RowResult<byte[]>, RuntimeException>() {
@Override
public boolean visit(RowResult<byte[]> item) throws RuntimeException {
Iterable<Map.Entry<Cell, byte[]>> cells = item.getCells();
Map.Entry<Cell, byte[]> entry = Iterables.getOnlyElement(cells);
assertThat(entry.getKey()).isEqualTo(theCell);
assertThat(entry.getValue()).isEqualTo(theValue);
count.increment();
return true;
}
}));
return null;
});
}
assertThat(count.longValue()).isEqualTo(2L);
}
Aggregations