Search in sources :

Example 1 with TableMappingNotFoundException

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);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) TableMappingNotFoundException(com.palantir.common.exception.TableMappingNotFoundException) HashSet(java.util.HashSet)

Example 2 with TableMappingNotFoundException

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());
    }
}
Also used : AgnosticResultSet(com.palantir.nexus.db.sql.AgnosticResultSet) TableMappingNotFoundException(com.palantir.common.exception.TableMappingNotFoundException) SqlConnection(com.palantir.nexus.db.sql.SqlConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with TableMappingNotFoundException

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;
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) TableMappingNotFoundException(com.palantir.common.exception.TableMappingNotFoundException)

Example 4 with TableMappingNotFoundException

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);
    }
}
Also used : TableMappingNotFoundException(com.palantir.common.exception.TableMappingNotFoundException) CheckAndSetRequest(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest)

Example 5 with TableMappingNotFoundException

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);
}
Also used : ConflictDetectionManager(com.palantir.atlasdb.transaction.impl.ConflictDetectionManager) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) TableMappingNotFoundException(com.palantir.common.exception.TableMappingNotFoundException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SweepStrategyManager(com.palantir.atlasdb.transaction.impl.SweepStrategyManager) BatchingVisitable(com.palantir.common.base.BatchingVisitable) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) AtlasDbTestCase(com.palantir.atlasdb.AtlasDbTestCase) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Lists(com.google.common.collect.Lists) MetricsManager(com.palantir.atlasdb.util.MetricsManager) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PTExecutors(com.palantir.common.concurrent.PTExecutors) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) AbortingVisitors(com.palantir.common.base.AbortingVisitors) ConflictDetectionManagers(com.palantir.atlasdb.transaction.impl.ConflictDetectionManagers) SweepStrategyManagers(com.palantir.atlasdb.transaction.impl.SweepStrategyManagers) Namespace(com.palantir.atlasdb.keyvalue.api.Namespace) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) MetricsManagers(com.palantir.atlasdb.util.MetricsManagers) ValueType(com.palantir.atlasdb.table.description.ValueType) TransactionTask(com.palantir.atlasdb.transaction.api.TransactionTask) TestTransactionManagerImpl(com.palantir.atlasdb.transaction.impl.TestTransactionManagerImpl) MultiTableSweepQueueWriter(com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter) DefaultTimestampCache(com.palantir.atlasdb.cache.DefaultTimestampCache) AbortingVisitor(com.palantir.common.base.AbortingVisitor) InMemoryKeyValueService(com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService) BatchingVisitable(com.palantir.common.base.BatchingVisitable) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) Cell(com.palantir.atlasdb.keyvalue.api.Cell) SweepStrategyManager(com.palantir.atlasdb.transaction.impl.SweepStrategyManager) TestTransactionManagerImpl(com.palantir.atlasdb.transaction.impl.TestTransactionManagerImpl) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) MutableLong(org.apache.commons.lang3.mutable.MutableLong) MetricsManager(com.palantir.atlasdb.util.MetricsManager) ConflictDetectionManager(com.palantir.atlasdb.transaction.impl.ConflictDetectionManager) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

TableMappingNotFoundException (com.palantir.common.exception.TableMappingNotFoundException)6 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 AtlasDbTestCase (com.palantir.atlasdb.AtlasDbTestCase)1 DefaultTimestampCache (com.palantir.atlasdb.cache.DefaultTimestampCache)1 PtBytes (com.palantir.atlasdb.encoding.PtBytes)1 Cell (com.palantir.atlasdb.keyvalue.api.Cell)1 CheckAndSetRequest (com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest)1 Namespace (com.palantir.atlasdb.keyvalue.api.Namespace)1 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 ConnectionSupplier (com.palantir.atlasdb.keyvalue.dbkvs.impl.ConnectionSupplier)1 SqlConnectionSupplier (com.palantir.atlasdb.keyvalue.dbkvs.impl.SqlConnectionSupplier)1 TableValueStyle (com.palantir.atlasdb.keyvalue.dbkvs.impl.TableValueStyle)1 InMemoryKeyValueService (com.palantir.atlasdb.keyvalue.impl.InMemoryKeyValueService)1 MultiTableSweepQueueWriter (com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter)1 TableDefinition (com.palantir.atlasdb.table.description.TableDefinition)1