Interface AgilityContext
- All Known Implementing Classes:
AgilityContext.Agile,AgilityContext.NonAgile
public interface AgilityContext
Create floating sub contexts from a caller context and commit when they reach time/write quota.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA floating window (agile) context - create sub contexts and commit them as they reach their time/size quota.static classA non-agile context - plainly use caller's context as context and never commit. -
Method Summary
Modifier and TypeMethodDescriptionvoidThis will abort the existing agile context (if agile) and prevent future operations.voidaccept(Consumer<FDBRecordContext> function) `accept` should be called when a returned value is not expected.static AgilityContextagile(FDBRecordContext callerContext, long timeQuotaMillis, long sizeQuotaBytes) static AgilityContextagile(FDBRecordContext callerContext, FDBRecordContextConfig.Builder contextBuilder, long timeQuotaMillis, long sizeQuotaBytes) <R> CompletableFuture<R>apply(Function<FDBRecordContext, CompletableFuture<R>> function) `apply` should be called when a returned value is expected.<R> CompletableFuture<R>applyInRecoveryPath(Function<FDBRecordContext, CompletableFuture<R>> function) This function is similar toapply(Function), but should only be called in the recovery path.default <T> TasyncToSync(StoreTimer.Wait event, CompletableFuture<T> async) default voidclear(byte[] key) default voiddefault voidcommit(FDBRecordContext context) voidflush()voidThis can be called to declare the object as 'closed' after flush.default CompletableFuture<byte[]>get(byte[] key) This function returns the caller's context.default <T> TgetPropertyValue(com.apple.foundationdb.record.provider.foundationdb.properties.RecordLayerPropertyKey<T> propertyKey) default CompletableFuture<List<KeyValue>>getRange(byte[] begin, byte[] end) default voidincrement(StoreTimer.Count count) default voidincrement(StoreTimer.Count count, int size) default <T> CompletableFuture<T>instrument(StoreTimer.Event event, CompletableFuture<T> future) default <T> CompletableFuture<T>instrument(StoreTimer.Event event, CompletableFuture<T> future, long start) booleanisClosed()static AgilityContextnonAgile(FDBRecordContext callerContext) default voidrecordEvent(StoreTimer.Event event, long timeDelta) default voidrecordSize(StoreTimer.SizeEvent sizeEvent, long size) voidset(byte[] key, byte[] value) `set` should be called for writes - keeping track of write size (if needed).voidsetCommitCheck(Function<FDBRecordContext, CompletableFuture<Void>> commitCheck) ThecommitCheckcallback is expected to use the argument context but should never call other agility context functions as it may cause a deadlock.
-
Method Details
-
nonAgile
-
agile
static AgilityContext agile(FDBRecordContext callerContext, @Nullable FDBRecordContextConfig.Builder contextBuilder, long timeQuotaMillis, long sizeQuotaBytes) -
agile
static AgilityContext agile(FDBRecordContext callerContext, long timeQuotaMillis, long sizeQuotaBytes) -
apply
`apply` should be called when a returned value is expected. Performed under appropriate lock.- Type Parameters:
R- future's type- Parameters:
function- a function accepting context, returning a future- Returns:
- the future of the function above
-
applyInRecoveryPath
<R> CompletableFuture<R> applyInRecoveryPath(Function<FDBRecordContext, CompletableFuture<R>> function) This function is similar toapply(Function), but should only be called in the recovery path. In Agile mode, it creates a new context for the function's apply to allow recovery, in non-Agile mode it's a no-op. This function may be called after agility context was closed.- Type Parameters:
R- future's type- Parameters:
function- a function accepting context, returning a future- Returns:
- the future of the function above
-
accept
`accept` should be called when a returned value is not expected. Performed under appropriate lock.- Parameters:
function- a function that accepts context
-
set
void set(byte[] key, byte[] value) `set` should be called for writes - keeping track of write size (if needed).- Parameters:
key- keyvalue- value
-
flush
void flush() -
flushAndClose
void flushAndClose()This can be called to declare the object as 'closed' after flush. Future "flush" will succeed, but any attempt to perform a transaction read/write will cause an exception. -
abortAndClose
void abortAndClose()This will abort the existing agile context (if agile) and prevent future operations. The only reason to call this function is after an exception, by a wrapper function. to clean potential locks after a failure and close, one should useapplyInRecoveryPath(Function) -
isClosed
boolean isClosed() -
get
-
clear
default void clear(byte[] key) -
clear
-
getRange
-
getCallerContext
This function returns the caller's context. If called by external entities, it should only be used for testing.- Returns:
- caller's context
-
instrument
-
instrument
default <T> CompletableFuture<T> instrument(StoreTimer.Event event, CompletableFuture<T> future, long start) -
increment
-
increment
-
recordEvent
-
recordSize
-
asyncToSync
-
getPropertyValue
@Nullable default <T> T getPropertyValue(@Nonnull com.apple.foundationdb.record.provider.foundationdb.properties.RecordLayerPropertyKey<T> propertyKey) -
setCommitCheck
ThecommitCheckcallback is expected to use the argument context but should never call other agility context functions as it may cause a deadlock.- Parameters:
commitCheck- callback
-
commit
-