2015-06-30 04:37:52 +03:00
|
|
|
syntax = "proto2";
|
2014-08-28 05:53:18 +04:00
|
|
|
package raftpb;
|
2014-08-28 04:53:36 +04:00
|
|
|
|
2015-09-03 19:57:59 +03:00
|
|
|
import "gogoproto/gogo.proto";
|
2014-08-28 04:53:36 +04:00
|
|
|
|
|
|
|
option (gogoproto.marshaler_all) = true;
|
|
|
|
option (gogoproto.sizer_all) = true;
|
|
|
|
option (gogoproto.unmarshaler_all) = true;
|
|
|
|
option (gogoproto.goproto_getters_all) = false;
|
2014-09-21 09:48:17 +04:00
|
|
|
option (gogoproto.goproto_enum_prefix_all) = false;
|
2014-08-28 04:53:36 +04:00
|
|
|
|
2014-09-21 09:48:17 +04:00
|
|
|
enum EntryType {
|
2019-07-19 14:50:03 +03:00
|
|
|
EntryNormal = 0;
|
|
|
|
EntryConfChange = 1; // corresponds to pb.ConfChange
|
|
|
|
EntryConfChangeV2 = 2; // corresponds to pb.ConfChangeV2
|
2014-09-21 09:48:17 +04:00
|
|
|
}
|
|
|
|
|
2014-08-28 04:53:36 +04:00
|
|
|
message Entry {
|
2016-07-08 21:13:53 +03:00
|
|
|
optional uint64 Term = 2 [(gogoproto.nullable) = false]; // must be 64-bit aligned for atomic operations
|
|
|
|
optional uint64 Index = 3 [(gogoproto.nullable) = false]; // must be 64-bit aligned for atomic operations
|
2015-06-30 02:05:55 +03:00
|
|
|
optional EntryType Type = 1 [(gogoproto.nullable) = false];
|
2015-06-30 04:37:52 +03:00
|
|
|
optional bytes Data = 4;
|
2014-08-28 04:53:36 +04:00
|
|
|
}
|
|
|
|
|
2014-11-20 00:17:50 +03:00
|
|
|
message SnapshotMetadata {
|
2015-06-30 02:05:55 +03:00
|
|
|
optional ConfState conf_state = 1 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 index = 2 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 term = 3 [(gogoproto.nullable) = false];
|
2014-11-20 00:17:50 +03:00
|
|
|
}
|
|
|
|
|
2014-08-28 04:53:36 +04:00
|
|
|
message Snapshot {
|
2015-06-30 04:37:52 +03:00
|
|
|
optional bytes data = 1;
|
|
|
|
optional SnapshotMetadata metadata = 2 [(gogoproto.nullable) = false];
|
2014-08-28 04:53:36 +04:00
|
|
|
}
|
|
|
|
|
2014-10-12 11:34:22 +04:00
|
|
|
enum MessageType {
|
2015-02-25 08:38:18 +03:00
|
|
|
MsgHup = 0;
|
|
|
|
MsgBeat = 1;
|
|
|
|
MsgProp = 2;
|
|
|
|
MsgApp = 3;
|
|
|
|
MsgAppResp = 4;
|
|
|
|
MsgVote = 5;
|
|
|
|
MsgVoteResp = 6;
|
|
|
|
MsgSnap = 7;
|
|
|
|
MsgHeartbeat = 8;
|
|
|
|
MsgHeartbeatResp = 9;
|
|
|
|
MsgUnreachable = 10;
|
|
|
|
MsgSnapStatus = 11;
|
2015-11-24 08:59:25 +03:00
|
|
|
MsgCheckQuorum = 12;
|
2016-03-24 14:59:41 +03:00
|
|
|
MsgTransferLeader = 13;
|
|
|
|
MsgTimeoutNow = 14;
|
2016-06-03 18:20:10 +03:00
|
|
|
MsgReadIndex = 15;
|
|
|
|
MsgReadIndexResp = 16;
|
2016-10-10 09:32:40 +03:00
|
|
|
MsgPreVote = 17;
|
|
|
|
MsgPreVoteResp = 18;
|
2014-10-12 11:34:22 +04:00
|
|
|
}
|
|
|
|
|
2014-08-28 04:53:36 +04:00
|
|
|
message Message {
|
2015-06-30 02:05:55 +03:00
|
|
|
optional MessageType type = 1 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 to = 2 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 from = 3 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 term = 4 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 logTerm = 5 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 index = 6 [(gogoproto.nullable) = false];
|
2014-12-31 06:42:59 +03:00
|
|
|
repeated Entry entries = 7 [(gogoproto.nullable) = false];
|
2015-06-30 02:05:55 +03:00
|
|
|
optional uint64 commit = 8 [(gogoproto.nullable) = false];
|
|
|
|
optional Snapshot snapshot = 9 [(gogoproto.nullable) = false];
|
|
|
|
optional bool reject = 10 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 rejectHint = 11 [(gogoproto.nullable) = false];
|
2016-07-12 11:14:06 +03:00
|
|
|
optional bytes context = 12;
|
2014-08-28 04:53:36 +04:00
|
|
|
}
|
2014-08-28 05:53:18 +04:00
|
|
|
|
2014-09-16 04:35:02 +04:00
|
|
|
message HardState {
|
2015-06-30 02:05:55 +03:00
|
|
|
optional uint64 term = 1 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 vote = 2 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 commit = 3 [(gogoproto.nullable) = false];
|
2014-08-28 05:53:18 +04:00
|
|
|
}
|
2014-09-23 01:38:21 +04:00
|
|
|
|
2019-07-19 14:50:03 +03:00
|
|
|
// ConfChangeTransition specifies the behavior of a configuration change with
|
|
|
|
// respect to joint consensus.
|
|
|
|
enum ConfChangeTransition {
|
|
|
|
// Automatically use the simple protocol if possible, otherwise fall back
|
|
|
|
// to ConfChangeJointImplicit. Most applications will want to use this.
|
|
|
|
ConfChangeTransitionAuto = 0;
|
|
|
|
// Use joint consensus unconditionally, and transition out of them
|
|
|
|
// automatically (by proposing a zero configuration change).
|
|
|
|
//
|
|
|
|
// This option is suitable for applications that want to minimize the time
|
|
|
|
// spent in the joint configuration and do not store the joint configuration
|
|
|
|
// in the state machine (outside of InitialState).
|
|
|
|
ConfChangeTransitionJointImplicit = 1;
|
|
|
|
// Use joint consensus and remain in the joint configuration until the
|
|
|
|
// application proposes a no-op configuration change. This is suitable for
|
|
|
|
// applications that want to explicitly control the transitions, for example
|
|
|
|
// to use a custom payload (via the Context field).
|
|
|
|
ConfChangeTransitionJointExplicit = 2;
|
|
|
|
}
|
|
|
|
|
2014-11-20 00:17:50 +03:00
|
|
|
message ConfState {
|
2019-07-19 14:50:03 +03:00
|
|
|
// The voters in the incoming config. (If the configuration is not joint,
|
|
|
|
// then the outgoing config is empty).
|
2019-07-23 01:34:46 +03:00
|
|
|
repeated uint64 voters = 1;
|
2019-07-19 14:50:03 +03:00
|
|
|
// The learners in the incoming config.
|
2019-07-23 01:34:46 +03:00
|
|
|
repeated uint64 learners = 2;
|
|
|
|
// The voters in the outgoing config.
|
|
|
|
repeated uint64 voters_outgoing = 3;
|
2019-07-19 14:50:03 +03:00
|
|
|
// The nodes that will become learners when the outgoing config is removed.
|
|
|
|
// These nodes are necessarily currently in nodes_joint (or they would have
|
|
|
|
// been added to the incoming config right away).
|
2019-07-23 01:34:46 +03:00
|
|
|
repeated uint64 learners_next = 4;
|
2019-07-19 14:50:03 +03:00
|
|
|
// If set, the config is joint and Raft will automatically transition into
|
|
|
|
// the final config (i.e. remove the outgoing config) when this is safe.
|
2019-07-23 01:34:46 +03:00
|
|
|
optional bool auto_leave = 5 [(gogoproto.nullable) = false];
|
2014-11-20 00:17:50 +03:00
|
|
|
}
|
|
|
|
|
2014-09-23 23:02:44 +04:00
|
|
|
enum ConfChangeType {
|
2017-11-11 05:38:21 +03:00
|
|
|
ConfChangeAddNode = 0;
|
|
|
|
ConfChangeRemoveNode = 1;
|
|
|
|
ConfChangeUpdateNode = 2;
|
|
|
|
ConfChangeAddLearnerNode = 3;
|
2014-09-23 01:38:21 +04:00
|
|
|
}
|
|
|
|
|
2014-09-23 23:02:44 +04:00
|
|
|
message ConfChange {
|
2019-07-19 14:50:03 +03:00
|
|
|
optional ConfChangeType type = 2 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 node_id = 3 [(gogoproto.nullable) = false, (gogoproto.customname) = "NodeID" ];
|
|
|
|
optional bytes context = 4;
|
|
|
|
|
|
|
|
// NB: this is used only by etcd to thread through a unique identifier.
|
|
|
|
// Ideally it should really use the Context instead. No counterpart to
|
|
|
|
// this field exists in ConfChangeV2.
|
|
|
|
optional uint64 id = 1 [(gogoproto.nullable) = false, (gogoproto.customname) = "ID" ];
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfChangeSingle is an individual configuration change operation. Multiple
|
|
|
|
// such operations can be carried out atomically via a ConfChangeV2.
|
|
|
|
message ConfChangeSingle {
|
|
|
|
optional ConfChangeType type = 1 [(gogoproto.nullable) = false];
|
|
|
|
optional uint64 node_id = 2 [(gogoproto.nullable) = false, (gogoproto.customname) = "NodeID"];
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfChangeV2 messages initiate configuration changes. They support both the
|
|
|
|
// simple "one at a time" membership change protocol and full Joint Consensus
|
|
|
|
// allowing for arbitrary changes in membership.
|
|
|
|
//
|
|
|
|
// The supplied context is treated as an opaque payload and can be used to
|
|
|
|
// attach an action on the state machine to the application of the config change
|
|
|
|
// proposal. Note that contrary to Joint Consensus as outlined in the Raft
|
|
|
|
// paper[1], configuration changes become active when they are *applied* to the
|
|
|
|
// state machine (not when they are appended to the log).
|
|
|
|
//
|
|
|
|
// The simple protocol can be used whenever only a single change is made.
|
|
|
|
//
|
|
|
|
// Non-simple changes require the use of Joint Consensus, for which two
|
|
|
|
// configuration changes are run. The first configuration change specifies the
|
|
|
|
// desired changes and transitions the Raft group into the joint configuration,
|
|
|
|
// in which quorum requires a majority of both the pre-changes and post-changes
|
|
|
|
// configuration. Joint Consensus avoids entering fragile intermediate
|
|
|
|
// configurations that could compromise survivability. For example, without the
|
|
|
|
// use of Joint Consensus and running across three availability zones with a
|
|
|
|
// replication factor of three, it is not possible to replace a voter without
|
|
|
|
// entering an intermediate configuration that does not survive the outage of
|
|
|
|
// one availability zone.
|
|
|
|
//
|
|
|
|
// The provided ConfChangeTransition specifies how (and whether) Joint Consensus
|
|
|
|
// is used, and assigns the task of leaving the joint configuration either to
|
|
|
|
// Raft or the application. Leaving the joint configuration is accomplished by
|
|
|
|
// proposing a ConfChangeV2 with only and optionally the Context field
|
|
|
|
// populated.
|
|
|
|
//
|
|
|
|
// For details on Raft membership changes, see:
|
|
|
|
//
|
|
|
|
// [1]: https://github.com/ongardie/dissertation/blob/master/online-trim.pdf
|
|
|
|
message ConfChangeV2 {
|
|
|
|
optional ConfChangeTransition transition = 1 [(gogoproto.nullable) = false];
|
|
|
|
repeated ConfChangeSingle changes = 2 [(gogoproto.nullable) = false];
|
|
|
|
optional bytes context = 3;
|
2014-09-23 01:38:21 +04:00
|
|
|
}
|