Add BatchStorer for batched persistence with robust features#254
Add BatchStorer for batched persistence with robust features#254
BatchStorer for batched persistence with robust features#254Conversation
…shing, and capacity handling
…background flush scheduler
…ary checks for uninitialized state in `BatchStorer`.
… details, emphasizing batching behavior and resource management.
…zation and background flush process.
There was a problem hiding this comment.
Pull request overview
This PR adds a new BatchStorer utility (Storer decorator) to batch persistence commits, with configurable flush triggering (size/time) and a scheduled background flush check to improve throughput for write-heavy workloads.
Changes:
- Introduces
BatchStorerinterface and default implementation that wraps aStorerand batches commits. - Adds
Controllerhelpers to trigger flushes based on time, size, or both. - Adds a scheduled background flush mechanism and AutoCloseable lifecycle management.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…accuracy and enhance thread-safety in synchronization and shutdown logic.
…ecks in `BatchStorer.Default`.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…gn `flush()` implementation with `commit()`.
… `pendingSinceNanos` for precision, and improve thread safety and close handling.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This change restructures the BatchStorer component by relocating it within the `types` package, simplifying its interface, and integrating new lifecycle management features. Added support for batch-storing creation methods in PersistenceManager and related classes, enabling easier control of store operations during write-heavy scenarios.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…dation, enhance synchronization, and improve lifecycle handling across persistence classes.
…eduling consistency.
…aryStorer` to simplify APIs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…naryStorer` Introduce tracking of the maximum byte count per channel and implement safety flush logic to prevent exceeding 2 GB per channel. Add related methods in `ChunksBuffer` and `BinaryStorer`, ensuring proper size-based flush decisions.
…hen writes are disabled, ensuring compliance with the write-disable contract.
… improve thread safety and prevent deadlocks. - Anti-pattern removal: Default's concurrency design explicitly warns against using the storer instance as a monitor because "outside logic could lock the storer first, reversing the lock order." Every synchronized method modifier in Batching used the storer instance (this) as the monitor — exactly this anti-pattern. - Consistent lock ordering: By using this.head (Default's designated internal mutex), Batching now follows the same this.head → objectRegistry lock ordering that Default established. The ensureObjectId* calls acquire objectRegistry and call back to this.head reentrantly (same thread), which is safe. - Serialization preserved: All Batching entry points still serialize through this.head, so only one thread at a time can enter ensureObjectId* or processItems, preventing the cross-thread head ↔ objectRegistry deadlock. - Added a block comment on the Batching class explaining the locking rationale.
…ush()` after storing to match `internalStore` logic.
…Flush()` after storing to align with `internalStore` logic.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Introduced a `HashMapIdId` utility for fast `long` to `long` mappings without boxing overhead. - Enhanced `ChunksBuffer` and `ChunksBufferByteReversing` to enable entity deduplication, leveraging `HashMapIdId` to avoid redundant storage. - Added logic to compact duplicate entities during buffer completion, reducing memory usage and improving efficiency. - Updated `BinaryStorer` to integrate deduplication support with configurable behavior.
…n thread leaks on invalid `checkInterval` values.
…plicitly passed root instances and improving flush consistency.
…is called after closure.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ency design, lock ordering, and deadlock prevention logic.
…ion and hide implementation details - Introduced `BatchStorer.Builder` for configuring `maxSize`, `flushCycle`, and `checkInterval` with a fluent API. - Added `Persister.batchStorerBuilder()` method for streamlined instantiation. - Updated usage examples to reflect the new builder pattern. - Enforced contract validation to ensure at least one threshold (`maxSize` or `flushCycle`) is configured before building.
Summary
This pull request introduces the
BatchStorerutility, designed to efficiently manage batched persistence operations. Key features include:Changes
BatchStorerutility for managing batching of persistence operations.BatchStorerthread-safe to prevent concurrent modification issues.BatchStorerbehavior, including auto-closing and capacity controls.BatchStorer, focusing on use cases and implementation details.lastFlushwith a timestamp.Notes
No breaking changes are introduced with this pull request. Existing functionality remains unaffected by the addition.