-
Notifications
You must be signed in to change notification settings - Fork 6
Vlad-week3-DB #21
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
base: main
Are you sure you want to change the base?
Vlad-week3-DB #21
Conversation
yunchen4
left a comment
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.
Hi Vlad,
You are doing a good job. I left a suggestion for deadlock situation. However I didn't find your answers for mongodb exercises. I have left a comment with the correct assignment file.
Please let me know on Slack when you complete it. Thank you and have a nice weekend!
| const fromRes = await db.query( | ||
| "SELECT balance FROM account WHERE account_number = $1 FOR UPDATE", | ||
| [fromAcc] | ||
| ); | ||
| const toRes = await db.query( | ||
| "SELECT balance FROM account WHERE account_number = $1 FOR UPDATE", | ||
| [toAcc] | ||
| ); |
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.
Suggestion: I see you want to lock the rows. It is better to always lock the rows based on a specific and predicted order, for example account ID with smaller number will be locked first. In this case the deadlock risk during high concurrency situation can be reduced. Otherwise, if two transactions happen almost the same time (for example account A->B and account B->A) the deadlock might happen.
| async function run() { | ||
| // 1) Connect | ||
| const client = new MongoClient(uri); | ||
| await client.connect(); | ||
|
|
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.
Needs rework: I didn't see the answers for exercises in this file?
yunchen4
left a comment
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.
LGTM, left a comment about possible blind spot.
| const updBushes = await col.updateMany( | ||
| { elements: "BUSHES" }, | ||
| { $set: { "elements.$": "BUSH" } } | ||
| ); |
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 not wrong, but be aware that this query only updates the first occurance of BUSHES.
No description provided.