Skip to content

Conversation

@drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Oct 31, 2025

Changelog

change: storage traits return io::Error

Issue #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::Error instead of StorageError<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 StorageIOResult trait for error conversion:

Upgrade tip:

Storage implementors should update trait methods to return io::Error:

// Before
async fn read_vote(&mut self) -> Result<Option<Vote>, StorageError<C>> {
    self.vote.read().map_err(|e| StorageError::read_vote(&e))
}

// After
async fn read_vote(&mut self) -> Result<Option<Vote>, io::Error> {
    self.vote.read()
}

Return io::Error directly - Openraft adds context automatically.
The method body may leave unchanged: io::Error can be converted to
StorageError with a simple ?.



This change is Reviewable

@drmingdrmer drmingdrmer force-pushed the 263-io-error branch 5 times, most recently from 57effc1 to e1d2650 Compare October 31, 2025 04:51
@drmingdrmer drmingdrmer marked this pull request as ready for review October 31, 2025 04:55
@drmingdrmer drmingdrmer force-pushed the 263-io-error branch 5 times, most recently from 5f0767d to b6747fe Compare October 31, 2025 11:56
Issue databendlabs#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::Error` instead of `StorageError<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 `StorageIOResult` trait for error conversion:
- Provides 14 methods like `.sto_read_logs()`, `.sto_write_snapshot()`, etc.
- Converts `io::Error` to `StorageError<C>` with proper context at Openraft boundaries

- Fix: databendlabs#1457

Upgrade tip:

Storage implementors should update trait methods to return `io::Error`:

```rust
// Before
async fn read_vote(&mut self) -> Result<Option<Vote>, StorageError<C>> {
    self.vote.read().map_err(|e| StorageError::read_vote(&e))
}

// After
async fn read_vote(&mut self) -> Result<Option<Vote>, io::Error> {
    self.vote.read()
}
```

Return `io::Error` directly - Openraft adds context automatically.
The method body may leave unchanged: `io::Error` can be converted to
`StorageError` with a simple `?`.
Copy link
Collaborator

@xp-trumpet xp-trumpet left a comment

Choose a reason for hiding this comment

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

@xp-trumpet reviewed 17 of 26 files at r1, 2 of 2 files at r2, 1 of 1 files at r3, 11 of 11 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @schreter)

@drmingdrmer drmingdrmer added this pull request to the merge queue Oct 31, 2025
Merged via the queue into databendlabs:main with commit d1ffaa2 Oct 31, 2025
35 checks passed
@drmingdrmer drmingdrmer deleted the 263-io-error branch October 31, 2025 12:23
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.

Simplify storage trait error API: Accept io::Error from applications, manually convert to StorageError<C> with context

2 participants