-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding transaction support #758
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #758 +/- ##
==========================================
+ Coverage 93.20% 94.47% +1.27%
==========================================
Files 96 96
Lines 2677 2732 +55
Branches 642 668 +26
==========================================
+ Hits 2495 2581 +86
+ Misses 182 151 -31 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this file?
## Creating a Transaction | ||
|
||
To create a transaction, an application must supply its logic inside an arrow function, | ||
including any conditional logic required. Once the arrow function has successfully run to conclusion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
including any conditional logic required. Once the arrow function has successfully run to conclusion, | |
including any conditional logic required. Once the arrow function has successfully run to completion, |
To create a transaction, an application must supply its logic inside an arrow function, | ||
including any conditional logic required. Once the arrow function has successfully run to conclusion, | ||
the transaction will be automatically committed. | ||
If at any point an error occurs, the transaction will rollback and the arrow function may run again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If at any point an error occurs, the transaction will rollback and the arrow function may run again. | |
If at any point an error occurs, the transaction will roll back and the arrow function may run again. |
Since the arrow function could be rerun multiple times, it is important that it does not contain any side effects. | ||
In particular, you should never perform regular operations on a Collection, such as `create()` without using the `ctx`, inside the arrow function. | ||
Such operations may be performed multiple times, and will not be performed transactionally. | ||
Instead, you should perform these operations through the using the `{ transactionContext: ctx }` to pass the Transaction Context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, you should perform these operations through the using the `{ transactionContext: ctx }` to pass the Transaction Context. | |
Instead, you should perform these operations by using the `{ transactionContext: ctx }` to pass the Transaction Context. |
|
||
Refer to [Error Handling](https://docs.couchbase.com/nodejs-sdk/current/concept-docs/transactions-error-handling.html#transaction_errors) for more details on these. | ||
|
||
Method that currently support transaction context: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method that currently support transaction context: | |
Methods that currently support transaction context: |
|
||
The default configuration should be appropriate for most use-cases. | ||
Transactions can optionally be globally configured when configuring the Cluster. | ||
For example, if you want to change the level of durability which must be attained, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, if you want to change the level of durability which must be attained, | |
For example, if you want to change the level of durability that must be attained, |
ensuring that each write is available in-memory on the majority of replicas before the transaction continues. | ||
There are two higher durability settings available that will additionally wait for all mutations | ||
to be written to physical storage on either the active or the majority of replicas, | ||
before continuing. This further increases safety, at a cost of additional latency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before continuing. This further increases safety, at a cost of additional latency. | |
before continuing. This further increases safety, at the cost of additional latency. |
if (options.maxExpiry !== undefined) { | ||
options.expiry = options.maxExpiry; | ||
delete options.maxExpiry; | ||
} | ||
if (options.cas) { | ||
storePromise = collection.replace(key, data, options); | ||
if (transactionContext) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this always be true because of the || {}
on line 18 above?
if (options.transactionContext) { | ||
const { transactionContext } = options; | ||
const result = await transactionContext.get(c, key); | ||
console.log(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to keep this logging in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be behind an if(debug)
flag?
// await delay(2500); | ||
// | ||
// const userRefdoc = await User.findRefName(userData.name, { transactionContext: ctx }); | ||
// expect(userRefdoc.name).toBe(userData.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transactions must use ctx.get, which doesn't work with plaintext docs
closes: #749, #741