-
Notifications
You must be signed in to change notification settings - Fork 12
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
Optimize vector get last written LSN #553
Conversation
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.
Looks correct comparing with the old code. I have some doubts about this though that are applicable to both the old and the new version though:
-
Why does GetLastWrittenLSNv() call SetLastWrittenLSNForBlock() for pages that were not in the cache previously? There are no comments on that and I find it pretty surprising. Luckily the PR description that added it Remember last written LSN when it is first requested #412 explains it. Let's copy that explanation to a comment in GetLastWrittenLSNv().
-
Is it correct to release the lock and then call SetLastWrittenLSNForBlock()? If the page is concurrently updated and written out, the LSN we set here might override the LSN that was set by the concurrent updater. There was discussion on PR Remember last written LSN when it is first requested #412 about a concurrent read scenario. ISTM it was considered to be just a performance issue, but isn't it also a potential correctness issue if the last-written LSN of a page is moved backwards?
-
I don't know if it matters from a performance point of view in practice, but it seems wasteful to release LastWrittenLsnLock, when SetLastWrittenLSNForBlock() will immediately re-acquire it. Instead of calling SetLastWrittenLSNForBlock(), you could hold the lock and copy some of the logic from SetLastWrittenLSNForBlock() into GetLastWrittenLSNv() itself, or introduce some common helper functions to reduce the duplication. That would also address the previous point about concurrent updates.
Done
Values can not be moved backward, because there is check in SetLastWrittenLSN performed in critical section which prevents it. But see 3)
Fixed. I did it only for pg17 because it is just optimization. |
323866d
to
89d27dc
Compare
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 think this whole "optimization" is invalid, as it completely ignores LW_EXCLUSIVE
/ LW_SHARED
conflicts.
With this, youre updating a shared hash table if it's locked, regardless of whether you're holding a read lock or write lock. That's just plain incorrect.
Sorry, stupid error:( |
By the way, isn't the comment:
above GetLastWrittenLSN outdated? |
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.
One bug, and some suggestions to address a lack of comments in the new code.
It was renamed to |
Yeah, I think that's been renamed to |
Co-authored-by: Matthias van de Meent <[email protected]>
Co-authored-by: Matthias van de Meent <[email protected]>
Co-authored-by: Matthias van de Meent <[email protected]>
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.
Some nitpicks, but apart from that LGTM.
Co-authored-by: Matthias van de Meent <[email protected]>
## Problem See #10281 pg17 performs extra lock/unlock operation when fetching LwLSN. ## Summary of changes Perform all lookups under one lock, moving initialization of not found keys to separate loop. Related Postgres PR: neondatabase/postgres#553 --------- Co-authored-by: Konstantin Knizhnik <[email protected]>
No description provided.