-
Notifications
You must be signed in to change notification settings - Fork 76
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
base: master
Are you sure you want to change the base?
Conversation
Thanks @liranmauda for comments. This is work in progress. Will make these changes in next iteration. |
Yes, noticed the draft after I reviewed 🙂 |
if (res && !res.ok) { | ||
dbg.error('got error on bulk execute', res.err); | ||
throw new Error(res.err); | ||
if (config.DB_TYPE === 'postgres') { |
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.
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
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.
Done. Good Idea.
src/util/postgres_client.js
Outdated
const queries = _.flatten(Object.values(bulk_per_collection).map(bulk => bulk.get_queries())); | ||
const transaction = new PgTransaction(client); | ||
|
||
let ok = false; |
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.
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
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.
Makes sense. Done.
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.
@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
Hi @aspandey,
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. |
923ddb5
to
d7f1560
Compare
try { | ||
await system_store.make_changes({ | ||
insert: { | ||
systems: [{ |
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 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 { | |||
} | |||
} | |||
|
|||
|
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.
Unnecessary change.
src/util/postgres_client.js
Outdated
@@ -368,6 +368,79 @@ class PgTransaction { | |||
|
|||
} | |||
|
|||
async function run_queries(transaction, queries) { |
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.
I suggest renaming to something like run_queries_in_transaction
.
Also, maybe it should be a static method of PgTransaction
d3019bc
to
434618e
Compare
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>
This PR had no activity for too long - it will now be labeled stale. Update it to prevent it from getting closed. |
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