Search in sources :

Example 21 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class CassandraKvsWrapperTest method ifWrapperIsInitializedDelegateIsCalled.

@Test
public void ifWrapperIsInitializedDelegateIsCalled() {
    when(kvsWrapper.isInitialized()).thenReturn(true);
    TableReference tableRef = TableReference.create(Namespace.DEFAULT_NAMESPACE, "test");
    kvsWrapper.createTable(tableRef, AtlasDbConstants.GENERIC_TABLE_METADATA);
    verify(kvs).createTable(any(TableReference.class), any());
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Test(org.junit.Test)

Example 22 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class CassandraKvsWrapperTest method ifWrapperIsNotInitializedDelegateIsNotCalled.

@Test
public void ifWrapperIsNotInitializedDelegateIsNotCalled() {
    when(kvsWrapper.isInitialized()).thenReturn(false);
    TableReference tableRef = TableReference.create(Namespace.DEFAULT_NAMESPACE, "test");
    assertThatThrownBy(() -> kvsWrapper.createTable(tableRef, AtlasDbConstants.GENERIC_TABLE_METADATA)).isInstanceOf(NotInitializedException.class);
    verify(kvs, never()).createTable(any(TableReference.class), any());
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Test(org.junit.Test)

Example 23 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class SchemaMutationLock method queryExistingLockColumn.

private Optional<Column> queryExistingLockColumn(CassandraClient client) throws TException {
    TableReference lockTableRef = lockTable.get();
    Column existingColumn = null;
    ConsistencyLevel localQuorum = ConsistencyLevel.LOCAL_QUORUM;
    try {
        ColumnOrSuperColumn result = queryRunner.run(client, lockTableRef, () -> client.get(lockTableRef, getGlobalDdlLockRowName(), getGlobalDdlLockColumnName(), localQuorum));
        existingColumn = result.getColumn();
    } catch (UnavailableException e) {
        throw new InsufficientConsistencyException("Checking the schema lock requires " + localQuorum + " Cassandra nodes to be up and available.", e);
    } catch (NotFoundException e) {
        log.debug("No existing schema lock found in table [{}]", SafeArg.of("tableName", lockTableRef));
    }
    return Optional.ofNullable(existingColumn);
}
Also used : ConsistencyLevel(org.apache.cassandra.thrift.ConsistencyLevel) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) InsufficientConsistencyException(com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Column(org.apache.cassandra.thrift.Column) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) UnavailableException(org.apache.cassandra.thrift.UnavailableException) NotFoundException(org.apache.cassandra.thrift.NotFoundException)

Example 24 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class JdbcKeyValueService method addGarbageCollectionSentinelValues.

@Override
public void addGarbageCollectionSentinelValues(final TableReference tableRef, Iterable<Cell> cells) {
    int numCells = Iterables.size(cells);
    if (numCells == 0) {
        return;
    }
    for (List<Cell> partCells : Iterables.partition(cells, batchSizeForMutations)) {
        Long timestamp = Value.INVALID_VALUE_TIMESTAMP;
        byte[] value = new byte[0];
        final RowN[] rows = new RowN[numCells];
        int i = 0;
        for (Cell cell : partCells) {
            rows[i++] = row(new Object[] { cell.getRowName(), cell.getColumnName(), timestamp, value });
        }
        run((Function<DSLContext, Void>) ctx -> {
            ctx.insertInto(table(tableName(tableRef)), field(ROW_NAME, byte[].class), field(COL_NAME, byte[].class), field(TIMESTAMP, Long.class), field(VALUE, byte[].class)).select(ctx.select(T1_ROW_NAME, T1_COL_NAME, T1_TIMESTAMP, T1_VALUE).from(values(ctx, rows, TEMP_TABLE_1, ROW_NAME, COL_NAME, TIMESTAMP, VALUE)).whereNotExists(ctx.selectOne().from(atlasTable(tableRef).as(ATLAS_TABLE)).where(A_ROW_NAME.eq(T1_ROW_NAME).and(A_COL_NAME.eq(T1_COL_NAME)).and(A_TIMESTAMP.eq(T1_TIMESTAMP))))).execute();
            return null;
        });
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) DSL(org.jooq.impl.DSL) DSL.field(org.jooq.impl.DSL.field) CheckAndSetRequest(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest) Condition(org.jooq.Condition) Record1(org.jooq.Record1) SelectField(org.jooq.SelectField) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) SQLDialect(org.jooq.SQLDialect) CandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping) Select(org.jooq.Select) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Cell(com.palantir.atlasdb.keyvalue.api.Cell) T1_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T1_TIMESTAMP) Set(java.util.Set) PutBatch(com.palantir.atlasdb.keyvalue.jdbc.impl.PutBatch) T1_COL_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T1_COL_NAME) Result(org.jooq.Result) StandardCharsets(java.nio.charset.StandardCharsets) InsufficientConsistencyException(com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException) AbstractKeyValueService(com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) Iterables(com.google.common.collect.Iterables) METADATA(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.METADATA) DSL.row(org.jooq.impl.DSL.row) ClusterAvailabilityStatus(com.palantir.atlasdb.keyvalue.api.ClusterAvailabilityStatus) R_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.R_TIMESTAMP) SQLException(java.sql.SQLException) T2_MAX_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T2_MAX_TIMESTAMP) Lists(com.google.common.collect.Lists) VARBINARY(org.jooq.impl.SQLDataType.VARBINARY) RANGE_TABLE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.RANGE_TABLE) VARCHAR(org.jooq.impl.SQLDataType.VARCHAR) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Record(org.jooq.Record) UnsignedBytes(com.google.common.primitives.UnsignedBytes) JdbcDataSourceConfiguration(com.palantir.atlasdb.jdbc.config.JdbcDataSourceConfiguration) T1_ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T1_ROW_NAME) BaseEncoding(com.google.common.io.BaseEncoding) COL_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.COL_NAME) MoreObjects(com.google.common.base.MoreObjects) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) BLOB(org.jooq.impl.SQLDataType.BLOB) MultiTimestampPutBatch(com.palantir.atlasdb.keyvalue.jdbc.impl.MultiTimestampPutBatch) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) DSL.table(org.jooq.impl.DSL.table) VALUE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.VALUE) GetCandidateCellsForSweepingShim(com.palantir.atlasdb.keyvalue.impl.GetCandidateCellsForSweepingShim) TEMP_TABLE_1(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.TEMP_TABLE_1) RowN(org.jooq.RowN) RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) TEMP_TABLE_2(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.TEMP_TABLE_2) Row(org.jooq.Row) Connection(java.sql.Connection) TABLE_VALUES(org.jooq.Clause.TABLE_VALUES) ATLAS_TABLE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.ATLAS_TABLE) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) ClosableIterator(com.palantir.common.base.ClosableIterator) Table(org.jooq.Table) TABLE_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.TABLE_NAME) SelectOffsetStep(org.jooq.SelectOffsetStep) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) KeyValueServices(com.palantir.atlasdb.keyvalue.impl.KeyValueServices) A_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.A_TIMESTAMP) RenderContext(org.jooq.RenderContext) HashMultimap(com.google.common.collect.HashMultimap) DSLContext(org.jooq.DSLContext) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractPagingIterable(com.palantir.util.paging.AbstractPagingIterable) Row3(org.jooq.Row3) Collection(java.util.Collection) SingleTimestampPutBatch(com.palantir.atlasdb.keyvalue.jdbc.impl.SingleTimestampPutBatch) ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.ROW_NAME) T1_VALUE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T1_VALUE) NavigableMap(java.util.NavigableMap) Sets(com.google.common.collect.Sets) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) List(java.util.List) InsertValuesStep4(org.jooq.InsertValuesStep4) CandidateCellForSweepingRequest(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest) Entry(java.util.Map.Entry) Query(org.jooq.Query) SortedMap(java.util.SortedMap) T2_COL_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T2_COL_NAME) A_COL_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.A_COL_NAME) HashMap(java.util.HashMap) Hashing(com.google.common.hash.Hashing) Multimap(com.google.common.collect.Multimap) BIGINT(org.jooq.impl.SQLDataType.BIGINT) TableLike(org.jooq.TableLike) ImmutableList(com.google.common.collect.ImmutableList) A_VALUE(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.A_VALUE) DataSource(javax.sql.DataSource) R_ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.R_ROW_NAME) ClosableIterators(com.palantir.common.base.ClosableIterators) DataAccessException(org.jooq.exception.DataAccessException) Value(com.palantir.atlasdb.keyvalue.api.Value) Settings(org.jooq.conf.Settings) MAX_TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.MAX_TIMESTAMP) TIMESTAMP(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.TIMESTAMP) A_ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.A_ROW_NAME) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Maps(com.google.common.collect.Maps) T2_ROW_NAME(com.palantir.atlasdb.keyvalue.jdbc.impl.JdbcConstants.T2_ROW_NAME) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) Closeable(java.io.Closeable) SimpleTokenBackedResultsPage(com.palantir.util.paging.SimpleTokenBackedResultsPage) BatchBindStep(org.jooq.BatchBindStep) RenderNameStyle(org.jooq.conf.RenderNameStyle) RowN(org.jooq.RowN) DSLContext(org.jooq.DSLContext) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 25 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class JdbcKeyValueService method getMetadataForTables.

@Override
public Map<TableReference, byte[]> getMetadataForTables() {
    return run(ctx -> {
        Result<? extends Record> records = ctx.select(TABLE_NAME, METADATA).from(METADATA_TABLE).fetch();
        Map<TableReference, byte[]> metadata = Maps.newHashMapWithExpectedSize(records.size());
        for (Record record : records) {
            metadata.put(TableReference.createUnsafe(record.getValue(TABLE_NAME)), record.getValue(METADATA));
        }
        return metadata;
    });
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Record(org.jooq.Record)

Aggregations

TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)112 Cell (com.palantir.atlasdb.keyvalue.api.Cell)41 Test (org.junit.Test)41 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)13 Multimap (com.google.common.collect.Multimap)13 Entry (java.util.Map.Entry)13 Set (java.util.Set)13 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)12 Value (com.palantir.atlasdb.keyvalue.api.Value)12 Collection (java.util.Collection)12 List (java.util.List)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)11 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)11 SortedMap (java.util.SortedMap)11 Lists (com.google.common.collect.Lists)10 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)10 Sets (com.google.common.collect.Sets)9 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)9