Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*.proto]
indent_style = space
indent_size = 2
tab_width = 2

6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ init:
check: init
$(CURDIR)/scripts/check.sh

proto-fmt: init
$(CURDIR)/scripts/proto_format.sh --write

proto-fmt-check: init
$(CURDIR)/scripts/proto_format.sh --check

go: check
# Standalone GOPATH
$(CURDIR)/scripts/generate_go.sh
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Protocol buffer files for TiKV
* Go
* Protoc 3.8.0

# Proto formatting

To avoid IDE-induced diffs, we use `buf format` to keep all `.proto` files consistently formatted.

* Check formatting (also runs as part of `make check`): `make proto-fmt-check`
* Format in-place: `make proto-fmt`

The formatter is pinned and will be downloaded automatically into `./bin` (gitignored) when needed.
If `make check` fails on formatting, run `make proto-fmt` and then rerun `make check`.

# Docker image

The easiest way to compile the protobufs is to use docker.
Expand Down
202 changes: 101 additions & 101 deletions include/eraftpb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ syntax = "proto3";
package eraftpb;

enum EntryType {
EntryNormal = 0;
EntryConfChange = 1;
EntryConfChangeV2 = 2;
EntryNormal = 0;
EntryConfChange = 1;
EntryConfChangeV2 = 2;
}

// The entry is a type of change that needs to be applied. It contains two data fields.
Expand All @@ -18,134 +18,134 @@ enum EntryType {
// context will provide anything needed to assist the configuration change. The context
// if for the user to set and use in this case.
message Entry {
EntryType entry_type = 1;
uint64 term = 2;
uint64 index = 3;
bytes data = 4;
bytes context = 6;

// Deprecated! It is kept for backward compatibility.
// TODO: remove it in the next major release.
bool sync_log = 5;
EntryType entry_type = 1;
uint64 term = 2;
uint64 index = 3;
bytes data = 4;
bytes context = 6;

// Deprecated! It is kept for backward compatibility.
// TODO: remove it in the next major release.
bool sync_log = 5;
}

message SnapshotMetadata {
// The current `ConfState`.
ConfState conf_state = 1;
// The applied index.
uint64 index = 2;
// The term of the applied index.
uint64 term = 3;
// The current `ConfState`.
ConfState conf_state = 1;
// The applied index.
uint64 index = 2;
// The term of the applied index.
uint64 term = 3;
}

message Snapshot {
bytes data = 1;
SnapshotMetadata metadata = 2;
bytes data = 1;
SnapshotMetadata metadata = 2;
}

enum MessageType {
MsgHup = 0;
MsgBeat = 1;
MsgPropose = 2;
MsgAppend = 3;
MsgAppendResponse = 4;
MsgRequestVote = 5;
MsgRequestVoteResponse = 6;
MsgSnapshot = 7;
MsgHeartbeat = 8;
MsgHeartbeatResponse = 9;
MsgUnreachable = 10;
MsgSnapStatus = 11;
MsgCheckQuorum = 12;
MsgTransferLeader = 13;
MsgTimeoutNow = 14;
MsgReadIndex = 15;
MsgReadIndexResp = 16;
MsgRequestPreVote = 17;
MsgRequestPreVoteResponse = 18;
MsgHup = 0;
MsgBeat = 1;
MsgPropose = 2;
MsgAppend = 3;
MsgAppendResponse = 4;
MsgRequestVote = 5;
MsgRequestVoteResponse = 6;
MsgSnapshot = 7;
MsgHeartbeat = 8;
MsgHeartbeatResponse = 9;
MsgUnreachable = 10;
MsgSnapStatus = 11;
MsgCheckQuorum = 12;
MsgTransferLeader = 13;
MsgTimeoutNow = 14;
MsgReadIndex = 15;
MsgReadIndexResp = 16;
MsgRequestPreVote = 17;
MsgRequestPreVoteResponse = 18;
}

message Message {
MessageType msg_type = 1;
uint64 to = 2;
uint64 from = 3;
uint64 term = 4;
uint64 log_term = 5;
uint64 index = 6;
repeated Entry entries = 7;
uint64 commit = 8;
Snapshot snapshot = 9;
uint64 request_snapshot = 13;
bool reject = 10;
uint64 reject_hint = 11;
bytes context = 12;
uint64 deprecated_priority = 14;
// If this new field is not set, then use the above old field; otherwise
// use the new field. When broadcasting request vote, both fields are
// set if the priority is larger than 0. This change is not a fully
// compatible change, but it makes minimal impact that only new priority
// is not recognized by the old nodes during rolling update.
int64 priority = 15;
MessageType msg_type = 1;
uint64 to = 2;
uint64 from = 3;
uint64 term = 4;
uint64 log_term = 5;
uint64 index = 6;
repeated Entry entries = 7;
uint64 commit = 8;
Snapshot snapshot = 9;
uint64 request_snapshot = 13;
bool reject = 10;
uint64 reject_hint = 11;
bytes context = 12;
uint64 deprecated_priority = 14;
// If this new field is not set, then use the above old field; otherwise
// use the new field. When broadcasting request vote, both fields are
// set if the priority is larger than 0. This change is not a fully
// compatible change, but it makes minimal impact that only new priority
// is not recognized by the old nodes during rolling update.
int64 priority = 15;
}

message HardState {
uint64 term = 1;
uint64 vote = 2;
uint64 commit = 3;
uint64 term = 1;
uint64 vote = 2;
uint64 commit = 3;
}

enum ConfChangeTransition {
// Automatically use the simple protocol if possible, otherwise fall back
// to ConfChangeType::Implicit. Most applications will want to use this.
Auto = 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).
Implicit = 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).
Explicit = 2;
// Automatically use the simple protocol if possible, otherwise fall back
// to ConfChangeType::Implicit. Most applications will want to use this.
Auto = 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).
Implicit = 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).
Explicit = 2;
}

