Class CoreTransactionAttemptContext
- java.lang.Object
-
- com.couchbase.client.core.transaction.CoreTransactionAttemptContext
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CoreTransactionAttemptContext.BufferedQueryResponse
-
Field Summary
Fields Modifier and Type Field Description static Duration
DEFAULT_DELAY_RETRYING_OPERATION
static int
STATE_BITS_MASK_BITS
static int
STATE_BITS_MASK_FINAL_ERROR
static int
STATE_BITS_POSITION_FINAL_ERROR
static int
TRANSACTION_STATE_BIT_APP_ROLLBACK_NOT_ALLOWED
static int
TRANSACTION_STATE_BIT_COMMIT_NOT_ALLOWED
static int
TRANSACTION_STATE_BIT_SHOULD_NOT_RETRY
static int
TRANSACTION_STATE_BIT_SHOULD_NOT_ROLLBACK
-
Constructor Summary
Constructors Constructor Description CoreTransactionAttemptContext(Core core, CoreTransactionContext overall, CoreMergedTransactionConfig config, String attemptId, CoreTransactionsReactive parent, Optional<SpanWrapper> parentSpan, CoreTransactionAttemptContextHooks hooks)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<CollectionIdentifier>
atrCollection()
Optional<String>
atrId()
String
attemptId()
Returns the globally unique ID of this attempt, which may be useful for debugging and logging purposes.Mono<Void>
commit()
Commits the transaction.Core
core()
<T> Mono<T>
doQueryOperation(String lockDebugIn, BiFunction<Integer,AtomicReference<ReactiveLock.Waiter>,Mono<T>> op)
Doesn't need everything from doKVOperation, as queryWrapper already centralises a lot of logicMono<CoreTransactionGetResult>
get(CollectionIdentifier collection, String id)
Gets a document with the specifiedid
and from the specified Couchbasebucket
.Mono<CoreTransactionGetResult>
insert(CollectionIdentifier collection, String id, byte[] content)
Inserts a new document into the specified Couchbasecollection
.CoreTransactionLogger
logger()
Returns theCoreTransactionLogger
used by this instance, so the developer can insert their own log messages.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.TransactionOperationFailedException
operationFailed(TransactionOperationFailedException err)
Mono<CoreTransactionAttemptContext.BufferedQueryResponse>
queryBlocking(String statement, String bucketName, String scopeName, com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode options, boolean tximplicit)
Used by AttemptContext, buffers all query rows in-memory.Mono<QueryResponse>
queryWrapperLocked(int sidx, String bucketName, String scopeName, String statement, com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode 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 pspan, boolean tximplicit, AtomicReference<ReactiveLock.Waiter> lockToken, boolean updateInternalState)
This will return a TransactionOperationFailedException if that's what query returns, else will return the error after passing through convertQueryError.protected String
randomAtrIdForVbucket(CoreTransactionAttemptContext self, Integer vbucketIdForDoc, int numAtrs)
Mono<Void>
remove(CoreTransactionGetResult doc)
Removes the specifieddoc
, using the document's lastCoreTransactionGetResult.cas()
.Mono<CoreTransactionGetResult>
replace(CoreTransactionGetResult doc, byte[] content)
Mutates the specifieddoc
with new content, using the document's lastCoreTransactionGetResult.cas()
.Mono<Void>
rollback()
Rolls back the transaction.Scheduler
scheduler()
String
toString()
String
transactionId()
Returns the globally unique ID of the overall transaction owning this attempt, which may be useful for debugging and logging purposes.
-
-
-
Field Detail
-
TRANSACTION_STATE_BIT_COMMIT_NOT_ALLOWED
public static int TRANSACTION_STATE_BIT_COMMIT_NOT_ALLOWED
-
TRANSACTION_STATE_BIT_APP_ROLLBACK_NOT_ALLOWED
public static int TRANSACTION_STATE_BIT_APP_ROLLBACK_NOT_ALLOWED
-
TRANSACTION_STATE_BIT_SHOULD_NOT_ROLLBACK
public static int TRANSACTION_STATE_BIT_SHOULD_NOT_ROLLBACK
-
TRANSACTION_STATE_BIT_SHOULD_NOT_RETRY
public static int TRANSACTION_STATE_BIT_SHOULD_NOT_RETRY
-
STATE_BITS_POSITION_FINAL_ERROR
public static int STATE_BITS_POSITION_FINAL_ERROR
-
STATE_BITS_MASK_FINAL_ERROR
public static int STATE_BITS_MASK_FINAL_ERROR
-
STATE_BITS_MASK_BITS
public static int STATE_BITS_MASK_BITS
-
DEFAULT_DELAY_RETRYING_OPERATION
public static Duration DEFAULT_DELAY_RETRYING_OPERATION
-
-
Constructor Detail
-
CoreTransactionAttemptContext
public CoreTransactionAttemptContext(Core core, CoreTransactionContext overall, CoreMergedTransactionConfig config, String attemptId, CoreTransactionsReactive parent, Optional<SpanWrapper> parentSpan, CoreTransactionAttemptContextHooks hooks)
-
-
Method Detail
-
core
public Core core()
-
scheduler
public Scheduler scheduler()
-
attemptId
public String attemptId()
Returns the globally unique ID of this attempt, which may be useful for debugging and logging purposes.
-
transactionId
public String transactionId()
Returns the globally unique ID of the overall transaction owning this attempt, which may be useful for debugging and logging purposes.
-
get
public Mono<CoreTransactionGetResult> get(CollectionIdentifier collection, String id)
Gets a document with the specifiedid
and from the specified Couchbasebucket
.- Parameters:
collection
- the Couchbase collection the document exists onid
- the document's ID- Returns:
- a
TransactionGetResultInternal
containing the document
-
atrCollection
public Optional<CollectionIdentifier> atrCollection()
-
insert
public Mono<CoreTransactionGetResult> insert(CollectionIdentifier collection, String id, byte[] content)
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
-
randomAtrIdForVbucket
protected String randomAtrIdForVbucket(CoreTransactionAttemptContext self, Integer vbucketIdForDoc, int numAtrs)
-
replace
public Mono<CoreTransactionGetResult> replace(CoreTransactionGetResult doc, byte[] content)
Mutates the specifieddoc
with 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.
-
doQueryOperation
public <T> Mono<T> doQueryOperation(String lockDebugIn, BiFunction<Integer,AtomicReference<ReactiveLock.Waiter>,Mono<T>> op)
Doesn't need everything from doKVOperation, as queryWrapper already centralises a lot of logic
-
remove
public Mono<Void> remove(CoreTransactionGetResult doc)
Removes the specifieddoc
, using the document's lastCoreTransactionGetResult.cas()
.- Parameters:
doc
- - the doc to be removed
-
commit
public Mono<Void> commit()
Commits the transaction. All staged replaces, inserts and removals will be written.The semantics are the same as
AttemptContext#commit()
, except that the aMono
is returned so the operation can be performed asynchronously.
-
rollback
public Mono<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.The semantics are the same as
AttemptContext#rollback()
, except that the aMono
is returned so the operation can be performed asynchronously.
-
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
public TransactionOperationFailedException operationFailed(TransactionOperationFailedException err)
-
queryWrapperLocked
public Mono<QueryResponse> queryWrapperLocked(int sidx, @Nullable String bucketName, @Nullable String scopeName, String statement, com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode 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 pspan, boolean tximplicit, AtomicReference<ReactiveLock.Waiter> lockToken, 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. Keep this routine in sync with queryWrapperReactiveLocked.
- Parameters:
lockToken
- if null, the lock is held throughout
-
queryBlocking
public Mono<CoreTransactionAttemptContext.BufferedQueryResponse> queryBlocking(String statement, @Nullable String bucketName, @Nullable String scopeName, com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode options, boolean tximplicit)
Used by AttemptContext, buffers all query rows in-memory.
-
logger
public CoreTransactionLogger logger()
Returns theCoreTransactionLogger
used by this instance, so the developer can insert their own log messages.
-
-