Skip to content

fix: address potential race conditions#36

Merged
Sammster10 merged 6 commits intomasterfrom
fix/race-conditions
Mar 13, 2026
Merged

fix: address potential race conditions#36
Sammster10 merged 6 commits intomasterfrom
fix/race-conditions

Conversation

@Sammster10
Copy link
Member

No description provided.

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 DataManager’s query result caching to better handle concurrent invalidation by introducing a dedicated dependency-tracking cache abstraction and tightening synchronization around the UniqueData instance cache.

Changes:

  • Added DependencyTrackingCache to encapsulate Caffeine caching + dependency-to-query tracking + generation-based invalidation.
  • Migrated DataManager’s relation/cell caches to DependencyTrackingCache and centralized cell-resolution logic via resolveCells(...).
  • Added finer-grained synchronization around uniqueDataInstanceCache accesses to reduce race conditions during delete/id-column updates/instance creation.

Reviewed changes

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

File Description
core/src/main/java/net/staticstudios/data/util/DependencyTrackingCache.java New dependency-tracking cache wrapper (generation gating, dependency mapping, invalidation + cleanup hooks).
core/src/main/java/net/staticstudios/data/DataManager.java Replaces inline cache logic with DependencyTrackingCache, consolidates invalidation cell resolution, and synchronizes instance-cache mutations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sammster10 and others added 3 commits March 13, 2026 16:51
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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

Introduces a dedicated dependency-aware cache abstraction to centralize Caffeine caching + dependency invalidation logic and applies it in DataManager, with additional synchronization changes to reduce race conditions around cached UniqueData instances.

Changes:

  • Added DependencyTrackingCache (Caffeine-backed) that tracks query dependencies and invalidates dependent queries on cell changes using a generation counter.
  • Refactored DataManager to replace separate relation/cell caches + dependency maps with DependencyTrackingCache instances and deduplicated invalidation cell-resolution logic.
  • Added DependencyTrackingCacheTest covering basic cache behavior, invalidation behavior, generation gating, and a put-vs-invalidate concurrency scenario.

Reviewed changes

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

File Description
core/src/main/java/net/staticstudios/data/util/DependencyTrackingCache.java New cache component that couples query results with cell-dependency tracking and supports generation-gated puts + dependency-driven invalidation.
core/src/test/java/net/staticstudios/data/util/DependencyTrackingCacheTest.java New unit tests for dependency tracking cache behavior, including some concurrency-oriented validation.
core/src/main/java/net/staticstudios/data/DataManager.java Swaps in DependencyTrackingCache for relation/cell caches, consolidates invalidation cell resolution, and adjusts synchronization for uniqueDataInstanceCache access.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sammster10 and others added 2 commits March 13, 2026 17:02
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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

Introduces a reusable, dependency-tracking cache abstraction to make cache invalidation and generation-gated writes consistent and thread-safe, then integrates it into DataManager to reduce race-condition risk.

Changes:

  • Added DependencyTrackingCache (Caffeine-backed) with generation gating, dependency mapping, and coordinated invalidation/cleanup.
  • Refactored DataManager relation/cell caches to use DependencyTrackingCache and tightened synchronization around uniqueDataInstanceCache operations.
  • Added a comprehensive JUnit test suite for cache behavior, including concurrent put/invalidate and concurrent replacement scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
core/src/main/java/net/staticstudios/data/util/DependencyTrackingCache.java New cache wrapper implementing dependency-based invalidation and generation-checked puts.
core/src/main/java/net/staticstudios/data/DataManager.java Swaps in DependencyTrackingCache for relation/cell caching and adjusts synchronization for race-condition fixes.
core/src/test/java/net/staticstudios/data/util/DependencyTrackingCacheTest.java New unit tests validating cache semantics and exercising concurrency edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@Sammster10 Sammster10 merged commit 6949654 into master Mar 13, 2026
5 checks passed
@Sammster10 Sammster10 deleted the fix/race-conditions branch March 13, 2026 21:11
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