Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Adding transaction support #758

wants to merge 3 commits into from

Conversation

gsi-alejandro
Copy link
Collaborator

closes: #749, #741

Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Attention: Patch coverage is 88.17204% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 94.47%. Comparing base (369c827) to head (d5398ce).

Files Patch % Lines
src/model/utils/update-refdoc-indexes.ts 60.00% 6 Missing ⚠️
src/model/index/refdoc/build-index-refdoc.ts 58.33% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Collaborator

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);
Copy link
Collaborator

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?

Copy link
Collaborator

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);
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tansactions support Implementation
2 participants