M
- type used to represent stored records@API(value=MAINTAINED) public class FDBTypedRecordStore<M extends Message> extends Object implements FDBRecordStoreBase<M>
FDBRecordStore
,
FDBRecordStoreBase
Modifier and Type | Class and Description |
---|---|
static class |
FDBTypedRecordStore.Builder<M extends Message>
A builder for
FDBTypedRecordStore . |
FDBRecordStoreBase.BaseBuilder<M extends Message,R extends FDBRecordStoreBase<M>>, FDBRecordStoreBase.PipelineSizer, FDBRecordStoreBase.RecordExistenceCheck, FDBRecordStoreBase.StoreExistenceCheck, FDBRecordStoreBase.UserVersionChecker, FDBRecordStoreBase.VersionstampSaveBehavior
Modifier | Constructor and Description |
---|---|
protected |
FDBTypedRecordStore(FDBRecordStore untypedStore,
RecordSerializer<M> typedSerializer) |
Modifier and Type | Method and Description |
---|---|
void |
addRecordReadConflict(Tuple primaryKey)
Add a read conflict as if one had read the record with the given primary key.
|
void |
addRecordWriteConflict(Tuple primaryKey)
Add a write conflict as if one had modified the record with the given primary key.
|
FDBTypedRecordStore.Builder<M> |
asBuilder() |
CompletableFuture<Integer> |
countRecords(Tuple low,
Tuple high,
EndpointType lowEndpoint,
EndpointType highEndpoint,
byte[] continuation,
ScanProperties scanProperties)
Count the number of records in the database in a range.
|
void |
deleteAllRecords()
Delete all the data in the record store.
|
CompletableFuture<Boolean> |
deleteRecordAsync(Tuple primaryKey)
Async version of
FDBRecordStoreBase.deleteRecord(com.apple.foundationdb.tuple.Tuple) . |
CompletableFuture<Void> |
deleteRecordsWhereAsync(QueryComponent component)
|
CompletableFuture<Tuple> |
evaluateAggregateFunction(List<String> recordTypeNames,
IndexAggregateFunction aggregateFunction,
TupleRange range,
IsolationLevel isolationLevel)
Evaluate an
IndexAggregateFunction against a range of the store. |
<T> CompletableFuture<T> |
evaluateIndexRecordFunction(EvaluationContext evaluationContext,
IndexRecordFunction<T> function,
FDBRecord<M> record)
Evaluate a
IndexRecordFunction against a record. |
<T> CompletableFuture<T> |
evaluateStoreFunction(EvaluationContext evaluationContext,
StoreRecordFunction<T> function,
FDBRecord<M> record)
Evaluate a
StoreRecordFunction against a record. |
FDBRecordContext |
getContext()
Get the record context (transaction) to use for the record store.
|
FDBRecordStoreBase.PipelineSizer |
getPipelineSizer()
Get the function for computing the number of elements to allow in the asynchronous pipeline for an operation of the given
type.
|
RecordMetaData |
getRecordMetaData()
Provide an instance of
RecordMetaData . |
RecordSerializer<M> |
getSerializer()
Get the serializer used to convert records into byte arrays.
|
CompletableFuture<Long> |
getSnapshotRecordCount(KeyExpression key,
Key.Evaluated value)
Get the number of records in a portion of the record store determined by a group key expression.
|
CompletableFuture<Long> |
getSnapshotRecordCountForRecordType(String recordTypeName)
Get the number of records in the record store of the given record type.
|
SubspaceProvider |
getSubspaceProvider()
Get the subspace provider.
|
FDBRecordStore |
getUntypedRecordStore()
Get the untyped record store associated with this possibly typed store.
|
CompletableFuture<FDBStoredRecord<M>> |
loadRecordInternal(Tuple primaryKey,
ExecuteState executeState,
boolean snapshot) |
static <M extends Message> |
newBuilder()
Create a new typed record store builder.
|
static <M extends Message,U extends Message,B extends Message.Builder> |
newBuilder(Descriptors.FieldDescriptor fieldDescriptor,
Supplier<B> builderSupplier,
Predicate<U> tester,
Function<U,M> getter,
BiConsumer<B,M> setter)
Create a new typed record store builder.
|
static <M extends Message,U extends Message,B extends Message.Builder> |
newBuilder(Descriptors.FileDescriptor fileDescriptor,
Descriptors.FieldDescriptor fieldDescriptor,
Supplier<B> builderSupplier,
Predicate<U> tester,
Function<U,M> getter,
BiConsumer<B,M> setter)
Create a new typed record store builder.
|
static <M extends Message> |
newBuilder(RecordSerializer<M> serializer)
Create a new typed record store builder.
|
RecordQueryPlan |
planQuery(RecordQuery query)
Plan a query.
|
CompletableFuture<Void> |
preloadRecordAsync(Tuple primaryKey)
Get record into FDB RYW cache.
|
CompletableFuture<Boolean> |
recordExistsAsync(Tuple primaryKey,
IsolationLevel isolationLevel)
Check if a record exists in the record store with the given primary key.
|
CompletableFuture<Void> |
resolveUniquenessViolation(Index index,
Tuple valueKey,
Tuple primaryKey)
Removes all of the records that have the given value set as their index value (and are thus causing a
uniqueness violation) except for the one that has the given primary key (if the key is not
null ). |
CompletableFuture<FDBStoredRecord<M>> |
saveRecordAsync(M record,
FDBRecordStoreBase.RecordExistenceCheck existenceCheck,
FDBRecordVersion version,
FDBRecordStoreBase.VersionstampSaveBehavior behavior)
|
RecordCursor<IndexEntry> |
scanIndex(Index index,
IndexScanType scanType,
TupleRange range,
byte[] continuation,
ScanProperties scanProperties)
Scan the entries in an index.
|
RecordCursor<FDBStoredRecord<M>> |
scanRecords(Tuple low,
Tuple high,
EndpointType lowEndpoint,
EndpointType highEndpoint,
byte[] continuation,
ScanProperties scanProperties)
Scan the records in the database in a range.
|
RecordCursor<RecordIndexUniquenessViolation> |
scanUniquenessViolations(Index index,
TupleRange range,
byte[] continuation,
ScanProperties scanProperties)
Scan the list of uniqueness violations identified for an index.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
countRecords, coveredIndexQueriedRecord, deleteRecord, deleteRecordsWhere, deleteRecordsWhere, deleteRecordsWhereAsync, evaluateAggregateFunction, evaluateAggregateFunction, evaluateRecordFunction, evaluateRecordFunction, evaluateStoreFunction, executeQuery, executeQuery, executeQuery, executeQuery, fetchIndexRecords, fetchIndexRecords, fetchIndexRecords, fetchIndexRecords, getExecutor, getPipelineSize, getSnapshotRecordCount, getSnapshotRecordUpdateCount, getSnapshotRecordUpdateCount, getTimer, getTypedRecordStore, hasIndexEntryRecord, hasIndexEntryRecord, indexEntryKey, indexEntryPrimaryKey, insertRecord, insertRecordAsync, loadIndexEntryRecord, loadIndexEntryRecord, loadIndexEntryRecord, loadIndexEntryRecord, loadRecord, loadRecord, loadRecordAsync, loadRecordAsync, queriedRecord, queriedRecord, recordExists, recordExists, recordExistsAsync, resolveUniquenessViolation, saveRecord, saveRecord, saveRecord, saveRecord, saveRecord, saveRecordAsync, saveRecordAsync, saveRecordAsync, saveRecordAsync, scanIndex, scanIndexRecords, scanIndexRecords, scanIndexRecords, scanIndexRecords, scanIndexRecords, scanIndexRecords, scanIndexRecordsBetween, scanIndexRecordsEqual, scanRecords, scanRecords, scanUniquenessViolations, scanUniquenessViolations, scanUniquenessViolations, scanUniquenessViolations, scanUniquenessViolations, scanUniquenessViolations, scanUniquenessViolations, uniquenessViolationKey, updateRecord, updateRecordAsync
protected FDBTypedRecordStore(@Nonnull FDBRecordStore untypedStore, @Nonnull RecordSerializer<M> typedSerializer)
public FDBRecordStore getUntypedRecordStore()
FDBRecordStoreBase
getUntypedRecordStore
in interface FDBRecordStoreBase<M extends Message>
@Nonnull public RecordMetaData getRecordMetaData()
RecordMetaDataProvider
RecordMetaData
.
Implementors should assume that this method will be called frequently, so it may
be necessary to cache the result if generating the RecordMetaData
is expensive.getRecordMetaData
in interface RecordMetaDataProvider
RecordMetaData
@Nonnull public FDBRecordContext getContext()
FDBRecordStoreBase
getContext
in interface FDBRecordStoreBase<M extends Message>
@Nullable public SubspaceProvider getSubspaceProvider()
FDBRecordStoreBase
getSubspaceProvider
in interface FDBRecordStoreBase<M extends Message>
@Nonnull public RecordSerializer<M> getSerializer()
FDBRecordStoreBase
getSerializer
in interface FDBRecordStoreBase<M extends Message>
@Nonnull public CompletableFuture<FDBStoredRecord<M>> saveRecordAsync(@Nonnull M record, @Nonnull FDBRecordStoreBase.RecordExistenceCheck existenceCheck, @Nullable FDBRecordVersion version, @Nonnull FDBRecordStoreBase.VersionstampSaveBehavior behavior)
FDBRecordStoreBase
FDBRecordStoreBase.saveRecord(Message, RecordExistenceCheck, FDBRecordVersion, VersionstampSaveBehavior)
.saveRecordAsync
in interface FDBRecordStoreBase<M extends Message>
record
- the record to saveexistenceCheck
- when to throw an exception if a record with the same primary key does or does not already existversion
- the associated record versionbehavior
- the save behavior w.r.t. the given version
@Nonnull public CompletableFuture<FDBStoredRecord<M>> loadRecordInternal(@Nonnull Tuple primaryKey, @Nonnull ExecuteState executeState, boolean snapshot)
loadRecordInternal
in interface FDBRecordStoreBase<M extends Message>
@Nonnull public CompletableFuture<Void> preloadRecordAsync(@Nonnull Tuple primaryKey)
FDBRecordStoreBase
preloadRecordAsync
in interface FDBRecordStoreBase<M extends Message>
primaryKey
- the primary key for the record to retrievenull
when the record is preloaded@Nonnull public CompletableFuture<Boolean> recordExistsAsync(@Nonnull Tuple primaryKey, @Nonnull IsolationLevel isolationLevel)
FDBRecordStoreBase
null
as it does not have to deserialize the record, though the record's contents are still read from the
database and sent over the network.recordExistsAsync
in interface FDBRecordStoreBase<M extends Message>
primaryKey
- the primary key of the recordisolationLevel
- the isolation level to use when readingtrue
if some record in record store has that primary key and
false
otherwisepublic void addRecordReadConflict(@Nonnull Tuple primaryKey)
FDBRecordStoreBase
FDBExceptions.FDBStoreTransactionConflictException
)
if a concurrent transaction modifies the record with the provided primary key. This call however does not require
performing any reads against the database, so it is faster and cheaper to perform than a real read. Note also that
read-only operations are not checked for conflicts, so if this method is called, but the transaction performs
no mutations, the transaction will never be failed with the above exception. Note also that this does not
check that a record with this primary key actually exists in the database.
One use case is that this can be used to promote a read from IsolationLevel.SNAPSHOT
to
IsolationLevel.SERIALIZABLE
. For example, if one performs a query at IsolationLevel.SNAPSHOT
and
then uses a subset of the records to determine a few other writes, then one can add conflicts to only
the records actually used.
This method should be used with care and is advised only for those users who need extra control over conflict ranges.
addRecordReadConflict
in interface FDBRecordStoreBase<M extends Message>
primaryKey
- the primary key of the record to add a read conflict onTransaction.addReadConflictRange(byte[], byte[])
public void addRecordWriteConflict(@Nonnull Tuple primaryKey)
FDBRecordStoreBase
FDBExceptions.FDBStoreTransactionConflictException
)
if they read the record with the provided primary key. This call however does not require performing any writes
against the database, so it is faster and cheaper to perform than a real write. Note that this does not check
if a record with this primary key actually exists in the database, and it does not update any indexes associated
with the record. In this way, it is identical (in terms of conflicts) with overwriting the given record with itself,
though it will not induce any disk I/O or cause any watches
on the modified keys to fire.
This method should be used with care and is advised only for those users who need extra control over conflict ranges.
addRecordWriteConflict
in interface FDBRecordStoreBase<M extends Message>
primaryKey
- the primary key of the record to add a write conflict onTransaction.addWriteConflictRange(byte[], byte[])
@Nonnull public RecordCursor<FDBStoredRecord<M>> scanRecords(@Nullable Tuple low, @Nullable Tuple high, @Nonnull EndpointType lowEndpoint, @Nonnull EndpointType highEndpoint, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
FDBRecordStoreBase
scanRecords
in interface FDBRecordStoreBase<M extends Message>
low
- low point of scan rangehigh
- high point of scan pointlowEndpoint
- whether low point is inclusive or exclusivehighEndpoint
- whether high point is inclusive or exclusivecontinuation
- any continuation from a previous scanscanProperties
- skip, limit and other scan properties@Nonnull public CompletableFuture<Integer> countRecords(@Nullable Tuple low, @Nullable Tuple high, @Nonnull EndpointType lowEndpoint, @Nonnull EndpointType highEndpoint, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
FDBRecordStoreBase
countRecords
in interface FDBRecordStoreBase<M extends Message>
low
- low point of scan rangehigh
- high point of scan pointlowEndpoint
- whether low point is inclusive or exclusivehighEndpoint
- whether high point is inclusive or exclusivecontinuation
- any continuation from a previous scanscanProperties
- skip, limit and other scan properties@Nonnull public RecordCursor<IndexEntry> scanIndex(@Nonnull Index index, @Nonnull IndexScanType scanType, @Nonnull TupleRange range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
FDBRecordStoreBase
scanIndex
in interface FDBRecordStoreBase<M extends Message>
index
- the index to scanscanType
- the type of scan to performrange
- range to scancontinuation
- any continuation from a previous scanscanProperties
- skip, limit and other scan properties@Nonnull public RecordCursor<RecordIndexUniquenessViolation> scanUniquenessViolations(@Nonnull Index index, @Nonnull TupleRange range, @Nullable byte[] continuation, @Nonnull ScanProperties scanProperties)
FDBRecordStoreBase
Because of how the data are stored, each primary key that is part of a uniqueness violation will appear at most once for each index key that is causing a violation. The associated existing key is going to be one of the other keys, but it might not be the only one. This means that the total number of violations per index key is capped at the number of records in the store (rather than the square), but it also means that the existing key data is of limited help.
scanUniquenessViolations
in interface FDBRecordStoreBase<M extends Message>
index
- the index to scan the uniqueness violations ofrange
- the range of tuples to include in the scancontinuation
- any continuation from a previous scanscanProperties
- skip, limit and other scan properties@Nonnull public CompletableFuture<Void> resolveUniquenessViolation(@Nonnull Index index, @Nonnull Tuple valueKey, @Nullable Tuple primaryKey)
FDBRecordStoreBase
null
).
It also cleans up the set of uniqueness violations so that none of the remaining entries will
be associated with the given value key.resolveUniquenessViolation
in interface FDBRecordStoreBase<M extends Message>
index
- the index to resolve uniqueness violations forvalueKey
- the value of the index that is being removedprimaryKey
- the primary key of the record that should remain (or null
to remove all of them)@Nonnull public CompletableFuture<Boolean> deleteRecordAsync(@Nonnull Tuple primaryKey)
FDBRecordStoreBase
FDBRecordStoreBase.deleteRecord(com.apple.foundationdb.tuple.Tuple)
.deleteRecordAsync
in interface FDBRecordStoreBase<M extends Message>
primaryKey
- the primary key of the record to deletetrue
if the record was present to be deletedpublic void deleteAllRecords()
FDBRecordStoreBase
Everything except the store header and index state information is cleared from the database.
This is is an efficient operation as all data are contiguous.
This means that any disabled or write-only
index will remain in its disabled or write-only state after all of the data are cleared. If one also wants
to reset all index states, one can call FDBRecordStore.rebuildAllIndexes()
, which should complete
quickly on an empty record store. If one wants to remove the record store entirely (including the store
header and all index states), one should call FDBRecordStore.deleteStore(FDBRecordContext, KeySpacePath)
instead of this method.
Note that, at the moment, this operation also has the side effect of resetting
MAX_EVER
and
MIN_EVER
indexes.
See: Issue #398.
deleteAllRecords
in interface FDBRecordStoreBase<M extends Message>
FDBRecordStore.deleteStore(FDBRecordContext, KeySpacePath)
,
FDBRecordStore.deleteStore(FDBRecordContext, Subspace)
@Nonnull public CompletableFuture<Void> deleteRecordsWhereAsync(@Nonnull QueryComponent component)
FDBRecordStoreBase
FDBRecordStoreBase.deleteRecordsWhereAsync(com.apple.foundationdb.record.query.expressions.QueryComponent)
.deleteRecordsWhereAsync
in interface FDBRecordStoreBase<M extends Message>
component
- the query filter for records to delete efficiently@Nonnull public FDBRecordStoreBase.PipelineSizer getPipelineSizer()
FDBRecordStoreBase
getPipelineSizer
in interface FDBRecordStoreBase<M extends Message>
@Nonnull public CompletableFuture<Long> getSnapshotRecordCount(@Nonnull KeyExpression key, @Nonnull Key.Evaluated value)
FDBRecordStoreBase
COUNT
type index defined.getSnapshotRecordCount
in interface FDBRecordStoreBase<M extends Message>
key
- the grouping key expressionvalue
- the value of key
to match@Nonnull public CompletableFuture<Long> getSnapshotRecordCountForRecordType(@Nonnull String recordTypeName)
FDBRecordStoreBase
COUNT
index defined for it.getSnapshotRecordCountForRecordType
in interface FDBRecordStoreBase<M extends Message>
recordTypeName
- record type for which to count records@Nonnull public <T> CompletableFuture<T> evaluateIndexRecordFunction(@Nonnull EvaluationContext evaluationContext, @Nonnull IndexRecordFunction<T> function, @Nonnull FDBRecord<M> record)
FDBRecordStoreBase
IndexRecordFunction
against a record.evaluateIndexRecordFunction
in interface FDBRecordStoreBase<M extends Message>
T
- the type of the resultevaluationContext
- evaluation context containing parameter bindingsfunction
- the function to evaluaterecord
- the record to evaluate against@Nonnull public <T> CompletableFuture<T> evaluateStoreFunction(@Nonnull EvaluationContext evaluationContext, @Nonnull StoreRecordFunction<T> function, @Nonnull FDBRecord<M> record)
FDBRecordStoreBase
StoreRecordFunction
against a record.evaluateStoreFunction
in interface FDBRecordStoreBase<M extends Message>
T
- the type of the resultevaluationContext
- evaluation context containing parameter bindingsfunction
- the function to evaluaterecord
- the record to evaluate against@Nonnull public CompletableFuture<Tuple> evaluateAggregateFunction(@Nonnull List<String> recordTypeNames, @Nonnull IndexAggregateFunction aggregateFunction, @Nonnull TupleRange range, @Nonnull IsolationLevel isolationLevel)
FDBRecordStoreBase
IndexAggregateFunction
against a range of the store.evaluateAggregateFunction
in interface FDBRecordStoreBase<M extends Message>
recordTypeNames
- record types for which to find a matching indexaggregateFunction
- the function to evaluaterange
- the range of records (group) for which to evaluateisolationLevel
- whether to use snapshot reads@Nonnull public RecordQueryPlan planQuery(@Nonnull RecordQuery query)
FDBRecordStoreBase
planQuery
in interface FDBRecordStoreBase<M extends Message>
query
- the query to planRecordQueryPlanner.plan(com.apple.foundationdb.record.query.RecordQuery)
@Nonnull public static <M extends Message> FDBTypedRecordStore.Builder<M> newBuilder()
M
- generated Protobuf class for the record message type@Nonnull public static <M extends Message> FDBTypedRecordStore.Builder<M> newBuilder(@Nonnull RecordSerializer<M> serializer)
M
- generated Protobuf class for the record message typeserializer
- a typed serializer to use@Nonnull public static <M extends Message,U extends Message,B extends Message.Builder> FDBTypedRecordStore.Builder<M> newBuilder(@Nonnull Descriptors.FieldDescriptor fieldDescriptor, @Nonnull Supplier<B> builderSupplier, @Nonnull Predicate<U> tester, @Nonnull Function<U,M> getter, @Nonnull BiConsumer<B,M> setter)
M
- generated Protobuf class for the record message typeU
- generated Protobuf class for the union messageB
- generated Protobuf class for the union message's builderfieldDescriptor
- field descriptor for the union field used to hold the target record typebuilderSupplier
- builder for the union message typetester
- predicate to determine whether an instance of the union message has the target record typegetter
- accessor to get record message instance from union message instancesetter
- access to store record message instance into union message instance@Nonnull public static <M extends Message,U extends Message,B extends Message.Builder> FDBTypedRecordStore.Builder<M> newBuilder(@Nonnull Descriptors.FileDescriptor fileDescriptor, @Nonnull Descriptors.FieldDescriptor fieldDescriptor, @Nonnull Supplier<B> builderSupplier, @Nonnull Predicate<U> tester, @Nonnull Function<U,M> getter, @Nonnull BiConsumer<B,M> setter)
static final FDBTypedRecordStore.Builder<MyProto.MyRecord, MyProto.RecordTypeUnion, MyProto.RecordTypeUnion.Builder> BUILDER =
FDBTypedRecordStore.newBuilder(
MyProto.getDescriptor(),
MyProto.RecordTypeUnion.getDescriptor().findFieldByNumber(MyProto.RecordTypeUnion._MYRECORD_FIELD_NUMBER),
MyProto.RecordTypeUnion::newBuilder,
MyProto.RecordTypeUnion::hasMyRecord,
MyProto.RecordTypeUnion::getMyRecord,
MyProto.RecordTypeUnion.Builder::setMyRecord)
final FDBTypedRecordStore<MyProto.MyRecord, MyProto.RecordTypeUnion, MyProto.RecordTypeUnion.Builder> store =
BUILDER.copyBuilder().setContext(ctx).setSubspace(s).createOrOpen();
final MyProto.MyRecord myrec1 = store.loadRecord(pkey).getRecord();
M
- generated Protobuf class for the record message typeU
- generated Protobuf class for the union messageB
- generated Protobuf class for the union message's builderfileDescriptor
- file descriptor for all record message typesfieldDescriptor
- field descriptor for the union field used to hold the target record typebuilderSupplier
- builder for the union message typetester
- predicate to determine whether an instance of the union message has the target record typegetter
- accessor to get record message instance from union message instancesetter
- access to store record message instance into union message instance@Nonnull public FDBTypedRecordStore.Builder<M> asBuilder()