-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: avoiding IDs override/conflict while creating concurrent runtime notifications #342
fix: avoiding IDs override/conflict while creating concurrent runtime notifications #342
Conversation
…ame, if it does not exist
const id = parseInt(row?.nextId.toString() || '1') | ||
|
||
// Update the id to be the next one in the overlay | ||
if (row) { |
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.
where did we increment the id for entity previously?
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.
In the addRuntimeNotification 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.
Not sure whether I get the logic, previously we invoked getNextIdForEntity
for multiple notifications and then incremented the row. Now we will increment it when each notification is being created, this way there arent conflicts?
No, there wont be any conflicts, because we are incrementing the ID and then reading it from the overlay (which is in-memory cache) and not db. So there is no asynchronous operation involved in update the id. |
… notifications (Joystream#342) * fix: avoiding IDs override while creating conturrent runtime notifications * create record in 'getNextIdForEntity' function in overlay for entityname, if it does not exist * fix: notifications unit tests
Context
While creating the runtime notifications addRuntimeNotification function reads the nextEntityId for the new notification from the db. And, then use this id to create a new entity in the overlay.
Now the problem is that if many concurrent notifications are being created e.g.
Promise.all([...])
. Then each concurrent call ofaddRuntimeNotification
will read the same next entity ID from the db, and only one notification can be created.Fix
Instead of using db to get the next entity ID, read the ID form the overlay and then update it too, so the each concurrent
addRuntimeNotification
instance has access to the correct next entity ID.