-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hide RaftStorage
and similar types from generic arguments to Raft
/RaftInner
#938
Comments
👋 Thanks for opening this issue! Get help or engage by:
|
Adding Network, LogStore, and StateMachine into |
Right... So a second trait? It also makes the upgrade path much simpler for existing users. |
A second trait would be fine to me. :) |
This addresses databendlabs#938 partially (just the outer API level).
This addresses databendlabs#938 partially (just the outer API level).
@schreter |
Yes, of course, now that the generics are gone :-). |
Currently, the types for storage, log and network factory are passed as generic arguments to
Raft
. This means that theSend
andSync
traits ofRaft
/RaftInner
are derived from these types as well.For single-threaded
Raft
instances, this means that theRaft
object would be!Send
and!Sync
, even though these types are only used in the single task whereRaftInner
is running. In the current implementation (see also PR #934), theSend
andSync
traits are explicitly implemented for single-threadedRaft
when the data types actually exchanged between threads (such as request and response) areSend
. However, such implementation must be markedunsafe
.Ideally, deriving
Send
andSync
traits should be left to the compiler.To fix this, we need to convert generic arguments to associated types. Then, only the respective usage of the associated type which is
!Send
would prevent cross-thread communication (i.e., within theRaft
task - where we do want to have it single-threaded).Other types (like request/response) are passed via
RaftTypeConfig
already. To pass storage, log and network factory types, we can either devise a new config trait, such asRaftStorageConfig
, where these types would be defined as associated types, or, we can simply add them toRaftTypeConfig
. In either case, the containing trait instance is as suchSend
+Sync
, only (some of) the associated types aren't. In this way, we don't need theunsafe impl
of the two traits.The question is, which way to go (single
RaftTypeConfig
or two traits). In any case, this is a breaking change to the API.For the latter case (two config traits), the API change can be hidden by forwarding from the old API to the new API via a suitably-written type alias and reexports and using a feature switch to enable this forwarding for old users.
Ideas? Suggestions?
The text was updated successfully, but these errors were encountered: