Class CassandraKeyValueServiceImpl
- java.lang.Object
-
- com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
-
- com.palantir.atlasdb.keyvalue.cassandra.CassandraKeyValueServiceImpl
-
- All Implemented Interfaces:
com.palantir.atlasdb.keyvalue.api.AsyncKeyValueService
,com.palantir.atlasdb.keyvalue.api.KeyValueService
,CassandraKeyValueService
,AutoCloseable
public class CassandraKeyValueServiceImpl extends com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService implements CassandraKeyValueService
Each service can have one or many C* KVS. For each C* KVS, it maintains a list of active nodes, and the client connections attached to each node: n1->c1, c2, c3 n2->c5, c4, c9 n3->[N C* thrift client connections] Where {n1, n2, n3} are the active nodes in the C* cluster. Also each node contains the clients which are attached to the node. if some nodes are down, and the change can be detected through active hosts, and these inactive nodes will be removed afterwards.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addGarbageCollectionSentinelValues(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<com.palantir.atlasdb.keyvalue.api.Cell> cells)
Adds a value with timestamp = Value.INVALID_VALUE_TIMESTAMP to each of the given cells.void
checkAndSet(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest request)
Performs a check-and-set into the key-value store.void
close()
Performs non-destructive cleanup when the KVS is no longer needed.void
compactInternally(com.palantir.atlasdb.keyvalue.api.TableReference tableRef)
static CassandraKeyValueService
create(com.palantir.atlasdb.util.MetricsManager metricsManager, CassandraKeyValueServiceConfig config, com.palantir.refreshable.Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, CassandraMutationTimestampProvider mutationTimestampProvider)
static CassandraKeyValueService
create(com.palantir.atlasdb.util.MetricsManager metricsManager, CassandraKeyValueServiceConfig config, com.palantir.refreshable.Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, CassandraMutationTimestampProvider mutationTimestampProvider, boolean initializeAsync)
static CassandraKeyValueService
create(com.palantir.atlasdb.util.MetricsManager metricsManager, CassandraKeyValueServiceConfig config, com.palantir.refreshable.Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, CassandraMutationTimestampProvider mutationTimestampProvider, CassandraClientPool clientPool)
static CassandraKeyValueService
createForTesting(CassandraKeyValueServiceConfig config, com.palantir.refreshable.Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig)
void
createTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, byte[] metadata)
Creates a table with the specified name.void
createTables(Map<com.palantir.atlasdb.keyvalue.api.TableReference,byte[]> tablesToMetadata)
Creates a table with the specified name.void
delete(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.google.common.collect.Multimap<com.palantir.atlasdb.keyvalue.api.Cell,Long> keys)
Deletes values from the key-value store.void
deleteAllTimestamps(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.TimestampRangeDelete> deletes)
void
deleteRange(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.palantir.atlasdb.keyvalue.api.RangeRequest range)
void
deleteRows(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<byte[]> rows)
void
dropTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef)
Drop the table, and also delete its table metadata.void
dropTables(Set<com.palantir.atlasdb.keyvalue.api.TableReference> tablesToDrop)
Drop the tables, and also delete their table metadata.Map<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.Value>
get(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,Long> timestampByCell)
Gets values from the key-value store.Set<com.palantir.atlasdb.keyvalue.api.TableReference>
getAllTableNames()
Return the list of tables stored in this key value service.com.google.common.collect.Multimap<com.palantir.atlasdb.keyvalue.api.Cell,Long>
getAllTimestamps(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Set<com.palantir.atlasdb.keyvalue.api.Cell> cells, long ts)
Gets timestamp values from the key-value store.com.google.common.util.concurrent.ListenableFuture<Map<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.Value>>
getAsync(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,Long> timestampByCell)
Asynchronously gets values from the cassandra key-value store.com.palantir.common.base.ClosableIterator<List<com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping>>
getCandidateCellsForSweeping(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest request)
com.palantir.atlasdb.keyvalue.cassandra.CassandraTables
getCassandraTables()
com.palantir.atlasdb.keyvalue.api.CheckAndSetCompatibility
getCheckAndSetCompatibility()
CassandraClientPool
getClientPool()
com.palantir.atlasdb.keyvalue.api.ClusterAvailabilityStatus
getClusterAvailabilityStatus()
Map<com.palantir.atlasdb.keyvalue.api.RangeRequest,com.palantir.util.paging.TokenBackedBasicResultsPage<com.palantir.atlasdb.keyvalue.api.RowResult<com.palantir.atlasdb.keyvalue.api.Value>,byte[]>>
getFirstBatchForRanges(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<com.palantir.atlasdb.keyvalue.api.RangeRequest> rangeRequests, long timestamp)
byte[]
getMetadataForTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef)
Gets the metadata for a given table.Map<com.palantir.atlasdb.keyvalue.api.TableReference,byte[]>
getMetadataForTables()
Gets the metadata for all non-hidden tables.protected int
getMultiPutBatchCount()
com.palantir.common.base.ClosableIterator<com.palantir.atlasdb.keyvalue.api.RowResult<com.palantir.atlasdb.keyvalue.api.Value>>
getRange(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.palantir.atlasdb.keyvalue.api.RangeRequest rangeRequest, long timestamp)
For each row in the specified range, returns the most recent version strictly before timestamp.com.palantir.common.base.ClosableIterator<com.palantir.atlasdb.keyvalue.api.RowResult<Set<Long>>>
getRangeOfTimestamps(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.palantir.atlasdb.keyvalue.api.RangeRequest rangeRequest, long timestamp)
Gets timestamp values from the key-value store.List<byte[]>
getRowKeysInRange(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, byte[] startRow, byte[] endRow, int maxResults)
Returns a sorted list of row keys in the specified range; seeKeyValueService.getRowKeysInRange(TableReference, byte[], byte[], int)
.Map<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.Value>
getRows(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<byte[]> rows, com.palantir.atlasdb.keyvalue.api.ColumnSelection selection, long startTs)
Gets values from the key-value store.Map<byte[],com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator>
getRowsColumnRange(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<byte[]> rows, com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection batchColumnRangeSelection, long timestamp)
Gets values from the key-value store for the specified rows and column range as separate iterators for each row.TracingQueryRunner
getTracingQueryRunner()
protected void
initialize(boolean asyncInitialize)
boolean
isInitialized()
void
multiCheckAndSet(com.palantir.atlasdb.keyvalue.api.MultiCheckAndSetRequest request)
Performs a check-and-set for multiple cells in a row into the key-value store.void
multiPut(Map<com.palantir.atlasdb.keyvalue.api.TableReference,? extends Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]>> valuesByTable, long timestamp)
Puts values into the key-value store.static Map<com.google.protobuf.ByteString,Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]>>
partitionPerRow(Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]> values)
boolean
performanceIsSensitiveToTombstones()
void
put(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]> values, long timestamp)
Puts values into the key-value store.void
putMetadataForTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, byte[] meta)
Records the specified metadata for a given table.void
putMetadataForTables(Map<com.palantir.atlasdb.keyvalue.api.TableReference,byte[]> tableRefToMetadata)
For each specified table records the respective metadata.void
putUnlessExists(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]> values)
Puts values into the key-value store.void
putWithTimestamps(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.google.common.collect.Multimap<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.Value> values)
Puts values into the key-value store with individually specified timestamps.void
setOnce(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]> values)
boolean
sweepsEntriesInStrictlyNonDecreasingFashion()
void
truncateTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef)
Truncate a table in the key-value store.void
truncateTables(Set<com.palantir.atlasdb.keyvalue.api.TableReference> tablesToTruncate)
Truncates tables in the key-value store.-
Methods inherited from class com.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
createFixedThreadPool, createThreadPool, createThreadPoolWithoutSpans, getDelegates, getLatestTimestamps, getMultiPutBatchSizeBytes, getRowsColumnRange, internalTableName
-
-
-
-
Method Detail
-
createForTesting
public static CassandraKeyValueService createForTesting(CassandraKeyValueServiceConfig config, com.palantir.refreshable.Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig)
-
create
public static CassandraKeyValueService create(com.palantir.atlasdb.util.MetricsManager metricsManager, CassandraKeyValueServiceConfig config, com.palantir.refreshable.Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, CassandraMutationTimestampProvider mutationTimestampProvider)
-
create
public static CassandraKeyValueService create(com.palantir.atlasdb.util.MetricsManager metricsManager, CassandraKeyValueServiceConfig config, com.palantir.refreshable.Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, CassandraMutationTimestampProvider mutationTimestampProvider, CassandraClientPool clientPool)
-
create
public static CassandraKeyValueService create(com.palantir.atlasdb.util.MetricsManager metricsManager, CassandraKeyValueServiceConfig config, com.palantir.refreshable.Refreshable<CassandraKeyValueServiceRuntimeConfig> runtimeConfig, CassandraMutationTimestampProvider mutationTimestampProvider, boolean initializeAsync)
-
isInitialized
public boolean isInitialized()
- Specified by:
isInitialized
in interfaceCassandraKeyValueService
- Specified by:
isInitialized
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
initialize
protected void initialize(boolean asyncInitialize)
-
getRows
public Map<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.Value> getRows(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<byte[]> rows, com.palantir.atlasdb.keyvalue.api.ColumnSelection selection, long startTs)
Gets values from the key-value store. Requires a quorum of Cassandra nodes to be reachable.- Specified by:
getRows
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to retrieve values from.rows
- set containing the rows to retrieve values for.selection
- specifies the set of columns to fetch.startTs
- specifies the maximum timestamp (exclusive) at which to retrieve each rows's value.- Returns:
- map of retrieved values. Values which do not exist (either because they were deleted or never created in the first place) are simply not returned.
- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable.IllegalArgumentException
- if any of the requests were invalid (e.g., attempting to retrieve values from a non-existent table).
-
get
public Map<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.Value> get(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,Long> timestampByCell)
Gets values from the key-value store. Requires a quorum of Cassandra nodes to be reachable.- Specified by:
get
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to retrieve values from.timestampByCell
- specifies, for each row, the maximum timestamp (exclusive) at which to retrieve that rows's value.- Returns:
- map of retrieved values. Values which do not exist (either because they were deleted or never created in the first place) are simply not returned.
- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable.IllegalArgumentException
- if any of the requests were invalid (e.g., attempting to retrieve values from a non-existent table).
-
getRowsColumnRange
public Map<byte[],com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator> getRowsColumnRange(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<byte[]> rows, com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection batchColumnRangeSelection, long timestamp)
Gets values from the key-value store for the specified rows and column range as separate iterators for each row. Requires a quorum of Cassandra nodes to be reachable, otherwise, the returned iterators will throw anAtlasDbDependencyException
when their methods are called.- Specified by:
getRowsColumnRange
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
getRowsColumnRange
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
- Parameters:
tableRef
- the name of the table to retrieve values from.rows
- set containing the rows to retrieve values for. Behavior is undefined ifrows
contains duplicates (as defined byArrays.equals(byte[], byte[])
).batchColumnRangeSelection
- specifies the column range and the per-row batchSize to fetch.timestamp
- specifies the maximum timestamp (exclusive) at which to retrieve each rows's value.- Returns:
- map of row names to
RowColumnRangeIterator
. EachRowColumnRangeIterator
can iterate over the values that are spanned by thebatchColumnRangeSelection
in increasing order by column name. - Throws:
IllegalArgumentException
- ifrows
contains duplicates.
-
put
public void put(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]> values, long timestamp)
Puts values into the key-value store. This call does not guarantee atomicity across cells. On failure, it is possible that some of the requests have succeeded (without having been rolled back). Similarly, concurrent batched requests may interleave.Requires a quorum of Cassandra nodes to be reachable.
- Specified by:
put
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to put values into.values
- map containing the key-value entries to put.timestamp
- must be non-negative and not equal toLong.MAX_VALUE
- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable.
-
putWithTimestamps
public void putWithTimestamps(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.google.common.collect.Multimap<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.Value> values)
Puts values into the key-value store with individually specified timestamps. This call does not guarantee atomicity across cells. On failure, it is possible that some of the requests have succeeded (without having been rolled back). Similarly, concurrent batched requests may interleave.Requires a quorum of Cassandra nodes to be reachable.
- Specified by:
putWithTimestamps
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to put values into.values
- map containing the key-value entries to put with non-negative timestamps less thanLong.MAX_VALUE
.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable.
-
getMultiPutBatchCount
protected int getMultiPutBatchCount()
- Overrides:
getMultiPutBatchCount
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
-
multiPut
public void multiPut(Map<com.palantir.atlasdb.keyvalue.api.TableReference,? extends Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]>> valuesByTable, long timestamp) throws com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException
Puts values into the key-value store. This call does not guarantee atomicity across cells. On failure, it is possible that some of the requests have succeeded (without having been rolled back). Similarly, concurrent batched requests may interleave.Overridden to batch more intelligently than the default implementation.
Requires a quorum of Cassandra nodes to be reachable.
- Specified by:
multiPut
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
valuesByTable
- map containing the key-value entries to put by table.timestamp
- must be non-negative and not equal toLong.MAX_VALUE
- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable.com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException
-
truncateTable
public void truncateTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef)
Truncate a table in the key-value store.This is preferred to dropping and re-adding a table, as live schema changes can be a complicated topic for distributed databases.
Requires all Cassandra nodes to be reachable.
- Specified by:
truncateTable
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to truncate.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if not all Cassandra nodes are reachable.RuntimeException
- if the table does not exist.
-
truncateTables
public void truncateTables(Set<com.palantir.atlasdb.keyvalue.api.TableReference> tablesToTruncate)
Truncates tables in the key-value store.This can be slightly faster than repeatedly truncating individual tables.
Requires all Cassandra nodes to be reachable.
- Specified by:
truncateTables
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
truncateTables
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
- Parameters:
tablesToTruncate
- set od tables to truncate.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if not all Cassandra nodes are reachable.RuntimeException
- if the table does not exist.
-
delete
public void delete(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.google.common.collect.Multimap<com.palantir.atlasdb.keyvalue.api.Cell,Long> keys)
Deletes values from the key-value store.Requires all Cassandra nodes to be up and available, otherwise throws an PalantirRuntimeException.
- Specified by:
delete
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to delete values from.keys
- map containing the keys to delete values for.- Throws:
com.palantir.common.exception.PalantirRuntimeException
- if not all hosts respond successfully.
-
getFirstBatchForRanges
@Idempotent public Map<com.palantir.atlasdb.keyvalue.api.RangeRequest,com.palantir.util.paging.TokenBackedBasicResultsPage<com.palantir.atlasdb.keyvalue.api.RowResult<com.palantir.atlasdb.keyvalue.api.Value>,byte[]>> getFirstBatchForRanges(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<com.palantir.atlasdb.keyvalue.api.RangeRequest> rangeRequests, long timestamp)
- Specified by:
getFirstBatchForRanges
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
getRange
@Idempotent public com.palantir.common.base.ClosableIterator<com.palantir.atlasdb.keyvalue.api.RowResult<com.palantir.atlasdb.keyvalue.api.Value>> getRange(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.palantir.atlasdb.keyvalue.api.RangeRequest rangeRequest, long timestamp)
For each row in the specified range, returns the most recent version strictly before timestamp. Requires a quorum of Cassandra nodes to be reachable. Remember to close anyClosableIterator
s you get in a finally block.- Specified by:
getRange
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
rangeRequest
- the range to load.timestamp
- specifies the maximum timestamp (exclusive) at which to retrieve each row's value.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable.
-
getRangeOfTimestamps
@Idempotent public com.palantir.common.base.ClosableIterator<com.palantir.atlasdb.keyvalue.api.RowResult<Set<Long>>> getRangeOfTimestamps(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.palantir.atlasdb.keyvalue.api.RangeRequest rangeRequest, long timestamp)
Gets timestamp values from the key-value store. For each row, this returns all associated timestamps < given_ts.This method has stronger consistency guarantees than regular read requests. This must return all timestamps stored anywhere in the system (because of sweep). Unless all nodes are up and available, this method will throw an InsufficientConsistencyException.
- Specified by:
getRangeOfTimestamps
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to read from.rangeRequest
- the range to load.timestamp
- the maximum timestamp to load.- Throws:
com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException
- if not all hosts respond successfully.
-
getCandidateCellsForSweeping
public com.palantir.common.base.ClosableIterator<List<com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping>> getCandidateCellsForSweeping(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.palantir.atlasdb.keyvalue.api.CandidateCellForSweepingRequest request)
- Specified by:
getCandidateCellsForSweeping
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
getRowKeysInRange
public List<byte[]> getRowKeysInRange(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, byte[] startRow, byte[] endRow, int maxResults)
Returns a sorted list of row keys in the specified range; seeKeyValueService.getRowKeysInRange(TableReference, byte[], byte[], int)
. Implementation specific: this method specifically does not read any of the columns and can therefore be used in the presence of wide rows. However, as a side-effect, it may return row where the row only contains Cassandra tombstones.- Specified by:
getRowKeysInRange
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
dropTable
public void dropTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef)
Drop the table, and also delete its table metadata. Requires a quorum of Cassandra nodes to be reachable.- Specified by:
dropTable
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to drop.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable, or the cluster cannot come to an agreement on schema versions. Note that this method is not atomic: if quorum is lost during its execution or Cassandra nodes fail to settle on a schema version after the Cassandra schema is mutated, we may drop the tables, but fail to to persist the changes to the _metadata table.com.google.common.util.concurrent.UncheckedExecutionException
- if there are multiple schema mutation lock tables.
-
dropTables
public void dropTables(Set<com.palantir.atlasdb.keyvalue.api.TableReference> tablesToDrop)
Drop the tables, and also delete their table metadata. Requires a quorum of Cassandra nodes to be reachable.Main gains here vs. dropTable: - problems excepting, we will basically be serializing a rapid series of schema changes through a single host checked out from the client pool, so reduced chance of schema disagreement issues - client-side in-memory lock to prevent misbehaving callers from shooting themselves in the foot - one less round trip
- Specified by:
dropTables
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
dropTables
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
- Parameters:
tablesToDrop
- the set of tables to drop.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable, or the cluster cannot come to an agreement on schema versions. Note that this method is not atomic: if quorum is lost during its execution or Cassandra nodes fail to settle on a schema version after the Cassandra schema is mutated, we may drop the tables, but fail to to persist the changes to the _metadata table.com.google.common.util.concurrent.UncheckedExecutionException
- if there are multiple schema mutation lock tables.
-
createTable
public void createTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, byte[] metadata)
Creates a table with the specified name. If the table already exists, no action is performed (the table is left in its current state). Requires a quorum of Cassandra nodes to be reachable.- Specified by:
createTable
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to create.metadata
- the metadata of the table to create.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable, or the cluster cannot come to an agreement on schema versions. Note that this method is not atomic: if quorum is lost during its execution or Cassandra nodes fail to settle on a schema version after the Cassandra schema is mutated, we may fail to persist the changes to the _metadata table.com.google.common.util.concurrent.UncheckedExecutionException
- if there are multiple schema mutation lock tables.
-
createTables
public void createTables(Map<com.palantir.atlasdb.keyvalue.api.TableReference,byte[]> tablesToMetadata)
Creates a table with the specified name. If the table already exists, no action is performed (the table is left in its current state).Requires a quorum of Cassandra nodes to be up and available.
Main gains here vs. createTable: - problems excepting, we will basically be serializing a rapid series of schema changes through a single host checked out from the client pool, so reduced chance of schema disagreement issues - client-side in-memory lock to prevent misbehaving callers from shooting themselves in the foot - one less round trip
createTables(existingTable, newMetadata) can perform a metadata-only update. Additionally, it is possible that this metadata-only update performs a schema mutation by altering the CFDef (e. g., user changes metadata of existing table to have new compression block size). This does not require the schema mutation lock, as it does not alter the CfId
- Specified by:
createTables
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
createTables
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
- Parameters:
tablesToMetadata
- a mapping of names of tables to create to their respective metadata.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable, or the cluster cannot come to an agreement on schema versions. Note that this method is not atomic: if quorum is lost during its execution or Cassandra nodes fail to settle on a schema version after the Cassandra schema is mutated, we may fail to persist the changes to the _metadata table.com.google.common.util.concurrent.UncheckedExecutionException
- if there are multiple schema mutation lock tables.
-
getAllTableNames
public Set<com.palantir.atlasdb.keyvalue.api.TableReference> getAllTableNames()
Return the list of tables stored in this key value service. Requires a quorum of Cassandra nodes to be reachable and agree on schema versions.This will not contain the names of any hidden tables (e. g., the _metadata table).
- Specified by:
getAllTableNames
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Returns:
- a set of TableReferences (table names) for all the visible tables
- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable, or the cluster cannot come to an agreement on schema versions.
-
getMetadataForTable
public byte[] getMetadataForTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef)
Gets the metadata for a given table. Do not use this method to see if a table exists as it can return false positives. Requires a quorum of Cassandra nodes to be reachable.- Specified by:
getMetadataForTable
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to get metadata for.- Returns:
- a byte array representing the metadata for the table. Array is empty if no table
with the given name exists. Consider
TableMetadata.BYTES_HYDRATOR
for hydrating. - Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable.
-
getMetadataForTables
public Map<com.palantir.atlasdb.keyvalue.api.TableReference,byte[]> getMetadataForTables()
Gets the metadata for all non-hidden tables. Requires a quorum of Cassandra nodes to be reachable.- Specified by:
getMetadataForTables
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
getMetadataForTables
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
- Returns:
- a mapping of table names to their respective metadata in form of a byte array. Consider
TableMetadata.BYTES_HYDRATOR
for hydrating. - Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are available.
-
putMetadataForTable
public void putMetadataForTable(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, byte[] meta)
Records the specified metadata for a given table. Requires a quorum of Cassandra nodes to be reachable.- Specified by:
putMetadataForTable
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to record metadata for.meta
- a byte array representing the metadata to record.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable, or the cluster cannot come to an agreement on schema versions. Note that this method is not atomic: if quorum is lost during its execution or Cassandra nodes fail to settle on a schema version after the Cassandra schema is mutated, we may fail to persist the changes to the _metadata table.
-
putMetadataForTables
public void putMetadataForTables(Map<com.palantir.atlasdb.keyvalue.api.TableReference,byte[]> tableRefToMetadata)
For each specified table records the respective metadata. Requires a quorum of Cassandra nodes to be reachable.- Specified by:
putMetadataForTables
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
putMetadataForTables
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
- Parameters:
tableRefToMetadata
- a mapping from each table's name to the respective byte array representing the metadata to record.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable, or the cluster cannot come to an agreement on schema versions. Note that this method is not atomic: if quorum is lost during its execution or Cassandra nodes fail to settle on a schema version after the Cassandra schema is mutated, we may fail to persist the changes to the _metadata table.
-
deleteRange
public void deleteRange(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, com.palantir.atlasdb.keyvalue.api.RangeRequest range)
- Specified by:
deleteRange
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
deleteRange
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
-
deleteRows
public void deleteRows(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<byte[]> rows)
- Specified by:
deleteRows
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
deleteRows
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
-
deleteAllTimestamps
public void deleteAllTimestamps(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.TimestampRangeDelete> deletes)
- Specified by:
deleteAllTimestamps
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
close
public void close()
Performs non-destructive cleanup when the KVS is no longer needed.- Specified by:
close
in interfacecom.palantir.atlasdb.keyvalue.api.AsyncKeyValueService
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
close
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
-
addGarbageCollectionSentinelValues
public void addGarbageCollectionSentinelValues(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Iterable<com.palantir.atlasdb.keyvalue.api.Cell> cells)
Adds a value with timestamp = Value.INVALID_VALUE_TIMESTAMP to each of the given cells. If a value already exists at that time stamp, nothing is written for that cell.Requires a quorum of Cassandra nodes to be reachable.
- Specified by:
addGarbageCollectionSentinelValues
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to add the value to.cells
- a set of cells to store the values in.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable.
-
getAllTimestamps
public com.google.common.collect.Multimap<com.palantir.atlasdb.keyvalue.api.Cell,Long> getAllTimestamps(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Set<com.palantir.atlasdb.keyvalue.api.Cell> cells, long ts)
Gets timestamp values from the key-value store. For each cell, this returns all associated timestamps < given_ts.This method has stronger consistency guarantees than regular read requests. This must return all timestamps stored anywhere in the system (because of sweep). Unless all nodes are up and available, this method will throw a PalantirRuntimeException.
- Specified by:
getAllTimestamps
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to retrieve timestamps from.cells
- set containg cells to retrieve timestamps for.ts
- maximum timestamp to get (exclusive).- Returns:
- multimap of timestamps by cell
- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if not all Cassandra nodes are reachable.
-
putUnlessExists
public void putUnlessExists(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]> values) throws com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException
Puts values into the key-value store. This call does not guarantee atomicity across cells. On failure, it is possible that some of the requests will have succeeded (without having been rolled back). Similarly, concurrent batched requests may interleave. However, concurrent writes to the same Cell will not both report success. One of them will throwKeyAlreadyExistsException
.Requires a quorum of Cassandra nodes to be reachable.
- Specified by:
putUnlessExists
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
tableRef
- the name of the table to put values into.values
- map containing the key-value entries to put.- Throws:
com.palantir.common.exception.AtlasDbDependencyException
- if fewer than a quorum of Cassandra nodes are reachable.com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException
- if you are putting a Cell with the same timestamp as one that already exists.
-
setOnce
public void setOnce(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]> values)
- Specified by:
setOnce
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
partitionPerRow
public static Map<com.google.protobuf.ByteString,Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]>> partitionPerRow(Map<com.palantir.atlasdb.keyvalue.api.Cell,byte[]> values)
-
getCheckAndSetCompatibility
public com.palantir.atlasdb.keyvalue.api.CheckAndSetCompatibility getCheckAndSetCompatibility()
- Specified by:
getCheckAndSetCompatibility
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Overrides:
getCheckAndSetCompatibility
in classcom.palantir.atlasdb.keyvalue.impl.AbstractKeyValueService
-
checkAndSet
public void checkAndSet(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest request) throws com.palantir.atlasdb.keyvalue.api.CheckAndSetException
Performs a check-and-set into the key-value store. Please seeCheckAndSetRequest
for information about how to create this request, andKeyValueService
for more detailed documentation.Does not require all Cassandra nodes to be up and available, works as long as quorum is achieved.
- Specified by:
checkAndSet
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
request
- the request, including table, cell, old value and new value.- Throws:
com.palantir.atlasdb.keyvalue.api.CheckAndSetException
- if the stored value for the cell was not as expected.
-
multiCheckAndSet
public void multiCheckAndSet(com.palantir.atlasdb.keyvalue.api.MultiCheckAndSetRequest request) throws com.palantir.atlasdb.keyvalue.api.MultiCheckAndSetException
Performs a check-and-set for multiple cells in a row into the key-value store. Please seeMultiCheckAndSetRequest
for information about how to create this request, andKeyValueService
for more detailed documentation. If the call completes successfully, then you know that the old cells initially had the values you expected. In this case, you can be sure that all your cells have been updated to their new values. If the old cells initially did not have the values you expected, none of the cells will be updated andMultiCheckAndSetException
will be thrown. Reads concurrent with this operation will not see a partial update. Another thing to note is that the check operation will **only be performed on values of cells that are declared in the set of expected values** i.e. the check operation DOES NOT take updates into account. Does not require all Cassandra nodes to be up and available, works as long as quorum is achieved.- Specified by:
multiCheckAndSet
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
- Parameters:
request
- the request, including table, rowName, old values and new values.- Throws:
com.palantir.atlasdb.keyvalue.api.MultiCheckAndSetException
- if the stored values for the cells were not as expected.
-
compactInternally
public void compactInternally(com.palantir.atlasdb.keyvalue.api.TableReference tableRef)
- Specified by:
compactInternally
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
getClusterAvailabilityStatus
public com.palantir.atlasdb.keyvalue.api.ClusterAvailabilityStatus getClusterAvailabilityStatus()
- Specified by:
getClusterAvailabilityStatus
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
sweepsEntriesInStrictlyNonDecreasingFashion
public boolean sweepsEntriesInStrictlyNonDecreasingFashion()
- Specified by:
sweepsEntriesInStrictlyNonDecreasingFashion
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
getClientPool
public CassandraClientPool getClientPool()
- Specified by:
getClientPool
in interfaceCassandraKeyValueService
-
getTracingQueryRunner
public TracingQueryRunner getTracingQueryRunner()
- Specified by:
getTracingQueryRunner
in interfaceCassandraKeyValueService
-
getCassandraTables
public com.palantir.atlasdb.keyvalue.cassandra.CassandraTables getCassandraTables()
- Specified by:
getCassandraTables
in interfaceCassandraKeyValueService
-
performanceIsSensitiveToTombstones
public boolean performanceIsSensitiveToTombstones()
- Specified by:
performanceIsSensitiveToTombstones
in interfacecom.palantir.atlasdb.keyvalue.api.KeyValueService
-
getAsync
public com.google.common.util.concurrent.ListenableFuture<Map<com.palantir.atlasdb.keyvalue.api.Cell,com.palantir.atlasdb.keyvalue.api.Value>> getAsync(com.palantir.atlasdb.keyvalue.api.TableReference tableRef, Map<com.palantir.atlasdb.keyvalue.api.Cell,Long> timestampByCell)
Asynchronously gets values from the cassandra key-value store.- Specified by:
getAsync
in interfacecom.palantir.atlasdb.keyvalue.api.AsyncKeyValueService
- Parameters:
tableRef
- the name of the table to retrieve values from.timestampByCell
- specifies, for each row, the maximum timestamp (exclusive) at which to retrieve that rows's value.- Returns:
- listenable future map of retrieved values. Values which do not exist (either because they were deleted or never created in the first place) are simply not returned.
-
-