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

noobaa/core: Transaction related changes #7249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aspandey
Copy link
Contributor

@aspandey aspandey commented Mar 29, 2023

This patch makes changes to send bulk queries for
multiple collections in one transaction for postgres DB. In case of failure of any query, all the bulk operations will be rollbacked.

unit test has not been added for this patch

@aspandey aspandey marked this pull request as draft March 29, 2023 11:37
@aspandey
Copy link
Contributor Author

@dannyzaken

@aspandey
Copy link
Contributor Author

Thanks @liranmauda for comments. This is work in progress. Will make these changes in next iteration.

@liranmauda
Copy link
Contributor

Thanks @liranmauda for comments. This is work in progress. Will make these changes in next iteration.

Yes, noticed the draft after I reviewed 🙂

@dannyzaken dannyzaken requested a review from guymguym April 2, 2023 14:02
if (res && !res.ok) {
dbg.error('got error on bulk execute', res.err);
throw new Error(res.err);
if (config.DB_TYPE === 'postgres') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth hiding the different implementations in the db clients. I suggest adding a function to DBClient interface in nb.d.ts, and then you can have a different implementation for postgres\mongo. Maybe something like execute_multiple_bulks().
This function should return a common bulk_results array that should be inspected the same for both DBs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Good Idea.

@dannyzaken dannyzaken requested review from a team and Neon-White and removed request for a team April 4, 2023 12:21
@aspandey aspandey marked this pull request as ready for review April 6, 2023 11:02
const queries = _.flatten(Object.values(bulk_per_collection).map(bulk => bulk.get_queries()));
const transaction = new PgTransaction(client);

let ok = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the same code as execute() of bulkOp class, I don't see a value in maintaining this code in 2 different functions, easily can move to a helper function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Done.

src/server/system_services/system_store.js Show resolved Hide resolved
Copy link
Contributor

@dannyzaken dannyzaken left a comment

Choose a reason for hiding this comment

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

@aspandey, I discussed with @romayalon, and we agreed this change is ok. We reviewed the make_changes calls, and it seems to behave better with this change.
We also agreed that it makes sense to refactor the common code in postgers_client

@romayalon
Copy link
Contributor

romayalon commented Apr 25, 2023

Hi @aspandey,
As Danny said I was worried about some specific make_changes() calls that make multiple changes and the queries are not related to each other.
For example, something like -

await system_store.make_changes({
        update: {
            buckets: buckets_updates,
            accounts: accounts_updates,
            pools: pools_updates,
            namespace_resources: namespace_resources_updates
        },
   });

I just wanted to make sure we won't roll back queries for no reason because this is the side effect of making one transaction per single make_changes() call instead of per collection in a make_changes() call.

@aspandey aspandey force-pushed the transaction branch 3 times, most recently from 923ddb5 to d7f1560 Compare April 26, 2023 09:03
try {
await system_store.make_changes({
insert: {
systems: [{
Copy link
Contributor

Choose a reason for hiding this comment

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

For the second make_changes you should add a change\insert to different tables (pools, accounts, etc.). After the failure, make sure all changes were not applied.
of course, this is the case for Postgres only, so we should skip this step for Mongo

@@ -757,6 +756,7 @@ class SystemStore extends EventEmitter {
}
}


Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary change.

@@ -368,6 +368,79 @@ class PgTransaction {

}

async function run_queries(transaction, queries) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest renaming to something like run_queries_in_transaction.
Also, maybe it should be a static method of PgTransaction

@aspandey aspandey force-pushed the transaction branch 2 times, most recently from d3019bc to 434618e Compare May 3, 2023 17:54
This patch makes changes to send bulk queries for
multiple collections in one transaction for postgres DB.
In case of failure of any query, all the bulk operations
will be rollbacked.

Signed-off-by: Ashish Pandey <aspandey@redhat.com>
Copy link

This PR had no activity for too long - it will now be labeled stale. Update it to prevent it from getting closed.

@github-actions github-actions bot added the Stale label May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants