Closed killme2008 closed 1 week ago
The updates enhance the thread-safety and state management of snapshot-related classes in the JRaft library. Critical modifications include marking multiple classes as not thread-safe and introducing state checks for proper resource handling in snapshot reader and writer classes.
Files | Change Summary |
---|---|
.../jraft/storage/snapshot/SnapshotReader.java .../jraft/storage/snapshot/SnapshotWriter.java .../jraft/storage/snapshot/local/SnapshotFileReader.java |
Added notes in documentation to indicate that the classes are not thread-safe, improving clarity about the limitations of these classes. |
.../jraft/storage/snapshot/local/LocalSnapshotReader.java |
Added a closed field, a checkState() method, and updated the close() method to check state before closing, enhancing state management to avoid operating on closed readers. |
.../jraft/storage/snapshot/local/LocalSnapshotWriter.java |
Introduced a closed field, a checkState() method, and state checks in multiple methods (close() , saveMeta() , sync() , addFile() , removeFile() ) to ensure proper state handling. |
Objective (Issues) | Addressed | Explanation |
---|---|---|
Improve thread-safety of snapshot classes (#1099) | ✅ |
In code we trust, we make it right, Ensuring threads won't clash with might. A reader closed, a state that's known, Our snapshots safe, stability shown.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Motivation:
SnapshotReader
andSnapshopWriter
close
state checking forSnapshotReader
andSnapshopWriter
Modification:
Describe the idea and modifications you've done.
Result:
After this PR, i think we can close #1099
If there is no issue then describe the changes introduced by this PR.
Summary by CodeRabbit
Documentation
SnapshotReader
,SnapshotWriter
, andSnapshotFileReader
are not thread-safe.New Features
closed
boolean field inLocalSnapshotReader
andLocalSnapshotWriter
.checkState()
method toLocalSnapshotReader
andLocalSnapshotWriter
to ensure operations are not performed on closed instances.