Class CoreTransactionAttemptContext
java.lang.Object
com.couchbase.client.core.transaction.CoreTransactionAttemptContext
Provides methods to allow an application's transaction logic to read, mutate, insert and delete documents, as well
as commit or rollback the transaction.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Durationstatic final byte[]static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionCoreTransactionAttemptContext(Core core, CoreTransactionContext overall, CoreMergedTransactionConfig config, String attemptId, Optional<SpanWrapper> parentSpan, CoreTransactionAttemptContextHooks hooks) -
Method Summary
Modifier and TypeMethodDescriptionatrId()Returns the globally unique ID of this attempt, which may be useful for debugging and logging purposes.voidcommit()Commits the transaction.core()<T> TdoQueryOperation(String lockDebugIn, String statement, CoreQueryOptions opts, SpanWrapper pspan, BiFunction<Integer, SpanWrapper, T> op) Doesn't need everything from doKVOperation, as queryWrapper already centralises a lot of logicget(CollectionIdentifier collection, String id) Gets a document with the specifiedidand from the specified Couchbasebucket.getMultiAlgo(List<CoreTransactionGetMultiSpec> specs, CoreGetMultiOptions options, boolean replicasFromPreferredServerGroup) reactor.core.publisher.Mono<List<CoreTransactionOptionalGetMultiResult>> getMultiAlgoReactive(List<CoreTransactionGetMultiSpec> specs, CoreGetMultiOptions options, boolean replicasFromPreferredServerGroup) getMultiDocumentFetch(CoreGetMultiState operationState) getMultiSingleDocumentFetch(CoreTransactionGetMultiSpec spec, CoreGetMultiState operationState) reactor.core.publisher.Mono<CoreTransactionGetResult> getReactive(CollectionIdentifier collection, String id) getReplicaFromPreferredServerGroup(CollectionIdentifier collection, String id) reactor.core.publisher.Mono<CoreTransactionGetResult> getReplicaFromPreferredServerGroupReactive(CollectionIdentifier collection, String id) insert(CollectionIdentifier collection, String id, byte[] content, int flagsToStage, CoreExpiry expiry, SpanWrapper pspan) Inserts a new document into the specified Couchbasecollection.reactor.core.publisher.Mono<CoreTransactionGetResult> insert(CollectionIdentifier collection, String id, byte[] content, SpanWrapper pspan) Deprecated.reactor.core.publisher.Mono<CoreTransactionGetResult> insertReactive(CollectionIdentifier collection, String id, byte[] content, int flagsToStage, CoreExpiry expiry, SpanWrapper pspan) logger()Returns theCoreTransactionLoggerused by this instance, so the developer can insert their own log messages.operationFailed(boolean updateInternalState, TransactionOperationFailedException err) Rollback errors rules: Errors during auto-rollback: do not update internal state, as the user cares more about the original error that provoked the rollback Errors during app-rollback: do update internal state.queryBlocking(String statement, CoreQueryContext qc, CoreQueryOptions options, boolean tximplicit) Used by AttemptContext, buffers all query rows in-memory.reactor.core.publisher.Mono<CoreQueryResult> queryReactive(String statement, CoreQueryContext qc, CoreQueryOptions options, boolean tximplicit) queryWrapperLocked(int sidx, CoreQueryContext qc, String statement, CoreQueryOptions options, String hookPoint, boolean isBeginWork, boolean existingErrorCheck, com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode txdata, com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ArrayNode params, SpanWrapper span, boolean tximplicit, boolean updateInternalState) This will return a TransactionOperationFailedException if that's what query returns, else will return the error after passing through convertQueryError.protected StringrandomAtrIdForVbucket(CoreTransactionAttemptContext self, Integer vbucketIdForDoc, int numAtrs) voidremove(CoreTransactionGetResult doc, SpanWrapper pspan) Removes the specifieddoc, using the document's lastCoreTransactionGetResult.cas().reactor.core.publisher.Mono<Void> removeReactive(CoreTransactionGetResult doc, SpanWrapper pspan) replace(CoreTransactionGetResult doc, byte[] content, int flags, CoreExpiry expiry, SpanWrapper pspan) Mutates the specifieddocwith new content, using the document's lastCoreTransactionGetResult.cas().reactor.core.publisher.Mono<CoreTransactionGetResult> replace(CoreTransactionGetResult doc, byte[] content, SpanWrapper pspan) Deprecated.in favor ofreplace(CoreTransactionGetResult, byte[], int, CoreExpiry, SpanWrapper)which takes an additional 'flags' argument.reactor.core.publisher.Mono<CoreTransactionGetResult> replaceReactive(CoreTransactionGetResult doc, byte[] content, int flags, CoreExpiry expiry, SpanWrapper pspan) voidrollback()Rolls back the transaction.span()toString()Returns the globally unique ID of the overall transaction owning this attempt, which may be useful for debugging and logging purposes.
-
Field Details
-
NEAR_EMPTY_BYTE_ARRAY
public static final byte[] NEAR_EMPTY_BYTE_ARRAY -
TRANSACTION_STATE_BIT_COMMIT_NOT_ALLOWED
public static final int TRANSACTION_STATE_BIT_COMMIT_NOT_ALLOWED- See Also:
-
TRANSACTION_STATE_BIT_APP_ROLLBACK_NOT_ALLOWED
public static final int TRANSACTION_STATE_BIT_APP_ROLLBACK_NOT_ALLOWED- See Also:
-
TRANSACTION_STATE_BIT_SHOULD_NOT_ROLLBACK
public static final int TRANSACTION_STATE_BIT_SHOULD_NOT_ROLLBACK- See Also:
-
TRANSACTION_STATE_BIT_SHOULD_NOT_RETRY
public static final int TRANSACTION_STATE_BIT_SHOULD_NOT_RETRY- See Also:
-
STATE_BITS_POSITION_FINAL_ERROR
public static final int STATE_BITS_POSITION_FINAL_ERROR- See Also:
-
STATE_BITS_MASK_FINAL_ERROR
public static final int STATE_BITS_MASK_FINAL_ERROR- See Also:
-
STATE_BITS_MASK_BITS
public static final int STATE_BITS_MASK_BITS- See Also:
-
UNSTAGING_PARALLELISM
public static final int UNSTAGING_PARALLELISM -
DEFAULT_DELAY_RETRYING_OPERATION
-
-
Constructor Details
-
CoreTransactionAttemptContext
public CoreTransactionAttemptContext(Core core, CoreTransactionContext overall, CoreMergedTransactionConfig config, String attemptId, Optional<SpanWrapper> parentSpan, CoreTransactionAttemptContextHooks hooks)
-
-
Method Details
-
core
-
attemptId
Returns the globally unique ID of this attempt, which may be useful for debugging and logging purposes. -
transactionId
Returns the globally unique ID of the overall transaction owning this attempt, which may be useful for debugging and logging purposes. -
get
Gets a document with the specifiedidand from the specified Couchbasebucket.- Parameters:
collection- the Couchbase collection the document exists onid- the document's ID- Returns:
- a
CoreTransactionGetResultcontaining the document
-
getReactive
public reactor.core.publisher.Mono<CoreTransactionGetResult> getReactive(CollectionIdentifier collection, String id) -
getReplicaFromPreferredServerGroup
public CoreTransactionGetResult getReplicaFromPreferredServerGroup(CollectionIdentifier collection, String id) -
getReplicaFromPreferredServerGroupReactive
public reactor.core.publisher.Mono<CoreTransactionGetResult> getReplicaFromPreferredServerGroupReactive(CollectionIdentifier collection, String id) -
getMultiAlgo
public List<CoreTransactionOptionalGetMultiResult> getMultiAlgo(List<CoreTransactionGetMultiSpec> specs, CoreGetMultiOptions options, boolean replicasFromPreferredServerGroup) -
getMultiAlgoReactive
public reactor.core.publisher.Mono<List<CoreTransactionOptionalGetMultiResult>> getMultiAlgoReactive(List<CoreTransactionGetMultiSpec> specs, CoreGetMultiOptions options, boolean replicasFromPreferredServerGroup) -
getMultiSingleDocumentFetch
public Either<CoreTransactionOptionalGetMultiResult,CoreGetMultiSignal> getMultiSingleDocumentFetch(CoreTransactionGetMultiSpec spec, CoreGetMultiState operationState) -
getMultiDocumentFetch
-
atrId
-
atrCollection
-
insert
public CoreTransactionGetResult insert(CollectionIdentifier collection, String id, byte[] content, int flagsToStage, @Nullable CoreExpiry expiry, SpanWrapper pspan) Inserts a new document into the specified Couchbasecollection.- Parameters:
collection- the Couchbase collection in which to insert the docid- the document's unique IDcontent- the content to insert- Returns:
- the doc, updated with its new CAS value and ID, and converted to a
TransactionGetResultInternal
-
insertReactive
public reactor.core.publisher.Mono<CoreTransactionGetResult> insertReactive(CollectionIdentifier collection, String id, byte[] content, int flagsToStage, @Nullable CoreExpiry expiry, SpanWrapper pspan) -
insert
@UsedBy(SPRING_DATA_COUCHBASE) @Deprecated public reactor.core.publisher.Mono<CoreTransactionGetResult> insert(CollectionIdentifier collection, String id, byte[] content, SpanWrapper pspan) Deprecated.in favor ofinsert(CollectionIdentifier, String, byte[], int, CoreExpiry, SpanWrapper)which takes an additional 'flags' argument. -
randomAtrIdForVbucket
protected String randomAtrIdForVbucket(CoreTransactionAttemptContext self, Integer vbucketIdForDoc, int numAtrs) -
replace
public CoreTransactionGetResult replace(CoreTransactionGetResult doc, byte[] content, int flags, @Nullable CoreExpiry expiry, SpanWrapper pspan) Mutates the specifieddocwith new content, using the document's lastCoreTransactionGetResult.cas().- Parameters:
doc- the doc to be mutatedcontent- the content to replace the doc with- Returns:
- the doc, updated with its new CAS value. For performance a copy is not created and the original doc object is modified.
-
replaceReactive
public reactor.core.publisher.Mono<CoreTransactionGetResult> replaceReactive(CoreTransactionGetResult doc, byte[] content, int flags, @Nullable CoreExpiry expiry, SpanWrapper pspan) -
replace
@UsedBy(SPRING_DATA_COUCHBASE) @Deprecated public reactor.core.publisher.Mono<CoreTransactionGetResult> replace(CoreTransactionGetResult doc, byte[] content, SpanWrapper pspan) Deprecated.in favor ofreplace(CoreTransactionGetResult, byte[], int, CoreExpiry, SpanWrapper)which takes an additional 'flags' argument. -
doQueryOperation
public <T> T doQueryOperation(String lockDebugIn, String statement, @Nullable CoreQueryOptions opts, @Nullable SpanWrapper pspan, BiFunction<Integer, SpanWrapper, T> op) Doesn't need everything from doKVOperation, as queryWrapper already centralises a lot of logic -
remove
Removes the specifieddoc, using the document's lastCoreTransactionGetResult.cas().- Parameters:
doc- - the doc to be removed
-
removeReactive
public reactor.core.publisher.Mono<Void> removeReactive(CoreTransactionGetResult doc, SpanWrapper pspan) -
commit
public void commit()Commits the transaction. All staged replaces, inserts and removals will be written. -
span
-
rollback
public void rollback()Rolls back the transaction. All staged replaces, inserts and removals will be removed. The transaction will not be retried, so this will be the final attempt. -
operationFailed
public TransactionOperationFailedException operationFailed(boolean updateInternalState, TransactionOperationFailedException err) Rollback errors rules: Errors during auto-rollback: do not update internal state, as the user cares more about the original error that provoked the rollback Errors during app-rollback: do update internal state. Nothing else has gone wrong with the transaction, and the user will care about rollback problems.If !updateInternalState, the internal state bits are not changed.
-
operationFailed
-
queryWrapperLocked
public ClassicCoreReactiveQueryResult queryWrapperLocked(int sidx, @Nullable CoreQueryContext qc, String statement, @Nullable CoreQueryOptions options, String hookPoint, boolean isBeginWork, boolean existingErrorCheck, @Nullable com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode txdata, @Nullable com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ArrayNode params, @Nullable SpanWrapper span, boolean tximplicit, boolean updateInternalState) This will return a TransactionOperationFailedException if that's what query returns, else will return the error after passing through convertQueryError.If an error is universally handled the same way, then convertQueryError will return a TransactionOperationFailedException.
Because this is a general-purpose wrapper, TransactionOperationFaileds will _not_ be added to internal errors array. So the transaction is allowed to continue after failures, unless the caller prevents it. Update: appears to no longer be the case.
Though the implementation is largely de-reactorised, this low-level function continues with ClassicCoreReactiveQueryResult as that supports streaming invalid input: '&' backpressure, which is needed for single query transactions.
-
queryBlocking
public CoreQueryResult queryBlocking(String statement, @Nullable CoreQueryContext qc, @Nullable CoreQueryOptions options, boolean tximplicit) Used by AttemptContext, buffers all query rows in-memory. -
queryReactive
public reactor.core.publisher.Mono<CoreQueryResult> queryReactive(String statement, @Nullable CoreQueryContext qc, @Nullable CoreQueryOptions options, boolean tximplicit) -
logger
Returns theCoreTransactionLoggerused by this instance, so the developer can insert their own log messages. -
toString
-
insert(CollectionIdentifier, String, byte[], int, CoreExpiry, SpanWrapper)which takes an additional 'flags' argument.