message ConfState {
repeated uint64 voters = 1;
repeated uint64 learners = 2;

// The voters in the outgoing config. If not empty the node is in joint consensus.
repeated uint64 voters_outgoing = 3;
// 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).
repeated uint64 learners_next = 4;
// 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.
bool auto_leave = 5;
repeated uint64 voters = 1;
repeated uint64 learners = 2;

// The voters in the outgoing config. If not empty the node is in joint consensus.
repeated uint64 voters_outgoing = 3;
// 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).
repeated uint64 learners_next = 4;
// 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.
bool auto_leave = 5;
}

enum ConfChangeType {
AddNode = 0;
RemoveNode = 1;
AddLearnerNode = 2;
AddNode = 0;
RemoveNode = 1;
AddLearnerNode = 2;
}

message ConfChange {
ConfChangeType change_type = 2;
uint64 node_id = 3;
bytes context = 4;
ConfChangeType change_type = 2;
uint64 node_id = 3;
bytes context = 4;

uint64 id = 1;
uint64 id = 1;
}

// ConfChangeSingle is an individual configuration change operation. Multiple
// such operations can be carried out atomically via a ConfChangeV2.
message ConfChangeSingle {
ConfChangeType change_type = 1;
uint64 node_id = 2;
ConfChangeType change_type = 1;
uint64 node_id = 2;
}

// ConfChangeV2 messages initiate configuration changes. They support both the
Expand Down Expand Up @@ -181,7 +181,7 @@ message ConfChangeSingle {
//
// [1]: https://github.com/ongardie/dissertation/blob/master/online-trim.pdf
message ConfChangeV2 {
ConfChangeTransition transition = 1;
repeated ConfChangeSingle changes = 2;
bytes context = 3;
ConfChangeTransition transition = 1;
repeated ConfChangeSingle changes = 2;
bytes context = 3;
}
66 changes: 33 additions & 33 deletions include/rustproto.proto
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
syntax = "proto2";

import "google/protobuf/descriptor.proto";

// see https://github.com/gogo/protobuf/blob/master/gogoproto/gogo.proto
// for the original idea

package rustproto;

import "google/protobuf/descriptor.proto";

extend google.protobuf.FileOptions {
// When true, oneof field is generated public
optional bool expose_oneof_all = 17001;
// When true all fields are public, and not accessors generated
optional bool expose_fields_all = 17003;
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
optional bool generate_accessors_all = 17004;
// Use `bytes::Bytes` for `bytes` fields
optional bool carllerche_bytes_for_bytes_all = 17011;
// Use `bytes::Bytes` for `string` fields
optional bool carllerche_bytes_for_string_all = 17012;
// When true, will only generate codes that works with lite runtime.
optional bool lite_runtime_all = 17035;
// When true, oneof field is generated public
optional bool expose_oneof_all = 17001;
// When true all fields are public, and not accessors generated
optional bool expose_fields_all = 17003;
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
optional bool generate_accessors_all = 17004;
// Use `bytes::Bytes` for `bytes` fields
optional bool carllerche_bytes_for_bytes_all = 17011;
// Use `bytes::Bytes` for `string` fields
optional bool carllerche_bytes_for_string_all = 17012;
// When true, will only generate codes that works with lite runtime.
optional bool lite_runtime_all = 17035;
}

extend google.protobuf.MessageOptions {
// When true, oneof field is generated public
optional bool expose_oneof = 17001;
// When true all fields are public, and not accessors generated
optional bool expose_fields = 17003;
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
optional bool generate_accessors = 17004;
// Use `bytes::Bytes` for `bytes` fields
optional bool carllerche_bytes_for_bytes = 17011;
// Use `bytes::Bytes` for `string` fields
optional bool carllerche_bytes_for_string = 17012;
// When true, oneof field is generated public
optional bool expose_oneof = 17001;
// When true all fields are public, and not accessors generated
optional bool expose_fields = 17003;
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
optional bool generate_accessors = 17004;
// Use `bytes::Bytes` for `bytes` fields
optional bool carllerche_bytes_for_bytes = 17011;
// Use `bytes::Bytes` for `string` fields
optional bool carllerche_bytes_for_string = 17012;
}

extend google.protobuf.FieldOptions {
// When true all fields are public, and not accessors generated
optional bool expose_fields_field = 17003;
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
optional bool generate_accessors_field = 17004;
// Use `bytes::Bytes` for `bytes` fields
optional bool carllerche_bytes_for_bytes_field = 17011;
// Use `bytes::Bytes` for `string` fields
optional bool carllerche_bytes_for_string_field = 17012;
}
// When true all fields are public, and not accessors generated
optional bool expose_fields_field = 17003;
// When false, `get_`, `set_`, `mut_` etc. accessors are not generated
optional bool generate_accessors_field = 17004;
// Use `bytes::Bytes` for `bytes` fields
optional bool carllerche_bytes_for_bytes_field = 17011;
// Use `bytes::Bytes` for `string` fields
optional bool carllerche_bytes_for_string_field = 17012;
}
Loading