Skip to content

Conversation

@dordsor21
Copy link
Member

thoughts?

@dordsor21 dordsor21 requested a review from a team as a code owner August 18, 2025 20:03
@github-actions github-actions bot added the Bugfix This PR fixes a bug label Aug 18, 2025
@dordsor21 dordsor21 force-pushed the fix/adapter-getblocks-synchronisation branch from 7c21bcf to c1f1d5a Compare August 24, 2025 17:08
@NotMyFault NotMyFault requested a review from Copilot August 26, 2025 15:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors synchronization in the trim method implementation across multiple version adapters to improve thread safety and performance. The change removes method-level synchronization in favor of more granular locking patterns.

  • Removes synchronized modifier from trim method signatures across all version adapters
  • Implements granular synchronization with proper try-finally blocks for write locks
  • Updates ChunkCache to delegate synchronization responsibility to individual implementations

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ChunkCache.java Removes synchronized block around igb.trim() call, delegating sync to implementation
PaperweightGetBlocks.java (v1_21_6) Refactors trim method with granular synchronization and proper lock handling
PaperweightGetBlocks.java (v1_21_5) Identical synchronization refactoring as v1_21_6
PaperweightGetBlocks.java (v1_21_4) Identical synchronization refactoring as v1_21_6
PaperweightGetBlocks.java (v1_21) Identical synchronization refactoring as v1_21_6
PaperweightGetBlocks.java (v1_20_5) Identical synchronization refactoring as v1_21_6
PaperweightGetBlocks.java (v1_20_4) Identical synchronization refactoring as v1_21_6
PaperweightGetBlocks.java (v1_20_2) Identical synchronization refactoring as v1_21_6

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@NotMyFault NotMyFault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable

@NotMyFault NotMyFault requested a review from a team September 8, 2025 16:31
@dordsor21 dordsor21 force-pushed the fix/adapter-getblocks-synchronisation branch from c1f1d5a to f9253ba Compare October 11, 2025 16:37
@dordsor21 dordsor21 force-pushed the fix/adapter-getblocks-synchronisation branch from f9253ba to 1178070 Compare October 11, 2025 16:38
@SirYwell
Copy link
Member

Do you remember what the exact deadlock situation was?

Reading levelChunk and the sections array without an appropriate lock sounds a bit dangerous, though I'm not fully sure about the details.

@dordsor21
Copy link
Member Author

dordsor21 commented Oct 11, 2025

Do you remember what the exact deadlock situation was?

Reading levelChunk and the sections array without an appropriate lock sounds a bit dangerous, though I'm not fully sure about the details.

Deadlock was reported by a user in august specifically on trimming. It seems to be a relatively rare circumstance that can lead to the specific trim settings which is why it's not been reported till now, but looking at the old code it was possible for a deadlock.

Is there a specific place you think we should be locking? I believe the methods called from here lock where it would be suitable to do so

@SirYwell
Copy link
Member

I don't have anything specific in mind, but I'd like to better understand the situation in which the deadlock was able to occur. Other than that, it's generally just rather difficult to keep track which lock is acquired where.

@dordsor21
Copy link
Member Author

I don't have anything specific in mind, but I'd like to better understand the situation in which the deadlock was able to occur. Other than that, it's generally just rather difficult to keep track which lock is acquired where.

Basically, trim synchronised on the instance and then locked the sectionLock. internallCall did it the opposite way round (it locked the sectionLock before calling getChunk which synchronises on the instance if this.levelChunk is null (which it will be when we're trimming a lot))

@SirYwell
Copy link
Member

Basically, trim synchronised on the instance and then locked the sectionLock. internallCall did it the opposite way round (it locked the sectionLock before calling getChunk which synchronises on the instance if this.levelChunk is null (which it will be when we're trimming a lot))

Thanks.

@dordsor21 dordsor21 merged commit 0fbaa95 into main Oct 13, 2025
9 of 10 checks passed
@dordsor21 dordsor21 deleted the fix/adapter-getblocks-synchronisation branch October 13, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants