Skip to content
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

PBTree: Fix Dead Lock and Refactor write/update inteface #11985

Merged
merged 2 commits into from
Feb 3, 2024

Conversation

bigreybear
Copy link
Contributor

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

  1. deleteSegment (handled by previous PR)
  2. purgeSegment (handled by previous PR)
  3. relocateSegment
    called by:
    3.1 SegmentedPage.write // covered when write within PageManager
    3.2 SegmentedPage.update // covered when update within PageManager
  4. reaarangeSegment
    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
  5. extendSegmentInPlace // only extend last segment so only decrease spare size
  6. registerNewSegment // only decrease

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:

  • been self-reviewed.
    • concurrent read
    • concurrent write
    • concurrent read and write
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods.
  • added or updated version, license, or notice information
  • added comments explaining the "why" and the intent of the code wherever would not be obvious
    for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold
    for code coverage.
  • added integration tests.
  • been tested in a test IoTDB cluster.

Key changed/added classes (or packages if there are too many classes) in this PR

@Cpaulyz Cpaulyz merged commit f1d7186 into apache:master Feb 3, 2024
36 checks passed
SzyWilliam pushed a commit to SzyWilliam/iotdb that referenced this pull request Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants