PBTree: Fix Dead Lock and Refactor write/update inteface #11985
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The recent deadlock issues are primarily attributed to the double-bucket index design. Each thread maintains a local collection that organizes pages into buckets based on available space, while the PageManager maintains another gloabl set. When a write thread requires a page for writing/updating, it first checks its local buckets and retrieves pages without locking(as they are already locked). If no suitable page is found locally, the thread then accesses the global buckets, where it must retrieve pages with a lock.
The issue arises when a page, which is appropriate for the expected size and referred by the thread previously, is recorded in the global buckets but not in the local ones. This results in the page being locked twice but unlocked only once, leading to a deadlock. Specifically, if a page increases its available space but is not checked and registered in the local buckets, a deadlock becomes highly probable.
This revision made a comprehensive review of any modifications made to the SchemaPage.spareSize field, which determines the page's suitability for the expected space. All methods that modify this attribute are listed below. Additionally, these methods are now accompanied by statements for recording them in the appropriate buckets
SegmentedPage spare size write-value occurence
called by:
3.1 SegmentedPage.write // covered when write within PageManager
3.2 SegmentedPage.update // covered when update within PageManager
called by:
4.1 relocateSegment, trace to 3.
4.2 compactSegment // covered
compactSegment called by
4.2.1 allocNewSegment, only called by pre-allocate, now covered with bucket sort
4.2.2 transplantSegment // covered previously
Furthermore, this PR also refactore SegmentedPage.write/update inteface so that overflow will return a negative value rather than an exception.
Content1 ...
Content2 ...
Content3 ...
This PR has:
for an unfamiliar reader.
for code coverage.
Key changed/added classes (or packages if there are too many classes) in this PR