@Stability.Internal public class CoreTransactionAttemptContext extends Object
Modifier and Type | Field and 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 and Description |
---|
CoreTransactionAttemptContext(Core core,
CoreTransactionContext overall,
CoreMergedTransactionConfig config,
String attemptId,
CoreTransactionsReactive parent,
Optional<SpanWrapper> parentSpan,
CoreTransactionAttemptContextHooks hooks) |
Modifier and Type | Method and 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,
String statement,
SpanWrapper pspan,
TriFunction<Integer,AtomicReference<ReactiveLock.Waiter>,SpanWrapper,Mono<T>> op)
Doesn't need everything from doKVOperation, as queryWrapper already centralises a lot of logic
|
Mono<CoreTransactionGetResult> |
get(CollectionIdentifier collection,
String id)
Gets a document with the specified
id and from the specified Couchbase bucket . |
Mono<CoreTransactionGetResult> |
insert(CollectionIdentifier collection,
String id,
byte[] content,
SpanWrapper pspan)
Inserts a new document into the specified Couchbase
collection . |
CoreTransactionLogger |
logger()
Returns the
CoreTransactionLogger 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<CoreQueryResult> |
queryBlocking(String statement,
CoreQueryContext qc,
CoreQueryOptions options,
boolean tximplicit)
Used by AttemptContext, buffers all query rows in-memory.
|
Mono<ClassicCoreReactiveQueryResult> |
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,
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,
SpanWrapper pspan)
Removes the specified
doc , using the document's last
CoreTransactionGetResult.cas() . |
Mono<CoreTransactionGetResult> |
replace(CoreTransactionGetResult doc,
byte[] content,
SpanWrapper pspan)
Mutates the specified
doc with new content, using the
document's last CoreTransactionGetResult.cas() . |
Mono<Void> |
rollback()
Rolls back the transaction.
|
Scheduler |
scheduler()
Bear in mind, in this code with the blocking API:
|
RequestSpan |
span() |
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.
|
public static final int TRANSACTION_STATE_BIT_COMMIT_NOT_ALLOWED
public static final int TRANSACTION_STATE_BIT_APP_ROLLBACK_NOT_ALLOWED
public static final int TRANSACTION_STATE_BIT_SHOULD_NOT_ROLLBACK
public static final int TRANSACTION_STATE_BIT_SHOULD_NOT_RETRY
public static final int STATE_BITS_POSITION_FINAL_ERROR
public static final int STATE_BITS_MASK_FINAL_ERROR
public static final int STATE_BITS_MASK_BITS
public static final Duration DEFAULT_DELAY_RETRYING_OPERATION
public CoreTransactionAttemptContext(Core core, CoreTransactionContext overall, CoreMergedTransactionConfig config, String attemptId, CoreTransactionsReactive parent, Optional<SpanWrapper> parentSpan, CoreTransactionAttemptContextHooks hooks)
public Core core()
public Scheduler scheduler()
cluster.transactions().run((ctx) -> { Thread ct = Thread.currentThread(); ctx.insert(collection, docId, content); Thread ct2 = Thread.currentThread(); });ct will _always_ equal ct2 (which is what we want), regardless of what we do with schedulers. As there's no way to change the current thread of execution in that way.
We put things onto our scheduler for the benefit of reactive users. Because we don't want to pass control back to user space (the lambda) while still on a limited internal SDK thread.
public String attemptId()
public String transactionId()
public Mono<CoreTransactionGetResult> get(CollectionIdentifier collection, String id)
id
and from the specified Couchbase bucket
.
collection
- the Couchbase collection the document exists onid
- the document's IDTransactionGetResultInternal
containing the documentpublic Optional<CollectionIdentifier> atrCollection()
public Mono<CoreTransactionGetResult> insert(CollectionIdentifier collection, String id, byte[] content, SpanWrapper pspan)
collection
.collection
- the Couchbase collection in which to insert the docid
- the document's unique IDcontent
- the content to insertTransactionGetResultInternal
protected String randomAtrIdForVbucket(CoreTransactionAttemptContext self, Integer vbucketIdForDoc, int numAtrs)
public Mono<CoreTransactionGetResult> replace(CoreTransactionGetResult doc, byte[] content, SpanWrapper pspan)
doc
with new content, using the
document's last CoreTransactionGetResult.cas()
.doc
- the doc to be mutatedcontent
- the content to replace the doc withpublic <T> Mono<T> doQueryOperation(String lockDebugIn, String statement, @Nullable SpanWrapper pspan, TriFunction<Integer,AtomicReference<ReactiveLock.Waiter>,SpanWrapper,Mono<T>> op)
public Mono<Void> remove(CoreTransactionGetResult doc, SpanWrapper pspan)
doc
, using the document's last
CoreTransactionGetResult.cas()
.
doc
- - the doc to be removedpublic Mono<Void> commit()
The semantics are the same as commit()
, except that the a Mono
is returned
so the operation can be performed asynchronously.
public RequestSpan span()
public Mono<Void> rollback()
public TransactionOperationFailedException operationFailed(boolean updateInternalState, TransactionOperationFailedException err)
public TransactionOperationFailedException operationFailed(TransactionOperationFailedException err)
public Mono<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, AtomicReference<ReactiveLock.Waiter> lockToken, boolean updateInternalState)
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.
lockToken
- if null, the lock is held throughoutpublic Mono<CoreQueryResult> queryBlocking(String statement, @Nullable CoreQueryContext qc, @Nullable CoreQueryOptions options, boolean tximplicit)
public CoreTransactionLogger logger()
CoreTransactionLogger
used by this instance, so the developer can insert their own log messages.Copyright © 2024 Couchbase, Inc.. All rights reserved.