public interface DistributedStorage
extends java.lang.AutoCloseable
Operation commands such as Get,
Scan, Put and Delete, which specify the location of storage entries and
optional information.
The data model behind this abstraction is a multi-dimensional map based on key-value data model. A logical record (or entry) is composed of partition key, clustering key and a set of columns. The column value is uniquely mapped by a primary key composed of partition key, clustering key and column name as described in the following scheme.
(partition key, clustering key, column name) => column value
The physical data model is a multi-dimensional map distributed to multiple nodes by key-based hash partitioning. Entries are assumed to be hash-partitioned by partition key (even though an underlying implementation supports range partitioning). Records with the same partition key, which we call a partition, are sorted by clustering key. Thus, each entry in the storage can be located with the partition key and the clustering key, which we call it primary key. Both a partition key and a clustering key also comprise a list of values. Having clustering key is optional, so in that case, primary key is composed of only partition key.
StorageFactory factory = StorageFactory.create(configFilePath);
DistributedStorage storage = factory.getStorage();
// Inserts a new entry which has the primary key value 0 to the storage.
// Assumes that the namespace name and the table name are NAMESPACE and TABLE respectively, and
// the primary key is composed of a integer column named COL_NAME.
Put put =
Put.newBuilder()
.namespace(NAMESPACE)
.table(TABLE)
.partitionKey(Key.ofInt(COL_NAME, 0))
...
.build();
storage.put(put);
// Retrieves the entry from the storage.
Get get =
Get.newBuilder()
.namespace(NAMESPACE)
.table(TABLE)
.partitionKey(Key.ofInt(COL_NAME, 0))
.build();
Optional<Result> result = storage.get(get);
// Deletes an entry which has the primary key value 1.
Delete delete =
Delete.newBuilder()
.namespace(NAMESPACE)
.table(TABLE)
.partitionKey(Key.ofInt(COL_NAME, 0))
.build();
storage.delete(delete);
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes connections to the cluster.
|
void |
delete(Delete delete)
Deletes an entry from the underlying storage with the specified
Delete command. |
void |
delete(java.util.List<Delete> deletes)
Deletes entries from the underlying storage with the specified list of
Delete commands. |
java.util.Optional<Result> |
get(Get get)
Retrieves a result from the underlying storage with the specified
Get command with a
primary key and returns the result. |
java.util.Optional<java.lang.String> |
getNamespace()
Deprecated.
As of release 3.6.0. Will be removed in release 5.0.0
|
java.util.Optional<java.lang.String> |
getTable()
Deprecated.
As of release 3.6.0. Will be removed in release 5.0.0
|
void |
mutate(java.util.List<? extends Mutation> mutations)
Mutates entries of the underlying storage with the specified list of
Mutation commands. |
void |
put(java.util.List<Put> puts)
Inserts multiple entries into or updates multiple entries within the same partition to the
underlying storage with the specified list of
Put commands. |
void |
put(Put put)
Inserts an entry into or updates an entry to the underlying storage with the specified
Put command. |
Scanner |
scan(Scan scan)
Retrieves results from the underlying storage with the specified
Scan or ScanAll or ScanWithIndex command and returns Scanner to iterate the results. |
void |
with(java.lang.String namespace,
java.lang.String tableName)
Deprecated.
As of release 3.6.0. Will be removed in release 5.0.0
|
void |
withNamespace(java.lang.String namespace)
Deprecated.
As of release 3.6.0. Will be removed in release 5.0.0
|
void |
withTable(java.lang.String tableName)
Deprecated.
As of release 3.6.0. Will be removed in release 5.0.0
|
@Deprecated
void with(java.lang.String namespace,
java.lang.String tableName)
namespace - default namespace to operate fortableName - default table name to operate for@Deprecated void withNamespace(java.lang.String namespace)
namespace - default namespace to operate for@Deprecated java.util.Optional<java.lang.String> getNamespace()
Optional with the namespace@Deprecated void withTable(java.lang.String tableName)
tableName - default table name to operate for@Deprecated java.util.Optional<java.lang.String> getTable()
Optional with the table namejava.util.Optional<Result> get(Get get) throws ExecutionException
Get command with a
primary key and returns the result.get - a Get commandOptional with the returned resultExecutionException - if the operation failsScanner scan(Scan scan) throws ExecutionException
Scan or ScanAll or ScanWithIndex command and returns Scanner to iterate the results.
Scan : by specifying a partition key, it will return results within the
partition. Results can be filtered by specifying a range of clustering keys.
ScanAll : for a given table, it will return all its records even if they span
several partitions.
ScanWithIndex : by specifying an index key, it will return results within the
index.
scan - a Scan or ScanAll commandScanner to iterate resultsExecutionException - if the operation failsvoid put(Put put) throws ExecutionException
Put command.put - a Put commandExecutionException - if the operation failsvoid put(java.util.List<Put> puts) throws ExecutionException
Put commands. When entries spanning
multiple partitions are inserted, this will throw MultiPartitionException.puts - a list of Put commandsExecutionException - if the operation failsvoid delete(Delete delete) throws ExecutionException
Delete command.delete - a Delete commandExecutionException - if the operation failsvoid delete(java.util.List<Delete> deletes) throws ExecutionException
Delete commands.deletes - a list of Delete commandsExecutionException - if the operation failsvoid mutate(java.util.List<? extends Mutation> mutations) throws ExecutionException
Mutation commands.mutations - a list of Mutation commandsExecutionException - if the operation failsvoid close()
close in interface java.lang.AutoCloseable