-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit refines the `RaftEntry` and related traits, to better support application defined log `Entry` type. Key Changes: 1. Remove `FromAppData` trait: - The `FromAppData` trait, which was used to create log `Entry` from application data, is removed. - Applications should now implement the new `RaftEntry::new()` method to create log entries directly. 2. Remove `RaftLogId` trait, it becomes an internal trait. 3. Update `RaftEntry` trait: - The `RaftEntry` trait no longer requires `RaftLogId` (due to its redefinition) and now mandates the implementation of: - `new()`: For creating a log `Entry`. - `log_id_parts()`: To return references to the log ID's committed leader ID(term) and index. - `set_log_id()`: To update the log entry's ID. - Default methods are provided: - `new_blank()`, `new_normal()`, `new_membership()` for creating different types of log entries. - `log_id()` returns an owned `LogId` instance. - `index()` returns the index of the log entry. 4. Introduce `RefLogId`: - `RefLogId` is a reference-based representation of a log ID, complementing the existing `LogIdOf<C>` (a storage-based implementation). - `RefLogId` adds system-defined properties (e.g., `Ord` implementation) while referencing an existing `LogIdOf<C>`. - Internal components now use `RefLogId` where possible, improving flexibility and consistency. 5. Update example `raft-kv-memstore-grpc`: - Updated to implement log `Entry` and related types using protobuf, including state machine and RPC message types. - Added snapshot streaming transmission implementation. - Removed `serde` dependency from the example. - Part of #1278. --- Upgrade tips: 1. For Applications with Custom `RaftEntry` Implementations: If you've declared a custom `RaftEntry` (e.g., `declare_raft_types!(MyTypes: Entry = MyEntry)`): - Remove the implementation of `FromAppData`. - Implement the following new methods: - `new()` - `log_id_parts()` - `set_log_id()` 2. For Applications Using OpenRaft's Default `Entry`: - No changes are required.
- Loading branch information
1 parent
791dc3e
commit 7bebecb
Showing
50 changed files
with
961 additions
and
462 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 19 additions & 21 deletions
40
examples/raft-kv-memstore-grpc/proto/management_service.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,48 @@ | ||
syntax = "proto3"; | ||
import "google/protobuf/empty.proto"; | ||
import "google/protobuf/wrappers.proto"; | ||
import "internal_service.proto"; | ||
import "api_service.proto"; | ||
package openraftpb; | ||
|
||
// ManagementService handles Raft cluster management operations | ||
service ManagementService { | ||
// Init initializes a new Raft cluster with the given nodes | ||
rpc Init(InitRequest) returns (RaftReplyString) {} | ||
rpc Init(InitRequest) returns (google.protobuf.Empty) {} | ||
|
||
// AddLearner adds a new learner node to the Raft cluster | ||
rpc AddLearner(AddLearnerRequest) returns (RaftReplyString) {} | ||
rpc AddLearner(AddLearnerRequest) returns (ClientWriteResponse) {} | ||
|
||
// ChangeMembership modifies the cluster membership configuration | ||
rpc ChangeMembership(ChangeMembershipRequest) returns (RaftReplyString) {} | ||
rpc ChangeMembership(ChangeMembershipRequest) returns (ClientWriteResponse) {} | ||
|
||
// Metrics retrieves cluster metrics and status information | ||
rpc Metrics(RaftRequestString) returns (RaftReplyString) {} | ||
rpc Metrics(google.protobuf.Empty) returns (google.protobuf.StringValue) {} | ||
} | ||
|
||
// InitRequest contains the initial set of nodes for cluster initialization | ||
message InitRequest { | ||
repeated Node nodes = 1; // List of initial cluster nodes | ||
} | ||
|
||
// Node represents a single node in the Raft cluster | ||
message Node { | ||
string rpc_addr = 1; // RPC address for node communication | ||
uint64 node_id = 2; // Unique identifier for the node | ||
} | ||
|
||
// AddLearnerRequest specifies parameters for adding a learner node | ||
message AddLearnerRequest { | ||
Node node = 1; // Node to be added as a learner | ||
} | ||
|
||
// RaftRequestString represents a string-based Raft request | ||
message RaftRequestString { | ||
string data = 1; // Request data in string format | ||
} | ||
|
||
// RaftReplyString represents a string-based Raft response | ||
message RaftReplyString { | ||
string data = 1; // Response data | ||
string error = 2; // Error message, if any | ||
} | ||
|
||
// ChangeMembershipRequest specifies parameters for modifying cluster membership | ||
message ChangeMembershipRequest { | ||
repeated uint64 members = 1; // New set of member node IDs | ||
bool retain = 2; // Whether to retain existing configuration | ||
} | ||
|
||
message ClientWriteResponse { | ||
// The log id of the committed log entry. | ||
LogId log_id = 1; | ||
|
||
// If the committed log entry is a normal one. | ||
Response data = 2; | ||
|
||
// If the committed log entry is a change-membership entry. | ||
Membership membership = 3; | ||
} |
Oops, something went wrong.