change: storage traits return io::Error
#1478
Merged
+477
−351
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changelog
change: storage traits return
io::ErrorIssue #1457: Simplify storage trait error API.
Benefits: Simpler trait implementation - Storage code doesn't need to
know about
StorageError<C>or generic type parameters in error handling.Changes
Storage trait methods now return
io::Errorinstead ofStorageError<C>:RaftLogStorage:append(),truncate(),purge(),save_vote(),save_committed()RaftLogReader:try_get_log_entries(),limited_get_log_entries(),read_vote(),get_key_log_ids()RaftStateMachine:applied_state(),apply(),get_current_snapshot(),begin_receiving_snapshot(),install_snapshot()RaftSnapshotBuilder:build_snapshot()Added internal
StorageIOResulttrait for error conversion:Provides 14 methods like
.sto_read_logs(),.sto_write_snapshot(), etc.Converts
io::ErrortoStorageError<C>with proper context at Openraft boundariesFix: Simplify storage trait error API: Accept io::Error from applications, manually convert to StorageError<C> with context #1457
Upgrade tip:
Storage implementors should update trait methods to return
io::Error:Return
io::Errordirectly - Openraft adds context automatically.The method body may leave unchanged:
io::Errorcan be converted toStorageErrorwith a simple?.This change is