From 3fe4369c30c78d8ab489819095260ab54893d509 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 30 Jan 2019 08:32:47 -0500 Subject: [PATCH 01/40] Replace script with build script, use features See https://github.com/pingcap/kvproto/pull/349 Signed-off-by: ice1000 --- Cargo.toml | 17 ++- build.rs | 163 +++++++++++++++++++++++ common.sh | 31 +++++ generate-proto.sh | 13 -- src/lib.rs | 7 +- src/rsprotobuf.rs | 1 + src/{ => rsprotobuf}/eraftpb.rs | 224 +++----------------------------- 7 files changed, 237 insertions(+), 219 deletions(-) create mode 100644 build.rs create mode 100644 common.sh delete mode 100755 generate-proto.sh create mode 100644 src/rsprotobuf.rs rename src/{ => rsprotobuf}/eraftpb.rs (83%) diff --git a/Cargo.toml b/Cargo.toml index d28a53740..d61adbea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,14 +10,27 @@ homepage = "https://github.com/pingcap/raft-rs" documentation = "https://docs.rs/raft" description = "The rust language implementation of Raft algorithm." categories = ["algorithms", "database-implementations"] +build = "build.rs" + +[build-dependencies] +protoc-rust = "2.2.4" +protoc-grpcio = "0.3.1" +regex = "1.1" +prost-build = { version = "0.4" } [features] -default = [] +default = ["lib-rust-protobuf"] +lib-rust-protobuf = ["protobuf"] +lib-prost = ["prost", "prost-derive", "bytes"] +regenerate = [] failpoint = ["fail"] [dependencies] log = ">0.2" -protobuf = "2.2.4" +protobuf = { version = "2.2.4", optional = true } +prost = { version = "0.4", optional = true } +prost-derive = { version = "0.4", optional = true } +bytes = { version = "0.4.11", optional = true } quick-error = "1.2.2" rand = "0.5.4" hashbrown = "0.1" diff --git a/build.rs b/build.rs new file mode 100644 index 000000000..fddfd09fe --- /dev/null +++ b/build.rs @@ -0,0 +1,163 @@ +// Copyright 2019 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +extern crate regex; + +use regex::Regex; +use std::env; +use std::fs::read_dir; +use std::fs::File; +use std::io::{Read, Write}; +use std::process::Command; + +fn main() { + // This build script creates files in the `src` directory. Since that is + // outside Cargo's OUT_DIR it will cause an error when this crate is used + // as a dependency. Therefore, the user must opt-in to regenerating the + // Rust files. + if env::var_os("CARGO_FEATURE_REGENERATE").is_none() { + println!("cargo:rerun-if-changed=build.rs"); + return; + } + + let buf_lib = BufferLib::from_env_vars(); + if buf_lib == BufferLib::Prost { + unimplemented!("Prost support is not yet implemented"); + } + + check_protoc_version(); + + let file_names: Vec<_> = read_dir("proto") + .expect("Couldn't read proto directory") + .map(|e| { + format!( + "proto/{}", + e.expect("Couldn't list file").file_name().to_string_lossy() + ) + }) + .collect(); + let file_names: Vec<_> = file_names.iter().map(|s| &**s).collect(); + + for f in &file_names { + println!("cargo:rerun-if-changed={}", f); + } + + if buf_lib == BufferLib::Protobuf { + generate_protobuf_files(file_names); + let mod_names: Vec<_> = read_dir("src/rsprotobuf") + .expect("Couldn't read src directory") + .filter_map(|e| { + let file_name = e.expect("Couldn't list file").file_name(); + file_name + .to_string_lossy() + .split(".rs") + .next() + .map(|n| n.to_owned()) + }) + .collect(); + replace_read_unknown_fields(&mod_names); + generate_protobuf_rs(&mod_names); + } +} + +#[derive(Eq, PartialEq)] +enum BufferLib { + Prost, + Protobuf, +} + +impl BufferLib { + fn from_env_vars() -> BufferLib { + match ( + env::var_os("CARGO_FEATURE_LIB_PROST"), + env::var_os("CARGO_FEATURE_LIB_RUST_PROTOBUF"), + ) { + (Some(_), Some(_)) | (None, None) => { + panic!("You must use exactly one of `lib-rust-protobuf` and `prost-buf` features") + } + (Some(_), _) => BufferLib::Prost, + (_, Some(_)) => BufferLib::Protobuf, + } + } +} + +fn check_protoc_version() { + let output = Command::new("bash") + .arg("common.sh") + .arg("check_protoc_version") + .output() + .expect("Could not execute `check_protoc_version`"); + if !output.status.success() { + panic!( + "Invalid version of protoc (required 3.1.x), or protoc not installed\n\nstdout:\n\n{}", + String::from_utf8_lossy(&output.stdout) + ); + } +} + +fn generate_protobuf_files(file_names: Vec<&str>) { + protoc_rust::run(protoc_rust::Args { + out_dir: "src/rsprotobuf", + input: &file_names, + includes: &["proto", "include"], + customize: protoc_rust::Customize { + ..Default::default() + }, + }) + .unwrap(); + + protoc_grpcio::compile_grpc_protos(file_names, &["proto", "include"], "src/rsprotobuf").unwrap(); +} + +// Use the old way to read protobuf enums. +// FIXME: Remove this once stepancheg/rust-protobuf#233 is resolved. +fn replace_read_unknown_fields(mod_names: &[String]) { + let regex = + Regex::new(r"::protobuf::rt::read_proto3_enum_with_unknown_fields_into\(([^,]+), ([^,]+), &mut ([^,]+), [^\)]+\)\?").unwrap(); + for mod_name in mod_names { + let file_name = &format!("src/rsprotobuf/{}.rs", mod_name); + + let mut text = String::new(); + { + let mut f = File::open(file_name).unwrap(); + f.read_to_string(&mut text) + .expect("Couldn't read source file"); + } + + let text = regex.replace_all( + &text, + "if $1 == ::protobuf::wire_format::WireTypeVarint {\ + $3 = $2.read_enum()?;\ + } else {\ + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));\ + }", + ); + let mut out = File::create(file_name).unwrap(); + out.write_all(text.as_bytes()) + .expect("Could not write source file"); + } +} + +fn generate_protobuf_rs(mod_names: &[String]) { + let mut text = "".to_owned(); + + for mod_name in mod_names { + text.push_str("pub mod "); + text.push_str(mod_name); + text.push_str(";\n"); + } + + let mut lib = File::create("src/rsprotobuf.rs").expect("Could not create rsprotobuf.rs"); + lib.write_all(text.as_bytes()) + .expect("Could not write rsprotobuf.rs"); +} diff --git a/common.sh b/common.sh new file mode 100644 index 000000000..b34032447 --- /dev/null +++ b/common.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -ex + +check_protoc_version() { + version=$(protoc --version) + major=$(echo ${version} | sed -n -e 's/.*\([0-9]\{1,\}\)\.[0-9]\{1,\}\.[0-9]\{1,\}.*/\1/p') + minor=$(echo ${version} | sed -n -e 's/.*[0-9]\{1,\}\.\([0-9]\{1,\}\)\.[0-9]\{1,\}.*/\1/p') + if [ "$major" -gt 3 ]; then + return 0 + fi + if [ "$major" -eq 3 ] && [ "$minor" -ge 1 ]; then + return 0 + fi + echo "protoc version not match, version 3.1.x is needed, current version: ${version}" + return 1 +} + +push () { + pushd $1 >/dev/null 2>&1 +} + +pop () { + popd $1 >/dev/null 2>&1 +} + +cmd_exists () { + which "$1" 1>/dev/null 2>&1 +} + +"$@" diff --git a/generate-proto.sh b/generate-proto.sh deleted file mode 100755 index ebe10c8cc..000000000 --- a/generate-proto.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -protoc proto/eraftpb.proto --rust_out=src/ -# TODO: remove this once stepancheg/rust-protobuf#233 is resolved. -python < { - if wire_type == ::protobuf::wire_format::WireTypeVarint {self.entry_type = is.read_enum()?;} else { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } + if wire_type == ::protobuf::wire_format::WireTypeVarint {self.entry_type = is.read_enum()?;} else {return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));} }, 2 => { if wire_type != ::protobuf::wire_format::WireTypeVarint { @@ -1095,7 +1095,7 @@ impl ::protobuf::Message for Message { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - if wire_type == ::protobuf::wire_format::WireTypeVarint {self.msg_type = is.read_enum()?;} else { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } + if wire_type == ::protobuf::wire_format::WireTypeVarint {self.msg_type = is.read_enum()?;} else {return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));} }, 2 => { if wire_type != ::protobuf::wire_format::WireTypeVarint { @@ -1945,7 +1945,7 @@ impl ::protobuf::Message for ConfChange { self.id = tmp; }, 2 => { - if wire_type == ::protobuf::wire_format::WireTypeVarint {self.change_type = is.read_enum()?;} else { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } + if wire_type == ::protobuf::wire_format::WireTypeVarint {self.change_type = is.read_enum()?;} else {return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));} }, 3 => { if wire_type != ::protobuf::wire_format::WireTypeVarint { @@ -2323,21 +2323,21 @@ impl ::protobuf::reflect::ProtobufValue for ConfChangeType { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x13proto/eraftpb.proto\x12\x07eraftpb\"\xad\x01\n\x05Entry\x121\n\nen\ - try_type\x18\x01\x20\x01(\x0e2\x12.eraftpb.EntryTypeR\tentryType\x12\x12\ - \n\x04term\x18\x02\x20\x01(\x04R\x04term\x12\x14\n\x05index\x18\x03\x20\ - \x01(\x04R\x05index\x12\x12\n\x04data\x18\x04\x20\x01(\x0cR\x04data\x12\ - \x18\n\x07context\x18\x06\x20\x01(\x0cR\x07context\x12\x19\n\x08sync_log\ - \x18\x05\x20\x01(\x08R\x07syncLog\"o\n\x10SnapshotMetadata\x121\n\nconf_\ - state\x18\x01\x20\x01(\x0b2\x12.eraftpb.ConfStateR\tconfState\x12\x14\n\ - \x05index\x18\x02\x20\x01(\x04R\x05index\x12\x12\n\x04term\x18\x03\x20\ - \x01(\x04R\x04term\"U\n\x08Snapshot\x12\x12\n\x04data\x18\x01\x20\x01(\ - \x0cR\x04data\x125\n\x08metadata\x18\x02\x20\x01(\x0b2\x19.eraftpb.Snaps\ - hotMetadataR\x08metadata\"\xe7\x02\n\x07Message\x12/\n\x08msg_type\x18\ - \x01\x20\x01(\x0e2\x14.eraftpb.MessageTypeR\x07msgType\x12\x0e\n\x02to\ - \x18\x02\x20\x01(\x04R\x02to\x12\x12\n\x04from\x18\x03\x20\x01(\x04R\x04\ - from\x12\x12\n\x04term\x18\x04\x20\x01(\x04R\x04term\x12\x19\n\x08log_te\ - rm\x18\x05\x20\x01(\x04R\x07logTerm\x12\x14\n\x05index\x18\x06\x20\x01(\ + \n\reraftpb.proto\x12\x07eraftpb\"\xad\x01\n\x05Entry\x121\n\nentry_type\ + \x18\x01\x20\x01(\x0e2\x12.eraftpb.EntryTypeR\tentryType\x12\x12\n\x04te\ + rm\x18\x02\x20\x01(\x04R\x04term\x12\x14\n\x05index\x18\x03\x20\x01(\x04\ + R\x05index\x12\x12\n\x04data\x18\x04\x20\x01(\x0cR\x04data\x12\x18\n\x07\ + context\x18\x06\x20\x01(\x0cR\x07context\x12\x19\n\x08sync_log\x18\x05\ + \x20\x01(\x08R\x07syncLog\"o\n\x10SnapshotMetadata\x121\n\nconf_state\ + \x18\x01\x20\x01(\x0b2\x12.eraftpb.ConfStateR\tconfState\x12\x14\n\x05in\ + dex\x18\x02\x20\x01(\x04R\x05index\x12\x12\n\x04term\x18\x03\x20\x01(\ + \x04R\x04term\"U\n\x08Snapshot\x12\x12\n\x04data\x18\x01\x20\x01(\x0cR\ + \x04data\x125\n\x08metadata\x18\x02\x20\x01(\x0b2\x19.eraftpb.SnapshotMe\ + tadataR\x08metadata\"\xe7\x02\n\x07Message\x12/\n\x08msg_type\x18\x01\ + \x20\x01(\x0e2\x14.eraftpb.MessageTypeR\x07msgType\x12\x0e\n\x02to\x18\ + \x02\x20\x01(\x04R\x02to\x12\x12\n\x04from\x18\x03\x20\x01(\x04R\x04from\ + \x12\x12\n\x04term\x18\x04\x20\x01(\x04R\x04term\x12\x19\n\x08log_term\ + \x18\x05\x20\x01(\x04R\x07logTerm\x12\x14\n\x05index\x18\x06\x20\x01(\ \x04R\x05index\x12(\n\x07entries\x18\x07\x20\x03(\x0b2\x0e.eraftpb.Entry\ R\x07entries\x12\x16\n\x06commit\x18\x08\x20\x01(\x04R\x06commit\x12-\n\ \x08snapshot\x18\t\x20\x01(\x0b2\x11.eraftpb.SnapshotR\x08snapshot\x12\ @@ -2363,189 +2363,7 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \x0f\x12\x14\n\x10MsgReadIndexResp\x10\x10\x12\x15\n\x11MsgRequestPreVot\ e\x10\x11\x12\x1d\n\x19MsgRequestPreVoteResponse\x10\x12*A\n\x0eConfChan\ geType\x12\x0b\n\x07AddNode\x10\0\x12\x0e\n\nRemoveNode\x10\x01\x12\x12\ - \n\x0eAddLearnerNode\x10\x02J\xd7\x20\n\x06\x12\x04\0\0d\x01\n\x08\n\x01\ - \x0c\x12\x03\0\0\x12\n\x08\n\x01\x02\x12\x03\x01\x08\x0f\n\n\n\x02\x05\0\ - \x12\x04\x03\0\x06\x01\n\n\n\x03\x05\0\x01\x12\x03\x03\x05\x0e\n\x0b\n\ - \x04\x05\0\x02\0\x12\x03\x04\x04\x14\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\ - \x04\x04\x0f\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x04\x12\x13\n\x0b\n\x04\ - \x05\0\x02\x01\x12\x03\x05\x04\x18\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\ - \x05\x04\x13\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x05\x16\x17\n\xdd\x04\ - \n\x02\x04\0\x12\x04\x12\0\x1c\x01\x1a\xd0\x04\x20The\x20entry\x20is\x20\ - a\x20type\x20of\x20change\x20that\x20needs\x20to\x20be\x20applied.\x20It\ - \x20contains\x20two\x20data\x20fields.\n\x20While\x20the\x20fields\x20ar\ - e\x20built\x20into\x20the\x20model;\x20their\x20usage\x20is\x20determine\ - d\x20by\x20the\x20entry_type.\n\n\x20For\x20normal\x20entries,\x20the\ - \x20data\x20field\x20should\x20contain\x20the\x20data\x20change\x20that\ - \x20should\x20be\x20applied.\n\x20The\x20context\x20field\x20can\x20be\ - \x20used\x20for\x20any\x20contextual\x20data\x20that\x20might\x20be\x20r\ - elevant\x20to\x20the\n\x20application\x20of\x20the\x20data.\n\n\x20For\ - \x20configuration\x20changes,\x20the\x20data\x20will\x20contain\x20the\ - \x20ConfChange\x20message\x20and\x20the\n\x20context\x20will\x20provide\ - \x20anything\x20needed\x20to\x20assist\x20the\x20configuration\x20change\ - .\x20The\x20context\n\x20if\x20for\x20the\x20user\x20to\x20set\x20and\ - \x20use\x20in\x20this\x20case.\n\n\n\n\x03\x04\0\x01\x12\x03\x12\x08\r\n\ - \x0b\n\x04\x04\0\x02\0\x12\x03\x13\x04\x1d\n\r\n\x05\x04\0\x02\0\x04\x12\ - \x04\x13\x04\x12\x0f\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x13\x04\r\n\x0c\ - \n\x05\x04\0\x02\0\x01\x12\x03\x13\x0e\x18\n\x0c\n\x05\x04\0\x02\0\x03\ - \x12\x03\x13\x1b\x1c\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x14\x04\x14\n\r\n\ - \x05\x04\0\x02\x01\x04\x12\x04\x14\x04\x13\x1d\n\x0c\n\x05\x04\0\x02\x01\ - \x05\x12\x03\x14\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x14\x0b\x0f\ - \n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x14\x12\x13\n\x0b\n\x04\x04\0\x02\ - \x02\x12\x03\x15\x04\x15\n\r\n\x05\x04\0\x02\x02\x04\x12\x04\x15\x04\x14\ - \x14\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x15\x04\n\n\x0c\n\x05\x04\0\ - \x02\x02\x01\x12\x03\x15\x0b\x10\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\ - \x15\x13\x14\n\x0b\n\x04\x04\0\x02\x03\x12\x03\x16\x04\x13\n\r\n\x05\x04\ - \0\x02\x03\x04\x12\x04\x16\x04\x15\x15\n\x0c\n\x05\x04\0\x02\x03\x05\x12\ - \x03\x16\x04\t\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x16\n\x0e\n\x0c\n\ - \x05\x04\0\x02\x03\x03\x12\x03\x16\x11\x12\n\x0b\n\x04\x04\0\x02\x04\x12\ - \x03\x17\x04\x16\n\r\n\x05\x04\0\x02\x04\x04\x12\x04\x17\x04\x16\x13\n\ - \x0c\n\x05\x04\0\x02\x04\x05\x12\x03\x17\x04\t\n\x0c\n\x05\x04\0\x02\x04\ - \x01\x12\x03\x17\n\x11\n\x0c\n\x05\x04\0\x02\x04\x03\x12\x03\x17\x14\x15\ - \nm\n\x04\x04\0\x02\x05\x12\x03\x1b\x04\x16\x1a`\x20Deprecated!\x20It\ - \x20is\x20kept\x20for\x20backward\x20compatibility.\n\x20TODO:\x20remove\ - \x20it\x20in\x20the\x20next\x20major\x20release.\n\n\r\n\x05\x04\0\x02\ - \x05\x04\x12\x04\x1b\x04\x17\x16\n\x0c\n\x05\x04\0\x02\x05\x05\x12\x03\ - \x1b\x04\x08\n\x0c\n\x05\x04\0\x02\x05\x01\x12\x03\x1b\t\x11\n\x0c\n\x05\ - \x04\0\x02\x05\x03\x12\x03\x1b\x14\x15\n\n\n\x02\x04\x01\x12\x04\x1e\0\"\ - \x01\n\n\n\x03\x04\x01\x01\x12\x03\x1e\x08\x18\n\x0b\n\x04\x04\x01\x02\0\ - \x12\x03\x1f\x04\x1d\n\r\n\x05\x04\x01\x02\0\x04\x12\x04\x1f\x04\x1e\x1a\ - \n\x0c\n\x05\x04\x01\x02\0\x06\x12\x03\x1f\x04\r\n\x0c\n\x05\x04\x01\x02\ - \0\x01\x12\x03\x1f\x0e\x18\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x1f\x1b\ - \x1c\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x20\x04\x15\n\r\n\x05\x04\x01\ - \x02\x01\x04\x12\x04\x20\x04\x1f\x1d\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\ - \x03\x20\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x20\x0b\x10\n\x0c\ - \n\x05\x04\x01\x02\x01\x03\x12\x03\x20\x13\x14\n\x0b\n\x04\x04\x01\x02\ - \x02\x12\x03!\x04\x14\n\r\n\x05\x04\x01\x02\x02\x04\x12\x04!\x04\x20\x15\ - \n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03!\x04\n\n\x0c\n\x05\x04\x01\x02\ - \x02\x01\x12\x03!\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03!\x12\ - \x13\n\n\n\x02\x04\x02\x12\x04$\0'\x01\n\n\n\x03\x04\x02\x01\x12\x03$\ - \x08\x10\n\x0b\n\x04\x04\x02\x02\0\x12\x03%\x04\x13\n\r\n\x05\x04\x02\ - \x02\0\x04\x12\x04%\x04$\x12\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03%\x04\ - \t\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03%\n\x0e\n\x0c\n\x05\x04\x02\x02\ - \0\x03\x12\x03%\x11\x12\n\x0b\n\x04\x04\x02\x02\x01\x12\x03&\x04\"\n\r\n\ - \x05\x04\x02\x02\x01\x04\x12\x04&\x04%\x13\n\x0c\n\x05\x04\x02\x02\x01\ - \x06\x12\x03&\x04\x14\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03&\x15\x1d\n\ - \x0c\n\x05\x04\x02\x02\x01\x03\x12\x03&\x20!\n\n\n\x02\x05\x01\x12\x04)\ - \0=\x01\n\n\n\x03\x05\x01\x01\x12\x03)\x05\x10\n\x0b\n\x04\x05\x01\x02\0\ - \x12\x03*\x04\x0f\n\x0c\n\x05\x05\x01\x02\0\x01\x12\x03*\x04\n\n\x0c\n\ - \x05\x05\x01\x02\0\x02\x12\x03*\r\x0e\n\x0b\n\x04\x05\x01\x02\x01\x12\ - \x03+\x04\x10\n\x0c\n\x05\x05\x01\x02\x01\x01\x12\x03+\x04\x0b\n\x0c\n\ - \x05\x05\x01\x02\x01\x02\x12\x03+\x0e\x0f\n\x0b\n\x04\x05\x01\x02\x02\ - \x12\x03,\x04\x13\n\x0c\n\x05\x05\x01\x02\x02\x01\x12\x03,\x04\x0e\n\x0c\ - \n\x05\x05\x01\x02\x02\x02\x12\x03,\x11\x12\n\x0b\n\x04\x05\x01\x02\x03\ - \x12\x03-\x04\x12\n\x0c\n\x05\x05\x01\x02\x03\x01\x12\x03-\x04\r\n\x0c\n\ - \x05\x05\x01\x02\x03\x02\x12\x03-\x10\x11\n\x0b\n\x04\x05\x01\x02\x04\ - \x12\x03.\x04\x1a\n\x0c\n\x05\x05\x01\x02\x04\x01\x12\x03.\x04\x15\n\x0c\ - \n\x05\x05\x01\x02\x04\x02\x12\x03.\x18\x19\n\x0b\n\x04\x05\x01\x02\x05\ - \x12\x03/\x04\x17\n\x0c\n\x05\x05\x01\x02\x05\x01\x12\x03/\x04\x12\n\x0c\ - \n\x05\x05\x01\x02\x05\x02\x12\x03/\x15\x16\n\x0b\n\x04\x05\x01\x02\x06\ - \x12\x030\x04\x1f\n\x0c\n\x05\x05\x01\x02\x06\x01\x12\x030\x04\x1a\n\x0c\ - \n\x05\x05\x01\x02\x06\x02\x12\x030\x1d\x1e\n\x0b\n\x04\x05\x01\x02\x07\ - \x12\x031\x04\x14\n\x0c\n\x05\x05\x01\x02\x07\x01\x12\x031\x04\x0f\n\x0c\ - \n\x05\x05\x01\x02\x07\x02\x12\x031\x12\x13\n\x0b\n\x04\x05\x01\x02\x08\ - \x12\x032\x04\x15\n\x0c\n\x05\x05\x01\x02\x08\x01\x12\x032\x04\x10\n\x0c\ - \n\x05\x05\x01\x02\x08\x02\x12\x032\x13\x14\n\x0b\n\x04\x05\x01\x02\t\ - \x12\x033\x04\x1d\n\x0c\n\x05\x05\x01\x02\t\x01\x12\x033\x04\x18\n\x0c\n\ - \x05\x05\x01\x02\t\x02\x12\x033\x1b\x1c\n\x0b\n\x04\x05\x01\x02\n\x12\ - \x034\x04\x18\n\x0c\n\x05\x05\x01\x02\n\x01\x12\x034\x04\x12\n\x0c\n\x05\ - \x05\x01\x02\n\x02\x12\x034\x15\x17\n\x0b\n\x04\x05\x01\x02\x0b\x12\x035\ - \x04\x17\n\x0c\n\x05\x05\x01\x02\x0b\x01\x12\x035\x04\x11\n\x0c\n\x05\ - \x05\x01\x02\x0b\x02\x12\x035\x14\x16\n\x0b\n\x04\x05\x01\x02\x0c\x12\ - \x036\x04\x18\n\x0c\n\x05\x05\x01\x02\x0c\x01\x12\x036\x04\x12\n\x0c\n\ - \x05\x05\x01\x02\x0c\x02\x12\x036\x15\x17\n\x0b\n\x04\x05\x01\x02\r\x12\ - \x037\x04\x1b\n\x0c\n\x05\x05\x01\x02\r\x01\x12\x037\x04\x15\n\x0c\n\x05\ - \x05\x01\x02\r\x02\x12\x037\x18\x1a\n\x0b\n\x04\x05\x01\x02\x0e\x12\x038\ - \x04\x17\n\x0c\n\x05\x05\x01\x02\x0e\x01\x12\x038\x04\x11\n\x0c\n\x05\ - \x05\x01\x02\x0e\x02\x12\x038\x14\x16\n\x0b\n\x04\x05\x01\x02\x0f\x12\ - \x039\x04\x16\n\x0c\n\x05\x05\x01\x02\x0f\x01\x12\x039\x04\x10\n\x0c\n\ - \x05\x05\x01\x02\x0f\x02\x12\x039\x13\x15\n\x0b\n\x04\x05\x01\x02\x10\ - \x12\x03:\x04\x1a\n\x0c\n\x05\x05\x01\x02\x10\x01\x12\x03:\x04\x14\n\x0c\ - \n\x05\x05\x01\x02\x10\x02\x12\x03:\x17\x19\n\x0b\n\x04\x05\x01\x02\x11\ - \x12\x03;\x04\x1b\n\x0c\n\x05\x05\x01\x02\x11\x01\x12\x03;\x04\x15\n\x0c\ - \n\x05\x05\x01\x02\x11\x02\x12\x03;\x18\x1a\n\x0b\n\x04\x05\x01\x02\x12\ - \x12\x03<\x04#\n\x0c\n\x05\x05\x01\x02\x12\x01\x12\x03<\x04\x1d\n\x0c\n\ - \x05\x05\x01\x02\x12\x02\x12\x03<\x20\"\n\n\n\x02\x04\x03\x12\x04?\0L\ - \x01\n\n\n\x03\x04\x03\x01\x12\x03?\x08\x0f\n\x0b\n\x04\x04\x03\x02\0\ - \x12\x03@\x04\x1d\n\r\n\x05\x04\x03\x02\0\x04\x12\x04@\x04?\x11\n\x0c\n\ - \x05\x04\x03\x02\0\x06\x12\x03@\x04\x0f\n\x0c\n\x05\x04\x03\x02\0\x01\ - \x12\x03@\x10\x18\n\x0c\n\x05\x04\x03\x02\0\x03\x12\x03@\x1b\x1c\n\x0b\n\ - \x04\x04\x03\x02\x01\x12\x03A\x04\x12\n\r\n\x05\x04\x03\x02\x01\x04\x12\ - \x04A\x04@\x1d\n\x0c\n\x05\x04\x03\x02\x01\x05\x12\x03A\x04\n\n\x0c\n\ - \x05\x04\x03\x02\x01\x01\x12\x03A\x0b\r\n\x0c\n\x05\x04\x03\x02\x01\x03\ - \x12\x03A\x10\x11\n\x0b\n\x04\x04\x03\x02\x02\x12\x03B\x04\x14\n\r\n\x05\ - \x04\x03\x02\x02\x04\x12\x04B\x04A\x12\n\x0c\n\x05\x04\x03\x02\x02\x05\ - \x12\x03B\x04\n\n\x0c\n\x05\x04\x03\x02\x02\x01\x12\x03B\x0b\x0f\n\x0c\n\ - \x05\x04\x03\x02\x02\x03\x12\x03B\x12\x13\n\x0b\n\x04\x04\x03\x02\x03\ - \x12\x03C\x04\x14\n\r\n\x05\x04\x03\x02\x03\x04\x12\x04C\x04B\x14\n\x0c\ - \n\x05\x04\x03\x02\x03\x05\x12\x03C\x04\n\n\x0c\n\x05\x04\x03\x02\x03\ - \x01\x12\x03C\x0b\x0f\n\x0c\n\x05\x04\x03\x02\x03\x03\x12\x03C\x12\x13\n\ - \x0b\n\x04\x04\x03\x02\x04\x12\x03D\x04\x18\n\r\n\x05\x04\x03\x02\x04\ - \x04\x12\x04D\x04C\x14\n\x0c\n\x05\x04\x03\x02\x04\x05\x12\x03D\x04\n\n\ - \x0c\n\x05\x04\x03\x02\x04\x01\x12\x03D\x0b\x13\n\x0c\n\x05\x04\x03\x02\ - \x04\x03\x12\x03D\x16\x17\n\x0b\n\x04\x04\x03\x02\x05\x12\x03E\x04\x15\n\ - \r\n\x05\x04\x03\x02\x05\x04\x12\x04E\x04D\x18\n\x0c\n\x05\x04\x03\x02\ - \x05\x05\x12\x03E\x04\n\n\x0c\n\x05\x04\x03\x02\x05\x01\x12\x03E\x0b\x10\ - \n\x0c\n\x05\x04\x03\x02\x05\x03\x12\x03E\x13\x14\n\x0b\n\x04\x04\x03\ - \x02\x06\x12\x03F\x04\x1f\n\x0c\n\x05\x04\x03\x02\x06\x04\x12\x03F\x04\ - \x0c\n\x0c\n\x05\x04\x03\x02\x06\x06\x12\x03F\r\x12\n\x0c\n\x05\x04\x03\ - \x02\x06\x01\x12\x03F\x13\x1a\n\x0c\n\x05\x04\x03\x02\x06\x03\x12\x03F\ - \x1d\x1e\n\x0b\n\x04\x04\x03\x02\x07\x12\x03G\x04\x16\n\r\n\x05\x04\x03\ - \x02\x07\x04\x12\x04G\x04F\x1f\n\x0c\n\x05\x04\x03\x02\x07\x05\x12\x03G\ - \x04\n\n\x0c\n\x05\x04\x03\x02\x07\x01\x12\x03G\x0b\x11\n\x0c\n\x05\x04\ - \x03\x02\x07\x03\x12\x03G\x14\x15\n\x0b\n\x04\x04\x03\x02\x08\x12\x03H\ - \x04\x1a\n\r\n\x05\x04\x03\x02\x08\x04\x12\x04H\x04G\x16\n\x0c\n\x05\x04\ - \x03\x02\x08\x06\x12\x03H\x04\x0c\n\x0c\n\x05\x04\x03\x02\x08\x01\x12\ - \x03H\r\x15\n\x0c\n\x05\x04\x03\x02\x08\x03\x12\x03H\x18\x19\n\x0b\n\x04\ - \x04\x03\x02\t\x12\x03I\x04\x15\n\r\n\x05\x04\x03\x02\t\x04\x12\x04I\x04\ - H\x1a\n\x0c\n\x05\x04\x03\x02\t\x05\x12\x03I\x04\x08\n\x0c\n\x05\x04\x03\ - \x02\t\x01\x12\x03I\t\x0f\n\x0c\n\x05\x04\x03\x02\t\x03\x12\x03I\x12\x14\ - \n\x0b\n\x04\x04\x03\x02\n\x12\x03J\x04\x1c\n\r\n\x05\x04\x03\x02\n\x04\ - \x12\x04J\x04I\x15\n\x0c\n\x05\x04\x03\x02\n\x05\x12\x03J\x04\n\n\x0c\n\ - \x05\x04\x03\x02\n\x01\x12\x03J\x0b\x16\n\x0c\n\x05\x04\x03\x02\n\x03\ - \x12\x03J\x19\x1b\n\x0b\n\x04\x04\x03\x02\x0b\x12\x03K\x04\x17\n\r\n\x05\ - \x04\x03\x02\x0b\x04\x12\x04K\x04J\x1c\n\x0c\n\x05\x04\x03\x02\x0b\x05\ - \x12\x03K\x04\t\n\x0c\n\x05\x04\x03\x02\x0b\x01\x12\x03K\n\x11\n\x0c\n\ - \x05\x04\x03\x02\x0b\x03\x12\x03K\x14\x16\n\n\n\x02\x04\x04\x12\x04N\0R\ - \x01\n\n\n\x03\x04\x04\x01\x12\x03N\x08\x11\n\x0b\n\x04\x04\x04\x02\0\ - \x12\x03O\x04\x14\n\r\n\x05\x04\x04\x02\0\x04\x12\x04O\x04N\x13\n\x0c\n\ - \x05\x04\x04\x02\0\x05\x12\x03O\x04\n\n\x0c\n\x05\x04\x04\x02\0\x01\x12\ - \x03O\x0b\x0f\n\x0c\n\x05\x04\x04\x02\0\x03\x12\x03O\x12\x13\n\x0b\n\x04\ - \x04\x04\x02\x01\x12\x03P\x04\x14\n\r\n\x05\x04\x04\x02\x01\x04\x12\x04P\ - \x04O\x14\n\x0c\n\x05\x04\x04\x02\x01\x05\x12\x03P\x04\n\n\x0c\n\x05\x04\ - \x04\x02\x01\x01\x12\x03P\x0b\x0f\n\x0c\n\x05\x04\x04\x02\x01\x03\x12\ - \x03P\x12\x13\n\x0b\n\x04\x04\x04\x02\x02\x12\x03Q\x04\x16\n\r\n\x05\x04\ - \x04\x02\x02\x04\x12\x04Q\x04P\x14\n\x0c\n\x05\x04\x04\x02\x02\x05\x12\ - \x03Q\x04\n\n\x0c\n\x05\x04\x04\x02\x02\x01\x12\x03Q\x0b\x11\n\x0c\n\x05\ - \x04\x04\x02\x02\x03\x12\x03Q\x14\x15\n\n\n\x02\x04\x05\x12\x04T\0W\x01\ - \n\n\n\x03\x04\x05\x01\x12\x03T\x08\x11\n\x0b\n\x04\x04\x05\x02\0\x12\ - \x03U\x04\x1e\n\x0c\n\x05\x04\x05\x02\0\x04\x12\x03U\x04\x0c\n\x0c\n\x05\ - \x04\x05\x02\0\x05\x12\x03U\r\x13\n\x0c\n\x05\x04\x05\x02\0\x01\x12\x03U\ - \x14\x19\n\x0c\n\x05\x04\x05\x02\0\x03\x12\x03U\x1c\x1d\n\x0b\n\x04\x04\ - \x05\x02\x01\x12\x03V\x04!\n\x0c\n\x05\x04\x05\x02\x01\x04\x12\x03V\x04\ - \x0c\n\x0c\n\x05\x04\x05\x02\x01\x05\x12\x03V\r\x13\n\x0c\n\x05\x04\x05\ - \x02\x01\x01\x12\x03V\x14\x1c\n\x0c\n\x05\x04\x05\x02\x01\x03\x12\x03V\ - \x1f\x20\n\n\n\x02\x05\x02\x12\x04Y\0]\x01\n\n\n\x03\x05\x02\x01\x12\x03\ - Y\x05\x13\n\x0b\n\x04\x05\x02\x02\0\x12\x03Z\x04\x13\n\x0c\n\x05\x05\x02\ - \x02\0\x01\x12\x03Z\x04\x0b\n\x0c\n\x05\x05\x02\x02\0\x02\x12\x03Z\x11\ - \x12\n\x0b\n\x04\x05\x02\x02\x01\x12\x03[\x04\x13\n\x0c\n\x05\x05\x02\ - \x02\x01\x01\x12\x03[\x04\x0e\n\x0c\n\x05\x05\x02\x02\x01\x02\x12\x03[\ - \x11\x12\n\x0b\n\x04\x05\x02\x02\x02\x12\x03\\\x04\x17\n\x0c\n\x05\x05\ - \x02\x02\x02\x01\x12\x03\\\x04\x12\n\x0c\n\x05\x05\x02\x02\x02\x02\x12\ - \x03\\\x15\x16\n\n\n\x02\x04\x06\x12\x04_\0d\x01\n\n\n\x03\x04\x06\x01\ - \x12\x03_\x08\x12\n\x0b\n\x04\x04\x06\x02\0\x12\x03`\x04\x12\n\r\n\x05\ - \x04\x06\x02\0\x04\x12\x04`\x04_\x14\n\x0c\n\x05\x04\x06\x02\0\x05\x12\ - \x03`\x04\n\n\x0c\n\x05\x04\x06\x02\0\x01\x12\x03`\x0b\r\n\x0c\n\x05\x04\ - \x06\x02\0\x03\x12\x03`\x10\x11\n\x0b\n\x04\x04\x06\x02\x01\x12\x03a\x04\ - #\n\r\n\x05\x04\x06\x02\x01\x04\x12\x04a\x04`\x12\n\x0c\n\x05\x04\x06\ - \x02\x01\x06\x12\x03a\x04\x12\n\x0c\n\x05\x04\x06\x02\x01\x01\x12\x03a\ - \x13\x1e\n\x0c\n\x05\x04\x06\x02\x01\x03\x12\x03a!\"\n\x0b\n\x04\x04\x06\ - \x02\x02\x12\x03b\x04\x17\n\r\n\x05\x04\x06\x02\x02\x04\x12\x04b\x04a#\n\ - \x0c\n\x05\x04\x06\x02\x02\x05\x12\x03b\x04\n\n\x0c\n\x05\x04\x06\x02\ - \x02\x01\x12\x03b\x0b\x12\n\x0c\n\x05\x04\x06\x02\x02\x03\x12\x03b\x15\ - \x16\n\x0b\n\x04\x04\x06\x02\x03\x12\x03c\x04\x16\n\r\n\x05\x04\x06\x02\ - \x03\x04\x12\x04c\x04b\x17\n\x0c\n\x05\x04\x06\x02\x03\x05\x12\x03c\x04\ - \t\n\x0c\n\x05\x04\x06\x02\x03\x01\x12\x03c\n\x11\n\x0c\n\x05\x04\x06\ - \x02\x03\x03\x12\x03c\x14\x15b\x06proto3\ + \n\x0eAddLearnerNode\x10\x02b\x06proto3\ "; static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { From 39996adfd026849942889e774ed180842d40a275 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 30 Jan 2019 09:22:33 -0500 Subject: [PATCH 02/40] Cargo fmt Signed-off-by: ice1000 --- build.rs | 7 ++++--- src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index fddfd09fe..ffa71cb11 100644 --- a/build.rs +++ b/build.rs @@ -116,7 +116,8 @@ fn generate_protobuf_files(file_names: Vec<&str>) { }) .unwrap(); - protoc_grpcio::compile_grpc_protos(file_names, &["proto", "include"], "src/rsprotobuf").unwrap(); + protoc_grpcio::compile_grpc_protos(file_names, &["proto", "include"], "src/rsprotobuf") + .unwrap(); } // Use the old way to read protobuf enums. @@ -137,9 +138,9 @@ fn replace_read_unknown_fields(mod_names: &[String]) { let text = regex.replace_all( &text, "if $1 == ::protobuf::wire_format::WireTypeVarint {\ - $3 = $2.read_enum()?;\ + $3 = $2.read_enum()?;\ } else {\ - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));\ + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));\ }", ); let mut out = File::create(file_name).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index f2c2df039..3e99f6cf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -277,9 +277,9 @@ extern crate quick_error; extern crate env_logger; extern crate rand; +mod config; #[cfg(feature = "lib-rust-protobuf")] mod rsprotobuf; -mod config; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. #[cfg(feature = "lib-rust-protobuf")] From 9323c470aabfc589568d4964a477c4856db5dda6 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Wed, 30 Jan 2019 12:14:20 -0500 Subject: [PATCH 03/40] Apply some suggestions from rust clippy Signed-off-by: ice1000 --- .travis.yml | 2 +- src/rsprotobuf/eraftpb.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 487bf79c0..400d6844c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ matrix: - rustup component add clippy-preview before_script: - cargo fmt --all -- --check - - cargo clippy --all -- -D clippy + - cargo clippy --all -- -D clippy::all # Since many users will use nightlies, also test that. - rust: nightly diff --git a/src/rsprotobuf/eraftpb.rs b/src/rsprotobuf/eraftpb.rs index 06ebc2812..a99f83338 100644 --- a/src/rsprotobuf/eraftpb.rs +++ b/src/rsprotobuf/eraftpb.rs @@ -3,7 +3,7 @@ // https://github.com/Manishearth/rust-clippy/issues/702 #![allow(unknown_lints)] -#![allow(clippy)] +#![allow(clippy::all)] #![cfg_attr(rustfmt, rustfmt_skip)] From 62d1f8ebb3abe293d4068631a995eb6f4703f5f3 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 31 Jan 2019 06:42:48 -0500 Subject: [PATCH 04/40] Remove everything related to prost Signed-off-by: ice1000 --- Cargo.toml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d61adbea3..abe1e99d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,21 +16,16 @@ build = "build.rs" protoc-rust = "2.2.4" protoc-grpcio = "0.3.1" regex = "1.1" -prost-build = { version = "0.4" } [features] default = ["lib-rust-protobuf"] lib-rust-protobuf = ["protobuf"] -lib-prost = ["prost", "prost-derive", "bytes"] regenerate = [] failpoint = ["fail"] [dependencies] log = ">0.2" protobuf = { version = "2.2.4", optional = true } -prost = { version = "0.4", optional = true } -prost-derive = { version = "0.4", optional = true } -bytes = { version = "0.4.11", optional = true } quick-error = "1.2.2" rand = "0.5.4" hashbrown = "0.1" From e63166a18a881f3911355dded12ca2d7397f4504 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 31 Jan 2019 16:52:28 -0500 Subject: [PATCH 05/40] Refactor build.rs Signed-off-by: ice1000 --- build.rs | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/build.rs b/build.rs index ffa71cb11..debe760b9 100644 --- a/build.rs +++ b/build.rs @@ -30,13 +30,6 @@ fn main() { return; } - let buf_lib = BufferLib::from_env_vars(); - if buf_lib == BufferLib::Prost { - unimplemented!("Prost support is not yet implemented"); - } - - check_protoc_version(); - let file_names: Vec<_> = read_dir("proto") .expect("Couldn't read proto directory") .map(|e| { @@ -45,28 +38,36 @@ fn main() { e.expect("Couldn't list file").file_name().to_string_lossy() ) }) + .map(|s| &**s) .collect(); - let file_names: Vec<_> = file_names.iter().map(|s| &**s).collect(); for f in &file_names { println!("cargo:rerun-if-changed={}", f); } - if buf_lib == BufferLib::Protobuf { - generate_protobuf_files(file_names); - let mod_names: Vec<_> = read_dir("src/rsprotobuf") - .expect("Couldn't read src directory") - .filter_map(|e| { - let file_name = e.expect("Couldn't list file").file_name(); - file_name - .to_string_lossy() - .split(".rs") - .next() - .map(|n| n.to_owned()) - }) - .collect(); - replace_read_unknown_fields(&mod_names); - generate_protobuf_rs(&mod_names); + match BufferLib::from_env_vars() { + BufferLib::Prost => { + unimplemented!("Prost support is not yet implemented"); + }, + + BufferLib::Protobuf => { + check_protoc_version(); + + generate_protobuf_files(file_names); + let mod_names: Vec<_> = read_dir("src/rsprotobuf") + .expect("Couldn't read src directory") + .filter_map(|e| { + let file_name = e.expect("Couldn't list file").file_name(); + file_name + .to_string_lossy() + .split(".rs") + .next() + .map(|n| n.to_owned()) + }) + .collect(); + replace_read_unknown_fields(&mod_names); + generate_protobuf_rs(&mod_names); + }, } } From 3e5ecc3d4d1ca69241d07b0115bc6a2fee52f5b8 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 31 Jan 2019 16:48:42 -0500 Subject: [PATCH 06/40] Save progress Signed-off-by: ice1000 --- Cargo.toml | 5 +++++ build.rs | 66 +++++++++++++++++++++++++++++++++++++++++++++++++----- src/lib.rs | 11 +++++++++ 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index abe1e99d2..d61adbea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,16 +16,21 @@ build = "build.rs" protoc-rust = "2.2.4" protoc-grpcio = "0.3.1" regex = "1.1" +prost-build = { version = "0.4" } [features] default = ["lib-rust-protobuf"] lib-rust-protobuf = ["protobuf"] +lib-prost = ["prost", "prost-derive", "bytes"] regenerate = [] failpoint = ["fail"] [dependencies] log = ">0.2" protobuf = { version = "2.2.4", optional = true } +prost = { version = "0.4", optional = true } +prost-derive = { version = "0.4", optional = true } +bytes = { version = "0.4.11", optional = true } quick-error = "1.2.2" rand = "0.5.4" hashbrown = "0.1" diff --git a/build.rs b/build.rs index debe760b9..f74208210 100644 --- a/build.rs +++ b/build.rs @@ -12,12 +12,14 @@ // limitations under the License. extern crate regex; +extern crate prost_build; use regex::Regex; use std::env; -use std::fs::read_dir; -use std::fs::File; -use std::io::{Read, Write}; +use std::error::Error; +use std::fs::{File, read_dir, remove_file}; +use std::io::{Read, Result, Write}; +use std::path::PathBuf; use std::process::Command; fn main() { @@ -38,8 +40,8 @@ fn main() { e.expect("Couldn't list file").file_name().to_string_lossy() ) }) - .map(|s| &**s) .collect(); + let file_names: Vec<_> = file_names.iter().map(|s| &**s).collect(); for f in &file_names { println!("cargo:rerun-if-changed={}", f); @@ -47,7 +49,26 @@ fn main() { match BufferLib::from_env_vars() { BufferLib::Prost => { - unimplemented!("Prost support is not yet implemented"); + let import_all = env::current_dir().map(|mut p| { + p.push("proto"); + p.push("import_all.proto"); + p + }).unwrap(); + let mut file = File::create(import_all.clone()).unwrap(); + + file.write("syntax = \"proto3\";\n".as_bytes()).unwrap(); + file.write("package this_file_is_supposed_to_be_empty;\n".as_bytes()).unwrap(); + file_names.iter().map(|name| { + file.write("import \"".as_bytes())?; + file.write(name.as_bytes())?; + file.write("\";\n".as_bytes())?; + Ok(()) + }).for_each(|x: Result<()>| x.unwrap()); + file.sync_all().unwrap(); + + generate_prost_files(); + remove_file(import_all).unwrap(); + generate_prost_rs(file_names).unwrap(); }, BufferLib::Protobuf => { @@ -106,6 +127,17 @@ fn check_protoc_version() { } } +fn generate_prost_files() { + prost_build::compile_protos( + &["proto/import_all.proto"], + &["proto"]) + .map_err(|err| { + println!("{}", err.description()); + Err::<(), ()>(()) + }) + .unwrap(); +} + fn generate_protobuf_files(file_names: Vec<&str>) { protoc_rust::run(protoc_rust::Args { out_dir: "src/rsprotobuf", @@ -163,3 +195,27 @@ fn generate_protobuf_rs(mod_names: &[String]) { lib.write_all(text.as_bytes()) .expect("Could not write rsprotobuf.rs"); } + +fn generate_prost_rs(protos: Vec<&str>) -> Result<()> { + let target: PathBuf = env::current_dir().map(|mut dir| { + dir.push("src"); + dir.push("rsprost.rs"); + dir + })?; + let mut file = File::create(target)?; + file.write("extern crate bytes;\n".as_bytes())?; + file.write("extern crate prost;\n".as_bytes())?; + file.write("#[macro_use]\n".as_bytes())?; + file.write("extern crate prost_derive;\n".as_bytes())?; + for s in protos { + let proto_name = s.trim_right_matches(".proto"); + file.write("pub mod ".as_bytes())?; + file.write(proto_name.as_bytes())?; + file.write(" { include!(concat!(env!(\"OUT_DIR\"), \"/".as_bytes())?; + file.write(proto_name.as_bytes())?; + file.write(".rs\")); }\n".as_bytes())?; + } + + Ok(()) +} + diff --git a/src/lib.rs b/src/lib.rs index 3e99f6cf4..6d58155ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -271,6 +271,13 @@ extern crate hashbrown; extern crate log; #[cfg(feature = "lib-rust-protobuf")] extern crate protobuf; +#[cfg(feature = "lib-prost")] +extern crate bytes; +#[cfg(feature = "lib-prost")] +extern crate prost; +#[cfg(feature = "lib-prost")] +#[macro_use] +extern crate prost_derive; #[macro_use] extern crate quick_error; #[cfg(test)] @@ -280,10 +287,14 @@ extern crate rand; mod config; #[cfg(feature = "lib-rust-protobuf")] mod rsprotobuf; +#[cfg(feature = "lib-prosy")] +mod rsprost; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. #[cfg(feature = "lib-rust-protobuf")] pub use crate::rsprotobuf::eraftpb; +#[cfg(feature = "lib-prosy")] +pub use crate::rsprost::eraftpb; mod errors; mod log_unstable; mod progress; From 96143b305543b434f237206a1a96d899baf3e96b Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 31 Jan 2019 16:52:28 -0500 Subject: [PATCH 07/40] Refactor build.rs Signed-off-by: ice1000 --- build.rs | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/build.rs b/build.rs index ffa71cb11..b507a69a4 100644 --- a/build.rs +++ b/build.rs @@ -30,13 +30,6 @@ fn main() { return; } - let buf_lib = BufferLib::from_env_vars(); - if buf_lib == BufferLib::Prost { - unimplemented!("Prost support is not yet implemented"); - } - - check_protoc_version(); - let file_names: Vec<_> = read_dir("proto") .expect("Couldn't read proto directory") .map(|e| { @@ -52,21 +45,29 @@ fn main() { println!("cargo:rerun-if-changed={}", f); } - if buf_lib == BufferLib::Protobuf { - generate_protobuf_files(file_names); - let mod_names: Vec<_> = read_dir("src/rsprotobuf") - .expect("Couldn't read src directory") - .filter_map(|e| { - let file_name = e.expect("Couldn't list file").file_name(); - file_name - .to_string_lossy() - .split(".rs") - .next() - .map(|n| n.to_owned()) - }) - .collect(); - replace_read_unknown_fields(&mod_names); - generate_protobuf_rs(&mod_names); + match BufferLib::from_env_vars() { + BufferLib::Prost => { + unimplemented!("Prost support is not yet implemented"); + }, + + BufferLib::Protobuf => { + check_protoc_version(); + + generate_protobuf_files(file_names); + let mod_names: Vec<_> = read_dir("src/rsprotobuf") + .expect("Couldn't read src directory") + .filter_map(|e| { + let file_name = e.expect("Couldn't list file").file_name(); + file_name + .to_string_lossy() + .split(".rs") + .next() + .map(|n| n.to_owned()) + }) + .collect(); + replace_read_unknown_fields(&mod_names); + generate_protobuf_rs(&mod_names); + }, } } From e14ae2882fff10254503207c6ddbcd2729ed67f7 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 31 Jan 2019 16:52:28 -0500 Subject: [PATCH 08/40] Refactor build.rs Signed-off-by: ice1000 --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index b507a69a4..debe760b9 100644 --- a/build.rs +++ b/build.rs @@ -38,8 +38,8 @@ fn main() { e.expect("Couldn't list file").file_name().to_string_lossy() ) }) + .map(|s| &**s) .collect(); - let file_names: Vec<_> = file_names.iter().map(|s| &**s).collect(); for f in &file_names { println!("cargo:rerun-if-changed={}", f); From 78e460f5cdb597d7ec51e6a5d36b5b2705adfe54 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 31 Jan 2019 16:48:42 -0500 Subject: [PATCH 09/40] Save progress Signed-off-by: ice1000 --- Cargo.toml | 5 +++++ build.rs | 66 +++++++++++++++++++++++++++++++++++++++++++++++++----- src/lib.rs | 11 +++++++++ 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index abe1e99d2..d61adbea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,16 +16,21 @@ build = "build.rs" protoc-rust = "2.2.4" protoc-grpcio = "0.3.1" regex = "1.1" +prost-build = { version = "0.4" } [features] default = ["lib-rust-protobuf"] lib-rust-protobuf = ["protobuf"] +lib-prost = ["prost", "prost-derive", "bytes"] regenerate = [] failpoint = ["fail"] [dependencies] log = ">0.2" protobuf = { version = "2.2.4", optional = true } +prost = { version = "0.4", optional = true } +prost-derive = { version = "0.4", optional = true } +bytes = { version = "0.4.11", optional = true } quick-error = "1.2.2" rand = "0.5.4" hashbrown = "0.1" diff --git a/build.rs b/build.rs index debe760b9..f74208210 100644 --- a/build.rs +++ b/build.rs @@ -12,12 +12,14 @@ // limitations under the License. extern crate regex; +extern crate prost_build; use regex::Regex; use std::env; -use std::fs::read_dir; -use std::fs::File; -use std::io::{Read, Write}; +use std::error::Error; +use std::fs::{File, read_dir, remove_file}; +use std::io::{Read, Result, Write}; +use std::path::PathBuf; use std::process::Command; fn main() { @@ -38,8 +40,8 @@ fn main() { e.expect("Couldn't list file").file_name().to_string_lossy() ) }) - .map(|s| &**s) .collect(); + let file_names: Vec<_> = file_names.iter().map(|s| &**s).collect(); for f in &file_names { println!("cargo:rerun-if-changed={}", f); @@ -47,7 +49,26 @@ fn main() { match BufferLib::from_env_vars() { BufferLib::Prost => { - unimplemented!("Prost support is not yet implemented"); + let import_all = env::current_dir().map(|mut p| { + p.push("proto"); + p.push("import_all.proto"); + p + }).unwrap(); + let mut file = File::create(import_all.clone()).unwrap(); + + file.write("syntax = \"proto3\";\n".as_bytes()).unwrap(); + file.write("package this_file_is_supposed_to_be_empty;\n".as_bytes()).unwrap(); + file_names.iter().map(|name| { + file.write("import \"".as_bytes())?; + file.write(name.as_bytes())?; + file.write("\";\n".as_bytes())?; + Ok(()) + }).for_each(|x: Result<()>| x.unwrap()); + file.sync_all().unwrap(); + + generate_prost_files(); + remove_file(import_all).unwrap(); + generate_prost_rs(file_names).unwrap(); }, BufferLib::Protobuf => { @@ -106,6 +127,17 @@ fn check_protoc_version() { } } +fn generate_prost_files() { + prost_build::compile_protos( + &["proto/import_all.proto"], + &["proto"]) + .map_err(|err| { + println!("{}", err.description()); + Err::<(), ()>(()) + }) + .unwrap(); +} + fn generate_protobuf_files(file_names: Vec<&str>) { protoc_rust::run(protoc_rust::Args { out_dir: "src/rsprotobuf", @@ -163,3 +195,27 @@ fn generate_protobuf_rs(mod_names: &[String]) { lib.write_all(text.as_bytes()) .expect("Could not write rsprotobuf.rs"); } + +fn generate_prost_rs(protos: Vec<&str>) -> Result<()> { + let target: PathBuf = env::current_dir().map(|mut dir| { + dir.push("src"); + dir.push("rsprost.rs"); + dir + })?; + let mut file = File::create(target)?; + file.write("extern crate bytes;\n".as_bytes())?; + file.write("extern crate prost;\n".as_bytes())?; + file.write("#[macro_use]\n".as_bytes())?; + file.write("extern crate prost_derive;\n".as_bytes())?; + for s in protos { + let proto_name = s.trim_right_matches(".proto"); + file.write("pub mod ".as_bytes())?; + file.write(proto_name.as_bytes())?; + file.write(" { include!(concat!(env!(\"OUT_DIR\"), \"/".as_bytes())?; + file.write(proto_name.as_bytes())?; + file.write(".rs\")); }\n".as_bytes())?; + } + + Ok(()) +} + diff --git a/src/lib.rs b/src/lib.rs index fc4568221..a5ceb0173 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -271,6 +271,13 @@ extern crate hashbrown; extern crate log; #[cfg(feature = "lib-rust-protobuf")] extern crate protobuf; +#[cfg(feature = "lib-prost")] +extern crate bytes; +#[cfg(feature = "lib-prost")] +extern crate prost; +#[cfg(feature = "lib-prost")] +#[macro_use] +extern crate prost_derive; #[macro_use] extern crate quick_error; #[cfg(test)] @@ -280,10 +287,14 @@ extern crate rand; mod config; #[cfg(feature = "lib-rust-protobuf")] mod rsprotobuf; +#[cfg(feature = "lib-prosy")] +mod rsprost; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. #[cfg(feature = "lib-rust-protobuf")] pub use crate::rsprotobuf::eraftpb; +#[cfg(feature = "lib-prosy")] +pub use crate::rsprost::eraftpb; mod errors; mod log_unstable; mod progress; From e9ceaa40026cff5c152d2fc6f60047ff5294c300 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 14 Feb 2019 21:57:51 -0500 Subject: [PATCH 10/40] Documentation in src/lib.rs --- src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index fc4568221..a0066eae3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,6 +258,23 @@ The `Ready` state contains quite a bit of information, and you need to check and For more information, check out an [example](examples/single_mem_node/main.rs#L113-L179). +## Protocal-buffer libraries support + +We're storing Message with protocal-buffer, while there're multiple Rust protocal-buffer +libraries. We support two protocal-buffer libraries via features. You need to choose +exactly one from prost and rust-protobuf (default). + +### rust-protobuf + +This is enabled by default and can be explicitly enabled via `lib-rust-protobuf` feature. +The generated protobuf struct, `eraftpb::Message`, will be included in the project if +`lib-rust-protobuf` is enabled. This means you don't need to install `protoc` to compile +the `.proto` files. If you really want to do a regeneration, enable `regenerate` feature. + +### prost + +It's a work-in-progress. + */ #![deny(clippy::all)] From e7e5ac059b05eb6c2263932bd1ea340bdaf35c34 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 14 Feb 2019 22:35:06 -0500 Subject: [PATCH 11/40] Add [cfg(feature = "lib-rust-protobuf")] to every protobuf places --- src/errors.rs | 2 ++ src/raft.rs | 4 ++++ src/raft_log.rs | 4 ++++ src/raw_node.rs | 3 +++ src/rsprotobuf/eraftpb.rs | 4 ---- src/storage.rs | 2 ++ src/util.rs | 1 + 7 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 2e187872c..a5812ef58 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -15,6 +15,7 @@ use std::error; use std::{cmp, io, result}; use StateRole; +#[cfg(feature = "lib-rust-protobuf")] use protobuf::ProtobufError; quick_error! { @@ -50,6 +51,7 @@ quick_error! { description(desc) } /// A Protobuf message failed in some manner. + #[cfg(feature = "lib-rust-protobuf")] Codec(err: ProtobufError) { from() cause(err) diff --git a/src/raft.rs b/src/raft.rs index 3896c4111..0466c05eb 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -31,7 +31,9 @@ use eraftpb::{ ConfChange, ConfChangeType, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; use hashbrown::{HashMap, HashSet}; +#[cfg(feature = "lib-rust-protobuf")] use protobuf; +#[cfg(feature = "lib-rust-protobuf")] use protobuf::RepeatedField; use rand::{self, Rng}; @@ -685,6 +687,7 @@ impl Raft { fn append_finalize_conf_change_entry(&mut self) { let mut conf_change = ConfChange::new(); conf_change.set_change_type(ConfChangeType::FinalizeMembershipChange); + #[cfg(feature = "lib-rust-protobuf")] let data = protobuf::Message::write_to_bytes(&conf_change).unwrap(); let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); @@ -2117,6 +2120,7 @@ impl Raft { conf_change.set_change_type(ConfChangeType::BeginMembershipChange); conf_change.set_configuration(config.into()); conf_change.set_start_index(destination_index); + #[cfg(feature = "lib-rust-protobuf")] let data = protobuf::Message::write_to_bytes(&conf_change)?; let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); diff --git a/src/raft_log.rs b/src/raft_log.rs index b348f57a2..7dd58e6ab 100644 --- a/src/raft_log.rs +++ b/src/raft_log.rs @@ -497,6 +497,7 @@ mod test { use eraftpb; use errors::{Error, StorageError}; + #[cfg(feature = "lib-rust-protobuf")] use protobuf; use raft_log::{self, RaftLog}; use setup_for_test; @@ -966,6 +967,9 @@ mod test { let (offset, num) = (100u64, 100u64); let (last, half) = (offset + num, offset + num / 2); let halfe = new_entry(half, half); + + // TODO: consider refactoring because prost can't "compute_size" + #[cfg(feature = "lib-rust-protobuf")] let halfe_size = u64::from(protobuf::Message::compute_size(&halfe)); let store = MemStorage::new(); diff --git a/src/raw_node.rs b/src/raw_node.rs index faef450c2..27c8bf9cc 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -36,6 +36,7 @@ use eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; +#[cfg(feature = "lib-rust-protobuf")] use protobuf::{self, RepeatedField}; use super::config::Config; @@ -239,6 +240,7 @@ impl RawNode { if let Some(ctx) = peer.context.take() { cc.set_context(ctx); } + #[cfg(feature = "lib-rust-protobuf")] let data = protobuf::Message::write_to_bytes(&cc).expect("unexpected marshal error"); let mut e = Entry::new(); @@ -319,6 +321,7 @@ impl RawNode { /// ProposeConfChange proposes a config change. #[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))] + #[cfg(feature = "lib-rust-protobuf")] pub fn propose_conf_change(&mut self, context: Vec, cc: ConfChange) -> Result<()> { let data = protobuf::Message::write_to_bytes(&cc)?; let mut m = Message::new(); diff --git a/src/rsprotobuf/eraftpb.rs b/src/rsprotobuf/eraftpb.rs index 12b5b979a..b8372310d 100644 --- a/src/rsprotobuf/eraftpb.rs +++ b/src/rsprotobuf/eraftpb.rs @@ -1,8 +1,4 @@ -<<<<<<< HEAD:src/rsprotobuf/eraftpb.rs // This file is generated by rust-protobuf 2.3.0. Do not edit -======= -// This file is generated by rust-protobuf 2.2.2. Do not edit ->>>>>>> tikv/master:src/eraftpb.rs // @generated // https://github.com/Manishearth/rust-clippy/issues/702 diff --git a/src/storage.rs b/src/storage.rs index 67df549de..8f9b7364c 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -375,6 +375,7 @@ impl Storage for MemStorage { #[cfg(test)] mod test { use eraftpb::{ConfState, Entry, Snapshot}; + #[cfg(feature = "lib-rust-protobuf")] use protobuf; use errors::{Error as RaftError, StorageError}; @@ -390,6 +391,7 @@ mod test { e } + #[cfg(feature = "lib-rust-protobuf")] fn size_of(m: &T) -> u32 { m.compute_size() } diff --git a/src/util.rs b/src/util.rs index cfddf2ea6..951fe1647 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,6 +17,7 @@ use std::u64; use eraftpb::{ConfChange, ConfChangeType, ConfState}; +#[cfg(feature = "lib-rust-protobuf")] use protobuf::Message; /// A number to represent that there is no limit. From 2ffb2841394f9c1d6393ca6d2efa913641cbae28 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Fri, 15 Feb 2019 19:05:57 -0500 Subject: [PATCH 12/40] Replace common.sh with rust code Signed-off-by: ice1000 --- build.rs | 24 ++++++++++++++---------- common.sh | 31 ------------------------------- 2 files changed, 14 insertions(+), 41 deletions(-) delete mode 100644 common.sh diff --git a/build.rs b/build.rs index b507a69a4..553a1cf76 100644 --- a/build.rs +++ b/build.rs @@ -14,7 +14,7 @@ extern crate regex; use regex::Regex; -use std::env; +use std::{str, env}; use std::fs::read_dir; use std::fs::File; use std::io::{Read, Write}; @@ -48,7 +48,7 @@ fn main() { match BufferLib::from_env_vars() { BufferLib::Prost => { unimplemented!("Prost support is not yet implemented"); - }, + } BufferLib::Protobuf => { check_protoc_version(); @@ -67,7 +67,7 @@ fn main() { .collect(); replace_read_unknown_fields(&mod_names); generate_protobuf_rs(&mod_names); - }, + } } } @@ -93,15 +93,19 @@ impl BufferLib { } fn check_protoc_version() { - let output = Command::new("bash") - .arg("common.sh") - .arg("check_protoc_version") + let ver_re = Regex::new(r"([0-9]+)\.([0-9]+)\.[0-9]").unwrap(); + let ver = Command::new("protoc") + .arg("--version") .output() - .expect("Could not execute `check_protoc_version`"); - if !output.status.success() { + .expect("Program `protoc` not installed (is it in PATH?)."); + let caps = ver_re.captures(str::from_utf8(&ver.stdout).unwrap()).unwrap(); + let major = caps.get(1).unwrap().as_str().parse::().unwrap(); + let minor = caps.get(2).unwrap().as_str().parse::().unwrap(); + if major == 3 && minor < 1 || major < 3 { panic!( - "Invalid version of protoc (required 3.1.x), or protoc not installed\n\nstdout:\n\n{}", - String::from_utf8_lossy(&output.stdout) + "Invalid version of protoc (required 3.1.x, get {}.{}.x).", + major, + minor, ); } } diff --git a/common.sh b/common.sh deleted file mode 100644 index b34032447..000000000 --- a/common.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -check_protoc_version() { - version=$(protoc --version) - major=$(echo ${version} | sed -n -e 's/.*\([0-9]\{1,\}\)\.[0-9]\{1,\}\.[0-9]\{1,\}.*/\1/p') - minor=$(echo ${version} | sed -n -e 's/.*[0-9]\{1,\}\.\([0-9]\{1,\}\)\.[0-9]\{1,\}.*/\1/p') - if [ "$major" -gt 3 ]; then - return 0 - fi - if [ "$major" -eq 3 ] && [ "$minor" -ge 1 ]; then - return 0 - fi - echo "protoc version not match, version 3.1.x is needed, current version: ${version}" - return 1 -} - -push () { - pushd $1 >/dev/null 2>&1 -} - -pop () { - popd $1 >/dev/null 2>&1 -} - -cmd_exists () { - which "$1" 1>/dev/null 2>&1 -} - -"$@" From 0993e1791636e15e5d377a145c82cc70bea4d38b Mon Sep 17 00:00:00 2001 From: ice1000 Date: Fri, 15 Feb 2019 19:11:45 -0500 Subject: [PATCH 13/40] Fix compilation error Signed-off-by: ice1000 --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index fb600eb45..4c76a4deb 100644 --- a/build.rs +++ b/build.rs @@ -200,7 +200,7 @@ fn generate_protobuf_rs(mod_names: &[String]) { } fn generate_prost_rs(protos: Vec<&str>) -> Result<()> { - let target: PathBuf = env::current_dir().map(|mut dir| { + let target = env::current_dir().map(|mut dir| { dir.push("src"); dir.push("rsprost.rs"); dir From e1e58686dc12c72aa292c207242026cd843eeae6 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Fri, 15 Feb 2019 19:18:00 -0500 Subject: [PATCH 14/40] Fix typo Signed-off-by: ice1000 --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 553a1cf76..0d713f14c 100644 --- a/build.rs +++ b/build.rs @@ -84,7 +84,7 @@ impl BufferLib { env::var_os("CARGO_FEATURE_LIB_RUST_PROTOBUF"), ) { (Some(_), Some(_)) | (None, None) => { - panic!("You must use exactly one of `lib-rust-protobuf` and `prost-buf` features") + panic!("You must use exactly one of `lib-rust-protobuf` and `lib-prost` features") } (Some(_), _) => BufferLib::Prost, (_, Some(_)) => BufferLib::Protobuf, From a52bace4bea060648538a97c276d7c91c45ffcb5 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sat, 16 Feb 2019 18:24:16 -0500 Subject: [PATCH 15/40] Cargo fmt Signed-off-by: ice1000 --- build.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 0d713f14c..ab0c063ce 100644 --- a/build.rs +++ b/build.rs @@ -14,11 +14,11 @@ extern crate regex; use regex::Regex; -use std::{str, env}; use std::fs::read_dir; use std::fs::File; use std::io::{Read, Write}; use std::process::Command; +use std::{env, str}; fn main() { // This build script creates files in the `src` directory. Since that is @@ -98,14 +98,15 @@ fn check_protoc_version() { .arg("--version") .output() .expect("Program `protoc` not installed (is it in PATH?)."); - let caps = ver_re.captures(str::from_utf8(&ver.stdout).unwrap()).unwrap(); + let caps = ver_re + .captures(str::from_utf8(&ver.stdout).unwrap()) + .unwrap(); let major = caps.get(1).unwrap().as_str().parse::().unwrap(); let minor = caps.get(2).unwrap().as_str().parse::().unwrap(); if major == 3 && minor < 1 || major < 3 { panic!( "Invalid version of protoc (required 3.1.x, get {}.{}.x).", - major, - minor, + major, minor, ); } } From b49d9409c81036d5258370fe339ec848a3966aba Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 21 Feb 2019 22:51:20 -0500 Subject: [PATCH 16/40] Fix typo-caused compilation error Signed-off-by: ice1000 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 54c9f44b1..6c9addde0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ categories = ["algorithms", "database-implementations"] build = "build.rs" [build-dependencies] -protoc-rust = "2.2.4" +protoc-rust = "~2.0-2.2" protoc-grpcio = "0.3.1" regex = "1.1" From 7a322ca93ebf6074de5e53764f9cb721c92e24b5 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 21 Feb 2019 22:58:07 -0500 Subject: [PATCH 17/40] Fix compilation errors Signed-off-by: ice1000 --- build.rs | 40 +++++++++++++++++++++------------------- src/lib.rs | 12 ++++++------ src/storage.rs | 2 +- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/build.rs b/build.rs index 602c06c9a..126481cff 100644 --- a/build.rs +++ b/build.rs @@ -11,13 +11,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -extern crate regex; extern crate prost_build; +extern crate regex; use regex::Regex; -use std::{str, env}; use std::error::Error; -use std::fs::{File, read_dir, remove_file}; +use std::fs::{read_dir, remove_file, File}; use std::io::{Read, Result, Write}; use std::process::Command; use std::{env, str}; @@ -49,21 +48,27 @@ fn main() { match BufferLib::from_env_vars() { BufferLib::Prost => { - let import_all = env::current_dir().map(|mut p| { - p.push("proto"); - p.push("import_all.proto"); - p - }).unwrap(); + let import_all = env::current_dir() + .map(|mut p| { + p.push("proto"); + p.push("import_all.proto"); + p + }) + .unwrap(); let mut file = File::create(import_all.clone()).unwrap(); file.write("syntax = \"proto3\";\n".as_bytes()).unwrap(); - file.write("package this_file_is_supposed_to_be_empty;\n".as_bytes()).unwrap(); - file_names.iter().map(|name| { - file.write("import \"".as_bytes())?; - file.write(name.as_bytes())?; - file.write("\";\n".as_bytes())?; - Ok(()) - }).for_each(|x: Result<()>| x.unwrap()); + file.write("package this_file_is_supposed_to_be_empty;\n".as_bytes()) + .unwrap(); + file_names + .iter() + .map(|name| { + file.write("import \"".as_bytes())?; + file.write(name.as_bytes())?; + file.write("\";\n".as_bytes())?; + Ok(()) + }) + .for_each(|x: Result<()>| x.unwrap()); file.sync_all().unwrap(); generate_prost_files(); @@ -133,9 +138,7 @@ fn check_protoc_version() { } fn generate_prost_files() { - prost_build::compile_protos( - &["proto/import_all.proto"], - &["proto"]) + prost_build::compile_protos(&["proto/import_all.proto"], &["proto"]) .map_err(|err| { println!("{}", err.description()); Err::<(), ()>(()) @@ -223,4 +226,3 @@ fn generate_prost_rs(protos: Vec<&str>) -> Result<()> { Ok(()) } - diff --git a/src/lib.rs b/src/lib.rs index 623482221..63912f210 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -391,12 +391,12 @@ extern crate harness; extern crate hashbrown; #[macro_use] extern crate log; -#[cfg(feature = "lib-rust-protobuf")] -extern crate protobuf; #[cfg(feature = "lib-prost")] extern crate bytes; #[cfg(feature = "lib-prost")] extern crate prost; +#[cfg(feature = "lib-rust-protobuf")] +extern crate protobuf; #[cfg(feature = "lib-prost")] #[macro_use] extern crate prost_derive; @@ -407,16 +407,16 @@ extern crate rand; extern crate getset; mod config; +#[cfg(feature = "lib-prost")] +mod rsprost; #[cfg(feature = "lib-rust-protobuf")] mod rsprotobuf; -#[cfg(feature = "lib-prosy")] -mod rsprost; +#[cfg(feature = "lib-prost")] +pub use crate::rsprost::eraftpb; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. #[cfg(feature = "lib-rust-protobuf")] pub use crate::rsprotobuf::eraftpb; -#[cfg(feature = "lib-prosy")] -pub use crate::rsprost::eraftpb; mod errors; mod log_unstable; mod progress; diff --git a/src/storage.rs b/src/storage.rs index 5b4de224e..0d806ecce 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -376,10 +376,10 @@ impl Storage for MemStorage { mod test { extern crate harness; use eraftpb::{ConfState, Entry, Snapshot}; + use errors::{Error as RaftError, StorageError}; use harness::setup_for_test; #[cfg(feature = "lib-rust-protobuf")] use protobuf; - use errors::{Error as RaftError, StorageError}; use storage::{MemStorage, Storage}; // TODO extract these duplicated utility functions for tests From e78a99cc5379e7d1f6cd7feb2cf485e0fc5d3f50 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sun, 24 Feb 2019 19:34:02 -0500 Subject: [PATCH 18/40] Add rsprost file to git repo Signed-off-by: ice1000 --- build.rs | 37 +++++++---- src/rsprost.rs | 1 + src/rsprost/eraftpb.rs | 145 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 14 deletions(-) create mode 100644 src/rsprost.rs create mode 100644 src/rsprost/eraftpb.rs diff --git a/build.rs b/build.rs index 126481cff..c1cb264ce 100644 --- a/build.rs +++ b/build.rs @@ -16,7 +16,7 @@ extern crate regex; use regex::Regex; use std::error::Error; -use std::fs::{read_dir, remove_file, File}; +use std::fs::{copy, read_dir, remove_file, File}; use std::io::{Read, Result, Write}; use std::process::Command; use std::{env, str}; @@ -71,7 +71,7 @@ fn main() { .for_each(|x: Result<()>| x.unwrap()); file.sync_all().unwrap(); - generate_prost_files(); + generate_and_move_prost_files(&file_names); remove_file(import_all).unwrap(); generate_prost_rs(file_names).unwrap(); } @@ -137,13 +137,27 @@ fn check_protoc_version() { } } -fn generate_prost_files() { - prost_build::compile_protos(&["proto/import_all.proto"], &["proto"]) +fn generate_and_move_prost_files(protos: &Vec<&str>) { + prost_build::compile_protos(&["proto/import_all.proto"], &["."]) .map_err(|err| { println!("{}", err.description()); Err::<(), ()>(()) }) .unwrap(); + let out_dir = env::var("OUT_DIR").unwrap(); + for s in protos { + let proto_name = s.trim_right_matches(".proto").trim_left_matches("proto/"); + let from = format!("{}/{}.rs", out_dir, proto_name); + let to = env::current_dir() + .map(|mut dir| { + dir.push("src"); + dir.push("rsprost"); + dir.push(format!("{}.rs", proto_name)); + dir + }) + .unwrap(); + copy(from, to).unwrap(); + } } fn generate_protobuf_files(file_names: Vec<&str>) { @@ -176,12 +190,13 @@ fn replace_read_unknown_fields(mod_names: &[String]) { .expect("Couldn't read source file"); } + #[rustfmt::skip] let text = regex.replace_all( &text, "if $1 == ::protobuf::wire_format::WireTypeVarint {\ - $3 = $2.read_enum()?;\ + $3 = $2.read_enum()?;\ } else {\ - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));\ + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));\ }", ); let mut out = File::create(file_name).unwrap(); @@ -211,17 +226,11 @@ fn generate_prost_rs(protos: Vec<&str>) -> Result<()> { dir })?; let mut file = File::create(target)?; - file.write("extern crate bytes;\n".as_bytes())?; - file.write("extern crate prost;\n".as_bytes())?; - file.write("#[macro_use]\n".as_bytes())?; - file.write("extern crate prost_derive;\n".as_bytes())?; for s in protos { - let proto_name = s.trim_right_matches(".proto"); + let proto_name = s.trim_right_matches(".proto").trim_left_matches("proto/"); file.write("pub mod ".as_bytes())?; file.write(proto_name.as_bytes())?; - file.write(" { include!(concat!(env!(\"OUT_DIR\"), \"/".as_bytes())?; - file.write(proto_name.as_bytes())?; - file.write(".rs\")); }\n".as_bytes())?; + file.write(";".as_bytes())?; } Ok(()) diff --git a/src/rsprost.rs b/src/rsprost.rs new file mode 100644 index 000000000..95a8c3b3d --- /dev/null +++ b/src/rsprost.rs @@ -0,0 +1 @@ +pub mod eraftpb; diff --git a/src/rsprost/eraftpb.rs b/src/rsprost/eraftpb.rs new file mode 100644 index 000000000..cc7225e09 --- /dev/null +++ b/src/rsprost/eraftpb.rs @@ -0,0 +1,145 @@ +/// The entry is a type of change that needs to be applied. It contains two data fields. +/// While the fields are built into the model; their usage is determined by the entry_type. +/// +/// For normal entries, the data field should contain the data change that should be applied. +/// The context field can be used for any contextual data that might be relevant to the +/// application of the data. +/// +/// For configuration changes, the data will contain the ConfChange message and the +/// context will provide anything needed to assist the configuration change. The context +/// if for the user to set and use in this case. +#[derive(Clone, PartialEq, Message)] +pub struct Entry { + #[prost(enumeration = "EntryType", tag = "1")] + pub entry_type: i32, + #[prost(uint64, tag = "2")] + pub term: u64, + #[prost(uint64, tag = "3")] + pub index: u64, + #[prost(bytes, tag = "4")] + pub data: Vec, + #[prost(bytes, tag = "6")] + pub context: Vec, + /// Deprecated! It is kept for backward compatibility. + /// TODO: remove it in the next major release. + #[prost(bool, tag = "5")] + pub sync_log: bool, +} +#[derive(Clone, PartialEq, Message)] +pub struct SnapshotMetadata { + #[prost(message, optional, tag = "1")] + pub conf_state: ::std::option::Option, + #[prost(message, optional, tag = "4")] + pub pending_membership_change: ::std::option::Option, + #[prost(uint64, tag = "5")] + pub pending_membership_change_index: u64, + #[prost(uint64, tag = "2")] + pub index: u64, + #[prost(uint64, tag = "3")] + pub term: u64, +} +#[derive(Clone, PartialEq, Message)] +pub struct Snapshot { + #[prost(bytes, tag = "1")] + pub data: Vec, + #[prost(message, optional, tag = "2")] + pub metadata: ::std::option::Option, +} +#[derive(Clone, PartialEq, Message)] +pub struct Message { + #[prost(enumeration = "MessageType", tag = "1")] + pub msg_type: i32, + #[prost(uint64, tag = "2")] + pub to: u64, + #[prost(uint64, tag = "3")] + pub from: u64, + #[prost(uint64, tag = "4")] + pub term: u64, + #[prost(uint64, tag = "5")] + pub log_term: u64, + #[prost(uint64, tag = "6")] + pub index: u64, + #[prost(message, repeated, tag = "7")] + pub entries: ::std::vec::Vec, + #[prost(uint64, tag = "8")] + pub commit: u64, + #[prost(message, optional, tag = "9")] + pub snapshot: ::std::option::Option, + #[prost(bool, tag = "10")] + pub reject: bool, + #[prost(uint64, tag = "11")] + pub reject_hint: u64, + #[prost(bytes, tag = "12")] + pub context: Vec, +} +#[derive(Clone, PartialEq, Message)] +pub struct HardState { + #[prost(uint64, tag = "1")] + pub term: u64, + #[prost(uint64, tag = "2")] + pub vote: u64, + #[prost(uint64, tag = "3")] + pub commit: u64, +} +#[derive(Clone, PartialEq, Message)] +pub struct ConfState { + #[prost(uint64, repeated, tag = "1")] + pub nodes: ::std::vec::Vec, + #[prost(uint64, repeated, tag = "2")] + pub learners: ::std::vec::Vec, +} +#[derive(Clone, PartialEq, Message)] +pub struct ConfChange { + #[prost(uint64, tag = "1")] + pub id: u64, + #[prost(enumeration = "ConfChangeType", tag = "2")] + pub change_type: i32, + /// Used in `AddNode`, `RemoveNode`, and `AddLearnerNode`. + #[prost(uint64, tag = "3")] + pub node_id: u64, + #[prost(bytes, tag = "4")] + pub context: Vec, + /// Used in `BeginMembershipChange` and `FinalizeMembershipChange`. + #[prost(message, optional, tag = "5")] + pub configuration: ::std::option::Option, + /// Used in `BeginMembershipChange` and `FinalizeMembershipChange`. + /// Because `RawNode::apply_conf_change` takes a `ConfChange` instead of an `Entry` we must + /// include this index so it can be known. + #[prost(uint64, tag = "6")] + pub start_index: u64, +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Enumeration)] +pub enum EntryType { + EntryNormal = 0, + EntryConfChange = 1, +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Enumeration)] +pub 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, +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Enumeration)] +pub enum ConfChangeType { + AddNode = 0, + RemoveNode = 1, + AddLearnerNode = 2, + BeginMembershipChange = 3, + FinalizeMembershipChange = 4, +} From b406b3a1e8e85d97787ae162b6602549dbc5791f Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 12 Mar 2019 08:22:05 -0400 Subject: [PATCH 19/40] Save progress --- Cargo.toml | 4 +- build.rs | 233 +++++++++------------------------ src/errors.rs | 6 +- src/lib.rs | 2 +- src/raft.rs | 6 + src/raw_node.rs | 4 + src/rsprost.rs | 1 + src/rsprost/protobuf_compat.rs | 8 ++ src/util.rs | 3 +- 9 files changed, 92 insertions(+), 175 deletions(-) create mode 100644 src/rsprost/protobuf_compat.rs diff --git a/Cargo.toml b/Cargo.toml index d6890df5d..2d03ca59c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,10 +17,10 @@ build = "build.rs" protoc-rust = "~2.0-2.2" protoc-grpcio = "0.3.1" regex = "1.1" -prost-build = { version = "0.4" } +protobuf-build = { git = "https://github.com/nrc/kvproto-build" } [features] -default = ["lib-rust-protobuf"] +default = ["lib-prost"] lib-rust-protobuf = ["protobuf"] lib-prost = ["prost", "prost-derive", "bytes"] regenerate = [] diff --git a/build.rs b/build.rs index c1cb264ce..15b77fe10 100644 --- a/build.rs +++ b/build.rs @@ -11,26 +11,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -extern crate prost_build; -extern crate regex; - -use regex::Regex; -use std::error::Error; -use std::fs::{copy, read_dir, remove_file, File}; -use std::io::{Read, Result, Write}; -use std::process::Command; -use std::{env, str}; +use protobuf_build::*; +use std::fs::{read_dir, File}; +use std::io::Write; fn main() { // This build script creates files in the `src` directory. Since that is // outside Cargo's OUT_DIR it will cause an error when this crate is used // as a dependency. Therefore, the user must opt-in to regenerating the // Rust files. - if env::var_os("CARGO_FEATURE_REGENERATE").is_none() { + if !cfg!(feature = "regenerate") { println!("cargo:rerun-if-changed=build.rs"); return; } + check_protoc_version(); + let file_names: Vec<_> = read_dir("proto") .expect("Couldn't read proto directory") .map(|e| { @@ -40,129 +36,41 @@ fn main() { ) }) .collect(); - let file_names: Vec<_> = file_names.iter().map(|s| &**s).collect(); for f in &file_names { println!("cargo:rerun-if-changed={}", f); } - match BufferLib::from_env_vars() { - BufferLib::Prost => { - let import_all = env::current_dir() - .map(|mut p| { - p.push("proto"); - p.push("import_all.proto"); - p - }) - .unwrap(); - let mut file = File::create(import_all.clone()).unwrap(); - - file.write("syntax = \"proto3\";\n".as_bytes()).unwrap(); - file.write("package this_file_is_supposed_to_be_empty;\n".as_bytes()) - .unwrap(); - file_names - .iter() - .map(|name| { - file.write("import \"".as_bytes())?; - file.write(name.as_bytes())?; - file.write("\";\n".as_bytes())?; - Ok(()) - }) - .for_each(|x: Result<()>| x.unwrap()); - file.sync_all().unwrap(); - - generate_and_move_prost_files(&file_names); - remove_file(import_all).unwrap(); - generate_prost_rs(file_names).unwrap(); - } - - BufferLib::Protobuf => { - check_protoc_version(); - - generate_protobuf_files(file_names); - let mod_names: Vec<_> = read_dir("src/rsprotobuf") - .expect("Couldn't read src directory") - .filter_map(|e| { - let file_name = e.expect("Couldn't list file").file_name(); - file_name - .to_string_lossy() - .split(".rs") - .next() - .map(|n| n.to_owned()) - }) - .collect(); - replace_read_unknown_fields(&mod_names); - generate_protobuf_rs(&mod_names); - } - } -} - -#[derive(Eq, PartialEq)] -enum BufferLib { - Prost, - Protobuf, -} - -impl BufferLib { - fn from_env_vars() -> BufferLib { - match ( - env::var_os("CARGO_FEATURE_LIB_PROST"), - env::var_os("CARGO_FEATURE_LIB_RUST_PROTOBUF"), - ) { - (Some(_), Some(_)) | (None, None) => { - panic!("You must use exactly one of `lib-rust-protobuf` and `lib-prost` features") - } - (Some(_), _) => BufferLib::Prost, - (_, Some(_)) => BufferLib::Protobuf, - } - } -} + // Generate Prost files. + generate_prost_files(&file_names, "src/rsprost"); + let mod_names = module_names_for_dir("src/rsprost"); + generate_wrappers( + &mod_names + .iter() + .map(|m| format!("src/rsprost/{}.rs", m)) + .collect::>(), + "src/rsprost", + ); + generate_prost_rs(&mod_names); + + // Generate rust-protobuf files. + let file_names: Vec<_> = file_names.iter().map(|s| &**s).collect(); + generate_protobuf_files(file_names, "src/protobuf"); -fn check_protoc_version() { - let ver_re = Regex::new(r"([0-9]+)\.([0-9]+)\.[0-9]").unwrap(); - let ver = Command::new("protoc") - .arg("--version") - .output() - .expect("Program `protoc` not installed (is it in PATH?)."); - let caps = ver_re - .captures(str::from_utf8(&ver.stdout).unwrap()) - .unwrap(); - let major = caps.get(1).unwrap().as_str().parse::().unwrap(); - let minor = caps.get(2).unwrap().as_str().parse::().unwrap(); - if major == 3 && minor < 1 || major < 3 { - panic!( - "Invalid version of protoc (required 3.1.x, get {}.{}.x).", - major, minor, - ); - } -} + let mod_names = module_names_for_dir("src/protobuf"); -fn generate_and_move_prost_files(protos: &Vec<&str>) { - prost_build::compile_protos(&["proto/import_all.proto"], &["."]) - .map_err(|err| { - println!("{}", err.description()); - Err::<(), ()>(()) - }) - .unwrap(); - let out_dir = env::var("OUT_DIR").unwrap(); - for s in protos { - let proto_name = s.trim_right_matches(".proto").trim_left_matches("proto/"); - let from = format!("{}/{}.rs", out_dir, proto_name); - let to = env::current_dir() - .map(|mut dir| { - dir.push("src"); - dir.push("rsprost"); - dir.push(format!("{}.rs", proto_name)); - dir - }) - .unwrap(); - copy(from, to).unwrap(); - } + let out_file_names: Vec<_> = mod_names + .iter() + .map(|m| format!("src/protobuf/{}.rs", m)) + .collect(); + let out_file_names: Vec<_> = out_file_names.iter().map(|f| &**f).collect(); + replace_read_unknown_fields(&out_file_names); + generate_protobuf_rs(&mod_names); } -fn generate_protobuf_files(file_names: Vec<&str>) { +fn generate_protobuf_files(file_names: Vec<&str>, out_dir: &str) { protoc_rust::run(protoc_rust::Args { - out_dir: "src/rsprotobuf", + out_dir, input: &file_names, includes: &["proto", "include"], customize: protoc_rust::Customize { @@ -175,38 +83,8 @@ fn generate_protobuf_files(file_names: Vec<&str>) { .unwrap(); } -// Use the old way to read protobuf enums. -// FIXME: Remove this once stepancheg/rust-protobuf#233 is resolved. -fn replace_read_unknown_fields(mod_names: &[String]) { - let regex = - Regex::new(r"::protobuf::rt::read_proto3_enum_with_unknown_fields_into\(([^,]+), ([^,]+), &mut ([^,]+), [^\)]+\)\?").unwrap(); - for mod_name in mod_names { - let file_name = &format!("src/rsprotobuf/{}.rs", mod_name); - - let mut text = String::new(); - { - let mut f = File::open(file_name).unwrap(); - f.read_to_string(&mut text) - .expect("Couldn't read source file"); - } - - #[rustfmt::skip] - let text = regex.replace_all( - &text, - "if $1 == ::protobuf::wire_format::WireTypeVarint {\ - $3 = $2.read_enum()?;\ - } else {\ - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));\ - }", - ); - let mut out = File::create(file_name).unwrap(); - out.write_all(text.as_bytes()) - .expect("Could not write source file"); - } -} - fn generate_protobuf_rs(mod_names: &[String]) { - let mut text = "".to_owned(); + let mut text = "pub use raft::eraftpb;\n\n".to_owned(); for mod_name in mod_names { text.push_str("pub mod "); @@ -214,24 +92,41 @@ fn generate_protobuf_rs(mod_names: &[String]) { text.push_str(";\n"); } - let mut lib = File::create("src/rsprotobuf.rs").expect("Could not create rsprotobuf.rs"); + let mut lib = File::create("src/protobuf.rs").expect("Could not create protobuf.rs"); lib.write_all(text.as_bytes()) - .expect("Could not write rsprotobuf.rs"); + .expect("Could not write protobuf.rs"); } -fn generate_prost_rs(protos: Vec<&str>) -> Result<()> { - let target = env::current_dir().map(|mut dir| { - dir.push("src"); - dir.push("rsprost.rs"); - dir - })?; - let mut file = File::create(target)?; - for s in protos { - let proto_name = s.trim_right_matches(".proto").trim_left_matches("proto/"); - file.write("pub mod ".as_bytes())?; - file.write(proto_name.as_bytes())?; - file.write(";".as_bytes())?; +fn generate_prost_rs(mod_names: &[String]) { + let mut text = "#![allow(dead_code)]\n\n".to_owned(); + + for mod_name in mod_names { + text.push_str("pub mod "); + text.push_str(mod_name); + text.push_str("{\n"); + text.push_str("include!(\"rsprost/"); + text.push_str(mod_name); + text.push_str(".rs\");"); + text.push_str("include!(\"rsprost/wrapper_"); + text.push_str(mod_name); + text.push_str(".rs\");"); + text.push_str("}\n\n"); } + text.push_str("pub mod protobuf_compat;\n"); - Ok(()) + let mut lib = File::create("src/rsprost.rs").expect("Could not create rsprost.rs"); + lib.write_all(text.as_bytes()) + .expect("Could not write rsprost.rs"); + + let protobuf_compat_text = " + pub struct RepeatedField; + impl RepeatedField { + #[inline] + pub fn from_vec(v: Vec) -> Vec { + v + } + }"; + let mut compat_file = File::create("src/rsprost/protobuf_compat.rs").expect("Could not create protobuf_compat.rs"); + compat_file.write_all(protobuf_compat_text.as_bytes()) + .expect("Could not write protobuf_compat.rs"); } diff --git a/src/errors.rs b/src/errors.rs index 3855a8331..c7c011522 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -15,8 +15,10 @@ use crate::StateRole; use std::error; use std::{cmp, io, result}; +#[cfg(feature = "lib-prost")] +use prost::DecodeError as PbError; #[cfg(feature = "lib-rust-protobuf")] -use protobuf::ProtobufError; +use protobuf::ProtobufError as PbError; quick_error! { /// The base error type for raft @@ -52,7 +54,7 @@ quick_error! { } /// A Protobuf message failed in some manner. #[cfg(feature = "lib-rust-protobuf")] - Codec(err: ProtobufError) { + Codec(err: PbError) { from() cause(err) description(err.description()) diff --git a/src/lib.rs b/src/lib.rs index b31ca48e2..c98122b0a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -409,7 +409,7 @@ mod rsprost; #[cfg(feature = "lib-rust-protobuf")] mod rsprotobuf; #[cfg(feature = "lib-prost")] -pub use crate::rsprost::eraftpb; +pub use crate::prost::eraftpb; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. #[cfg(feature = "lib-rust-protobuf")] diff --git a/src/raft.rs b/src/raft.rs index a68696cc8..1a67b1e4b 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -30,6 +30,8 @@ use std::cmp; use crate::eraftpb::{ ConfChange, ConfChangeType, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; +#[cfg(feature = "lib-prost")] +use crate::prost::protobuf_compat::*; use hashbrown::{HashMap, HashSet}; #[cfg(feature = "lib-rust-protobuf")] use protobuf; @@ -689,6 +691,8 @@ impl Raft { conf_change.set_change_type(ConfChangeType::FinalizeMembershipChange); #[cfg(feature = "lib-rust-protobuf")] let data = protobuf::Message::write_to_bytes(&conf_change).unwrap(); + #[cfg(feature = "lib-prost")] + let data = prost::Message::decode(&conf_change).unwrap(); let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); @@ -2122,6 +2126,8 @@ impl Raft { conf_change.set_start_index(destination_index); #[cfg(feature = "lib-rust-protobuf")] let data = protobuf::Message::write_to_bytes(&conf_change)?; + #[cfg(feature = "lib-prost")] + let data = prost::Message::decode(&conf_change).unwrap(); let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); diff --git a/src/raw_node.rs b/src/raw_node.rs index 81d4b6ade..1aba00682 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -36,6 +36,8 @@ use crate::eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; +#[cfg(feature = "lib-prost")] +use crate::prost::protobuf_compat::*; #[cfg(feature = "lib-rust-protobuf")] use protobuf::{self, RepeatedField}; @@ -243,6 +245,8 @@ impl RawNode { #[cfg(feature = "lib-rust-protobuf")] let data = protobuf::Message::write_to_bytes(&cc).expect("unexpected marshal error"); + #[cfg(feature = "lib-prost")] + let data = prost::Message::decode(&cc).unwrap(); let mut e = Entry::new(); e.set_entry_type(EntryType::EntryConfChange); e.set_term(1); diff --git a/src/rsprost.rs b/src/rsprost.rs index 95a8c3b3d..d378ee93c 100644 --- a/src/rsprost.rs +++ b/src/rsprost.rs @@ -1 +1,2 @@ pub mod eraftpb; +pub mod protobuf_compat; diff --git a/src/rsprost/protobuf_compat.rs b/src/rsprost/protobuf_compat.rs new file mode 100644 index 000000000..0fd05a634 --- /dev/null +++ b/src/rsprost/protobuf_compat.rs @@ -0,0 +1,8 @@ +pub struct RepeatedField; + +impl RepeatedField { + #[inline] + pub fn from_vec(v: Vec) -> Vec { + v + } +} diff --git a/src/util.rs b/src/util.rs index aa70c9d90..8798bf8da 100644 --- a/src/util.rs +++ b/src/util.rs @@ -16,8 +16,9 @@ use std::u64; -#[cfg(feature = "lib-rust-protobuf")] use crate::eraftpb::{ConfChange, ConfChangeType, ConfState}; +#[cfg(feature = "lib-prost")] +use prost::Message; #[cfg(feature = "lib-rust-protobuf")] use protobuf::Message; From 995c775a77c43d80294d5bf478506fcc60d70bf4 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 12 Mar 2019 08:24:42 -0400 Subject: [PATCH 20/40] Save progress --- src/lib.rs | 2 +- src/raft.rs | 2 +- src/raw_node.rs | 2 +- src/util.rs | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c98122b0a..b31ca48e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -409,7 +409,7 @@ mod rsprost; #[cfg(feature = "lib-rust-protobuf")] mod rsprotobuf; #[cfg(feature = "lib-prost")] -pub use crate::prost::eraftpb; +pub use crate::rsprost::eraftpb; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. #[cfg(feature = "lib-rust-protobuf")] diff --git a/src/raft.rs b/src/raft.rs index 8ab27e20a..8e044dbb7 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -31,7 +31,7 @@ use crate::eraftpb::{ ConfChange, ConfChangeType, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; #[cfg(feature = "lib-prost")] -use crate::prost::protobuf_compat::*; +use crate::rsprost::protobuf_compat::*; use hashbrown::{HashMap, HashSet}; #[cfg(feature = "lib-rust-protobuf")] use protobuf; diff --git a/src/raw_node.rs b/src/raw_node.rs index cfae3e6e8..0c6caf581 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -37,7 +37,7 @@ use crate::eraftpb::{ Snapshot, }; #[cfg(feature = "lib-prost")] -use crate::prost::protobuf_compat::*; +use crate::rsprost::protobuf_compat::*; #[cfg(feature = "lib-rust-protobuf")] use protobuf::{self, RepeatedField}; diff --git a/src/util.rs b/src/util.rs index 6b6864a9e..43d0452f2 100644 --- a/src/util.rs +++ b/src/util.rs @@ -16,11 +16,11 @@ use std::u64; -use crate::eraftpb::{ConfChange, ConfChangeType, ConfState}; +use crate::eraftpb::{ConfChange, ConfChangeType, ConfState, Message, Entry}; #[cfg(feature = "lib-prost")] -use prost::Message; +use prost::Message as Msg; #[cfg(feature = "lib-rust-protobuf")] -use protobuf; +use protobuf::Message as Msg; /// A number to represent that there is no limit. pub const NO_LIMIT: u64 = u64::MAX; @@ -56,7 +56,7 @@ pub const NO_LIMIT: u64 = u64::MAX; /// limit_size(&mut entries, Some(0)); /// assert_eq!(entries.len(), 1); /// ``` -pub fn limit_size(entries: &mut Vec, max: Option) { +pub fn limit_size(entries: &mut Vec, max: Option) { if entries.len() <= 1 { return; } @@ -70,10 +70,10 @@ pub fn limit_size(entries: &mut Vec, max: Optio .iter() .take_while(|&e| { if size == 0 { - size += u64::from(protobuf::Message::compute_size(e)); + size += u64::from(Msg::compute_size(e)); true } else { - size += u64::from(protobuf::Message::compute_size(e)); + size += u64::from(Msg::compute_size(e)); size <= max } }) From 08e408ca7a0ae89219f1497a252b763403f06c26 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 12 Mar 2019 08:39:10 -0400 Subject: [PATCH 21/40] Successfully generate! --- build.rs | 28 +- src/rsprost.rs | 8 +- src/rsprost/eraftpb.rs | 33 +-- src/rsprost/protobuf_compat.rs | 2 +- src/rsprotobuf.rs | 2 + src/rsprotobuf/eraftpb.rs | 464 +++++++++------------------------ src/util.rs | 2 +- 7 files changed, 174 insertions(+), 365 deletions(-) diff --git a/build.rs b/build.rs index 15b77fe10..2ec6c67f1 100644 --- a/build.rs +++ b/build.rs @@ -29,11 +29,13 @@ fn main() { let file_names: Vec<_> = read_dir("proto") .expect("Couldn't read proto directory") - .map(|e| { - format!( - "proto/{}", - e.expect("Couldn't list file").file_name().to_string_lossy() - ) + .filter_map(|e| { + let e = e.expect("Couldn't list file"); + if e.file_type().expect("File broken").is_dir() { + None + } else { + Some(format!("proto/{}", e.file_name().to_string_lossy())) + } }) .collect(); @@ -55,13 +57,13 @@ fn main() { // Generate rust-protobuf files. let file_names: Vec<_> = file_names.iter().map(|s| &**s).collect(); - generate_protobuf_files(file_names, "src/protobuf"); + generate_protobuf_files(file_names, "src/rsprotobuf"); - let mod_names = module_names_for_dir("src/protobuf"); + let mod_names = module_names_for_dir("src/rsprotobuf"); let out_file_names: Vec<_> = mod_names .iter() - .map(|m| format!("src/protobuf/{}.rs", m)) + .map(|m| format!("src/rsprotobuf/{}.rs", m)) .collect(); let out_file_names: Vec<_> = out_file_names.iter().map(|f| &**f).collect(); replace_read_unknown_fields(&out_file_names); @@ -92,9 +94,9 @@ fn generate_protobuf_rs(mod_names: &[String]) { text.push_str(";\n"); } - let mut lib = File::create("src/protobuf.rs").expect("Could not create protobuf.rs"); + let mut lib = File::create("src/rsprotobuf.rs").expect("Could not create rsprotobuf.rs"); lib.write_all(text.as_bytes()) - .expect("Could not write protobuf.rs"); + .expect("Could not write rsprotobuf.rs"); } fn generate_prost_rs(mod_names: &[String]) { @@ -126,7 +128,9 @@ fn generate_prost_rs(mod_names: &[String]) { v } }"; - let mut compat_file = File::create("src/rsprost/protobuf_compat.rs").expect("Could not create protobuf_compat.rs"); - compat_file.write_all(protobuf_compat_text.as_bytes()) + let mut compat_file = File::create("src/rsprost/protobuf_compat.rs") + .expect("Could not create protobuf_compat.rs"); + compat_file + .write_all(protobuf_compat_text.as_bytes()) .expect("Could not write protobuf_compat.rs"); } diff --git a/src/rsprost.rs b/src/rsprost.rs index d378ee93c..6132d0187 100644 --- a/src/rsprost.rs +++ b/src/rsprost.rs @@ -1,2 +1,8 @@ -pub mod eraftpb; +#![allow(dead_code)] + +pub mod eraftpb { + include!("rsprost/eraftpb.rs"); + include!("rsprost/wrapper_eraftpb.rs"); +} + pub mod protobuf_compat; diff --git a/src/rsprost/eraftpb.rs b/src/rsprost/eraftpb.rs index cc7225e09..f8c9174e7 100644 --- a/src/rsprost/eraftpb.rs +++ b/src/rsprost/eraftpb.rs @@ -8,7 +8,7 @@ /// For configuration changes, the data will contain the ConfChange message and the /// context will provide anything needed to assist the configuration change. The context /// if for the user to set and use in this case. -#[derive(Clone, PartialEq, Message)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct Entry { #[prost(enumeration = "EntryType", tag = "1")] pub entry_type: i32, @@ -17,15 +17,15 @@ pub struct Entry { #[prost(uint64, tag = "3")] pub index: u64, #[prost(bytes, tag = "4")] - pub data: Vec, + pub data: std::vec::Vec, #[prost(bytes, tag = "6")] - pub context: Vec, + pub context: std::vec::Vec, /// Deprecated! It is kept for backward compatibility. /// TODO: remove it in the next major release. #[prost(bool, tag = "5")] pub sync_log: bool, } -#[derive(Clone, PartialEq, Message)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct SnapshotMetadata { #[prost(message, optional, tag = "1")] pub conf_state: ::std::option::Option, @@ -38,14 +38,14 @@ pub struct SnapshotMetadata { #[prost(uint64, tag = "3")] pub term: u64, } -#[derive(Clone, PartialEq, Message)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct Snapshot { #[prost(bytes, tag = "1")] - pub data: Vec, + pub data: std::vec::Vec, #[prost(message, optional, tag = "2")] pub metadata: ::std::option::Option, } -#[derive(Clone, PartialEq, Message)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct Message { #[prost(enumeration = "MessageType", tag = "1")] pub msg_type: i32, @@ -70,9 +70,9 @@ pub struct Message { #[prost(uint64, tag = "11")] pub reject_hint: u64, #[prost(bytes, tag = "12")] - pub context: Vec, + pub context: std::vec::Vec, } -#[derive(Clone, PartialEq, Message)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct HardState { #[prost(uint64, tag = "1")] pub term: u64, @@ -81,14 +81,14 @@ pub struct HardState { #[prost(uint64, tag = "3")] pub commit: u64, } -#[derive(Clone, PartialEq, Message)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct ConfState { #[prost(uint64, repeated, tag = "1")] pub nodes: ::std::vec::Vec, #[prost(uint64, repeated, tag = "2")] pub learners: ::std::vec::Vec, } -#[derive(Clone, PartialEq, Message)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct ConfChange { #[prost(uint64, tag = "1")] pub id: u64, @@ -98,7 +98,7 @@ pub struct ConfChange { #[prost(uint64, tag = "3")] pub node_id: u64, #[prost(bytes, tag = "4")] - pub context: Vec, + pub context: std::vec::Vec, /// Used in `BeginMembershipChange` and `FinalizeMembershipChange`. #[prost(message, optional, tag = "5")] pub configuration: ::std::option::Option, @@ -108,12 +108,14 @@ pub struct ConfChange { #[prost(uint64, tag = "6")] pub start_index: u64, } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Enumeration)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] pub enum EntryType { EntryNormal = 0, EntryConfChange = 1, } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Enumeration)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] pub enum MessageType { MsgHup = 0, MsgBeat = 1, @@ -135,7 +137,8 @@ pub enum MessageType { MsgRequestPreVote = 17, MsgRequestPreVoteResponse = 18, } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Enumeration)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] pub enum ConfChangeType { AddNode = 0, RemoveNode = 1, diff --git a/src/rsprost/protobuf_compat.rs b/src/rsprost/protobuf_compat.rs index 0fd05a634..0dd4b6744 100644 --- a/src/rsprost/protobuf_compat.rs +++ b/src/rsprost/protobuf_compat.rs @@ -1,5 +1,5 @@ -pub struct RepeatedField; +pub struct RepeatedField; impl RepeatedField { #[inline] pub fn from_vec(v: Vec) -> Vec { diff --git a/src/rsprotobuf.rs b/src/rsprotobuf.rs index 95a8c3b3d..a6fa108a0 100644 --- a/src/rsprotobuf.rs +++ b/src/rsprotobuf.rs @@ -1 +1,3 @@ +pub use raft::eraftpb; + pub mod eraftpb; diff --git a/src/rsprotobuf/eraftpb.rs b/src/rsprotobuf/eraftpb.rs index 5c5a75a83..29044d6e2 100644 --- a/src/rsprotobuf/eraftpb.rs +++ b/src/rsprotobuf/eraftpb.rs @@ -1,9 +1,9 @@ -// This file is generated by rust-protobuf 2.3.0. Do not edit +// This file is generated by rust-protobuf 2.0.6. Do not edit // @generated // https://github.com/Manishearth/rust-clippy/issues/702 #![allow(unknown_lints)] -#![allow(clippy::all)] +#![allow(clippy)] #![cfg_attr(rustfmt, rustfmt_skip)] @@ -31,8 +31,8 @@ pub struct Entry { pub context: ::std::vec::Vec, pub sync_log: bool, // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, } impl Entry { @@ -158,7 +158,7 @@ impl ::protobuf::Message for Entry { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -227,7 +227,7 @@ impl ::protobuf::Message for Entry { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { if self.entry_type != EntryType::EntryNormal { os.write_enum(1, self.entry_type.value())?; } @@ -262,13 +262,13 @@ impl ::protobuf::Message for Entry { &mut self.unknown_fields } - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { self } @@ -351,13 +351,13 @@ impl ::protobuf::Clear for Entry { } impl ::std::fmt::Debug for Entry { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Entry { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -371,8 +371,8 @@ pub struct SnapshotMetadata { pub index: u64, pub term: u64, // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, } impl SnapshotMetadata { @@ -507,7 +507,7 @@ impl ::protobuf::Message for SnapshotMetadata { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -572,7 +572,7 @@ impl ::protobuf::Message for SnapshotMetadata { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { if let Some(ref v) = self.conf_state.as_ref() { os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; @@ -608,13 +608,13 @@ impl ::protobuf::Message for SnapshotMetadata { &mut self.unknown_fields } - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { self } @@ -691,13 +691,13 @@ impl ::protobuf::Clear for SnapshotMetadata { } impl ::std::fmt::Debug for SnapshotMetadata { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for SnapshotMetadata { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -708,8 +708,8 @@ pub struct Snapshot { pub data: ::std::vec::Vec, pub metadata: ::protobuf::SingularPtrField, // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, } impl Snapshot { @@ -787,7 +787,7 @@ impl ::protobuf::Message for Snapshot { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -821,7 +821,7 @@ impl ::protobuf::Message for Snapshot { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { if !self.data.is_empty() { os.write_bytes(1, &self.data)?; } @@ -846,13 +846,13 @@ impl ::protobuf::Message for Snapshot { &mut self.unknown_fields } - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { self } @@ -911,13 +911,13 @@ impl ::protobuf::Clear for Snapshot { } impl ::std::fmt::Debug for Snapshot { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Snapshot { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -938,8 +938,8 @@ pub struct Message { pub reject_hint: u64, pub context: ::std::vec::Vec, // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, } impl Message { @@ -1182,7 +1182,7 @@ impl ::protobuf::Message for Message { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -1309,7 +1309,7 @@ impl ::protobuf::Message for Message { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { if self.msg_type != MessageType::MsgHup { os.write_enum(1, self.msg_type.value())?; } @@ -1366,13 +1366,13 @@ impl ::protobuf::Message for Message { &mut self.unknown_fields } - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { self } @@ -1491,13 +1491,13 @@ impl ::protobuf::Clear for Message { } impl ::std::fmt::Debug for Message { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Message { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -1509,8 +1509,8 @@ pub struct HardState { pub vote: u64, pub commit: u64, // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, } impl HardState { @@ -1569,7 +1569,7 @@ impl ::protobuf::Message for HardState { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -1620,7 +1620,7 @@ impl ::protobuf::Message for HardState { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { if self.term != 0 { os.write_uint64(1, self.term)?; } @@ -1646,13 +1646,13 @@ impl ::protobuf::Message for HardState { &mut self.unknown_fields } - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { self } @@ -1717,13 +1717,13 @@ impl ::protobuf::Clear for HardState { } impl ::std::fmt::Debug for HardState { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for HardState { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -1734,8 +1734,8 @@ pub struct ConfState { pub nodes: ::std::vec::Vec, pub learners: ::std::vec::Vec, // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, } impl ConfState { @@ -1799,7 +1799,7 @@ impl ::protobuf::Message for ConfState { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -1832,7 +1832,7 @@ impl ::protobuf::Message for ConfState { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { for v in &self.nodes { os.write_uint64(1, *v)?; }; @@ -1855,13 +1855,13 @@ impl ::protobuf::Message for ConfState { &mut self.unknown_fields } - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { self } @@ -1920,13 +1920,13 @@ impl ::protobuf::Clear for ConfState { } impl ::std::fmt::Debug for ConfState { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for ConfState { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -1941,8 +1941,8 @@ pub struct ConfChange { pub configuration: ::protobuf::SingularPtrField, pub start_index: u64, // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, } impl ConfChange { @@ -2080,7 +2080,7 @@ impl ::protobuf::Message for ConfChange { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -2150,7 +2150,7 @@ impl ::protobuf::Message for ConfChange { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { if self.id != 0 { os.write_uint64(1, self.id)?; } @@ -2187,13 +2187,13 @@ impl ::protobuf::Message for ConfChange { &mut self.unknown_fields } - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { self } @@ -2276,13 +2276,13 @@ impl ::protobuf::Clear for ConfChange { } impl ::std::fmt::Debug for ConfChange { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for ConfChange { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -2337,7 +2337,7 @@ impl ::std::default::Default for EntryType { } impl ::protobuf::reflect::ProtobufValue for EntryType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } @@ -2443,7 +2443,7 @@ impl ::std::default::Default for MessageType { } impl ::protobuf::reflect::ProtobufValue for MessageType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } @@ -2507,265 +2507,59 @@ impl ::std::default::Default for ConfChangeType { } impl ::protobuf::reflect::ProtobufValue for ConfChangeType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x13proto/eraftpb.proto\x12\x07eraftpb\"\xad\x01\n\x05Entry\x121\n\nen\ - try_type\x18\x01\x20\x01(\x0e2\x12.eraftpb.EntryTypeR\tentryType\x12\x12\ - \n\x04term\x18\x02\x20\x01(\x04R\x04term\x12\x14\n\x05index\x18\x03\x20\ - \x01(\x04R\x05index\x12\x12\n\x04data\x18\x04\x20\x01(\x0cR\x04data\x12\ - \x18\n\x07context\x18\x06\x20\x01(\x0cR\x07context\x12\x19\n\x08sync_log\ - \x18\x05\x20\x01(\x08R\x07syncLog\"\x86\x02\n\x10SnapshotMetadata\x121\n\ - \nconf_state\x18\x01\x20\x01(\x0b2\x12.eraftpb.ConfStateR\tconfState\x12\ - N\n\x19pending_membership_change\x18\x04\x20\x01(\x0b2\x12.eraftpb.ConfS\ - tateR\x17pendingMembershipChange\x12E\n\x1fpending_membership_change_ind\ - ex\x18\x05\x20\x01(\x04R\x1cpendingMembershipChangeIndex\x12\x14\n\x05in\ - dex\x18\x02\x20\x01(\x04R\x05index\x12\x12\n\x04term\x18\x03\x20\x01(\ - \x04R\x04term\"U\n\x08Snapshot\x12\x12\n\x04data\x18\x01\x20\x01(\x0cR\ - \x04data\x125\n\x08metadata\x18\x02\x20\x01(\x0b2\x19.eraftpb.SnapshotMe\ - tadataR\x08metadata\"\xe7\x02\n\x07Message\x12/\n\x08msg_type\x18\x01\ - \x20\x01(\x0e2\x14.eraftpb.MessageTypeR\x07msgType\x12\x0e\n\x02to\x18\ - \x02\x20\x01(\x04R\x02to\x12\x12\n\x04from\x18\x03\x20\x01(\x04R\x04from\ - \x12\x12\n\x04term\x18\x04\x20\x01(\x04R\x04term\x12\x19\n\x08log_term\ - \x18\x05\x20\x01(\x04R\x07logTerm\x12\x14\n\x05index\x18\x06\x20\x01(\ - \x04R\x05index\x12(\n\x07entries\x18\x07\x20\x03(\x0b2\x0e.eraftpb.Entry\ - R\x07entries\x12\x16\n\x06commit\x18\x08\x20\x01(\x04R\x06commit\x12-\n\ - \x08snapshot\x18\t\x20\x01(\x0b2\x11.eraftpb.SnapshotR\x08snapshot\x12\ - \x16\n\x06reject\x18\n\x20\x01(\x08R\x06reject\x12\x1f\n\x0breject_hint\ - \x18\x0b\x20\x01(\x04R\nrejectHint\x12\x18\n\x07context\x18\x0c\x20\x01(\ - \x0cR\x07context\"K\n\tHardState\x12\x12\n\x04term\x18\x01\x20\x01(\x04R\ - \x04term\x12\x12\n\x04vote\x18\x02\x20\x01(\x04R\x04vote\x12\x16\n\x06co\ - mmit\x18\x03\x20\x01(\x04R\x06commit\"=\n\tConfState\x12\x14\n\x05nodes\ - \x18\x01\x20\x03(\x04R\x05nodes\x12\x1a\n\x08learners\x18\x02\x20\x03(\ - \x04R\x08learners\"\xe4\x01\n\nConfChange\x12\x0e\n\x02id\x18\x01\x20\ - \x01(\x04R\x02id\x128\n\x0bchange_type\x18\x02\x20\x01(\x0e2\x17.eraftpb\ - .ConfChangeTypeR\nchangeType\x12\x17\n\x07node_id\x18\x03\x20\x01(\x04R\ - \x06nodeId\x12\x18\n\x07context\x18\x04\x20\x01(\x0cR\x07context\x128\n\ - \rconfiguration\x18\x05\x20\x01(\x0b2\x12.eraftpb.ConfStateR\rconfigurat\ - ion\x12\x1f\n\x0bstart_index\x18\x06\x20\x01(\x04R\nstartIndex*1\n\tEntr\ - yType\x12\x0f\n\x0bEntryNormal\x10\0\x12\x13\n\x0fEntryConfChange\x10\ - \x01*\x8c\x03\n\x0bMessageType\x12\n\n\x06MsgHup\x10\0\x12\x0b\n\x07MsgB\ - eat\x10\x01\x12\x0e\n\nMsgPropose\x10\x02\x12\r\n\tMsgAppend\x10\x03\x12\ - \x15\n\x11MsgAppendResponse\x10\x04\x12\x12\n\x0eMsgRequestVote\x10\x05\ - \x12\x1a\n\x16MsgRequestVoteResponse\x10\x06\x12\x0f\n\x0bMsgSnapshot\ - \x10\x07\x12\x10\n\x0cMsgHeartbeat\x10\x08\x12\x18\n\x14MsgHeartbeatResp\ - onse\x10\t\x12\x12\n\x0eMsgUnreachable\x10\n\x12\x11\n\rMsgSnapStatus\ - \x10\x0b\x12\x12\n\x0eMsgCheckQuorum\x10\x0c\x12\x15\n\x11MsgTransferLea\ - der\x10\r\x12\x11\n\rMsgTimeoutNow\x10\x0e\x12\x10\n\x0cMsgReadIndex\x10\ - \x0f\x12\x14\n\x10MsgReadIndexResp\x10\x10\x12\x15\n\x11MsgRequestPreVot\ - e\x10\x11\x12\x1d\n\x19MsgRequestPreVoteResponse\x10\x12*z\n\x0eConfChan\ - geType\x12\x0b\n\x07AddNode\x10\0\x12\x0e\n\nRemoveNode\x10\x01\x12\x12\ - \n\x0eAddLearnerNode\x10\x02\x12\x19\n\x15BeginMembershipChange\x10\x03\ - \x12\x1c\n\x18FinalizeMembershipChange\x10\x04J\x84&\n\x06\x12\x04\0\0o\ - \x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\x08\n\x01\x02\x12\x03\x01\x08\x0f\ - \n\n\n\x02\x05\0\x12\x04\x03\0\x06\x01\n\n\n\x03\x05\0\x01\x12\x03\x03\ - \x05\x0e\n\x0b\n\x04\x05\0\x02\0\x12\x03\x04\x04\x14\n\x0c\n\x05\x05\0\ - \x02\0\x01\x12\x03\x04\x04\x0f\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x04\ - \x12\x13\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x05\x04\x18\n\x0c\n\x05\x05\0\ - \x02\x01\x01\x12\x03\x05\x04\x13\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\ - \x05\x16\x17\n\xdd\x04\n\x02\x04\0\x12\x04\x12\0\x1c\x01\x1a\xd0\x04\x20\ - The\x20entry\x20is\x20a\x20type\x20of\x20change\x20that\x20needs\x20to\ - \x20be\x20applied.\x20It\x20contains\x20two\x20data\x20fields.\n\x20Whil\ - e\x20the\x20fields\x20are\x20built\x20into\x20the\x20model;\x20their\x20\ - usage\x20is\x20determined\x20by\x20the\x20entry_type.\n\n\x20For\x20norm\ - al\x20entries,\x20the\x20data\x20field\x20should\x20contain\x20the\x20da\ - ta\x20change\x20that\x20should\x20be\x20applied.\n\x20The\x20context\x20\ - field\x20can\x20be\x20used\x20for\x20any\x20contextual\x20data\x20that\ - \x20might\x20be\x20relevant\x20to\x20the\n\x20application\x20of\x20the\ - \x20data.\n\n\x20For\x20configuration\x20changes,\x20the\x20data\x20will\ - \x20contain\x20the\x20ConfChange\x20message\x20and\x20the\n\x20context\ - \x20will\x20provide\x20anything\x20needed\x20to\x20assist\x20the\x20conf\ - iguration\x20change.\x20The\x20context\n\x20if\x20for\x20the\x20user\x20\ - to\x20set\x20and\x20use\x20in\x20this\x20case.\n\n\n\n\x03\x04\0\x01\x12\ - \x03\x12\x08\r\n\x0b\n\x04\x04\0\x02\0\x12\x03\x13\x04\x1d\n\r\n\x05\x04\ - \0\x02\0\x04\x12\x04\x13\x04\x12\x0f\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\ - \x13\x04\r\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x13\x0e\x18\n\x0c\n\x05\ - \x04\0\x02\0\x03\x12\x03\x13\x1b\x1c\n\x0b\n\x04\x04\0\x02\x01\x12\x03\ - \x14\x04\x14\n\r\n\x05\x04\0\x02\x01\x04\x12\x04\x14\x04\x13\x1d\n\x0c\n\ - \x05\x04\0\x02\x01\x05\x12\x03\x14\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\ - \x12\x03\x14\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x14\x12\x13\n\ - \x0b\n\x04\x04\0\x02\x02\x12\x03\x15\x04\x15\n\r\n\x05\x04\0\x02\x02\x04\ - \x12\x04\x15\x04\x14\x14\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x15\x04\n\ - \n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x15\x0b\x10\n\x0c\n\x05\x04\0\x02\ - \x02\x03\x12\x03\x15\x13\x14\n\x0b\n\x04\x04\0\x02\x03\x12\x03\x16\x04\ - \x13\n\r\n\x05\x04\0\x02\x03\x04\x12\x04\x16\x04\x15\x15\n\x0c\n\x05\x04\ - \0\x02\x03\x05\x12\x03\x16\x04\t\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\ - \x16\n\x0e\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x16\x11\x12\n\x0b\n\x04\ - \x04\0\x02\x04\x12\x03\x17\x04\x16\n\r\n\x05\x04\0\x02\x04\x04\x12\x04\ - \x17\x04\x16\x13\n\x0c\n\x05\x04\0\x02\x04\x05\x12\x03\x17\x04\t\n\x0c\n\ - \x05\x04\0\x02\x04\x01\x12\x03\x17\n\x11\n\x0c\n\x05\x04\0\x02\x04\x03\ - \x12\x03\x17\x14\x15\nm\n\x04\x04\0\x02\x05\x12\x03\x1b\x04\x16\x1a`\x20\ - Deprecated!\x20It\x20is\x20kept\x20for\x20backward\x20compatibility.\n\ - \x20TODO:\x20remove\x20it\x20in\x20the\x20next\x20major\x20release.\n\n\ - \r\n\x05\x04\0\x02\x05\x04\x12\x04\x1b\x04\x17\x16\n\x0c\n\x05\x04\0\x02\ - \x05\x05\x12\x03\x1b\x04\x08\n\x0c\n\x05\x04\0\x02\x05\x01\x12\x03\x1b\t\ - \x11\n\x0c\n\x05\x04\0\x02\x05\x03\x12\x03\x1b\x14\x15\n\n\n\x02\x04\x01\ - \x12\x04\x1e\0$\x01\n\n\n\x03\x04\x01\x01\x12\x03\x1e\x08\x18\n\x0b\n\ - \x04\x04\x01\x02\0\x12\x03\x1f\x04\x1d\n\r\n\x05\x04\x01\x02\0\x04\x12\ - \x04\x1f\x04\x1e\x1a\n\x0c\n\x05\x04\x01\x02\0\x06\x12\x03\x1f\x04\r\n\ - \x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x1f\x0e\x18\n\x0c\n\x05\x04\x01\x02\ - \0\x03\x12\x03\x1f\x1b\x1c\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x20\x04,\ - \n\r\n\x05\x04\x01\x02\x01\x04\x12\x04\x20\x04\x1f\x1d\n\x0c\n\x05\x04\ - \x01\x02\x01\x06\x12\x03\x20\x04\r\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\ - \x03\x20\x0e'\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x20*+\n\x0b\n\x04\ - \x04\x01\x02\x02\x12\x03!\x04/\n\r\n\x05\x04\x01\x02\x02\x04\x12\x04!\ - \x04\x20,\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03!\x04\n\n\x0c\n\x05\x04\ - \x01\x02\x02\x01\x12\x03!\x0b*\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03!-\ - .\n\x0b\n\x04\x04\x01\x02\x03\x12\x03\"\x04\x15\n\r\n\x05\x04\x01\x02\ - \x03\x04\x12\x04\"\x04!/\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\"\x04\n\ - \n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\"\x0b\x10\n\x0c\n\x05\x04\x01\ - \x02\x03\x03\x12\x03\"\x13\x14\n\x0b\n\x04\x04\x01\x02\x04\x12\x03#\x04\ - \x14\n\r\n\x05\x04\x01\x02\x04\x04\x12\x04#\x04\"\x15\n\x0c\n\x05\x04\ - \x01\x02\x04\x05\x12\x03#\x04\n\n\x0c\n\x05\x04\x01\x02\x04\x01\x12\x03#\ - \x0b\x0f\n\x0c\n\x05\x04\x01\x02\x04\x03\x12\x03#\x12\x13\n\n\n\x02\x04\ - \x02\x12\x04&\0)\x01\n\n\n\x03\x04\x02\x01\x12\x03&\x08\x10\n\x0b\n\x04\ - \x04\x02\x02\0\x12\x03'\x04\x13\n\r\n\x05\x04\x02\x02\0\x04\x12\x04'\x04\ - &\x12\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03'\x04\t\n\x0c\n\x05\x04\x02\ - \x02\0\x01\x12\x03'\n\x0e\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03'\x11\x12\ - \n\x0b\n\x04\x04\x02\x02\x01\x12\x03(\x04\"\n\r\n\x05\x04\x02\x02\x01\ - \x04\x12\x04(\x04'\x13\n\x0c\n\x05\x04\x02\x02\x01\x06\x12\x03(\x04\x14\ - \n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03(\x15\x1d\n\x0c\n\x05\x04\x02\ - \x02\x01\x03\x12\x03(\x20!\n\n\n\x02\x05\x01\x12\x04+\0?\x01\n\n\n\x03\ - \x05\x01\x01\x12\x03+\x05\x10\n\x0b\n\x04\x05\x01\x02\0\x12\x03,\x04\x0f\ - \n\x0c\n\x05\x05\x01\x02\0\x01\x12\x03,\x04\n\n\x0c\n\x05\x05\x01\x02\0\ - \x02\x12\x03,\r\x0e\n\x0b\n\x04\x05\x01\x02\x01\x12\x03-\x04\x10\n\x0c\n\ - \x05\x05\x01\x02\x01\x01\x12\x03-\x04\x0b\n\x0c\n\x05\x05\x01\x02\x01\ - \x02\x12\x03-\x0e\x0f\n\x0b\n\x04\x05\x01\x02\x02\x12\x03.\x04\x13\n\x0c\ - \n\x05\x05\x01\x02\x02\x01\x12\x03.\x04\x0e\n\x0c\n\x05\x05\x01\x02\x02\ - \x02\x12\x03.\x11\x12\n\x0b\n\x04\x05\x01\x02\x03\x12\x03/\x04\x12\n\x0c\ - \n\x05\x05\x01\x02\x03\x01\x12\x03/\x04\r\n\x0c\n\x05\x05\x01\x02\x03\ - \x02\x12\x03/\x10\x11\n\x0b\n\x04\x05\x01\x02\x04\x12\x030\x04\x1a\n\x0c\ - \n\x05\x05\x01\x02\x04\x01\x12\x030\x04\x15\n\x0c\n\x05\x05\x01\x02\x04\ - \x02\x12\x030\x18\x19\n\x0b\n\x04\x05\x01\x02\x05\x12\x031\x04\x17\n\x0c\ - \n\x05\x05\x01\x02\x05\x01\x12\x031\x04\x12\n\x0c\n\x05\x05\x01\x02\x05\ - \x02\x12\x031\x15\x16\n\x0b\n\x04\x05\x01\x02\x06\x12\x032\x04\x1f\n\x0c\ - \n\x05\x05\x01\x02\x06\x01\x12\x032\x04\x1a\n\x0c\n\x05\x05\x01\x02\x06\ - \x02\x12\x032\x1d\x1e\n\x0b\n\x04\x05\x01\x02\x07\x12\x033\x04\x14\n\x0c\ - \n\x05\x05\x01\x02\x07\x01\x12\x033\x04\x0f\n\x0c\n\x05\x05\x01\x02\x07\ - \x02\x12\x033\x12\x13\n\x0b\n\x04\x05\x01\x02\x08\x12\x034\x04\x15\n\x0c\ - \n\x05\x05\x01\x02\x08\x01\x12\x034\x04\x10\n\x0c\n\x05\x05\x01\x02\x08\ - \x02\x12\x034\x13\x14\n\x0b\n\x04\x05\x01\x02\t\x12\x035\x04\x1d\n\x0c\n\ - \x05\x05\x01\x02\t\x01\x12\x035\x04\x18\n\x0c\n\x05\x05\x01\x02\t\x02\ - \x12\x035\x1b\x1c\n\x0b\n\x04\x05\x01\x02\n\x12\x036\x04\x18\n\x0c\n\x05\ - \x05\x01\x02\n\x01\x12\x036\x04\x12\n\x0c\n\x05\x05\x01\x02\n\x02\x12\ - \x036\x15\x17\n\x0b\n\x04\x05\x01\x02\x0b\x12\x037\x04\x17\n\x0c\n\x05\ - \x05\x01\x02\x0b\x01\x12\x037\x04\x11\n\x0c\n\x05\x05\x01\x02\x0b\x02\ - \x12\x037\x14\x16\n\x0b\n\x04\x05\x01\x02\x0c\x12\x038\x04\x18\n\x0c\n\ - \x05\x05\x01\x02\x0c\x01\x12\x038\x04\x12\n\x0c\n\x05\x05\x01\x02\x0c\ - \x02\x12\x038\x15\x17\n\x0b\n\x04\x05\x01\x02\r\x12\x039\x04\x1b\n\x0c\n\ - \x05\x05\x01\x02\r\x01\x12\x039\x04\x15\n\x0c\n\x05\x05\x01\x02\r\x02\ - \x12\x039\x18\x1a\n\x0b\n\x04\x05\x01\x02\x0e\x12\x03:\x04\x17\n\x0c\n\ - \x05\x05\x01\x02\x0e\x01\x12\x03:\x04\x11\n\x0c\n\x05\x05\x01\x02\x0e\ - \x02\x12\x03:\x14\x16\n\x0b\n\x04\x05\x01\x02\x0f\x12\x03;\x04\x16\n\x0c\ - \n\x05\x05\x01\x02\x0f\x01\x12\x03;\x04\x10\n\x0c\n\x05\x05\x01\x02\x0f\ - \x02\x12\x03;\x13\x15\n\x0b\n\x04\x05\x01\x02\x10\x12\x03<\x04\x1a\n\x0c\ - \n\x05\x05\x01\x02\x10\x01\x12\x03<\x04\x14\n\x0c\n\x05\x05\x01\x02\x10\ - \x02\x12\x03<\x17\x19\n\x0b\n\x04\x05\x01\x02\x11\x12\x03=\x04\x1b\n\x0c\ - \n\x05\x05\x01\x02\x11\x01\x12\x03=\x04\x15\n\x0c\n\x05\x05\x01\x02\x11\ - \x02\x12\x03=\x18\x1a\n\x0b\n\x04\x05\x01\x02\x12\x12\x03>\x04#\n\x0c\n\ - \x05\x05\x01\x02\x12\x01\x12\x03>\x04\x1d\n\x0c\n\x05\x05\x01\x02\x12\ - \x02\x12\x03>\x20\"\n\n\n\x02\x04\x03\x12\x04A\0N\x01\n\n\n\x03\x04\x03\ - \x01\x12\x03A\x08\x0f\n\x0b\n\x04\x04\x03\x02\0\x12\x03B\x04\x1d\n\r\n\ - \x05\x04\x03\x02\0\x04\x12\x04B\x04A\x11\n\x0c\n\x05\x04\x03\x02\0\x06\ - \x12\x03B\x04\x0f\n\x0c\n\x05\x04\x03\x02\0\x01\x12\x03B\x10\x18\n\x0c\n\ - \x05\x04\x03\x02\0\x03\x12\x03B\x1b\x1c\n\x0b\n\x04\x04\x03\x02\x01\x12\ - \x03C\x04\x12\n\r\n\x05\x04\x03\x02\x01\x04\x12\x04C\x04B\x1d\n\x0c\n\ - \x05\x04\x03\x02\x01\x05\x12\x03C\x04\n\n\x0c\n\x05\x04\x03\x02\x01\x01\ - \x12\x03C\x0b\r\n\x0c\n\x05\x04\x03\x02\x01\x03\x12\x03C\x10\x11\n\x0b\n\ - \x04\x04\x03\x02\x02\x12\x03D\x04\x14\n\r\n\x05\x04\x03\x02\x02\x04\x12\ - \x04D\x04C\x12\n\x0c\n\x05\x04\x03\x02\x02\x05\x12\x03D\x04\n\n\x0c\n\ - \x05\x04\x03\x02\x02\x01\x12\x03D\x0b\x0f\n\x0c\n\x05\x04\x03\x02\x02\ - \x03\x12\x03D\x12\x13\n\x0b\n\x04\x04\x03\x02\x03\x12\x03E\x04\x14\n\r\n\ - \x05\x04\x03\x02\x03\x04\x12\x04E\x04D\x14\n\x0c\n\x05\x04\x03\x02\x03\ - \x05\x12\x03E\x04\n\n\x0c\n\x05\x04\x03\x02\x03\x01\x12\x03E\x0b\x0f\n\ - \x0c\n\x05\x04\x03\x02\x03\x03\x12\x03E\x12\x13\n\x0b\n\x04\x04\x03\x02\ - \x04\x12\x03F\x04\x18\n\r\n\x05\x04\x03\x02\x04\x04\x12\x04F\x04E\x14\n\ - \x0c\n\x05\x04\x03\x02\x04\x05\x12\x03F\x04\n\n\x0c\n\x05\x04\x03\x02\ - \x04\x01\x12\x03F\x0b\x13\n\x0c\n\x05\x04\x03\x02\x04\x03\x12\x03F\x16\ - \x17\n\x0b\n\x04\x04\x03\x02\x05\x12\x03G\x04\x15\n\r\n\x05\x04\x03\x02\ - \x05\x04\x12\x04G\x04F\x18\n\x0c\n\x05\x04\x03\x02\x05\x05\x12\x03G\x04\ - \n\n\x0c\n\x05\x04\x03\x02\x05\x01\x12\x03G\x0b\x10\n\x0c\n\x05\x04\x03\ - \x02\x05\x03\x12\x03G\x13\x14\n\x0b\n\x04\x04\x03\x02\x06\x12\x03H\x04\ - \x1f\n\x0c\n\x05\x04\x03\x02\x06\x04\x12\x03H\x04\x0c\n\x0c\n\x05\x04\ - \x03\x02\x06\x06\x12\x03H\r\x12\n\x0c\n\x05\x04\x03\x02\x06\x01\x12\x03H\ - \x13\x1a\n\x0c\n\x05\x04\x03\x02\x06\x03\x12\x03H\x1d\x1e\n\x0b\n\x04\ - \x04\x03\x02\x07\x12\x03I\x04\x16\n\r\n\x05\x04\x03\x02\x07\x04\x12\x04I\ - \x04H\x1f\n\x0c\n\x05\x04\x03\x02\x07\x05\x12\x03I\x04\n\n\x0c\n\x05\x04\ - \x03\x02\x07\x01\x12\x03I\x0b\x11\n\x0c\n\x05\x04\x03\x02\x07\x03\x12\ - \x03I\x14\x15\n\x0b\n\x04\x04\x03\x02\x08\x12\x03J\x04\x1a\n\r\n\x05\x04\ - \x03\x02\x08\x04\x12\x04J\x04I\x16\n\x0c\n\x05\x04\x03\x02\x08\x06\x12\ - \x03J\x04\x0c\n\x0c\n\x05\x04\x03\x02\x08\x01\x12\x03J\r\x15\n\x0c\n\x05\ - \x04\x03\x02\x08\x03\x12\x03J\x18\x19\n\x0b\n\x04\x04\x03\x02\t\x12\x03K\ - \x04\x15\n\r\n\x05\x04\x03\x02\t\x04\x12\x04K\x04J\x1a\n\x0c\n\x05\x04\ - \x03\x02\t\x05\x12\x03K\x04\x08\n\x0c\n\x05\x04\x03\x02\t\x01\x12\x03K\t\ - \x0f\n\x0c\n\x05\x04\x03\x02\t\x03\x12\x03K\x12\x14\n\x0b\n\x04\x04\x03\ - \x02\n\x12\x03L\x04\x1c\n\r\n\x05\x04\x03\x02\n\x04\x12\x04L\x04K\x15\n\ - \x0c\n\x05\x04\x03\x02\n\x05\x12\x03L\x04\n\n\x0c\n\x05\x04\x03\x02\n\ - \x01\x12\x03L\x0b\x16\n\x0c\n\x05\x04\x03\x02\n\x03\x12\x03L\x19\x1b\n\ - \x0b\n\x04\x04\x03\x02\x0b\x12\x03M\x04\x17\n\r\n\x05\x04\x03\x02\x0b\ - \x04\x12\x04M\x04L\x1c\n\x0c\n\x05\x04\x03\x02\x0b\x05\x12\x03M\x04\t\n\ - \x0c\n\x05\x04\x03\x02\x0b\x01\x12\x03M\n\x11\n\x0c\n\x05\x04\x03\x02\ - \x0b\x03\x12\x03M\x14\x16\n\n\n\x02\x04\x04\x12\x04P\0T\x01\n\n\n\x03\ - \x04\x04\x01\x12\x03P\x08\x11\n\x0b\n\x04\x04\x04\x02\0\x12\x03Q\x04\x14\ - \n\r\n\x05\x04\x04\x02\0\x04\x12\x04Q\x04P\x13\n\x0c\n\x05\x04\x04\x02\0\ - \x05\x12\x03Q\x04\n\n\x0c\n\x05\x04\x04\x02\0\x01\x12\x03Q\x0b\x0f\n\x0c\ - \n\x05\x04\x04\x02\0\x03\x12\x03Q\x12\x13\n\x0b\n\x04\x04\x04\x02\x01\ - \x12\x03R\x04\x14\n\r\n\x05\x04\x04\x02\x01\x04\x12\x04R\x04Q\x14\n\x0c\ - \n\x05\x04\x04\x02\x01\x05\x12\x03R\x04\n\n\x0c\n\x05\x04\x04\x02\x01\ - \x01\x12\x03R\x0b\x0f\n\x0c\n\x05\x04\x04\x02\x01\x03\x12\x03R\x12\x13\n\ - \x0b\n\x04\x04\x04\x02\x02\x12\x03S\x04\x16\n\r\n\x05\x04\x04\x02\x02\ - \x04\x12\x04S\x04R\x14\n\x0c\n\x05\x04\x04\x02\x02\x05\x12\x03S\x04\n\n\ - \x0c\n\x05\x04\x04\x02\x02\x01\x12\x03S\x0b\x11\n\x0c\n\x05\x04\x04\x02\ - \x02\x03\x12\x03S\x14\x15\n\n\n\x02\x04\x05\x12\x04V\0Y\x01\n\n\n\x03\ - \x04\x05\x01\x12\x03V\x08\x11\n\x0b\n\x04\x04\x05\x02\0\x12\x03W\x04\x1e\ - \n\x0c\n\x05\x04\x05\x02\0\x04\x12\x03W\x04\x0c\n\x0c\n\x05\x04\x05\x02\ - \0\x05\x12\x03W\r\x13\n\x0c\n\x05\x04\x05\x02\0\x01\x12\x03W\x14\x19\n\ - \x0c\n\x05\x04\x05\x02\0\x03\x12\x03W\x1c\x1d\n\x0b\n\x04\x04\x05\x02\ - \x01\x12\x03X\x04!\n\x0c\n\x05\x04\x05\x02\x01\x04\x12\x03X\x04\x0c\n\ - \x0c\n\x05\x04\x05\x02\x01\x05\x12\x03X\r\x13\n\x0c\n\x05\x04\x05\x02\ - \x01\x01\x12\x03X\x14\x1c\n\x0c\n\x05\x04\x05\x02\x01\x03\x12\x03X\x1f\ - \x20\n\n\n\x02\x05\x02\x12\x04[\0a\x01\n\n\n\x03\x05\x02\x01\x12\x03[\ - \x05\x13\n\x0b\n\x04\x05\x02\x02\0\x12\x03\\\x04\x13\n\x0c\n\x05\x05\x02\ - \x02\0\x01\x12\x03\\\x04\x0b\n\x0c\n\x05\x05\x02\x02\0\x02\x12\x03\\\x11\ - \x12\n\x0b\n\x04\x05\x02\x02\x01\x12\x03]\x04\x13\n\x0c\n\x05\x05\x02\ - \x02\x01\x01\x12\x03]\x04\x0e\n\x0c\n\x05\x05\x02\x02\x01\x02\x12\x03]\ - \x11\x12\n\x0b\n\x04\x05\x02\x02\x02\x12\x03^\x04\x17\n\x0c\n\x05\x05\ - \x02\x02\x02\x01\x12\x03^\x04\x12\n\x0c\n\x05\x05\x02\x02\x02\x02\x12\ - \x03^\x15\x16\n\x0b\n\x04\x05\x02\x02\x03\x12\x03_\x04\x1e\n\x0c\n\x05\ - \x05\x02\x02\x03\x01\x12\x03_\x04\x19\n\x0c\n\x05\x05\x02\x02\x03\x02\ - \x12\x03_\x1c\x1d\n\x0b\n\x04\x05\x02\x02\x04\x12\x03`\x04!\n\x0c\n\x05\ - \x05\x02\x02\x04\x01\x12\x03`\x04\x1c\n\x0c\n\x05\x05\x02\x02\x04\x02\ - \x12\x03`\x1f\x20\n\n\n\x02\x04\x06\x12\x04c\0o\x01\n\n\n\x03\x04\x06\ - \x01\x12\x03c\x08\x12\n\x0b\n\x04\x04\x06\x02\0\x12\x03d\x04\x12\n\r\n\ - \x05\x04\x06\x02\0\x04\x12\x04d\x04c\x14\n\x0c\n\x05\x04\x06\x02\0\x05\ - \x12\x03d\x04\n\n\x0c\n\x05\x04\x06\x02\0\x01\x12\x03d\x0b\r\n\x0c\n\x05\ - \x04\x06\x02\0\x03\x12\x03d\x10\x11\n\x0b\n\x04\x04\x06\x02\x01\x12\x03e\ - \x04#\n\r\n\x05\x04\x06\x02\x01\x04\x12\x04e\x04d\x12\n\x0c\n\x05\x04\ - \x06\x02\x01\x06\x12\x03e\x04\x12\n\x0c\n\x05\x04\x06\x02\x01\x01\x12\ - \x03e\x13\x1e\n\x0c\n\x05\x04\x06\x02\x01\x03\x12\x03e!\"\nE\n\x04\x04\ - \x06\x02\x02\x12\x03g\x04\x17\x1a8\x20Used\x20in\x20`AddNode`,\x20`Remov\ - eNode`,\x20and\x20`AddLearnerNode`.\n\n\r\n\x05\x04\x06\x02\x02\x04\x12\ - \x04g\x04e#\n\x0c\n\x05\x04\x06\x02\x02\x05\x12\x03g\x04\n\n\x0c\n\x05\ - \x04\x06\x02\x02\x01\x12\x03g\x0b\x12\n\x0c\n\x05\x04\x06\x02\x02\x03\ - \x12\x03g\x15\x16\n\x0b\n\x04\x04\x06\x02\x03\x12\x03h\x04\x16\n\r\n\x05\ - \x04\x06\x02\x03\x04\x12\x04h\x04g\x17\n\x0c\n\x05\x04\x06\x02\x03\x05\ - \x12\x03h\x04\t\n\x0c\n\x05\x04\x06\x02\x03\x01\x12\x03h\n\x11\n\x0c\n\ - \x05\x04\x06\x02\x03\x03\x12\x03h\x14\x15\nN\n\x04\x04\x06\x02\x04\x12\ - \x03j\x04\x20\x1aA\x20Used\x20in\x20`BeginMembershipChange`\x20and\x20`F\ - inalizeMembershipChange`.\n\n\r\n\x05\x04\x06\x02\x04\x04\x12\x04j\x04h\ - \x16\n\x0c\n\x05\x04\x06\x02\x04\x06\x12\x03j\x04\r\n\x0c\n\x05\x04\x06\ - \x02\x04\x01\x12\x03j\x0e\x1b\n\x0c\n\x05\x04\x06\x02\x04\x03\x12\x03j\ - \x1e\x1f\n\xd0\x01\n\x04\x04\x06\x02\x05\x12\x03n\x04\x1b\x1a\xc2\x01\ - \x20Used\x20in\x20`BeginMembershipChange`\x20and\x20`FinalizeMembershipC\ - hange`.\n\x20Because\x20`RawNode::apply_conf_change`\x20takes\x20a\x20`C\ - onfChange`\x20instead\x20of\x20an\x20`Entry`\x20we\x20must\n\x20include\ - \x20this\x20index\x20so\x20it\x20can\x20be\x20known.\n\n\r\n\x05\x04\x06\ - \x02\x05\x04\x12\x04n\x04j\x20\n\x0c\n\x05\x04\x06\x02\x05\x05\x12\x03n\ - \x04\n\n\x0c\n\x05\x04\x06\x02\x05\x01\x12\x03n\x0b\x16\n\x0c\n\x05\x04\ - \x06\x02\x05\x03\x12\x03n\x19\x1ab\x06proto3\ + \n\reraftpb.proto\x12\x07eraftpb\"\xad\x01\n\x05Entry\x121\n\nentry_type\ + \x18\x01\x20\x01(\x0e2\x12.eraftpb.EntryTypeR\tentryType\x12\x12\n\x04te\ + rm\x18\x02\x20\x01(\x04R\x04term\x12\x14\n\x05index\x18\x03\x20\x01(\x04\ + R\x05index\x12\x12\n\x04data\x18\x04\x20\x01(\x0cR\x04data\x12\x18\n\x07\ + context\x18\x06\x20\x01(\x0cR\x07context\x12\x19\n\x08sync_log\x18\x05\ + \x20\x01(\x08R\x07syncLog\"\x86\x02\n\x10SnapshotMetadata\x121\n\nconf_s\ + tate\x18\x01\x20\x01(\x0b2\x12.eraftpb.ConfStateR\tconfState\x12N\n\x19p\ + ending_membership_change\x18\x04\x20\x01(\x0b2\x12.eraftpb.ConfStateR\ + \x17pendingMembershipChange\x12E\n\x1fpending_membership_change_index\ + \x18\x05\x20\x01(\x04R\x1cpendingMembershipChangeIndex\x12\x14\n\x05inde\ + x\x18\x02\x20\x01(\x04R\x05index\x12\x12\n\x04term\x18\x03\x20\x01(\x04R\ + \x04term\"U\n\x08Snapshot\x12\x12\n\x04data\x18\x01\x20\x01(\x0cR\x04dat\ + a\x125\n\x08metadata\x18\x02\x20\x01(\x0b2\x19.eraftpb.SnapshotMetadataR\ + \x08metadata\"\xe7\x02\n\x07Message\x12/\n\x08msg_type\x18\x01\x20\x01(\ + \x0e2\x14.eraftpb.MessageTypeR\x07msgType\x12\x0e\n\x02to\x18\x02\x20\ + \x01(\x04R\x02to\x12\x12\n\x04from\x18\x03\x20\x01(\x04R\x04from\x12\x12\ + \n\x04term\x18\x04\x20\x01(\x04R\x04term\x12\x19\n\x08log_term\x18\x05\ + \x20\x01(\x04R\x07logTerm\x12\x14\n\x05index\x18\x06\x20\x01(\x04R\x05in\ + dex\x12(\n\x07entries\x18\x07\x20\x03(\x0b2\x0e.eraftpb.EntryR\x07entrie\ + s\x12\x16\n\x06commit\x18\x08\x20\x01(\x04R\x06commit\x12-\n\x08snapshot\ + \x18\t\x20\x01(\x0b2\x11.eraftpb.SnapshotR\x08snapshot\x12\x16\n\x06reje\ + ct\x18\n\x20\x01(\x08R\x06reject\x12\x1f\n\x0breject_hint\x18\x0b\x20\ + \x01(\x04R\nrejectHint\x12\x18\n\x07context\x18\x0c\x20\x01(\x0cR\x07con\ + text\"K\n\tHardState\x12\x12\n\x04term\x18\x01\x20\x01(\x04R\x04term\x12\ + \x12\n\x04vote\x18\x02\x20\x01(\x04R\x04vote\x12\x16\n\x06commit\x18\x03\ + \x20\x01(\x04R\x06commit\"=\n\tConfState\x12\x14\n\x05nodes\x18\x01\x20\ + \x03(\x04R\x05nodes\x12\x1a\n\x08learners\x18\x02\x20\x03(\x04R\x08learn\ + ers\"\xe4\x01\n\nConfChange\x12\x0e\n\x02id\x18\x01\x20\x01(\x04R\x02id\ + \x128\n\x0bchange_type\x18\x02\x20\x01(\x0e2\x17.eraftpb.ConfChangeTypeR\ + \nchangeType\x12\x17\n\x07node_id\x18\x03\x20\x01(\x04R\x06nodeId\x12\ + \x18\n\x07context\x18\x04\x20\x01(\x0cR\x07context\x128\n\rconfiguration\ + \x18\x05\x20\x01(\x0b2\x12.eraftpb.ConfStateR\rconfiguration\x12\x1f\n\ + \x0bstart_index\x18\x06\x20\x01(\x04R\nstartIndex*1\n\tEntryType\x12\x0f\ + \n\x0bEntryNormal\x10\0\x12\x13\n\x0fEntryConfChange\x10\x01*\x8c\x03\n\ + \x0bMessageType\x12\n\n\x06MsgHup\x10\0\x12\x0b\n\x07MsgBeat\x10\x01\x12\ + \x0e\n\nMsgPropose\x10\x02\x12\r\n\tMsgAppend\x10\x03\x12\x15\n\x11MsgAp\ + pendResponse\x10\x04\x12\x12\n\x0eMsgRequestVote\x10\x05\x12\x1a\n\x16Ms\ + gRequestVoteResponse\x10\x06\x12\x0f\n\x0bMsgSnapshot\x10\x07\x12\x10\n\ + \x0cMsgHeartbeat\x10\x08\x12\x18\n\x14MsgHeartbeatResponse\x10\t\x12\x12\ + \n\x0eMsgUnreachable\x10\n\x12\x11\n\rMsgSnapStatus\x10\x0b\x12\x12\n\ + \x0eMsgCheckQuorum\x10\x0c\x12\x15\n\x11MsgTransferLeader\x10\r\x12\x11\ + \n\rMsgTimeoutNow\x10\x0e\x12\x10\n\x0cMsgReadIndex\x10\x0f\x12\x14\n\ + \x10MsgReadIndexResp\x10\x10\x12\x15\n\x11MsgRequestPreVote\x10\x11\x12\ + \x1d\n\x19MsgRequestPreVoteResponse\x10\x12*z\n\x0eConfChangeType\x12\ + \x0b\n\x07AddNode\x10\0\x12\x0e\n\nRemoveNode\x10\x01\x12\x12\n\x0eAddLe\ + arnerNode\x10\x02\x12\x19\n\x15BeginMembershipChange\x10\x03\x12\x1c\n\ + \x18FinalizeMembershipChange\x10\x04b\x06proto3\ "; static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { diff --git a/src/util.rs b/src/util.rs index 43d0452f2..25b62286e 100644 --- a/src/util.rs +++ b/src/util.rs @@ -16,7 +16,7 @@ use std::u64; -use crate::eraftpb::{ConfChange, ConfChangeType, ConfState, Message, Entry}; +use crate::eraftpb::{ConfChange, ConfChangeType, ConfState, Entry, Message}; #[cfg(feature = "lib-prost")] use prost::Message as Msg; #[cfg(feature = "lib-rust-protobuf")] From 76df7aa5cd95285470954c16efe8e4c468b04f4c Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sun, 17 Mar 2019 12:34:17 -0400 Subject: [PATCH 22/40] Refactor, only one error is left now --- Cargo.toml | 8 +- src/errors.rs | 12 +- src/lib.rs | 2 +- src/raft.rs | 18 +- src/raw_node.rs | 11 +- src/rsprost/protobuf_compat.rs | 1 - src/rsprost/wrapper_eraftpb.rs | 807 +++++++++++++++++++++++++++++++++ src/storage.rs | 1 + src/util.rs | 6 +- 9 files changed, 835 insertions(+), 31 deletions(-) create mode 100644 src/rsprost/wrapper_eraftpb.rs diff --git a/Cargo.toml b/Cargo.toml index 2d03ca59c..d6a245548 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,12 +17,12 @@ build = "build.rs" protoc-rust = "~2.0-2.2" protoc-grpcio = "0.3.1" regex = "1.1" -protobuf-build = { git = "https://github.com/nrc/kvproto-build" } +protobuf-build = { path = "../kvproto-build" } [features] default = ["lib-prost"] lib-rust-protobuf = ["protobuf"] -lib-prost = ["prost", "prost-derive", "bytes"] +lib-prost = ["prost", "prost-derive", "bytes", "protobuf"] regenerate = [] # Enable failpoints failpoint = ["fail"] @@ -31,8 +31,8 @@ failpoint = ["fail"] [dependencies] log = ">0.2" protobuf = { version = "~2.0-2.2", optional = true } -prost = { version = "0.4", optional = true } -prost-derive = { version = "0.4", optional = true } +prost = { version = "0.5", optional = true } +prost-derive = { version = "0.5", optional = true } bytes = { version = "0.4.11", optional = true } quick-error = "1.2.2" rand = "0.5.4" diff --git a/src/errors.rs b/src/errors.rs index c7c011522..4ad407340 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -15,10 +15,11 @@ use crate::StateRole; use std::error; use std::{cmp, io, result}; -#[cfg(feature = "lib-prost")] -use prost::DecodeError as PbError; -#[cfg(feature = "lib-rust-protobuf")] -use protobuf::ProtobufError as PbError; +//#[cfg(feature = "lib-prost")] +//use prost::DecodeError as PbError; +//#[cfg(feature = "lib-rust-protobuf")] +//use protobuf::ProtobufError as PbError; +use protobuf::ProtobufError; quick_error! { /// The base error type for raft @@ -53,8 +54,7 @@ quick_error! { description(desc) } /// A Protobuf message failed in some manner. - #[cfg(feature = "lib-rust-protobuf")] - Codec(err: PbError) { + Codec(err: ProtobufError) { from() cause(err) description(err.description()) diff --git a/src/lib.rs b/src/lib.rs index b31ca48e2..a6db80988 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -393,7 +393,7 @@ extern crate log; extern crate bytes; #[cfg(feature = "lib-prost")] extern crate prost; -#[cfg(feature = "lib-rust-protobuf")] +//#[cfg(feature = "lib-rust-protobuf")] extern crate protobuf; #[cfg(feature = "lib-prost")] #[macro_use] diff --git a/src/raft.rs b/src/raft.rs index 8e044dbb7..e063690c4 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -30,13 +30,14 @@ use std::cmp; use crate::eraftpb::{ ConfChange, ConfChangeType, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; -#[cfg(feature = "lib-prost")] -use crate::rsprost::protobuf_compat::*; use hashbrown::{HashMap, HashSet}; -#[cfg(feature = "lib-rust-protobuf")] +//#[cfg(feature = "lib-rust-protobuf")] use protobuf; #[cfg(feature = "lib-rust-protobuf")] use protobuf::RepeatedField; +#[cfg(feature = "lib-prost")] +use crate::rsprost::protobuf_compat::RepeatedField; +use protobuf::Message as _; use rand::{self, Rng}; use super::errors::{Error, Result, StorageError}; @@ -583,7 +584,10 @@ impl Raft { if !util::is_continuous_ents(msg, ents) { return is_batched; } - let mut batched_entries = msg.take_entries().into_vec(); + #[cfg(feature = "lib-rust-protobuf")] + let mut batched_entries = msg.take_entries().into_vec(); + #[cfg(feature = "lib-prost")] + let mut batched_entries = msg.take_entries(); batched_entries.append(ents); msg.set_entries(RepeatedField::from_vec(batched_entries)); let last_idx = msg.get_entries().last().unwrap().get_index(); @@ -720,10 +724,7 @@ impl Raft { fn append_finalize_conf_change_entry(&mut self) { let mut conf_change = ConfChange::new(); conf_change.set_change_type(ConfChangeType::FinalizeMembershipChange); - #[cfg(feature = "lib-rust-protobuf")] let data = protobuf::Message::write_to_bytes(&conf_change).unwrap(); - #[cfg(feature = "lib-prost")] - let data = prost::Message::decode(&conf_change).unwrap(); let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); @@ -2153,10 +2154,7 @@ impl Raft { conf_change.set_change_type(ConfChangeType::BeginMembershipChange); conf_change.set_configuration(config.into()); conf_change.set_start_index(destination_index); - #[cfg(feature = "lib-rust-protobuf")] let data = protobuf::Message::write_to_bytes(&conf_change)?; - #[cfg(feature = "lib-prost")] - let data = prost::Message::decode(&conf_change).unwrap(); let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); diff --git a/src/raw_node.rs b/src/raw_node.rs index 0c6caf581..941920e06 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -36,10 +36,12 @@ use crate::eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; -#[cfg(feature = "lib-prost")] -use crate::rsprost::protobuf_compat::*; + #[cfg(feature = "lib-rust-protobuf")] -use protobuf::{self, RepeatedField}; +use protobuf::RepeatedField; +#[cfg(feature = "lib-prost")] +use crate::rsprost::protobuf_compat::RepeatedField; +use protobuf::Message as _; use super::config::Config; use super::errors::{Error, Result}; @@ -242,11 +244,8 @@ impl RawNode { if let Some(ctx) = peer.context.take() { cc.set_context(ctx); } - #[cfg(feature = "lib-rust-protobuf")] let data = protobuf::Message::write_to_bytes(&cc).expect("unexpected marshal error"); - #[cfg(feature = "lib-prost")] - let data = prost::Message::decode(&cc).unwrap(); let mut e = Entry::new(); e.set_entry_type(EntryType::EntryConfChange); e.set_term(1); diff --git a/src/rsprost/protobuf_compat.rs b/src/rsprost/protobuf_compat.rs index 0dd4b6744..9aef90e1a 100644 --- a/src/rsprost/protobuf_compat.rs +++ b/src/rsprost/protobuf_compat.rs @@ -1,4 +1,3 @@ - pub struct RepeatedField; impl RepeatedField { #[inline] diff --git a/src/rsprost/wrapper_eraftpb.rs b/src/rsprost/wrapper_eraftpb.rs new file mode 100644 index 000000000..cd6192393 --- /dev/null +++ b/src/rsprost/wrapper_eraftpb.rs @@ -0,0 +1,807 @@ +impl Entry { + pub fn new_() -> Entry { + ::std::default::Default::default() + } + pub fn clear_entry_type(&mut self) { + self.entry_type = 0 + } + pub fn set_entry_type_(&mut self, v: EntryType) { + self.entry_type = unsafe { ::std::mem::transmute::(v) }; + } + pub fn get_entry_type(&self) -> EntryType { + unsafe { ::std::mem::transmute::(self.entry_type) } + } + pub fn clear_term(&mut self) { + self.term = 0 + } + pub fn set_term(&mut self, v: u64) { + self.term = v; + } + pub fn get_term(&self) -> u64 { + self.term + } + pub fn clear_index(&mut self) { + self.index = 0 + } + pub fn set_index(&mut self, v: u64) { + self.index = v; + } + pub fn get_index(&self) -> u64 { + self.index + } + pub fn clear_data(&mut self) { + self.data.clear(); + } + pub fn set_data(&mut self, v: std::vec::Vec) { + self.data = v; + } + pub fn get_data(&self) -> &[u8] { + &self.data + } + pub fn mut_data(&mut self) -> &mut std::vec::Vec { + &mut self.data + } + pub fn take_data(&mut self) -> std::vec::Vec { + ::std::mem::replace(&mut self.data, ::std::vec::Vec::new()) + } + pub fn clear_context(&mut self) { + self.context.clear(); + } + pub fn set_context(&mut self, v: std::vec::Vec) { + self.context = v; + } + pub fn get_context(&self) -> &[u8] { + &self.context + } + pub fn mut_context(&mut self) -> &mut std::vec::Vec { + &mut self.context + } + pub fn take_context(&mut self) -> std::vec::Vec { + ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) + } + pub fn clear_sync_log(&mut self) { + self.sync_log = false + } + pub fn set_sync_log(&mut self, v: bool) { + self.sync_log = v; + } + pub fn get_sync_log(&self) -> bool { + self.sync_log + } +} +impl ::protobuf::Clear for Entry { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for Entry { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static Entry { + unimplemented!(); + } + fn is_initialized(&self) -> bool { + unimplemented!(); + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } +} +impl SnapshotMetadata { + pub fn new_() -> SnapshotMetadata { + ::std::default::Default::default() + } + pub fn has_conf_state(&self) -> bool { + self.conf_state.is_some() + } + pub fn clear_conf_state(&mut self) { + self.conf_state = ::std::option::Option::None + } + pub fn set_conf_state(&mut self, v: ConfState) { + self.conf_state = ::std::option::Option::Some(v);; } + pub fn get_conf_state(&self) -> &ConfState { + match self.conf_state.as_ref() { + Some(v) => v, + None => ::default_instance(), + } + } + pub fn mut_conf_state(&mut self) -> &mut ConfState { + if self.conf_state.is_none() { + self.conf_state = ::std::option::Option::Some(ConfState::default()); + } + self.conf_state.as_mut().unwrap() + } + pub fn take_conf_state(&mut self) -> ConfState { + self.conf_state + .take() + .unwrap_or_else(|| ConfState::default()) + } + pub fn has_pending_membership_change(&self) -> bool { + self.pending_membership_change.is_some() + } + pub fn clear_pending_membership_change(&mut self) { + self.pending_membership_change = ::std::option::Option::None + } + pub fn set_pending_membership_change(&mut self, v: ConfState) { + self.pending_membership_change = ::std::option::Option::Some(v);; } + pub fn get_pending_membership_change(&self) -> &ConfState { + match self.pending_membership_change.as_ref() { + Some(v) => v, + None => ::default_instance(), + } + } + pub fn mut_pending_membership_change(&mut self) -> &mut ConfState { + if self.pending_membership_change.is_none() { + self.pending_membership_change = ::std::option::Option::Some(ConfState::default()); + } + self.pending_membership_change.as_mut().unwrap() + } + pub fn take_pending_membership_change(&mut self) -> ConfState { + self.pending_membership_change + .take() + .unwrap_or_else(|| ConfState::default()) + } + pub fn clear_pending_membership_change_index(&mut self) { + self.pending_membership_change_index = 0 + } + pub fn set_pending_membership_change_index(&mut self, v: u64) { + self.pending_membership_change_index = v; + } + pub fn get_pending_membership_change_index(&self) -> u64 { + self.pending_membership_change_index + } + pub fn clear_index(&mut self) { + self.index = 0 + } + pub fn set_index(&mut self, v: u64) { + self.index = v; + } + pub fn get_index(&self) -> u64 { + self.index + } + pub fn clear_term(&mut self) { + self.term = 0 + } + pub fn set_term(&mut self, v: u64) { + self.term = v; + } + pub fn get_term(&self) -> u64 { + self.term + } +} +impl ::protobuf::Clear for SnapshotMetadata { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for SnapshotMetadata { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static SnapshotMetadata { + unimplemented!(); + } + fn is_initialized(&self) -> bool { + unimplemented!(); + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } +} +impl Snapshot { + pub fn new_() -> Snapshot { + ::std::default::Default::default() + } + pub fn clear_data(&mut self) { + self.data.clear(); + } + pub fn set_data(&mut self, v: std::vec::Vec) { + self.data = v; + } + pub fn get_data(&self) -> &[u8] { + &self.data + } + pub fn mut_data(&mut self) -> &mut std::vec::Vec { + &mut self.data + } + pub fn take_data(&mut self) -> std::vec::Vec { + ::std::mem::replace(&mut self.data, ::std::vec::Vec::new()) + } + pub fn has_metadata(&self) -> bool { + self.metadata.is_some() + } + pub fn clear_metadata(&mut self) { + self.metadata = ::std::option::Option::None + } + pub fn set_metadata(&mut self, v: SnapshotMetadata) { + self.metadata = ::std::option::Option::Some(v);; } + pub fn get_metadata(&self) -> &SnapshotMetadata { + match self.metadata.as_ref() { + Some(v) => v, + None => ::default_instance(), + } + } + pub fn mut_metadata(&mut self) -> &mut SnapshotMetadata { + if self.metadata.is_none() { + self.metadata = ::std::option::Option::Some(SnapshotMetadata::default()); + } + self.metadata.as_mut().unwrap() + } + pub fn take_metadata(&mut self) -> SnapshotMetadata { + self.metadata + .take() + .unwrap_or_else(|| SnapshotMetadata::default()) + } +} +impl ::protobuf::Clear for Snapshot { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for Snapshot { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static Snapshot { + unimplemented!(); + } + fn is_initialized(&self) -> bool { + unimplemented!(); + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } +} +impl Message { + pub fn new_() -> Message { + ::std::default::Default::default() + } + pub fn clear_msg_type(&mut self) { + self.msg_type = 0 + } + pub fn set_msg_type_(&mut self, v: MessageType) { + self.msg_type = unsafe { ::std::mem::transmute::(v) }; + } + pub fn get_msg_type(&self) -> MessageType { + unsafe { ::std::mem::transmute::(self.msg_type) } + } + pub fn clear_to(&mut self) { + self.to = 0 + } + pub fn set_to(&mut self, v: u64) { + self.to = v; + } + pub fn get_to(&self) -> u64 { + self.to + } + pub fn clear_from(&mut self) { + self.from = 0 + } + pub fn set_from(&mut self, v: u64) { + self.from = v; + } + pub fn get_from(&self) -> u64 { + self.from + } + pub fn clear_term(&mut self) { + self.term = 0 + } + pub fn set_term(&mut self, v: u64) { + self.term = v; + } + pub fn get_term(&self) -> u64 { + self.term + } + pub fn clear_log_term(&mut self) { + self.log_term = 0 + } + pub fn set_log_term(&mut self, v: u64) { + self.log_term = v; + } + pub fn get_log_term(&self) -> u64 { + self.log_term + } + pub fn clear_index(&mut self) { + self.index = 0 + } + pub fn set_index(&mut self, v: u64) { + self.index = v; + } + pub fn get_index(&self) -> u64 { + self.index + } + pub fn clear_entries(&mut self) { + self.entries.clear(); + } + pub fn set_entries(&mut self, v: ::std::vec::Vec) { + self.entries = v; + } + pub fn get_entries(&self) -> &::std::vec::Vec { + &self.entries + } + pub fn mut_entries(&mut self) -> &mut ::std::vec::Vec { + &mut self.entries + } + pub fn take_entries(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.entries, ::std::vec::Vec::new()) + } + pub fn clear_commit(&mut self) { + self.commit = 0 + } + pub fn set_commit(&mut self, v: u64) { + self.commit = v; + } + pub fn get_commit(&self) -> u64 { + self.commit + } + pub fn has_snapshot(&self) -> bool { + self.snapshot.is_some() + } + pub fn clear_snapshot(&mut self) { + self.snapshot = ::std::option::Option::None + } + pub fn set_snapshot(&mut self, v: Snapshot) { + self.snapshot = ::std::option::Option::Some(v);; } + pub fn get_snapshot(&self) -> &Snapshot { + match self.snapshot.as_ref() { + Some(v) => v, + None => ::default_instance(), + } + } + pub fn mut_snapshot(&mut self) -> &mut Snapshot { + if self.snapshot.is_none() { + self.snapshot = ::std::option::Option::Some(Snapshot::default()); + } + self.snapshot.as_mut().unwrap() + } + pub fn take_snapshot(&mut self) -> Snapshot { + self.snapshot.take().unwrap_or_else(|| Snapshot::default()) + } + pub fn clear_reject(&mut self) { + self.reject = false + } + pub fn set_reject(&mut self, v: bool) { + self.reject = v; + } + pub fn get_reject(&self) -> bool { + self.reject + } + pub fn clear_reject_hint(&mut self) { + self.reject_hint = 0 + } + pub fn set_reject_hint(&mut self, v: u64) { + self.reject_hint = v; + } + pub fn get_reject_hint(&self) -> u64 { + self.reject_hint + } + pub fn clear_context(&mut self) { + self.context.clear(); + } + pub fn set_context(&mut self, v: std::vec::Vec) { + self.context = v; + } + pub fn get_context(&self) -> &[u8] { + &self.context + } + pub fn mut_context(&mut self) -> &mut std::vec::Vec { + &mut self.context + } + pub fn take_context(&mut self) -> std::vec::Vec { + ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) + } +} +impl ::protobuf::Clear for Message { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for Message { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static Message { + unimplemented!(); + } + fn is_initialized(&self) -> bool { + unimplemented!(); + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } +} +impl HardState { + pub fn new_() -> HardState { + ::std::default::Default::default() + } + pub fn clear_term(&mut self) { + self.term = 0 + } + pub fn set_term(&mut self, v: u64) { + self.term = v; + } + pub fn get_term(&self) -> u64 { + self.term + } + pub fn clear_vote(&mut self) { + self.vote = 0 + } + pub fn set_vote(&mut self, v: u64) { + self.vote = v; + } + pub fn get_vote(&self) -> u64 { + self.vote + } + pub fn clear_commit(&mut self) { + self.commit = 0 + } + pub fn set_commit(&mut self, v: u64) { + self.commit = v; + } + pub fn get_commit(&self) -> u64 { + self.commit + } +} +impl ::protobuf::Clear for HardState { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for HardState { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static HardState { + unimplemented!(); + } + fn is_initialized(&self) -> bool { + unimplemented!(); + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } +} +impl ConfState { + pub fn new_() -> ConfState { + ::std::default::Default::default() + } + pub fn clear_nodes(&mut self) { + self.nodes.clear(); + } + pub fn set_nodes(&mut self, v: ::std::vec::Vec) { + self.nodes = v; + } + pub fn get_nodes(&self) -> &::std::vec::Vec { + &self.nodes + } + pub fn mut_nodes(&mut self) -> &mut ::std::vec::Vec { + &mut self.nodes + } + pub fn take_nodes(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.nodes, ::std::vec::Vec::new()) + } + pub fn clear_learners(&mut self) { + self.learners.clear(); + } + pub fn set_learners(&mut self, v: ::std::vec::Vec) { + self.learners = v; + } + pub fn get_learners(&self) -> &::std::vec::Vec { + &self.learners + } + pub fn mut_learners(&mut self) -> &mut ::std::vec::Vec { + &mut self.learners + } + pub fn take_learners(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.learners, ::std::vec::Vec::new()) + } +} +impl ::protobuf::Clear for ConfState { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for ConfState { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static ConfState { + unimplemented!(); + } + fn is_initialized(&self) -> bool { + unimplemented!(); + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } +} +impl ConfChange { + pub fn new_() -> ConfChange { + ::std::default::Default::default() + } + pub fn clear_id(&mut self) { + self.id = 0 + } + pub fn set_id(&mut self, v: u64) { + self.id = v; + } + pub fn get_id(&self) -> u64 { + self.id + } + pub fn clear_change_type(&mut self) { + self.change_type = 0 + } + pub fn set_change_type_(&mut self, v: ConfChangeType) { + self.change_type = unsafe { ::std::mem::transmute::(v) }; + } + pub fn get_change_type(&self) -> ConfChangeType { + unsafe { ::std::mem::transmute::(self.change_type) } + } + pub fn clear_node_id(&mut self) { + self.node_id = 0 + } + pub fn set_node_id(&mut self, v: u64) { + self.node_id = v; + } + pub fn get_node_id(&self) -> u64 { + self.node_id + } + pub fn clear_context(&mut self) { + self.context.clear(); + } + pub fn set_context(&mut self, v: std::vec::Vec) { + self.context = v; + } + pub fn get_context(&self) -> &[u8] { + &self.context + } + pub fn mut_context(&mut self) -> &mut std::vec::Vec { + &mut self.context + } + pub fn take_context(&mut self) -> std::vec::Vec { + ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) + } + pub fn has_configuration(&self) -> bool { + self.configuration.is_some() + } + pub fn clear_configuration(&mut self) { + self.configuration = ::std::option::Option::None + } + pub fn set_configuration(&mut self, v: ConfState) { + self.configuration = ::std::option::Option::Some(v);; } + pub fn get_configuration(&self) -> &ConfState { + match self.configuration.as_ref() { + Some(v) => v, + None => ::default_instance(), + } + } + pub fn mut_configuration(&mut self) -> &mut ConfState { + if self.configuration.is_none() { + self.configuration = ::std::option::Option::Some(ConfState::default()); + } + self.configuration.as_mut().unwrap() + } + pub fn take_configuration(&mut self) -> ConfState { + self.configuration + .take() + .unwrap_or_else(|| ConfState::default()) + } + pub fn clear_start_index(&mut self) { + self.start_index = 0 + } + pub fn set_start_index(&mut self, v: u64) { + self.start_index = v; + } + pub fn get_start_index(&self) -> u64 { + self.start_index + } +} +impl ::protobuf::Clear for ConfChange { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for ConfChange { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static ConfChange { + unimplemented!(); + } + fn is_initialized(&self) -> bool { + unimplemented!(); + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } +} diff --git a/src/storage.rs b/src/storage.rs index 401a03cb5..7c74d5ae3 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -34,6 +34,7 @@ use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::eraftpb::{ConfChange, ConfState, Entry, HardState, Snapshot}; +use protobuf::Message as _; use crate::errors::{Error, Result, StorageError}; use crate::util; diff --git a/src/util.rs b/src/util.rs index 25b62286e..ccbca224e 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,9 +17,9 @@ use std::u64; use crate::eraftpb::{ConfChange, ConfChangeType, ConfState, Entry, Message}; -#[cfg(feature = "lib-prost")] -use prost::Message as Msg; -#[cfg(feature = "lib-rust-protobuf")] +//#[cfg(feature = "lib-prost")] +//use prost::Message as Msg; +//#[cfg(feature = "lib-rust-protobuf")] use protobuf::Message as Msg; /// A number to represent that there is no limit. From 11fd985f33779b644e6409dc3055e2f7304944ef Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sun, 17 Mar 2019 18:48:44 -0400 Subject: [PATCH 23/40] Fix all errors occurred in `src`, start working on `tests` --- build.rs | 8 ++++++-- src/lib.rs | 3 ++- src/log_unstable.rs | 1 + src/raft.rs | 12 ++++++------ src/raft_log.rs | 4 +--- src/raw_node.rs | 5 ++--- src/rsprost.rs | 3 +++ src/storage.rs | 3 +-- tests/integration_cases/test_membership_changes.rs | 8 +++++++- tests/integration_cases/test_raft.rs | 7 ++++++- tests/integration_cases/test_raft_paper.rs | 5 +++++ 11 files changed, 40 insertions(+), 19 deletions(-) diff --git a/build.rs b/build.rs index 2ec6c67f1..2972068c3 100644 --- a/build.rs +++ b/build.rs @@ -12,9 +12,10 @@ // limitations under the License. use protobuf_build::*; -use std::fs::{read_dir, File}; +use std::fs::{read_dir, remove_file, File}; use std::io::Write; +#[allow(unused_must_use)] fn main() { // This build script creates files in the `src` directory. Since that is // outside Cargo's OUT_DIR it will cause an error when this crate is used @@ -43,6 +44,9 @@ fn main() { println!("cargo:rerun-if-changed={}", f); } + // Delete the previously-generated wrapper, we're ok if the file does not exist + remove_file("rsprost/protobuf_compat.rs"); + // Generate Prost files. generate_prost_files(&file_names, "src/rsprost"); let mod_names = module_names_for_dir("src/rsprost"); @@ -100,7 +104,7 @@ fn generate_protobuf_rs(mod_names: &[String]) { } fn generate_prost_rs(mod_names: &[String]) { - let mut text = "#![allow(dead_code)]\n\n".to_owned(); + let mut text = "#![allow(dead_code)]\n#![allow(missing_docs)]\n\n".to_owned(); for mod_name in mod_names { text.push_str("pub mod "); diff --git a/src/lib.rs b/src/lib.rs index a6db80988..871b1ef3d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -410,6 +410,8 @@ mod rsprost; mod rsprotobuf; #[cfg(feature = "lib-prost")] pub use crate::rsprost::eraftpb; +#[cfg(feature = "lib-prost")] +pub use crate::rsprost::protobuf_compat; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. #[cfg(feature = "lib-rust-protobuf")] @@ -452,7 +454,6 @@ pub mod prelude { //! //! The prelude may grow over time as additional items see ubiquitous use. - #[cfg(feature = "lib-rust-protobuf")] pub use crate::eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message, MessageType, Snapshot, SnapshotMetadata, diff --git a/src/log_unstable.rs b/src/log_unstable.rs index 5304fd4f9..9570f93e1 100644 --- a/src/log_unstable.rs +++ b/src/log_unstable.rs @@ -186,6 +186,7 @@ mod test { use crate::eraftpb::{Entry, Snapshot, SnapshotMetadata}; use crate::log_unstable::Unstable; use harness::setup_for_test; + use protobuf::Message as _; fn new_entry(index: u64, term: u64) -> Entry { let mut e = Entry::new(); diff --git a/src/raft.rs b/src/raft.rs index e063690c4..cafedaa1e 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -32,12 +32,12 @@ use crate::eraftpb::{ }; use hashbrown::{HashMap, HashSet}; //#[cfg(feature = "lib-rust-protobuf")] -use protobuf; -#[cfg(feature = "lib-rust-protobuf")] -use protobuf::RepeatedField; #[cfg(feature = "lib-prost")] use crate::rsprost::protobuf_compat::RepeatedField; +use protobuf; use protobuf::Message as _; +#[cfg(feature = "lib-rust-protobuf")] +use protobuf::RepeatedField; use rand::{self, Rng}; use super::errors::{Error, Result, StorageError}; @@ -585,9 +585,9 @@ impl Raft { return is_batched; } #[cfg(feature = "lib-rust-protobuf")] - let mut batched_entries = msg.take_entries().into_vec(); + let mut batched_entries = msg.take_entries().into_vec(); #[cfg(feature = "lib-prost")] - let mut batched_entries = msg.take_entries(); + let mut batched_entries = msg.take_entries(); batched_entries.append(ents); msg.set_entries(RepeatedField::from_vec(batched_entries)); let last_idx = msg.get_entries().last().unwrap().get_index(); @@ -1189,7 +1189,7 @@ impl Raft { // ...we haven't voted and we don't think there's a leader yet in this term... (self.vote == INVALID_ID && self.leader_id == INVALID_ID) || // ...or this is a PreVote for a future term... - (m.msg_type == MessageType::MsgRequestPreVote && m.get_term() > self.term); + (m.msg_type == MessageType::MsgRequestPreVote as i32 && m.get_term() > self.term); // ...and we believe the candidate is up to date. if can_vote && self.raft_log.is_up_to_date(m.get_index(), m.get_log_term()) { // When responding to Msg{Pre,}Vote messages we include the term diff --git a/src/raft_log.rs b/src/raft_log.rs index ad557b286..d2f9ffecc 100644 --- a/src/raft_log.rs +++ b/src/raft_log.rs @@ -507,8 +507,8 @@ mod test { use crate::raft_log::{self, RaftLog}; use crate::storage::MemStorage; use harness::setup_for_test; - #[cfg(feature = "lib-rust-protobuf")] use protobuf; + use protobuf::Message as _; fn new_raft_log(s: MemStorage) -> RaftLog { RaftLog::new(s, String::from("")) @@ -973,8 +973,6 @@ mod test { let (last, half) = (offset + num, offset + num / 2); let halfe = new_entry(half, half); - // TODO: consider refactoring because prost can't "compute_size" - #[cfg(feature = "lib-rust-protobuf")] let halfe_size = u64::from(protobuf::Message::compute_size(&halfe)); let store = MemStorage::new(); diff --git a/src/raw_node.rs b/src/raw_node.rs index 941920e06..6b6bbff67 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -37,11 +37,11 @@ use crate::eraftpb::{ Snapshot, }; -#[cfg(feature = "lib-rust-protobuf")] -use protobuf::RepeatedField; #[cfg(feature = "lib-prost")] use crate::rsprost::protobuf_compat::RepeatedField; use protobuf::Message as _; +#[cfg(feature = "lib-rust-protobuf")] +use protobuf::RepeatedField; use super::config::Config; use super::errors::{Error, Result}; @@ -324,7 +324,6 @@ impl RawNode { /// ProposeConfChange proposes a config change. #[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))] - #[cfg(feature = "lib-rust-protobuf")] pub fn propose_conf_change(&mut self, context: Vec, cc: ConfChange) -> Result<()> { let data = protobuf::Message::write_to_bytes(&cc)?; let mut m = Message::new(); diff --git a/src/rsprost.rs b/src/rsprost.rs index 6132d0187..d07a991c8 100644 --- a/src/rsprost.rs +++ b/src/rsprost.rs @@ -1,8 +1,11 @@ #![allow(dead_code)] +#![allow(missing_docs)] +/// Protobuf structs. pub mod eraftpb { include!("rsprost/eraftpb.rs"); include!("rsprost/wrapper_eraftpb.rs"); } +/// `RepeatedField` wrapper. pub mod protobuf_compat; diff --git a/src/storage.rs b/src/storage.rs index 7c74d5ae3..664827e3f 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -381,8 +381,8 @@ mod test { use crate::errors::{Error as RaftError, StorageError}; use crate::storage::{MemStorage, Storage}; use harness::setup_for_test; - #[cfg(feature = "lib-rust-protobuf")] use protobuf; + use protobuf::Message as _; // TODO extract these duplicated utility functions for tests @@ -393,7 +393,6 @@ mod test { e } - #[cfg(feature = "lib-rust-protobuf")] fn size_of(m: &T) -> u32 { m.compute_size() } diff --git a/tests/integration_cases/test_membership_changes.rs b/tests/integration_cases/test_membership_changes.rs index d83f66e76..0b80b7521 100644 --- a/tests/integration_cases/test_membership_changes.rs +++ b/tests/integration_cases/test_membership_changes.rs @@ -15,7 +15,13 @@ use crate::test_util::new_message; use harness::{setup_for_test, Network}; use hashbrown::{HashMap, HashSet}; -use protobuf::{self, RepeatedField}; + +use protobuf; +use protobuf::Message as _; +#[cfg(feature = "lib-rust-protobuf")] +use protobuf::RepeatedField; +#[cfg(feature = "lib-prost")] +use raft::protobuf_compat::RepeatedField; use raft::{ eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, Message, MessageType, Snapshot, diff --git a/tests/integration_cases/test_raft.rs b/tests/integration_cases/test_raft.rs index 48b3582cf..91da6123c 100644 --- a/tests/integration_cases/test_raft.rs +++ b/tests/integration_cases/test_raft.rs @@ -33,10 +33,15 @@ use std::panic::{self, AssertUnwindSafe}; use crate::test_util::*; use harness::*; use hashbrown::HashSet; -use protobuf::{self, RepeatedField}; +use protobuf; +use protobuf::Message as _; +#[cfg(feature = "lib-rust-protobuf")] +use protobuf::RepeatedField; use raft::eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message, MessageType, }; +#[cfg(feature = "lib-prost")] +use raft::protobuf_compat::RepeatedField; use raft::storage::MemStorage; use raft::*; diff --git a/tests/integration_cases/test_raft_paper.rs b/tests/integration_cases/test_raft_paper.rs index ea0340a49..9d80a38ef 100644 --- a/tests/integration_cases/test_raft_paper.rs +++ b/tests/integration_cases/test_raft_paper.rs @@ -27,8 +27,13 @@ use crate::test_util::*; use harness::*; +use protobuf; +use protobuf::Message as _; +#[cfg(feature = "lib-rust-protobuf")] use protobuf::RepeatedField; use raft::eraftpb::*; +#[cfg(feature = "lib-prost")] +use raft::protobuf_compat::RepeatedField; use raft::storage::MemStorage; use raft::*; From 51ad68a19715008ce16c00441ba203cab57faba5 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sun, 24 Mar 2019 07:25:59 -0400 Subject: [PATCH 24/40] Test compiles, remove rust-protobuf support --- Cargo.toml | 12 +- build.rs | 43 - src/lib.rs | 33 +- src/raft.rs | 7 - src/raw_node.rs | 3 - src/rsprost.rs | 5 +- src/rsprost/protobuf_compat.rs | 15 +- src/rsprotobuf/eraftpb.rs | 2580 ----------------- src/util.rs | 3 - .../test_membership_changes.rs | 3 - tests/integration_cases/test_raft.rs | 3 - tests/integration_cases/test_raft_paper.rs | 3 - tests/integration_cases/test_raw_node.rs | 13 +- tests/test_util/mod.rs | 3 +- 14 files changed, 25 insertions(+), 2701 deletions(-) delete mode 100644 src/rsprotobuf/eraftpb.rs diff --git a/Cargo.toml b/Cargo.toml index d6a245548..c5fcf1de0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,7 @@ regex = "1.1" protobuf-build = { path = "../kvproto-build" } [features] -default = ["lib-prost"] -lib-rust-protobuf = ["protobuf"] -lib-prost = ["prost", "prost-derive", "bytes", "protobuf"] +default = [] regenerate = [] # Enable failpoints failpoint = ["fail"] @@ -30,10 +28,10 @@ failpoint = ["fail"] # Make sure to synchronize updates with Harness. [dependencies] log = ">0.2" -protobuf = { version = "~2.0-2.2", optional = true } -prost = { version = "0.5", optional = true } -prost-derive = { version = "0.5", optional = true } -bytes = { version = "0.4.11", optional = true } +protobuf = "~2.0-2.2" +prost = "0.5" +prost-derive = "0.5" +bytes = "0.4.11" quick-error = "1.2.2" rand = "0.5.4" hashbrown = "0.1" diff --git a/build.rs b/build.rs index 2972068c3..b17cd664f 100644 --- a/build.rs +++ b/build.rs @@ -58,49 +58,6 @@ fn main() { "src/rsprost", ); generate_prost_rs(&mod_names); - - // Generate rust-protobuf files. - let file_names: Vec<_> = file_names.iter().map(|s| &**s).collect(); - generate_protobuf_files(file_names, "src/rsprotobuf"); - - let mod_names = module_names_for_dir("src/rsprotobuf"); - - let out_file_names: Vec<_> = mod_names - .iter() - .map(|m| format!("src/rsprotobuf/{}.rs", m)) - .collect(); - let out_file_names: Vec<_> = out_file_names.iter().map(|f| &**f).collect(); - replace_read_unknown_fields(&out_file_names); - generate_protobuf_rs(&mod_names); -} - -fn generate_protobuf_files(file_names: Vec<&str>, out_dir: &str) { - protoc_rust::run(protoc_rust::Args { - out_dir, - input: &file_names, - includes: &["proto", "include"], - customize: protoc_rust::Customize { - ..Default::default() - }, - }) - .unwrap(); - - protoc_grpcio::compile_grpc_protos(file_names, &["proto", "include"], "src/rsprotobuf") - .unwrap(); -} - -fn generate_protobuf_rs(mod_names: &[String]) { - let mut text = "pub use raft::eraftpb;\n\n".to_owned(); - - for mod_name in mod_names { - text.push_str("pub mod "); - text.push_str(mod_name); - text.push_str(";\n"); - } - - let mut lib = File::create("src/rsprotobuf.rs").expect("Could not create rsprotobuf.rs"); - lib.write_all(text.as_bytes()) - .expect("Could not write rsprotobuf.rs"); } fn generate_prost_rs(mod_names: &[String]) { diff --git a/src/lib.rs b/src/lib.rs index 871b1ef3d..a8be11da6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -361,23 +361,6 @@ This process is a two-phase process, during the midst of it the peer group's lea active), it is very important to wait until the entire peer group has exited the transition phase before taking old, removed peers offline. -## Protocal-buffer libraries support - -We're storing Message with protocal-buffer, while there're multiple Rust protocal-buffer -libraries. We support two protocal-buffer libraries via features. You need to choose -exactly one from prost and rust-protobuf (default). - -### rust-protobuf - -This is enabled by default and can be explicitly enabled via `lib-rust-protobuf` feature. -The generated protobuf struct, `eraftpb::Message`, will be included in the project if -`lib-rust-protobuf` is enabled. This means you don't need to install `protoc` to compile -the `.proto` files. If you really want to do a regeneration, enable `regenerate` feature. - -### prost - -It's a work-in-progress. - */ #![deny(clippy::all)] @@ -389,14 +372,9 @@ extern crate fail; #[macro_use] extern crate log; -#[cfg(feature = "lib-prost")] extern crate bytes; -#[cfg(feature = "lib-prost")] extern crate prost; -//#[cfg(feature = "lib-rust-protobuf")] extern crate protobuf; -#[cfg(feature = "lib-prost")] -#[macro_use] extern crate prost_derive; #[macro_use] extern crate quick_error; @@ -404,18 +382,11 @@ extern crate quick_error; extern crate getset; mod config; -#[cfg(feature = "lib-prost")] mod rsprost; -#[cfg(feature = "lib-rust-protobuf")] -mod rsprotobuf; -#[cfg(feature = "lib-prost")] -pub use crate::rsprost::eraftpb; -#[cfg(feature = "lib-prost")] -pub use crate::rsprost::protobuf_compat; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. -#[cfg(feature = "lib-rust-protobuf")] -pub use crate::rsprotobuf::eraftpb; +pub use crate::rsprost::eraftpb; +pub use crate::rsprost::protobuf_compat; mod errors; mod log_unstable; mod progress; diff --git a/src/raft.rs b/src/raft.rs index cafedaa1e..f98a5c58d 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -31,13 +31,9 @@ use crate::eraftpb::{ ConfChange, ConfChangeType, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; use hashbrown::{HashMap, HashSet}; -//#[cfg(feature = "lib-rust-protobuf")] -#[cfg(feature = "lib-prost")] use crate::rsprost::protobuf_compat::RepeatedField; use protobuf; use protobuf::Message as _; -#[cfg(feature = "lib-rust-protobuf")] -use protobuf::RepeatedField; use rand::{self, Rng}; use super::errors::{Error, Result, StorageError}; @@ -584,9 +580,6 @@ impl Raft { if !util::is_continuous_ents(msg, ents) { return is_batched; } - #[cfg(feature = "lib-rust-protobuf")] - let mut batched_entries = msg.take_entries().into_vec(); - #[cfg(feature = "lib-prost")] let mut batched_entries = msg.take_entries(); batched_entries.append(ents); msg.set_entries(RepeatedField::from_vec(batched_entries)); diff --git a/src/raw_node.rs b/src/raw_node.rs index 6b6bbff67..dabcebfde 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -37,11 +37,8 @@ use crate::eraftpb::{ Snapshot, }; -#[cfg(feature = "lib-prost")] use crate::rsprost::protobuf_compat::RepeatedField; use protobuf::Message as _; -#[cfg(feature = "lib-rust-protobuf")] -use protobuf::RepeatedField; use super::config::Config; use super::errors::{Error, Result}; diff --git a/src/rsprost.rs b/src/rsprost.rs index d07a991c8..82bea3342 100644 --- a/src/rsprost.rs +++ b/src/rsprost.rs @@ -1,11 +1,8 @@ #![allow(dead_code)] #![allow(missing_docs)] -/// Protobuf structs. pub mod eraftpb { - include!("rsprost/eraftpb.rs"); - include!("rsprost/wrapper_eraftpb.rs"); + include!("rsprost/eraftpb.rs");include!("rsprost/wrapper_eraftpb.rs"); } -/// `RepeatedField` wrapper. pub mod protobuf_compat; diff --git a/src/rsprost/protobuf_compat.rs b/src/rsprost/protobuf_compat.rs index 9aef90e1a..56992a47d 100644 --- a/src/rsprost/protobuf_compat.rs +++ b/src/rsprost/protobuf_compat.rs @@ -1,7 +1,8 @@ -pub struct RepeatedField; -impl RepeatedField { - #[inline] - pub fn from_vec(v: Vec) -> Vec { - v - } -} + + pub struct RepeatedField; + impl RepeatedField { + #[inline] + pub fn from_vec(v: Vec) -> Vec { + v + } + } \ No newline at end of file diff --git a/src/rsprotobuf/eraftpb.rs b/src/rsprotobuf/eraftpb.rs deleted file mode 100644 index 29044d6e2..000000000 --- a/src/rsprotobuf/eraftpb.rs +++ /dev/null @@ -1,2580 +0,0 @@ -// This file is generated by rust-protobuf 2.0.6. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -#[derive(PartialEq,Clone,Default)] -pub struct Entry { - // message fields - pub entry_type: EntryType, - pub term: u64, - pub index: u64, - pub data: ::std::vec::Vec, - pub context: ::std::vec::Vec, - pub sync_log: bool, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -impl Entry { - pub fn new() -> Entry { - ::std::default::Default::default() - } - - // .eraftpb.EntryType entry_type = 1; - - pub fn clear_entry_type(&mut self) { - self.entry_type = EntryType::EntryNormal; - } - - // Param is passed by value, moved - pub fn set_entry_type(&mut self, v: EntryType) { - self.entry_type = v; - } - - pub fn get_entry_type(&self) -> EntryType { - self.entry_type - } - - // uint64 term = 2; - - pub fn clear_term(&mut self) { - self.term = 0; - } - - // Param is passed by value, moved - pub fn set_term(&mut self, v: u64) { - self.term = v; - } - - pub fn get_term(&self) -> u64 { - self.term - } - - // uint64 index = 3; - - pub fn clear_index(&mut self) { - self.index = 0; - } - - // Param is passed by value, moved - pub fn set_index(&mut self, v: u64) { - self.index = v; - } - - pub fn get_index(&self) -> u64 { - self.index - } - - // bytes data = 4; - - pub fn clear_data(&mut self) { - self.data.clear(); - } - - // Param is passed by value, moved - pub fn set_data(&mut self, v: ::std::vec::Vec) { - self.data = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_data(&mut self) -> &mut ::std::vec::Vec { - &mut self.data - } - - // Take field - pub fn take_data(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.data, ::std::vec::Vec::new()) - } - - pub fn get_data(&self) -> &[u8] { - &self.data - } - - // bytes context = 6; - - pub fn clear_context(&mut self) { - self.context.clear(); - } - - // Param is passed by value, moved - pub fn set_context(&mut self, v: ::std::vec::Vec) { - self.context = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_context(&mut self) -> &mut ::std::vec::Vec { - &mut self.context - } - - // Take field - pub fn take_context(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) - } - - pub fn get_context(&self) -> &[u8] { - &self.context - } - - // bool sync_log = 5; - - pub fn clear_sync_log(&mut self) { - self.sync_log = false; - } - - // Param is passed by value, moved - pub fn set_sync_log(&mut self, v: bool) { - self.sync_log = v; - } - - pub fn get_sync_log(&self) -> bool { - self.sync_log - } -} - -impl ::protobuf::Message for Entry { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type == ::protobuf::wire_format::WireTypeVarint {self.entry_type = is.read_enum()?;} else {return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));} - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.term = tmp; - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.index = tmp; - }, - 4 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.data)?; - }, - 6 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.context)?; - }, - 5 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_bool()?; - self.sync_log = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.entry_type != EntryType::EntryNormal { - my_size += ::protobuf::rt::enum_size(1, self.entry_type); - } - if self.term != 0 { - my_size += ::protobuf::rt::value_size(2, self.term, ::protobuf::wire_format::WireTypeVarint); - } - if self.index != 0 { - my_size += ::protobuf::rt::value_size(3, self.index, ::protobuf::wire_format::WireTypeVarint); - } - if !self.data.is_empty() { - my_size += ::protobuf::rt::bytes_size(4, &self.data); - } - if !self.context.is_empty() { - my_size += ::protobuf::rt::bytes_size(6, &self.context); - } - if self.sync_log != false { - my_size += 2; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - if self.entry_type != EntryType::EntryNormal { - os.write_enum(1, self.entry_type.value())?; - } - if self.term != 0 { - os.write_uint64(2, self.term)?; - } - if self.index != 0 { - os.write_uint64(3, self.index)?; - } - if !self.data.is_empty() { - os.write_bytes(4, &self.data)?; - } - if !self.context.is_empty() { - os.write_bytes(6, &self.context)?; - } - if self.sync_log != false { - os.write_bool(5, self.sync_log)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Entry { - Entry::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( - "entry_type", - |m: &Entry| { &m.entry_type }, - |m: &mut Entry| { &mut m.entry_type }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "term", - |m: &Entry| { &m.term }, - |m: &mut Entry| { &mut m.term }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "index", - |m: &Entry| { &m.index }, - |m: &mut Entry| { &mut m.index }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "data", - |m: &Entry| { &m.data }, - |m: &mut Entry| { &mut m.data }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "context", - |m: &Entry| { &m.context }, - |m: &mut Entry| { &mut m.context }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "sync_log", - |m: &Entry| { &m.sync_log }, - |m: &mut Entry| { &mut m.sync_log }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Entry", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static Entry { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Entry, - }; - unsafe { - instance.get(Entry::new) - } - } -} - -impl ::protobuf::Clear for Entry { - fn clear(&mut self) { - self.clear_entry_type(); - self.clear_term(); - self.clear_index(); - self.clear_data(); - self.clear_context(); - self.clear_sync_log(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Entry { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Entry { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct SnapshotMetadata { - // message fields - pub conf_state: ::protobuf::SingularPtrField, - pub pending_membership_change: ::protobuf::SingularPtrField, - pub pending_membership_change_index: u64, - pub index: u64, - pub term: u64, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -impl SnapshotMetadata { - pub fn new() -> SnapshotMetadata { - ::std::default::Default::default() - } - - // .eraftpb.ConfState conf_state = 1; - - pub fn clear_conf_state(&mut self) { - self.conf_state.clear(); - } - - pub fn has_conf_state(&self) -> bool { - self.conf_state.is_some() - } - - // Param is passed by value, moved - pub fn set_conf_state(&mut self, v: ConfState) { - self.conf_state = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_conf_state(&mut self) -> &mut ConfState { - if self.conf_state.is_none() { - self.conf_state.set_default(); - } - self.conf_state.as_mut().unwrap() - } - - // Take field - pub fn take_conf_state(&mut self) -> ConfState { - self.conf_state.take().unwrap_or_else(|| ConfState::new()) - } - - pub fn get_conf_state(&self) -> &ConfState { - self.conf_state.as_ref().unwrap_or_else(|| ConfState::default_instance()) - } - - // .eraftpb.ConfState pending_membership_change = 4; - - pub fn clear_pending_membership_change(&mut self) { - self.pending_membership_change.clear(); - } - - pub fn has_pending_membership_change(&self) -> bool { - self.pending_membership_change.is_some() - } - - // Param is passed by value, moved - pub fn set_pending_membership_change(&mut self, v: ConfState) { - self.pending_membership_change = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_pending_membership_change(&mut self) -> &mut ConfState { - if self.pending_membership_change.is_none() { - self.pending_membership_change.set_default(); - } - self.pending_membership_change.as_mut().unwrap() - } - - // Take field - pub fn take_pending_membership_change(&mut self) -> ConfState { - self.pending_membership_change.take().unwrap_or_else(|| ConfState::new()) - } - - pub fn get_pending_membership_change(&self) -> &ConfState { - self.pending_membership_change.as_ref().unwrap_or_else(|| ConfState::default_instance()) - } - - // uint64 pending_membership_change_index = 5; - - pub fn clear_pending_membership_change_index(&mut self) { - self.pending_membership_change_index = 0; - } - - // Param is passed by value, moved - pub fn set_pending_membership_change_index(&mut self, v: u64) { - self.pending_membership_change_index = v; - } - - pub fn get_pending_membership_change_index(&self) -> u64 { - self.pending_membership_change_index - } - - // uint64 index = 2; - - pub fn clear_index(&mut self) { - self.index = 0; - } - - // Param is passed by value, moved - pub fn set_index(&mut self, v: u64) { - self.index = v; - } - - pub fn get_index(&self) -> u64 { - self.index - } - - // uint64 term = 3; - - pub fn clear_term(&mut self) { - self.term = 0; - } - - // Param is passed by value, moved - pub fn set_term(&mut self, v: u64) { - self.term = v; - } - - pub fn get_term(&self) -> u64 { - self.term - } -} - -impl ::protobuf::Message for SnapshotMetadata { - fn is_initialized(&self) -> bool { - for v in &self.conf_state { - if !v.is_initialized() { - return false; - } - }; - for v in &self.pending_membership_change { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.conf_state)?; - }, - 4 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.pending_membership_change)?; - }, - 5 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.pending_membership_change_index = tmp; - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.index = tmp; - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.term = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(ref v) = self.conf_state.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if let Some(ref v) = self.pending_membership_change.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if self.pending_membership_change_index != 0 { - my_size += ::protobuf::rt::value_size(5, self.pending_membership_change_index, ::protobuf::wire_format::WireTypeVarint); - } - if self.index != 0 { - my_size += ::protobuf::rt::value_size(2, self.index, ::protobuf::wire_format::WireTypeVarint); - } - if self.term != 0 { - my_size += ::protobuf::rt::value_size(3, self.term, ::protobuf::wire_format::WireTypeVarint); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - if let Some(ref v) = self.conf_state.as_ref() { - os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if let Some(ref v) = self.pending_membership_change.as_ref() { - os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if self.pending_membership_change_index != 0 { - os.write_uint64(5, self.pending_membership_change_index)?; - } - if self.index != 0 { - os.write_uint64(2, self.index)?; - } - if self.term != 0 { - os.write_uint64(3, self.term)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> SnapshotMetadata { - SnapshotMetadata::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "conf_state", - |m: &SnapshotMetadata| { &m.conf_state }, - |m: &mut SnapshotMetadata| { &mut m.conf_state }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "pending_membership_change", - |m: &SnapshotMetadata| { &m.pending_membership_change }, - |m: &mut SnapshotMetadata| { &mut m.pending_membership_change }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "pending_membership_change_index", - |m: &SnapshotMetadata| { &m.pending_membership_change_index }, - |m: &mut SnapshotMetadata| { &mut m.pending_membership_change_index }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "index", - |m: &SnapshotMetadata| { &m.index }, - |m: &mut SnapshotMetadata| { &mut m.index }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "term", - |m: &SnapshotMetadata| { &m.term }, - |m: &mut SnapshotMetadata| { &mut m.term }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "SnapshotMetadata", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static SnapshotMetadata { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const SnapshotMetadata, - }; - unsafe { - instance.get(SnapshotMetadata::new) - } - } -} - -impl ::protobuf::Clear for SnapshotMetadata { - fn clear(&mut self) { - self.clear_conf_state(); - self.clear_pending_membership_change(); - self.clear_pending_membership_change_index(); - self.clear_index(); - self.clear_term(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for SnapshotMetadata { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for SnapshotMetadata { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Snapshot { - // message fields - pub data: ::std::vec::Vec, - pub metadata: ::protobuf::SingularPtrField, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -impl Snapshot { - pub fn new() -> Snapshot { - ::std::default::Default::default() - } - - // bytes data = 1; - - pub fn clear_data(&mut self) { - self.data.clear(); - } - - // Param is passed by value, moved - pub fn set_data(&mut self, v: ::std::vec::Vec) { - self.data = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_data(&mut self) -> &mut ::std::vec::Vec { - &mut self.data - } - - // Take field - pub fn take_data(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.data, ::std::vec::Vec::new()) - } - - pub fn get_data(&self) -> &[u8] { - &self.data - } - - // .eraftpb.SnapshotMetadata metadata = 2; - - pub fn clear_metadata(&mut self) { - self.metadata.clear(); - } - - pub fn has_metadata(&self) -> bool { - self.metadata.is_some() - } - - // Param is passed by value, moved - pub fn set_metadata(&mut self, v: SnapshotMetadata) { - self.metadata = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_metadata(&mut self) -> &mut SnapshotMetadata { - if self.metadata.is_none() { - self.metadata.set_default(); - } - self.metadata.as_mut().unwrap() - } - - // Take field - pub fn take_metadata(&mut self) -> SnapshotMetadata { - self.metadata.take().unwrap_or_else(|| SnapshotMetadata::new()) - } - - pub fn get_metadata(&self) -> &SnapshotMetadata { - self.metadata.as_ref().unwrap_or_else(|| SnapshotMetadata::default_instance()) - } -} - -impl ::protobuf::Message for Snapshot { - fn is_initialized(&self) -> bool { - for v in &self.metadata { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.data)?; - }, - 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.metadata)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.data.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.data); - } - if let Some(ref v) = self.metadata.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - if !self.data.is_empty() { - os.write_bytes(1, &self.data)?; - } - if let Some(ref v) = self.metadata.as_ref() { - os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Snapshot { - Snapshot::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "data", - |m: &Snapshot| { &m.data }, - |m: &mut Snapshot| { &mut m.data }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "metadata", - |m: &Snapshot| { &m.metadata }, - |m: &mut Snapshot| { &mut m.metadata }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Snapshot", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static Snapshot { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Snapshot, - }; - unsafe { - instance.get(Snapshot::new) - } - } -} - -impl ::protobuf::Clear for Snapshot { - fn clear(&mut self) { - self.clear_data(); - self.clear_metadata(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Snapshot { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Snapshot { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Message { - // message fields - pub msg_type: MessageType, - pub to: u64, - pub from: u64, - pub term: u64, - pub log_term: u64, - pub index: u64, - pub entries: ::protobuf::RepeatedField, - pub commit: u64, - pub snapshot: ::protobuf::SingularPtrField, - pub reject: bool, - pub reject_hint: u64, - pub context: ::std::vec::Vec, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -impl Message { - pub fn new() -> Message { - ::std::default::Default::default() - } - - // .eraftpb.MessageType msg_type = 1; - - pub fn clear_msg_type(&mut self) { - self.msg_type = MessageType::MsgHup; - } - - // Param is passed by value, moved - pub fn set_msg_type(&mut self, v: MessageType) { - self.msg_type = v; - } - - pub fn get_msg_type(&self) -> MessageType { - self.msg_type - } - - // uint64 to = 2; - - pub fn clear_to(&mut self) { - self.to = 0; - } - - // Param is passed by value, moved - pub fn set_to(&mut self, v: u64) { - self.to = v; - } - - pub fn get_to(&self) -> u64 { - self.to - } - - // uint64 from = 3; - - pub fn clear_from(&mut self) { - self.from = 0; - } - - // Param is passed by value, moved - pub fn set_from(&mut self, v: u64) { - self.from = v; - } - - pub fn get_from(&self) -> u64 { - self.from - } - - // uint64 term = 4; - - pub fn clear_term(&mut self) { - self.term = 0; - } - - // Param is passed by value, moved - pub fn set_term(&mut self, v: u64) { - self.term = v; - } - - pub fn get_term(&self) -> u64 { - self.term - } - - // uint64 log_term = 5; - - pub fn clear_log_term(&mut self) { - self.log_term = 0; - } - - // Param is passed by value, moved - pub fn set_log_term(&mut self, v: u64) { - self.log_term = v; - } - - pub fn get_log_term(&self) -> u64 { - self.log_term - } - - // uint64 index = 6; - - pub fn clear_index(&mut self) { - self.index = 0; - } - - // Param is passed by value, moved - pub fn set_index(&mut self, v: u64) { - self.index = v; - } - - pub fn get_index(&self) -> u64 { - self.index - } - - // repeated .eraftpb.Entry entries = 7; - - pub fn clear_entries(&mut self) { - self.entries.clear(); - } - - // Param is passed by value, moved - pub fn set_entries(&mut self, v: ::protobuf::RepeatedField) { - self.entries = v; - } - - // Mutable pointer to the field. - pub fn mut_entries(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.entries - } - - // Take field - pub fn take_entries(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.entries, ::protobuf::RepeatedField::new()) - } - - pub fn get_entries(&self) -> &[Entry] { - &self.entries - } - - // uint64 commit = 8; - - pub fn clear_commit(&mut self) { - self.commit = 0; - } - - // Param is passed by value, moved - pub fn set_commit(&mut self, v: u64) { - self.commit = v; - } - - pub fn get_commit(&self) -> u64 { - self.commit - } - - // .eraftpb.Snapshot snapshot = 9; - - pub fn clear_snapshot(&mut self) { - self.snapshot.clear(); - } - - pub fn has_snapshot(&self) -> bool { - self.snapshot.is_some() - } - - // Param is passed by value, moved - pub fn set_snapshot(&mut self, v: Snapshot) { - self.snapshot = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_snapshot(&mut self) -> &mut Snapshot { - if self.snapshot.is_none() { - self.snapshot.set_default(); - } - self.snapshot.as_mut().unwrap() - } - - // Take field - pub fn take_snapshot(&mut self) -> Snapshot { - self.snapshot.take().unwrap_or_else(|| Snapshot::new()) - } - - pub fn get_snapshot(&self) -> &Snapshot { - self.snapshot.as_ref().unwrap_or_else(|| Snapshot::default_instance()) - } - - // bool reject = 10; - - pub fn clear_reject(&mut self) { - self.reject = false; - } - - // Param is passed by value, moved - pub fn set_reject(&mut self, v: bool) { - self.reject = v; - } - - pub fn get_reject(&self) -> bool { - self.reject - } - - // uint64 reject_hint = 11; - - pub fn clear_reject_hint(&mut self) { - self.reject_hint = 0; - } - - // Param is passed by value, moved - pub fn set_reject_hint(&mut self, v: u64) { - self.reject_hint = v; - } - - pub fn get_reject_hint(&self) -> u64 { - self.reject_hint - } - - // bytes context = 12; - - pub fn clear_context(&mut self) { - self.context.clear(); - } - - // Param is passed by value, moved - pub fn set_context(&mut self, v: ::std::vec::Vec) { - self.context = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_context(&mut self) -> &mut ::std::vec::Vec { - &mut self.context - } - - // Take field - pub fn take_context(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) - } - - pub fn get_context(&self) -> &[u8] { - &self.context - } -} - -impl ::protobuf::Message for Message { - fn is_initialized(&self) -> bool { - for v in &self.entries { - if !v.is_initialized() { - return false; - } - }; - for v in &self.snapshot { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type == ::protobuf::wire_format::WireTypeVarint {self.msg_type = is.read_enum()?;} else {return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));} - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.to = tmp; - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.from = tmp; - }, - 4 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.term = tmp; - }, - 5 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.log_term = tmp; - }, - 6 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.index = tmp; - }, - 7 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.entries)?; - }, - 8 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.commit = tmp; - }, - 9 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.snapshot)?; - }, - 10 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_bool()?; - self.reject = tmp; - }, - 11 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.reject_hint = tmp; - }, - 12 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.context)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.msg_type != MessageType::MsgHup { - my_size += ::protobuf::rt::enum_size(1, self.msg_type); - } - if self.to != 0 { - my_size += ::protobuf::rt::value_size(2, self.to, ::protobuf::wire_format::WireTypeVarint); - } - if self.from != 0 { - my_size += ::protobuf::rt::value_size(3, self.from, ::protobuf::wire_format::WireTypeVarint); - } - if self.term != 0 { - my_size += ::protobuf::rt::value_size(4, self.term, ::protobuf::wire_format::WireTypeVarint); - } - if self.log_term != 0 { - my_size += ::protobuf::rt::value_size(5, self.log_term, ::protobuf::wire_format::WireTypeVarint); - } - if self.index != 0 { - my_size += ::protobuf::rt::value_size(6, self.index, ::protobuf::wire_format::WireTypeVarint); - } - for value in &self.entries { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; - if self.commit != 0 { - my_size += ::protobuf::rt::value_size(8, self.commit, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(ref v) = self.snapshot.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if self.reject != false { - my_size += 2; - } - if self.reject_hint != 0 { - my_size += ::protobuf::rt::value_size(11, self.reject_hint, ::protobuf::wire_format::WireTypeVarint); - } - if !self.context.is_empty() { - my_size += ::protobuf::rt::bytes_size(12, &self.context); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - if self.msg_type != MessageType::MsgHup { - os.write_enum(1, self.msg_type.value())?; - } - if self.to != 0 { - os.write_uint64(2, self.to)?; - } - if self.from != 0 { - os.write_uint64(3, self.from)?; - } - if self.term != 0 { - os.write_uint64(4, self.term)?; - } - if self.log_term != 0 { - os.write_uint64(5, self.log_term)?; - } - if self.index != 0 { - os.write_uint64(6, self.index)?; - } - for v in &self.entries { - os.write_tag(7, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }; - if self.commit != 0 { - os.write_uint64(8, self.commit)?; - } - if let Some(ref v) = self.snapshot.as_ref() { - os.write_tag(9, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if self.reject != false { - os.write_bool(10, self.reject)?; - } - if self.reject_hint != 0 { - os.write_uint64(11, self.reject_hint)?; - } - if !self.context.is_empty() { - os.write_bytes(12, &self.context)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Message { - Message::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( - "msg_type", - |m: &Message| { &m.msg_type }, - |m: &mut Message| { &mut m.msg_type }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "to", - |m: &Message| { &m.to }, - |m: &mut Message| { &mut m.to }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "from", - |m: &Message| { &m.from }, - |m: &mut Message| { &mut m.from }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "term", - |m: &Message| { &m.term }, - |m: &mut Message| { &mut m.term }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "log_term", - |m: &Message| { &m.log_term }, - |m: &mut Message| { &mut m.log_term }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "index", - |m: &Message| { &m.index }, - |m: &mut Message| { &mut m.index }, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "entries", - |m: &Message| { &m.entries }, - |m: &mut Message| { &mut m.entries }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "commit", - |m: &Message| { &m.commit }, - |m: &mut Message| { &mut m.commit }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "snapshot", - |m: &Message| { &m.snapshot }, - |m: &mut Message| { &mut m.snapshot }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "reject", - |m: &Message| { &m.reject }, - |m: &mut Message| { &mut m.reject }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "reject_hint", - |m: &Message| { &m.reject_hint }, - |m: &mut Message| { &mut m.reject_hint }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "context", - |m: &Message| { &m.context }, - |m: &mut Message| { &mut m.context }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Message", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static Message { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Message, - }; - unsafe { - instance.get(Message::new) - } - } -} - -impl ::protobuf::Clear for Message { - fn clear(&mut self) { - self.clear_msg_type(); - self.clear_to(); - self.clear_from(); - self.clear_term(); - self.clear_log_term(); - self.clear_index(); - self.clear_entries(); - self.clear_commit(); - self.clear_snapshot(); - self.clear_reject(); - self.clear_reject_hint(); - self.clear_context(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Message { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Message { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct HardState { - // message fields - pub term: u64, - pub vote: u64, - pub commit: u64, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -impl HardState { - pub fn new() -> HardState { - ::std::default::Default::default() - } - - // uint64 term = 1; - - pub fn clear_term(&mut self) { - self.term = 0; - } - - // Param is passed by value, moved - pub fn set_term(&mut self, v: u64) { - self.term = v; - } - - pub fn get_term(&self) -> u64 { - self.term - } - - // uint64 vote = 2; - - pub fn clear_vote(&mut self) { - self.vote = 0; - } - - // Param is passed by value, moved - pub fn set_vote(&mut self, v: u64) { - self.vote = v; - } - - pub fn get_vote(&self) -> u64 { - self.vote - } - - // uint64 commit = 3; - - pub fn clear_commit(&mut self) { - self.commit = 0; - } - - // Param is passed by value, moved - pub fn set_commit(&mut self, v: u64) { - self.commit = v; - } - - pub fn get_commit(&self) -> u64 { - self.commit - } -} - -impl ::protobuf::Message for HardState { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.term = tmp; - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.vote = tmp; - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.commit = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.term != 0 { - my_size += ::protobuf::rt::value_size(1, self.term, ::protobuf::wire_format::WireTypeVarint); - } - if self.vote != 0 { - my_size += ::protobuf::rt::value_size(2, self.vote, ::protobuf::wire_format::WireTypeVarint); - } - if self.commit != 0 { - my_size += ::protobuf::rt::value_size(3, self.commit, ::protobuf::wire_format::WireTypeVarint); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - if self.term != 0 { - os.write_uint64(1, self.term)?; - } - if self.vote != 0 { - os.write_uint64(2, self.vote)?; - } - if self.commit != 0 { - os.write_uint64(3, self.commit)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> HardState { - HardState::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "term", - |m: &HardState| { &m.term }, - |m: &mut HardState| { &mut m.term }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "vote", - |m: &HardState| { &m.vote }, - |m: &mut HardState| { &mut m.vote }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "commit", - |m: &HardState| { &m.commit }, - |m: &mut HardState| { &mut m.commit }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "HardState", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static HardState { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const HardState, - }; - unsafe { - instance.get(HardState::new) - } - } -} - -impl ::protobuf::Clear for HardState { - fn clear(&mut self) { - self.clear_term(); - self.clear_vote(); - self.clear_commit(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for HardState { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for HardState { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct ConfState { - // message fields - pub nodes: ::std::vec::Vec, - pub learners: ::std::vec::Vec, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -impl ConfState { - pub fn new() -> ConfState { - ::std::default::Default::default() - } - - // repeated uint64 nodes = 1; - - pub fn clear_nodes(&mut self) { - self.nodes.clear(); - } - - // Param is passed by value, moved - pub fn set_nodes(&mut self, v: ::std::vec::Vec) { - self.nodes = v; - } - - // Mutable pointer to the field. - pub fn mut_nodes(&mut self) -> &mut ::std::vec::Vec { - &mut self.nodes - } - - // Take field - pub fn take_nodes(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.nodes, ::std::vec::Vec::new()) - } - - pub fn get_nodes(&self) -> &[u64] { - &self.nodes - } - - // repeated uint64 learners = 2; - - pub fn clear_learners(&mut self) { - self.learners.clear(); - } - - // Param is passed by value, moved - pub fn set_learners(&mut self, v: ::std::vec::Vec) { - self.learners = v; - } - - // Mutable pointer to the field. - pub fn mut_learners(&mut self) -> &mut ::std::vec::Vec { - &mut self.learners - } - - // Take field - pub fn take_learners(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.learners, ::std::vec::Vec::new()) - } - - pub fn get_learners(&self) -> &[u64] { - &self.learners - } -} - -impl ::protobuf::Message for ConfState { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_repeated_uint64_into(wire_type, is, &mut self.nodes)?; - }, - 2 => { - ::protobuf::rt::read_repeated_uint64_into(wire_type, is, &mut self.learners)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - for value in &self.nodes { - my_size += ::protobuf::rt::value_size(1, *value, ::protobuf::wire_format::WireTypeVarint); - }; - for value in &self.learners { - my_size += ::protobuf::rt::value_size(2, *value, ::protobuf::wire_format::WireTypeVarint); - }; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - for v in &self.nodes { - os.write_uint64(1, *v)?; - }; - for v in &self.learners { - os.write_uint64(2, *v)?; - }; - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> ConfState { - ConfState::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_vec_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "nodes", - |m: &ConfState| { &m.nodes }, - |m: &mut ConfState| { &mut m.nodes }, - )); - fields.push(::protobuf::reflect::accessor::make_vec_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "learners", - |m: &ConfState| { &m.learners }, - |m: &mut ConfState| { &mut m.learners }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "ConfState", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static ConfState { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ConfState, - }; - unsafe { - instance.get(ConfState::new) - } - } -} - -impl ::protobuf::Clear for ConfState { - fn clear(&mut self) { - self.clear_nodes(); - self.clear_learners(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for ConfState { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for ConfState { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct ConfChange { - // message fields - pub id: u64, - pub change_type: ConfChangeType, - pub node_id: u64, - pub context: ::std::vec::Vec, - pub configuration: ::protobuf::SingularPtrField, - pub start_index: u64, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -impl ConfChange { - pub fn new() -> ConfChange { - ::std::default::Default::default() - } - - // uint64 id = 1; - - pub fn clear_id(&mut self) { - self.id = 0; - } - - // Param is passed by value, moved - pub fn set_id(&mut self, v: u64) { - self.id = v; - } - - pub fn get_id(&self) -> u64 { - self.id - } - - // .eraftpb.ConfChangeType change_type = 2; - - pub fn clear_change_type(&mut self) { - self.change_type = ConfChangeType::AddNode; - } - - // Param is passed by value, moved - pub fn set_change_type(&mut self, v: ConfChangeType) { - self.change_type = v; - } - - pub fn get_change_type(&self) -> ConfChangeType { - self.change_type - } - - // uint64 node_id = 3; - - pub fn clear_node_id(&mut self) { - self.node_id = 0; - } - - // Param is passed by value, moved - pub fn set_node_id(&mut self, v: u64) { - self.node_id = v; - } - - pub fn get_node_id(&self) -> u64 { - self.node_id - } - - // bytes context = 4; - - pub fn clear_context(&mut self) { - self.context.clear(); - } - - // Param is passed by value, moved - pub fn set_context(&mut self, v: ::std::vec::Vec) { - self.context = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_context(&mut self) -> &mut ::std::vec::Vec { - &mut self.context - } - - // Take field - pub fn take_context(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) - } - - pub fn get_context(&self) -> &[u8] { - &self.context - } - - // .eraftpb.ConfState configuration = 5; - - pub fn clear_configuration(&mut self) { - self.configuration.clear(); - } - - pub fn has_configuration(&self) -> bool { - self.configuration.is_some() - } - - // Param is passed by value, moved - pub fn set_configuration(&mut self, v: ConfState) { - self.configuration = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_configuration(&mut self) -> &mut ConfState { - if self.configuration.is_none() { - self.configuration.set_default(); - } - self.configuration.as_mut().unwrap() - } - - // Take field - pub fn take_configuration(&mut self) -> ConfState { - self.configuration.take().unwrap_or_else(|| ConfState::new()) - } - - pub fn get_configuration(&self) -> &ConfState { - self.configuration.as_ref().unwrap_or_else(|| ConfState::default_instance()) - } - - // uint64 start_index = 6; - - pub fn clear_start_index(&mut self) { - self.start_index = 0; - } - - // Param is passed by value, moved - pub fn set_start_index(&mut self, v: u64) { - self.start_index = v; - } - - pub fn get_start_index(&self) -> u64 { - self.start_index - } -} - -impl ::protobuf::Message for ConfChange { - fn is_initialized(&self) -> bool { - for v in &self.configuration { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.id = tmp; - }, - 2 => { - if wire_type == ::protobuf::wire_format::WireTypeVarint {self.change_type = is.read_enum()?;} else {return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));} - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.node_id = tmp; - }, - 4 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.context)?; - }, - 5 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.configuration)?; - }, - 6 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.start_index = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.id != 0 { - my_size += ::protobuf::rt::value_size(1, self.id, ::protobuf::wire_format::WireTypeVarint); - } - if self.change_type != ConfChangeType::AddNode { - my_size += ::protobuf::rt::enum_size(2, self.change_type); - } - if self.node_id != 0 { - my_size += ::protobuf::rt::value_size(3, self.node_id, ::protobuf::wire_format::WireTypeVarint); - } - if !self.context.is_empty() { - my_size += ::protobuf::rt::bytes_size(4, &self.context); - } - if let Some(ref v) = self.configuration.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if self.start_index != 0 { - my_size += ::protobuf::rt::value_size(6, self.start_index, ::protobuf::wire_format::WireTypeVarint); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { - if self.id != 0 { - os.write_uint64(1, self.id)?; - } - if self.change_type != ConfChangeType::AddNode { - os.write_enum(2, self.change_type.value())?; - } - if self.node_id != 0 { - os.write_uint64(3, self.node_id)?; - } - if !self.context.is_empty() { - os.write_bytes(4, &self.context)?; - } - if let Some(ref v) = self.configuration.as_ref() { - os.write_tag(5, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if self.start_index != 0 { - os.write_uint64(6, self.start_index)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> ConfChange { - ConfChange::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "id", - |m: &ConfChange| { &m.id }, - |m: &mut ConfChange| { &mut m.id }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( - "change_type", - |m: &ConfChange| { &m.change_type }, - |m: &mut ConfChange| { &mut m.change_type }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "node_id", - |m: &ConfChange| { &m.node_id }, - |m: &mut ConfChange| { &mut m.node_id }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "context", - |m: &ConfChange| { &m.context }, - |m: &mut ConfChange| { &mut m.context }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "configuration", - |m: &ConfChange| { &m.configuration }, - |m: &mut ConfChange| { &mut m.configuration }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "start_index", - |m: &ConfChange| { &m.start_index }, - |m: &mut ConfChange| { &mut m.start_index }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "ConfChange", - fields, - file_descriptor_proto() - ) - }) - } - } - - fn default_instance() -> &'static ConfChange { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ConfChange, - }; - unsafe { - instance.get(ConfChange::new) - } - } -} - -impl ::protobuf::Clear for ConfChange { - fn clear(&mut self) { - self.clear_id(); - self.clear_change_type(); - self.clear_node_id(); - self.clear_context(); - self.clear_configuration(); - self.clear_start_index(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for ConfChange { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for ConfChange { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum EntryType { - EntryNormal = 0, - EntryConfChange = 1, -} - -impl ::protobuf::ProtobufEnum for EntryType { - fn value(&self) -> i32 { - *self as i32 - } - - fn from_i32(value: i32) -> ::std::option::Option { - match value { - 0 => ::std::option::Option::Some(EntryType::EntryNormal), - 1 => ::std::option::Option::Some(EntryType::EntryConfChange), - _ => ::std::option::Option::None - } - } - - fn values() -> &'static [Self] { - static values: &'static [EntryType] = &[ - EntryType::EntryNormal, - EntryType::EntryConfChange, - ]; - values - } - - fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::EnumDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::EnumDescriptor, - }; - unsafe { - descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new("EntryType", file_descriptor_proto()) - }) - } - } -} - -impl ::std::marker::Copy for EntryType { -} - -impl ::std::default::Default for EntryType { - fn default() -> Self { - EntryType::EntryNormal - } -} - -impl ::protobuf::reflect::ProtobufValue for EntryType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) - } -} - -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub 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, -} - -impl ::protobuf::ProtobufEnum for MessageType { - fn value(&self) -> i32 { - *self as i32 - } - - fn from_i32(value: i32) -> ::std::option::Option { - match value { - 0 => ::std::option::Option::Some(MessageType::MsgHup), - 1 => ::std::option::Option::Some(MessageType::MsgBeat), - 2 => ::std::option::Option::Some(MessageType::MsgPropose), - 3 => ::std::option::Option::Some(MessageType::MsgAppend), - 4 => ::std::option::Option::Some(MessageType::MsgAppendResponse), - 5 => ::std::option::Option::Some(MessageType::MsgRequestVote), - 6 => ::std::option::Option::Some(MessageType::MsgRequestVoteResponse), - 7 => ::std::option::Option::Some(MessageType::MsgSnapshot), - 8 => ::std::option::Option::Some(MessageType::MsgHeartbeat), - 9 => ::std::option::Option::Some(MessageType::MsgHeartbeatResponse), - 10 => ::std::option::Option::Some(MessageType::MsgUnreachable), - 11 => ::std::option::Option::Some(MessageType::MsgSnapStatus), - 12 => ::std::option::Option::Some(MessageType::MsgCheckQuorum), - 13 => ::std::option::Option::Some(MessageType::MsgTransferLeader), - 14 => ::std::option::Option::Some(MessageType::MsgTimeoutNow), - 15 => ::std::option::Option::Some(MessageType::MsgReadIndex), - 16 => ::std::option::Option::Some(MessageType::MsgReadIndexResp), - 17 => ::std::option::Option::Some(MessageType::MsgRequestPreVote), - 18 => ::std::option::Option::Some(MessageType::MsgRequestPreVoteResponse), - _ => ::std::option::Option::None - } - } - - fn values() -> &'static [Self] { - static values: &'static [MessageType] = &[ - MessageType::MsgHup, - MessageType::MsgBeat, - MessageType::MsgPropose, - MessageType::MsgAppend, - MessageType::MsgAppendResponse, - MessageType::MsgRequestVote, - MessageType::MsgRequestVoteResponse, - MessageType::MsgSnapshot, - MessageType::MsgHeartbeat, - MessageType::MsgHeartbeatResponse, - MessageType::MsgUnreachable, - MessageType::MsgSnapStatus, - MessageType::MsgCheckQuorum, - MessageType::MsgTransferLeader, - MessageType::MsgTimeoutNow, - MessageType::MsgReadIndex, - MessageType::MsgReadIndexResp, - MessageType::MsgRequestPreVote, - MessageType::MsgRequestPreVoteResponse, - ]; - values - } - - fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::EnumDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::EnumDescriptor, - }; - unsafe { - descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new("MessageType", file_descriptor_proto()) - }) - } - } -} - -impl ::std::marker::Copy for MessageType { -} - -impl ::std::default::Default for MessageType { - fn default() -> Self { - MessageType::MsgHup - } -} - -impl ::protobuf::reflect::ProtobufValue for MessageType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) - } -} - -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum ConfChangeType { - AddNode = 0, - RemoveNode = 1, - AddLearnerNode = 2, - BeginMembershipChange = 3, - FinalizeMembershipChange = 4, -} - -impl ::protobuf::ProtobufEnum for ConfChangeType { - fn value(&self) -> i32 { - *self as i32 - } - - fn from_i32(value: i32) -> ::std::option::Option { - match value { - 0 => ::std::option::Option::Some(ConfChangeType::AddNode), - 1 => ::std::option::Option::Some(ConfChangeType::RemoveNode), - 2 => ::std::option::Option::Some(ConfChangeType::AddLearnerNode), - 3 => ::std::option::Option::Some(ConfChangeType::BeginMembershipChange), - 4 => ::std::option::Option::Some(ConfChangeType::FinalizeMembershipChange), - _ => ::std::option::Option::None - } - } - - fn values() -> &'static [Self] { - static values: &'static [ConfChangeType] = &[ - ConfChangeType::AddNode, - ConfChangeType::RemoveNode, - ConfChangeType::AddLearnerNode, - ConfChangeType::BeginMembershipChange, - ConfChangeType::FinalizeMembershipChange, - ]; - values - } - - fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::EnumDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::EnumDescriptor, - }; - unsafe { - descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new("ConfChangeType", file_descriptor_proto()) - }) - } - } -} - -impl ::std::marker::Copy for ConfChangeType { -} - -impl ::std::default::Default for ConfChangeType { - fn default() -> Self { - ConfChangeType::AddNode - } -} - -impl ::protobuf::reflect::ProtobufValue for ConfChangeType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\reraftpb.proto\x12\x07eraftpb\"\xad\x01\n\x05Entry\x121\n\nentry_type\ - \x18\x01\x20\x01(\x0e2\x12.eraftpb.EntryTypeR\tentryType\x12\x12\n\x04te\ - rm\x18\x02\x20\x01(\x04R\x04term\x12\x14\n\x05index\x18\x03\x20\x01(\x04\ - R\x05index\x12\x12\n\x04data\x18\x04\x20\x01(\x0cR\x04data\x12\x18\n\x07\ - context\x18\x06\x20\x01(\x0cR\x07context\x12\x19\n\x08sync_log\x18\x05\ - \x20\x01(\x08R\x07syncLog\"\x86\x02\n\x10SnapshotMetadata\x121\n\nconf_s\ - tate\x18\x01\x20\x01(\x0b2\x12.eraftpb.ConfStateR\tconfState\x12N\n\x19p\ - ending_membership_change\x18\x04\x20\x01(\x0b2\x12.eraftpb.ConfStateR\ - \x17pendingMembershipChange\x12E\n\x1fpending_membership_change_index\ - \x18\x05\x20\x01(\x04R\x1cpendingMembershipChangeIndex\x12\x14\n\x05inde\ - x\x18\x02\x20\x01(\x04R\x05index\x12\x12\n\x04term\x18\x03\x20\x01(\x04R\ - \x04term\"U\n\x08Snapshot\x12\x12\n\x04data\x18\x01\x20\x01(\x0cR\x04dat\ - a\x125\n\x08metadata\x18\x02\x20\x01(\x0b2\x19.eraftpb.SnapshotMetadataR\ - \x08metadata\"\xe7\x02\n\x07Message\x12/\n\x08msg_type\x18\x01\x20\x01(\ - \x0e2\x14.eraftpb.MessageTypeR\x07msgType\x12\x0e\n\x02to\x18\x02\x20\ - \x01(\x04R\x02to\x12\x12\n\x04from\x18\x03\x20\x01(\x04R\x04from\x12\x12\ - \n\x04term\x18\x04\x20\x01(\x04R\x04term\x12\x19\n\x08log_term\x18\x05\ - \x20\x01(\x04R\x07logTerm\x12\x14\n\x05index\x18\x06\x20\x01(\x04R\x05in\ - dex\x12(\n\x07entries\x18\x07\x20\x03(\x0b2\x0e.eraftpb.EntryR\x07entrie\ - s\x12\x16\n\x06commit\x18\x08\x20\x01(\x04R\x06commit\x12-\n\x08snapshot\ - \x18\t\x20\x01(\x0b2\x11.eraftpb.SnapshotR\x08snapshot\x12\x16\n\x06reje\ - ct\x18\n\x20\x01(\x08R\x06reject\x12\x1f\n\x0breject_hint\x18\x0b\x20\ - \x01(\x04R\nrejectHint\x12\x18\n\x07context\x18\x0c\x20\x01(\x0cR\x07con\ - text\"K\n\tHardState\x12\x12\n\x04term\x18\x01\x20\x01(\x04R\x04term\x12\ - \x12\n\x04vote\x18\x02\x20\x01(\x04R\x04vote\x12\x16\n\x06commit\x18\x03\ - \x20\x01(\x04R\x06commit\"=\n\tConfState\x12\x14\n\x05nodes\x18\x01\x20\ - \x03(\x04R\x05nodes\x12\x1a\n\x08learners\x18\x02\x20\x03(\x04R\x08learn\ - ers\"\xe4\x01\n\nConfChange\x12\x0e\n\x02id\x18\x01\x20\x01(\x04R\x02id\ - \x128\n\x0bchange_type\x18\x02\x20\x01(\x0e2\x17.eraftpb.ConfChangeTypeR\ - \nchangeType\x12\x17\n\x07node_id\x18\x03\x20\x01(\x04R\x06nodeId\x12\ - \x18\n\x07context\x18\x04\x20\x01(\x0cR\x07context\x128\n\rconfiguration\ - \x18\x05\x20\x01(\x0b2\x12.eraftpb.ConfStateR\rconfiguration\x12\x1f\n\ - \x0bstart_index\x18\x06\x20\x01(\x04R\nstartIndex*1\n\tEntryType\x12\x0f\ - \n\x0bEntryNormal\x10\0\x12\x13\n\x0fEntryConfChange\x10\x01*\x8c\x03\n\ - \x0bMessageType\x12\n\n\x06MsgHup\x10\0\x12\x0b\n\x07MsgBeat\x10\x01\x12\ - \x0e\n\nMsgPropose\x10\x02\x12\r\n\tMsgAppend\x10\x03\x12\x15\n\x11MsgAp\ - pendResponse\x10\x04\x12\x12\n\x0eMsgRequestVote\x10\x05\x12\x1a\n\x16Ms\ - gRequestVoteResponse\x10\x06\x12\x0f\n\x0bMsgSnapshot\x10\x07\x12\x10\n\ - \x0cMsgHeartbeat\x10\x08\x12\x18\n\x14MsgHeartbeatResponse\x10\t\x12\x12\ - \n\x0eMsgUnreachable\x10\n\x12\x11\n\rMsgSnapStatus\x10\x0b\x12\x12\n\ - \x0eMsgCheckQuorum\x10\x0c\x12\x15\n\x11MsgTransferLeader\x10\r\x12\x11\ - \n\rMsgTimeoutNow\x10\x0e\x12\x10\n\x0cMsgReadIndex\x10\x0f\x12\x14\n\ - \x10MsgReadIndexResp\x10\x10\x12\x15\n\x11MsgRequestPreVote\x10\x11\x12\ - \x1d\n\x19MsgRequestPreVoteResponse\x10\x12*z\n\x0eConfChangeType\x12\ - \x0b\n\x07AddNode\x10\0\x12\x0e\n\nRemoveNode\x10\x01\x12\x12\n\x0eAddLe\ - arnerNode\x10\x02\x12\x19\n\x15BeginMembershipChange\x10\x03\x12\x1c\n\ - \x18FinalizeMembershipChange\x10\x04b\x06proto3\ -"; - -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } -} diff --git a/src/util.rs b/src/util.rs index ccbca224e..86808683b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,9 +17,6 @@ use std::u64; use crate::eraftpb::{ConfChange, ConfChangeType, ConfState, Entry, Message}; -//#[cfg(feature = "lib-prost")] -//use prost::Message as Msg; -//#[cfg(feature = "lib-rust-protobuf")] use protobuf::Message as Msg; /// A number to represent that there is no limit. diff --git a/tests/integration_cases/test_membership_changes.rs b/tests/integration_cases/test_membership_changes.rs index 0b80b7521..290d47484 100644 --- a/tests/integration_cases/test_membership_changes.rs +++ b/tests/integration_cases/test_membership_changes.rs @@ -18,9 +18,6 @@ use hashbrown::{HashMap, HashSet}; use protobuf; use protobuf::Message as _; -#[cfg(feature = "lib-rust-protobuf")] -use protobuf::RepeatedField; -#[cfg(feature = "lib-prost")] use raft::protobuf_compat::RepeatedField; use raft::{ eraftpb::{ diff --git a/tests/integration_cases/test_raft.rs b/tests/integration_cases/test_raft.rs index 91da6123c..cd237c388 100644 --- a/tests/integration_cases/test_raft.rs +++ b/tests/integration_cases/test_raft.rs @@ -35,12 +35,9 @@ use harness::*; use hashbrown::HashSet; use protobuf; use protobuf::Message as _; -#[cfg(feature = "lib-rust-protobuf")] -use protobuf::RepeatedField; use raft::eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message, MessageType, }; -#[cfg(feature = "lib-prost")] use raft::protobuf_compat::RepeatedField; use raft::storage::MemStorage; use raft::*; diff --git a/tests/integration_cases/test_raft_paper.rs b/tests/integration_cases/test_raft_paper.rs index 9d80a38ef..20c762862 100644 --- a/tests/integration_cases/test_raft_paper.rs +++ b/tests/integration_cases/test_raft_paper.rs @@ -29,10 +29,7 @@ use crate::test_util::*; use harness::*; use protobuf; use protobuf::Message as _; -#[cfg(feature = "lib-rust-protobuf")] -use protobuf::RepeatedField; use raft::eraftpb::*; -#[cfg(feature = "lib-prost")] use raft::protobuf_compat::RepeatedField; use raft::storage::MemStorage; use raft::*; diff --git a/tests/integration_cases/test_raw_node.rs b/tests/integration_cases/test_raw_node.rs index 0f385a64c..6f6382dbf 100644 --- a/tests/integration_cases/test_raw_node.rs +++ b/tests/integration_cases/test_raw_node.rs @@ -27,7 +27,7 @@ use crate::test_util::*; use harness::*; -use protobuf::{self, ProtobufEnum}; +use protobuf::{self, Message as _}; use raft::eraftpb::*; use raft::storage::MemStorage; use raft::*; @@ -88,16 +88,17 @@ fn new_raw_node( storage, peer_nodes, ) - .unwrap() + .unwrap() } // test_raw_node_step ensures that RawNode.Step ignore local message. #[test] fn test_raw_node_step() { setup_for_test(); - for msg_t in MessageType::values() { + for msg_t in 0..18 { + let msg_t = MessageType::from_i32(msg_t).unwrap(); let mut raw_node = new_raw_node(1, vec![], 10, 1, new_storage(), vec![new_peer(1)]); - let res = raw_node.step(new_message(0, 0, *msg_t, 0)); + let res = raw_node.step(new_message(0, 0, msg_t, 0)); // local msg should be ignored. if vec![ MessageType::MsgBeat, @@ -105,7 +106,7 @@ fn test_raw_node_step() { MessageType::MsgUnreachable, MessageType::MsgSnapStatus, ] - .contains(msg_t) + .contains(&msg_t) { assert_eq!(res, Err(Error::StepLocalMsg)); } @@ -432,7 +433,7 @@ fn test_raw_node_restart() { &None, &[], entries[..1].to_vec(), - false + false, )); raw_node.advance(rd); assert!(!raw_node.has_ready()); diff --git a/tests/test_util/mod.rs b/tests/test_util/mod.rs index 88f6b8a3b..e6c92a7f9 100644 --- a/tests/test_util/mod.rs +++ b/tests/test_util/mod.rs @@ -26,7 +26,8 @@ // limitations under the License. use harness::*; -use protobuf::RepeatedField; +use protobuf::Message as _; +use raft::protobuf_compat::RepeatedField; use raft::eraftpb::*; use raft::storage::MemStorage; use raft::*; From d050f12341df788465580fd112a97601815aabf1 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sat, 30 Mar 2019 18:26:34 -0400 Subject: [PATCH 25/40] Compatible with stable rust, pass 150 tests now Signed-off-by: ice1000 --- src/log_unstable.rs | 2 +- src/raft.rs | 2 +- src/raft_log.rs | 2 +- src/raw_node.rs | 2 +- src/rsprost/wrapper_eraftpb.rs | 14 +++++++------- src/storage.rs | 4 ++-- tests/integration_cases/test_membership_changes.rs | 2 +- tests/integration_cases/test_raft.rs | 2 +- tests/integration_cases/test_raft_paper.rs | 2 +- tests/integration_cases/test_raw_node.rs | 2 +- tests/test_util/mod.rs | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/log_unstable.rs b/src/log_unstable.rs index 9570f93e1..cf91056ca 100644 --- a/src/log_unstable.rs +++ b/src/log_unstable.rs @@ -186,7 +186,7 @@ mod test { use crate::eraftpb::{Entry, Snapshot, SnapshotMetadata}; use crate::log_unstable::Unstable; use harness::setup_for_test; - use protobuf::Message as _; + use protobuf::Message as Msg; fn new_entry(index: u64, term: u64) -> Entry { let mut e = Entry::new(); diff --git a/src/raft.rs b/src/raft.rs index 3ebd7706e..2a21f95d1 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -33,7 +33,7 @@ use crate::eraftpb::{ use crate::rsprost::protobuf_compat::RepeatedField; use hashbrown::{HashMap, HashSet}; use protobuf; -use protobuf::Message as _; +use protobuf::Message as Msg; use rand::{self, Rng}; use super::errors::{Error, Result, StorageError}; diff --git a/src/raft_log.rs b/src/raft_log.rs index 9eb6e94c3..187313eb6 100644 --- a/src/raft_log.rs +++ b/src/raft_log.rs @@ -508,7 +508,7 @@ mod test { use crate::storage::MemStorage; use harness::setup_for_test; use protobuf; - use protobuf::Message as _; + use protobuf::Message as Msg; fn new_raft_log(s: MemStorage) -> RaftLog { RaftLog::new(s, String::from("")) diff --git a/src/raw_node.rs b/src/raw_node.rs index dabcebfde..c88f1e870 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -38,7 +38,7 @@ use crate::eraftpb::{ }; use crate::rsprost::protobuf_compat::RepeatedField; -use protobuf::Message as _; +use protobuf::Message as Msg; use super::config::Config; use super::errors::{Error, Result}; diff --git a/src/rsprost/wrapper_eraftpb.rs b/src/rsprost/wrapper_eraftpb.rs index cd6192393..247c8ca1f 100644 --- a/src/rsprost/wrapper_eraftpb.rs +++ b/src/rsprost/wrapper_eraftpb.rs @@ -100,7 +100,7 @@ impl ::protobuf::Message for Entry { unimplemented!(); } fn is_initialized(&self) -> bool { - unimplemented!(); + true } fn merge_from( &mut self, @@ -228,7 +228,7 @@ impl ::protobuf::Message for SnapshotMetadata { unimplemented!(); } fn is_initialized(&self) -> bool { - unimplemented!(); + true } fn merge_from( &mut self, @@ -319,7 +319,7 @@ impl ::protobuf::Message for Snapshot { unimplemented!(); } fn is_initialized(&self) -> bool { - unimplemented!(); + true } fn merge_from( &mut self, @@ -504,7 +504,7 @@ impl ::protobuf::Message for Message { unimplemented!(); } fn is_initialized(&self) -> bool { - unimplemented!(); + true } fn merge_from( &mut self, @@ -582,7 +582,7 @@ impl ::protobuf::Message for HardState { unimplemented!(); } fn is_initialized(&self) -> bool { - unimplemented!(); + true } fn merge_from( &mut self, @@ -663,7 +663,7 @@ impl ::protobuf::Message for ConfState { unimplemented!(); } fn is_initialized(&self) -> bool { - unimplemented!(); + true } fn merge_from( &mut self, @@ -790,7 +790,7 @@ impl ::protobuf::Message for ConfChange { unimplemented!(); } fn is_initialized(&self) -> bool { - unimplemented!(); + true } fn merge_from( &mut self, diff --git a/src/storage.rs b/src/storage.rs index 47df75eab..9faa09f06 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -34,7 +34,7 @@ use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::eraftpb::*; -use protobuf::Message as _; +use protobuf::Message as Msg; use crate::errors::{Error, Result, StorageError}; use crate::util::limit_size; @@ -444,7 +444,7 @@ mod test { use crate::eraftpb::{ConfState, Entry, Snapshot}; use crate::errors::{Error as RaftError, StorageError}; use crate::storage::{MemStorage, Storage}; - use protobuf::Message as _; + use protobuf::Message as Msg; fn new_entry(index: u64, term: u64) -> Entry { let mut e = Entry::new(); diff --git a/tests/integration_cases/test_membership_changes.rs b/tests/integration_cases/test_membership_changes.rs index fcd69cab9..3f2896708 100644 --- a/tests/integration_cases/test_membership_changes.rs +++ b/tests/integration_cases/test_membership_changes.rs @@ -17,7 +17,7 @@ use harness::{setup_for_test, Network}; use hashbrown::{HashMap, HashSet}; use protobuf; -use protobuf::Message as _; +use protobuf::Message as Msg; use raft::protobuf_compat::RepeatedField; use raft::{ eraftpb::{ diff --git a/tests/integration_cases/test_raft.rs b/tests/integration_cases/test_raft.rs index f4c8cd81d..088a7b794 100644 --- a/tests/integration_cases/test_raft.rs +++ b/tests/integration_cases/test_raft.rs @@ -34,7 +34,7 @@ use crate::test_util::*; use harness::*; use hashbrown::HashSet; use protobuf; -use protobuf::Message as _; +use protobuf::Message as Msg; use raft::eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, HardState, Message, MessageType, }; diff --git a/tests/integration_cases/test_raft_paper.rs b/tests/integration_cases/test_raft_paper.rs index bfd313b09..ebc8886e8 100644 --- a/tests/integration_cases/test_raft_paper.rs +++ b/tests/integration_cases/test_raft_paper.rs @@ -28,7 +28,7 @@ use crate::test_util::*; use harness::*; use protobuf; -use protobuf::Message as _; +use protobuf::Message as Msg; use raft::eraftpb::*; use raft::protobuf_compat::RepeatedField; use raft::storage::MemStorage; diff --git a/tests/integration_cases/test_raw_node.rs b/tests/integration_cases/test_raw_node.rs index 9c39353dc..da369f10f 100644 --- a/tests/integration_cases/test_raw_node.rs +++ b/tests/integration_cases/test_raw_node.rs @@ -27,7 +27,7 @@ use crate::test_util::*; use harness::*; -use protobuf::{self, Message as _}; +use protobuf::{self, Message as Msg}; use raft::eraftpb::*; use raft::storage::MemStorage; use raft::*; diff --git a/tests/test_util/mod.rs b/tests/test_util/mod.rs index 71312fc06..fd2ac49cb 100644 --- a/tests/test_util/mod.rs +++ b/tests/test_util/mod.rs @@ -26,7 +26,7 @@ // limitations under the License. use harness::*; -use protobuf::Message as _; +use protobuf::Message as Msg; use raft::eraftpb::*; use raft::protobuf_compat::RepeatedField; use raft::storage::MemStorage; From 139624d4216368e63d3484f769cf1b4de3f6eca0 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sat, 30 Mar 2019 19:14:01 -0400 Subject: [PATCH 26/40] Sounds like all tests are passed Signed-off-by: ice1000 --- src/errors.rs | 19 +++++++++++++++---- src/lib.rs | 1 + src/raft.rs | 7 +++++-- src/raw_node.rs | 8 +++++--- src/rsprost/wrapper_eraftpb.rs | 12 ++++++++++-- src/storage.rs | 4 ++-- .../test_membership_changes.rs | 12 +++++++----- tests/integration_cases/test_raft.rs | 5 ++++- tests/integration_cases/test_raw_node.rs | 17 +++++++++++------ 9 files changed, 60 insertions(+), 25 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 4ad407340..3a3fc8c38 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -15,10 +15,7 @@ use crate::StateRole; use std::error; use std::{cmp, io, result}; -//#[cfg(feature = "lib-prost")] -//use prost::DecodeError as PbError; -//#[cfg(feature = "lib-rust-protobuf")] -//use protobuf::ProtobufError as PbError; +use prost::{DecodeError, EncodeError}; use protobuf::ProtobufError; quick_error! { @@ -60,6 +57,20 @@ quick_error! { description(err.description()) display("protobuf error {:?}", err) } + /// A Prost message encode failed in some manner. + ProstEncode(err: EncodeError) { + from() + cause(err) + description(err.description()) + display("prost encode error {:?}", err) + } + /// A Prost message decode failed in some manner. + ProstDecode(err: DecodeError) { + from() + cause(err) + description(err.description()) + display("prost decode error {:?}", err) + } /// The node exists, but should not. Exists(id: u64, set: &'static str) { display("The node {} already exists in the {} set.", id, set) diff --git a/src/lib.rs b/src/lib.rs index 2ed42734d..9963ed2ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -365,6 +365,7 @@ before taking old, removed peers offline. #![deny(clippy::all)] #![deny(missing_docs)] +#![recursion_limit = "128"] #[cfg(feature = "failpoint")] #[macro_use] diff --git a/src/raft.rs b/src/raft.rs index 2a21f95d1..17123852f 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -32,6 +32,7 @@ use crate::eraftpb::{ }; use crate::rsprost::protobuf_compat::RepeatedField; use hashbrown::{HashMap, HashSet}; +use prost::Message as ProstMsg; use protobuf; use protobuf::Message as Msg; use rand::{self, Rng}; @@ -717,7 +718,8 @@ impl Raft { fn append_finalize_conf_change_entry(&mut self) { let mut conf_change = ConfChange::new(); conf_change.set_change_type(ConfChangeType::FinalizeMembershipChange); - let data = protobuf::Message::write_to_bytes(&conf_change).unwrap(); + let mut data = Vec::with_capacity(conf_change.compute_size() as usize); + conf_change.encode(&mut data).unwrap(); let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); @@ -2147,7 +2149,8 @@ impl Raft { conf_change.set_change_type(ConfChangeType::BeginMembershipChange); conf_change.set_configuration(config.into()); conf_change.set_start_index(destination_index); - let data = protobuf::Message::write_to_bytes(&conf_change)?; + let mut data = Vec::with_capacity(conf_change.compute_size() as usize); + conf_change.encode(&mut data).unwrap(); let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); diff --git a/src/raw_node.rs b/src/raw_node.rs index c88f1e870..32f21a3dc 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -39,6 +39,7 @@ use crate::eraftpb::{ use crate::rsprost::protobuf_compat::RepeatedField; use protobuf::Message as Msg; +use prost::Message as ProstMsg; use super::config::Config; use super::errors::{Error, Result}; @@ -241,8 +242,8 @@ impl RawNode { if let Some(ctx) = peer.context.take() { cc.set_context(ctx); } - let data = - protobuf::Message::write_to_bytes(&cc).expect("unexpected marshal error"); + let mut data = Vec::with_capacity(cc.compute_size() as usize); + cc.encode(&mut data).expect("unexpected marshal error"); let mut e = Entry::new(); e.set_entry_type(EntryType::EntryConfChange); e.set_term(1); @@ -322,7 +323,8 @@ impl RawNode { /// ProposeConfChange proposes a config change. #[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))] pub fn propose_conf_change(&mut self, context: Vec, cc: ConfChange) -> Result<()> { - let data = protobuf::Message::write_to_bytes(&cc)?; + let mut data = Vec::with_capacity(cc.compute_size() as usize); + cc.encode(&mut data)?; let mut m = Message::new(); m.set_msg_type(MessageType::MsgPropose); let mut e = Entry::new(); diff --git a/src/rsprost/wrapper_eraftpb.rs b/src/rsprost/wrapper_eraftpb.rs index 247c8ca1f..a18a94e74 100644 --- a/src/rsprost/wrapper_eraftpb.rs +++ b/src/rsprost/wrapper_eraftpb.rs @@ -225,7 +225,11 @@ impl ::protobuf::Message for SnapshotMetadata { unimplemented!(); } fn default_instance() -> &'static SnapshotMetadata { - unimplemented!(); + static mut INSTANCE: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const SnapshotMetadata, + }; + unsafe { INSTANCE.get(SnapshotMetadata::new) } } fn is_initialized(&self) -> bool { true @@ -316,7 +320,11 @@ impl ::protobuf::Message for Snapshot { unimplemented!(); } fn default_instance() -> &'static Snapshot { - unimplemented!(); + static mut INSTANCE: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Snapshot, + }; + unsafe { INSTANCE.get(Snapshot::new) } } fn is_initialized(&self) -> bool { true diff --git a/src/storage.rs b/src/storage.rs index 9faa09f06..30bfc7f05 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -79,7 +79,7 @@ impl RaftState { /// Storage saves all the information about the current Raft implementation, including Raft Log, /// commit index, the leader to vote for, etc. /// -/// If any Storage method returns an error, the raft instance will +/// If any Storage method returns an error, the raft INSTANCE will /// become inoperable and refuse to participate in elections; the /// application is responsible for cleanup and recovery in this case. pub trait Storage { @@ -119,7 +119,7 @@ pub trait Storage { fn snapshot(&self) -> Result; } -/// The Memory Storage Core instance holds the actual state of the storage struct. To access this +/// The Memory Storage Core INSTANCE holds the actual state of the storage struct. To access this /// value, use the `rl` and `wl` functions on the main MemStorage implementation. pub struct MemStorageCore { raft_state: RaftState, diff --git a/tests/integration_cases/test_membership_changes.rs b/tests/integration_cases/test_membership_changes.rs index 3f2896708..bdb4b370b 100644 --- a/tests/integration_cases/test_membership_changes.rs +++ b/tests/integration_cases/test_membership_changes.rs @@ -16,6 +16,7 @@ use crate::test_util::new_message; use harness::{setup_for_test, Network}; use hashbrown::{HashMap, HashSet}; +use prost::Message as ProstMsg; use protobuf; use protobuf::Message as Msg; use raft::protobuf_compat::RepeatedField; @@ -1479,8 +1480,7 @@ impl Scenario { let mut found = false; for entry in &entries { if entry.get_entry_type() == EntryType::EntryConfChange { - let conf_change = - protobuf::parse_from_bytes::(entry.get_data())?; + let conf_change = ConfChange::decode(entry.get_data())?; if conf_change.get_change_type() == entry_type { found = true; match entry_type { @@ -1593,7 +1593,7 @@ impl Scenario { .slice(index, index + 1, None) .unwrap()[0]; assert_eq!(entry.get_entry_type(), EntryType::EntryConfChange); - let conf_change = protobuf::parse_from_bytes::(entry.get_data()).unwrap(); + let conf_change = ConfChange::decode(entry.get_data()).unwrap(); assert_eq!(conf_change.get_change_type(), entry_type); } } @@ -1648,7 +1648,8 @@ fn begin_entry<'a>( index: u64, ) -> Entry { let conf_change = begin_conf_change(voters, learners, index); - let data = protobuf::Message::write_to_bytes(&conf_change).unwrap(); + let mut data = Vec::with_capacity(conf_change.compute_size() as usize); + conf_change.encode(&mut data).unwrap(); let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); @@ -1676,7 +1677,8 @@ fn build_propose_add_node_message(recipient: u64, added_id: u64, index: u64) -> let mut conf_change = ConfChange::new(); conf_change.set_change_type(ConfChangeType::AddNode); conf_change.set_node_id(added_id); - let data = protobuf::Message::write_to_bytes(&conf_change).unwrap(); + let mut data = Vec::with_capacity(conf_change.compute_size() as usize); + conf_change.encode(&mut data).unwrap(); let mut entry = Entry::new(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); diff --git a/tests/integration_cases/test_raft.rs b/tests/integration_cases/test_raft.rs index 088a7b794..e65ab71d2 100644 --- a/tests/integration_cases/test_raft.rs +++ b/tests/integration_cases/test_raft.rs @@ -33,6 +33,7 @@ use std::panic::{self, AssertUnwindSafe}; use crate::test_util::*; use harness::*; use hashbrown::HashSet; +use prost::Message as ProstMsg; use protobuf; use protobuf::Message as Msg; use raft::eraftpb::{ @@ -3110,7 +3111,9 @@ fn test_commit_after_remove_node() -> Result<()> { let mut cc = ConfChange::new(); cc.set_change_type(ConfChangeType::RemoveNode); cc.set_node_id(2); - e.set_data(protobuf::Message::write_to_bytes(&cc).unwrap()); + let mut ccdata = Vec::with_capacity(cc.compute_size() as usize); + cc.encode(&mut ccdata).unwrap(); + e.set_data(ccdata); m.mut_entries().push(e); r.step(m).expect(""); // Stabilize the log and make sure nothing is committed yet. diff --git a/tests/integration_cases/test_raw_node.rs b/tests/integration_cases/test_raw_node.rs index da369f10f..646311525 100644 --- a/tests/integration_cases/test_raw_node.rs +++ b/tests/integration_cases/test_raw_node.rs @@ -27,6 +27,7 @@ use crate::test_util::*; use harness::*; +use prost::Message as ProstMsg; use protobuf::{self, Message as Msg}; use raft::eraftpb::*; use raft::storage::MemStorage; @@ -197,7 +198,8 @@ fn test_raw_node_propose_and_conf_change() { raw_node.propose(vec![], b"somedata".to_vec()).expect(""); let cc = conf_change(ConfChangeType::AddNode, 1); - ccdata = protobuf::Message::write_to_bytes(&cc).unwrap(); + ccdata.reserve_exact(cc.compute_size() as usize); + cc.encode(&mut ccdata).unwrap(); raw_node.propose_conf_change(vec![], cc).expect(""); proposed = true; @@ -247,7 +249,7 @@ fn test_raw_node_propose_add_duplicate_node() { s.wl().append(rd.entries()).expect(""); for e in rd.committed_entries.as_ref().unwrap() { if e.get_entry_type() == EntryType::EntryConfChange { - let conf_change = protobuf::parse_from_bytes(e.get_data()).unwrap(); + let conf_change = ConfChange::decode(e.get_data()).unwrap(); raw_node.apply_conf_change(&conf_change).ok(); } } @@ -255,7 +257,8 @@ fn test_raw_node_propose_add_duplicate_node() { }; let cc1 = conf_change(ConfChangeType::AddNode, 1); - let ccdata1 = protobuf::Message::write_to_bytes(&cc1).unwrap(); + let mut ccdata1 = Vec::with_capacity(cc1.compute_size() as usize); + cc1.encode(&mut ccdata1).unwrap(); propose_conf_change_and_apply(cc1.clone()); // try to add the same node again @@ -263,7 +266,8 @@ fn test_raw_node_propose_add_duplicate_node() { // the new node join should be ok let cc2 = conf_change(ConfChangeType::AddNode, 2); - let ccdata2 = protobuf::Message::write_to_bytes(&cc2).unwrap(); + let mut ccdata2 = Vec::with_capacity(cc2.compute_size() as usize); + cc2.encode(&mut ccdata2).unwrap(); propose_conf_change_and_apply(cc2); let last_index = s.last_index().unwrap(); @@ -308,7 +312,7 @@ fn test_raw_node_propose_add_learner_node() -> Result<()> { ); let e = &rd.committed_entries.as_ref().unwrap()[0]; - let conf_change = protobuf::parse_from_bytes(e.get_data()).unwrap(); + let conf_change = ConfChange::decode(e.get_data()).unwrap(); let conf_state = raw_node.apply_conf_change(&conf_change)?; assert_eq!(conf_state.nodes, vec![1]); assert_eq!(conf_state.learners, vec![2]); @@ -366,7 +370,8 @@ fn test_raw_node_read_index() { fn test_raw_node_start() { setup_for_test(); let cc = conf_change(ConfChangeType::AddNode, 1); - let ccdata = protobuf::Message::write_to_bytes(&cc).unwrap(); + let mut ccdata = Vec::with_capacity(cc.compute_size() as usize); + cc.encode(&mut ccdata).unwrap(); let store = new_storage(); let mut raw_node = new_raw_node(1, vec![], 10, 1, store.clone(), vec![new_peer(1)]); let rd = raw_node.ready(); From 72da68cc2429302f740141778d05fa8aba849f13 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sat, 30 Mar 2019 19:18:06 -0400 Subject: [PATCH 27/40] Passing all doc-tests Signed-off-by: ice1000 --- src/lib.rs | 7 +++---- src/util.rs | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9963ed2ed..84006bfd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -316,6 +316,7 @@ This means it's possible to do: ```rust use raft::{Config, storage::MemStorage, raw_node::RawNode, eraftpb::{Message, ConfChange}}; +use prost::Message as Msg; let config = Config { id: 1, peers: vec![1, 2], ..Default::default() }; let mut node = RawNode::new(&config, MemStorage::default(), vec![]).unwrap(); node.raft.become_candidate(); @@ -332,8 +333,7 @@ node.raft.propose_membership_change(( # let entry = &node.raft.raft_log.entries(2, 1).unwrap()[0]; // ...Later when the begin entry is recieved from a `ready()` in the `entries` field... -let conf_change = protobuf::parse_from_bytes::(entry.get_data()) - .unwrap(); +let conf_change = ConfChange::decode(entry.get_data()).unwrap(); node.raft.begin_membership_change(&conf_change).unwrap(); assert!(node.raft.is_in_membership_change()); assert!(node.raft.prs().voter_ids().contains(&2)); @@ -346,8 +346,7 @@ assert!(node.raft.prs().voter_ids().contains(&3)); # # let entry = &node.raft.raft_log.entries(3, 1).unwrap()[0]; // ...Later, when the finalize entry is recieved from a `ready()` in the `entries` field... -let conf_change = protobuf::parse_from_bytes::(entry.get_data()) - .unwrap(); +let conf_change = ConfChange::decode(entry.get_data()).unwrap(); node.raft.finalize_membership_change(&conf_change).unwrap(); assert!(!node.raft.prs().voter_ids().contains(&2)); assert!(node.raft.prs().voter_ids().contains(&3)); diff --git a/src/util.rs b/src/util.rs index 86808683b..ef143fb12 100644 --- a/src/util.rs +++ b/src/util.rs @@ -29,6 +29,7 @@ pub const NO_LIMIT: u64 = u64::MAX; /// /// ``` /// use raft::{util::limit_size, prelude::*}; +/// use protobuf::Message as Msg; /// /// let template = { /// let mut entry = Entry::new(); From f3ea8328437151fbf6d509ed61fd697a65650981 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sat, 30 Mar 2019 19:42:56 -0400 Subject: [PATCH 28/40] Use git dependency instead of relative path Signed-off-by: ice1000 --- Cargo.toml | 2 +- src/raw_node.rs | 2 +- src/rsprost/protobuf_compat.rs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5fcf1de0..e9ad23983 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ build = "build.rs" protoc-rust = "~2.0-2.2" protoc-grpcio = "0.3.1" regex = "1.1" -protobuf-build = { path = "../kvproto-build" } +protobuf-build = { git = "https://github.com/nrc/kvproto-build" } [features] default = [] diff --git a/src/raw_node.rs b/src/raw_node.rs index 32f21a3dc..a73f1eb5c 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -38,8 +38,8 @@ use crate::eraftpb::{ }; use crate::rsprost::protobuf_compat::RepeatedField; -use protobuf::Message as Msg; use prost::Message as ProstMsg; +use protobuf::Message as Msg; use super::config::Config; use super::errors::{Error, Result}; diff --git a/src/rsprost/protobuf_compat.rs b/src/rsprost/protobuf_compat.rs index 0dd4b6744..9aef90e1a 100644 --- a/src/rsprost/protobuf_compat.rs +++ b/src/rsprost/protobuf_compat.rs @@ -1,4 +1,3 @@ - pub struct RepeatedField; impl RepeatedField { #[inline] From 48724b44cbf25c0d93ef0c0d8ae5d374a52c8eb8 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Mon, 1 Apr 2019 15:55:06 -0400 Subject: [PATCH 29/40] Partially address comments Signed-off-by: ice1000 --- Cargo.toml | 1 - src/lib.rs | 4 ---- src/rsprotobuf.rs | 3 --- 3 files changed, 8 deletions(-) delete mode 100644 src/rsprotobuf.rs diff --git a/Cargo.toml b/Cargo.toml index e9ad23983..a367dfd3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ build = "build.rs" [build-dependencies] protoc-rust = "~2.0-2.2" -protoc-grpcio = "0.3.1" regex = "1.1" protobuf-build = { git = "https://github.com/nrc/kvproto-build" } diff --git a/src/lib.rs b/src/lib.rs index 84006bfd9..8346971c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -372,10 +372,6 @@ extern crate fail; #[macro_use] extern crate log; -extern crate bytes; -extern crate prost; -extern crate prost_derive; -extern crate protobuf; #[macro_use] extern crate quick_error; #[macro_use] diff --git a/src/rsprotobuf.rs b/src/rsprotobuf.rs deleted file mode 100644 index a6fa108a0..000000000 --- a/src/rsprotobuf.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub use raft::eraftpb; - -pub mod eraftpb; From cc996afb1d832edfb22dac2fcdd5e4fef9eeba3f Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 11:16:59 -0400 Subject: [PATCH 30/40] Fix tests after merge Signed-off-by: ice1000 --- tests/integration_cases/test_raw_node.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/integration_cases/test_raw_node.rs b/tests/integration_cases/test_raw_node.rs index 3085fc7d4..15f015fae 100644 --- a/tests/integration_cases/test_raw_node.rs +++ b/tests/integration_cases/test_raw_node.rs @@ -81,20 +81,19 @@ fn new_raw_node( fn test_raw_node_step() { setup_for_test(); for msg_t in 0..18 { + let msg_t = MessageType::from_i32(msg_t).unwrap(); if vec![ // Vote messages with term 0 will cause panics. MessageType::MsgRequestVote, MessageType::MsgRequestPreVote, ] - .contains(msg_t) + .contains(&msg_t) { continue; } - let msg_t = MessageType::from_i32(msg_t).unwrap(); - let mut raw_node = new_raw_node(1, vec![1], 10, 1, new_storage()); - let res = raw_node.step(new_message(0, 0, *msg_t, 0)); + let res = raw_node.step(new_message(0, 0, msg_t, 0)); // local msg should be ignored. if vec![ MessageType::MsgBeat, @@ -473,7 +472,9 @@ fn test_skip_bcast_commit() { let mut cc = ConfChange::new(); cc.set_change_type(ConfChangeType::RemoveNode); cc.set_node_id(3); - let data = cc.write_to_bytes().unwrap(); + let mut data = Vec::with_capacity(cc.compute_size() as usize); + data.reserve_exact(cc.compute_size() as usize); + cc.encode(&mut data).unwrap(); let mut cc_entry = Entry::new(); cc_entry.set_entry_type(EntryType::EntryConfChange); cc_entry.set_data(data); From 19a42e26234e3935667c7ee5572ba8b7586e8c8b Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 11:59:41 -0400 Subject: [PATCH 31/40] Rename generated mod to `prost` from `rsprost` Signed-off-by: ice1000 --- Cargo.toml | 8 +++----- build.rs | 24 +++++++++++------------ src/lib.rs | 6 +++--- src/prost.rs | 7 +++++++ src/{rsprost => prost}/eraftpb.rs | 0 src/{rsprost => prost}/protobuf_compat.rs | 1 + src/{rsprost => prost}/wrapper_eraftpb.rs | 0 src/raft.rs | 2 +- src/raw_node.rs | 2 +- src/rsprost.rs | 9 --------- 10 files changed, 28 insertions(+), 31 deletions(-) create mode 100644 src/prost.rs rename src/{rsprost => prost}/eraftpb.rs (100%) rename src/{rsprost => prost}/protobuf_compat.rs (99%) rename src/{rsprost => prost}/wrapper_eraftpb.rs (100%) delete mode 100644 src/rsprost.rs diff --git a/Cargo.toml b/Cargo.toml index a367dfd3a..42eb05ed0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,20 +14,18 @@ edition = "2018" build = "build.rs" [build-dependencies] -protoc-rust = "~2.0-2.2" -regex = "1.1" -protobuf-build = { git = "https://github.com/nrc/kvproto-build" } +protobuf-build = "0.3" [features] default = [] -regenerate = [] +gen = [] # Enable failpoints failpoint = ["fail"] # Make sure to synchronize updates with Harness. [dependencies] log = ">0.2" -protobuf = "~2.0-2.2" +protobuf = "~2.1-2.2" prost = "0.5" prost-derive = "0.5" bytes = "0.4.11" diff --git a/build.rs b/build.rs index b17cd664f..920485e62 100644 --- a/build.rs +++ b/build.rs @@ -21,7 +21,7 @@ fn main() { // outside Cargo's OUT_DIR it will cause an error when this crate is used // as a dependency. Therefore, the user must opt-in to regenerating the // Rust files. - if !cfg!(feature = "regenerate") { + if !cfg!(feature = "gen") { println!("cargo:rerun-if-changed=build.rs"); return; } @@ -45,17 +45,17 @@ fn main() { } // Delete the previously-generated wrapper, we're ok if the file does not exist - remove_file("rsprost/protobuf_compat.rs"); + remove_file("prost/protobuf_compat.rs"); // Generate Prost files. - generate_prost_files(&file_names, "src/rsprost"); - let mod_names = module_names_for_dir("src/rsprost"); + generate_prost_files(&file_names, "src/prost"); + let mod_names = module_names_for_dir("src/prost"); generate_wrappers( &mod_names .iter() - .map(|m| format!("src/rsprost/{}.rs", m)) + .map(|m| format!("src/prost/{}.rs", m)) .collect::>(), - "src/rsprost", + "src/prost", ); generate_prost_rs(&mod_names); } @@ -67,19 +67,19 @@ fn generate_prost_rs(mod_names: &[String]) { text.push_str("pub mod "); text.push_str(mod_name); text.push_str("{\n"); - text.push_str("include!(\"rsprost/"); + text.push_str("include!(\"prost/"); text.push_str(mod_name); text.push_str(".rs\");"); - text.push_str("include!(\"rsprost/wrapper_"); + text.push_str("include!(\"prost/wrapper_"); text.push_str(mod_name); text.push_str(".rs\");"); text.push_str("}\n\n"); } text.push_str("pub mod protobuf_compat;\n"); - let mut lib = File::create("src/rsprost.rs").expect("Could not create rsprost.rs"); + let mut lib = File::create("src/prost.rs").expect("Could not create prost.rs"); lib.write_all(text.as_bytes()) - .expect("Could not write rsprost.rs"); + .expect("Could not write prost.rs"); let protobuf_compat_text = " pub struct RepeatedField; @@ -89,8 +89,8 @@ fn generate_prost_rs(mod_names: &[String]) { v } }"; - let mut compat_file = File::create("src/rsprost/protobuf_compat.rs") - .expect("Could not create protobuf_compat.rs"); + let mut compat_file = + File::create("src/prost/protobuf_compat.rs").expect("Could not create protobuf_compat.rs"); compat_file .write_all(protobuf_compat_text.as_bytes()) .expect("Could not write protobuf_compat.rs"); diff --git a/src/lib.rs b/src/lib.rs index 9c2cf1677..c04d9c5c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -382,11 +382,11 @@ extern crate quick_error; extern crate getset; mod config; -mod rsprost; +mod prost; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. -pub use crate::rsprost::eraftpb; -pub use crate::rsprost::protobuf_compat; +pub use crate::prost::eraftpb; +pub use crate::prost::protobuf_compat; mod errors; mod log_unstable; mod progress; diff --git a/src/prost.rs b/src/prost.rs new file mode 100644 index 000000000..ecfcc4af9 --- /dev/null +++ b/src/prost.rs @@ -0,0 +1,7 @@ +#![allow(dead_code)] +#![allow(missing_docs)] + +pub mod eraftpb{ +include!("prost/eraftpb.rs");include!("prost/wrapper_eraftpb.rs");} + +pub mod protobuf_compat; diff --git a/src/rsprost/eraftpb.rs b/src/prost/eraftpb.rs similarity index 100% rename from src/rsprost/eraftpb.rs rename to src/prost/eraftpb.rs diff --git a/src/rsprost/protobuf_compat.rs b/src/prost/protobuf_compat.rs similarity index 99% rename from src/rsprost/protobuf_compat.rs rename to src/prost/protobuf_compat.rs index 9aef90e1a..0fd05a634 100644 --- a/src/rsprost/protobuf_compat.rs +++ b/src/prost/protobuf_compat.rs @@ -1,4 +1,5 @@ pub struct RepeatedField; + impl RepeatedField { #[inline] pub fn from_vec(v: Vec) -> Vec { diff --git a/src/rsprost/wrapper_eraftpb.rs b/src/prost/wrapper_eraftpb.rs similarity index 100% rename from src/rsprost/wrapper_eraftpb.rs rename to src/prost/wrapper_eraftpb.rs diff --git a/src/raft.rs b/src/raft.rs index 472cc006f..ffaa09018 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -30,7 +30,7 @@ use std::cmp; use crate::eraftpb::{ ConfChange, ConfChangeType, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; -use crate::rsprost::protobuf_compat::RepeatedField; +use crate::prost::protobuf_compat::RepeatedField; use hashbrown::{HashMap, HashSet}; use prost::Message as ProstMsg; use protobuf; diff --git a/src/raw_node.rs b/src/raw_node.rs index 3d9bbf6fe..f8cf0219b 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -32,7 +32,7 @@ use std::mem; -use crate::rsprost::protobuf_compat::RepeatedField; +use crate::prost::protobuf_compat::RepeatedField; use prost::Message as ProstMsg; use protobuf::Message as Msg; diff --git a/src/rsprost.rs b/src/rsprost.rs deleted file mode 100644 index b74214e4d..000000000 --- a/src/rsprost.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![allow(dead_code)] -#![allow(missing_docs)] - -pub mod eraftpb { - include!("rsprost/eraftpb.rs"); - include!("rsprost/wrapper_eraftpb.rs"); -} - -pub mod protobuf_compat; From bf889903ad31b4fb15e4c074f9cfa10201f1cbf9 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 12:11:37 -0400 Subject: [PATCH 32/40] Remove `RepeatedField::from_vec` Signed-off-by: ice1000 --- build.rs | 18 ------------------ src/lib.rs | 1 - src/prost.rs | 6 ++++-- src/raft.rs | 7 +++---- src/raw_node.rs | 13 +++++++------ .../test_membership_changes.rs | 5 ++--- tests/integration_cases/test_raft.rs | 13 +++++-------- tests/integration_cases/test_raft_paper.rs | 11 +++++------ tests/test_util/mod.rs | 5 ++--- 9 files changed, 28 insertions(+), 51 deletions(-) diff --git a/build.rs b/build.rs index 920485e62..e81dd5faf 100644 --- a/build.rs +++ b/build.rs @@ -44,9 +44,6 @@ fn main() { println!("cargo:rerun-if-changed={}", f); } - // Delete the previously-generated wrapper, we're ok if the file does not exist - remove_file("prost/protobuf_compat.rs"); - // Generate Prost files. generate_prost_files(&file_names, "src/prost"); let mod_names = module_names_for_dir("src/prost"); @@ -75,23 +72,8 @@ fn generate_prost_rs(mod_names: &[String]) { text.push_str(".rs\");"); text.push_str("}\n\n"); } - text.push_str("pub mod protobuf_compat;\n"); let mut lib = File::create("src/prost.rs").expect("Could not create prost.rs"); lib.write_all(text.as_bytes()) .expect("Could not write prost.rs"); - - let protobuf_compat_text = " - pub struct RepeatedField; - impl RepeatedField { - #[inline] - pub fn from_vec(v: Vec) -> Vec { - v - } - }"; - let mut compat_file = - File::create("src/prost/protobuf_compat.rs").expect("Could not create protobuf_compat.rs"); - compat_file - .write_all(protobuf_compat_text.as_bytes()) - .expect("Could not write protobuf_compat.rs"); } diff --git a/src/lib.rs b/src/lib.rs index c04d9c5c6..1c71755b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -386,7 +386,6 @@ mod prost; /// This module supplies the needed message types. However, it is autogenerated and thus cannot be /// documented by field. pub use crate::prost::eraftpb; -pub use crate::prost::protobuf_compat; mod errors; mod log_unstable; mod progress; diff --git a/src/prost.rs b/src/prost.rs index ecfcc4af9..b6172921c 100644 --- a/src/prost.rs +++ b/src/prost.rs @@ -1,7 +1,9 @@ #![allow(dead_code)] #![allow(missing_docs)] -pub mod eraftpb{ -include!("prost/eraftpb.rs");include!("prost/wrapper_eraftpb.rs");} +pub mod eraftpb { + include!("prost/eraftpb.rs"); + include!("prost/wrapper_eraftpb.rs"); +} pub mod protobuf_compat; diff --git a/src/raft.rs b/src/raft.rs index ffaa09018..c909ec984 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -30,7 +30,6 @@ use std::cmp; use crate::eraftpb::{ ConfChange, ConfChangeType, Entry, EntryType, HardState, Message, MessageType, Snapshot, }; -use crate::prost::protobuf_compat::RepeatedField; use hashbrown::{HashMap, HashSet}; use prost::Message as ProstMsg; use protobuf; @@ -551,7 +550,7 @@ impl Raft { m.set_msg_type(MessageType::MsgAppend); m.set_index(pr.next_idx - 1); m.set_log_term(term); - m.set_entries(RepeatedField::from_vec(ents)); + m.set_entries(ents); m.set_commit(self.raft_log.committed); if !m.get_entries().is_empty() { let last = m.get_entries().last().unwrap().get_index(); @@ -571,7 +570,7 @@ impl Raft { } let mut batched_entries = msg.take_entries(); batched_entries.append(ents); - msg.set_entries(RepeatedField::from_vec(batched_entries)); + msg.set_entries(batched_entries); let last_idx = msg.get_entries().last().unwrap().get_index(); pr.update_state(last_idx); } @@ -2148,7 +2147,7 @@ impl Raft { message.set_msg_type(MessageType::MsgPropose); message.set_from(self.id); message.set_index(destination_index); - message.set_entries(RepeatedField::from_vec(vec![entry])); + message.set_entries(vec![entry]); // `append_entry` sets term, index for us. self.step(message)?; Ok(()) diff --git a/src/raw_node.rs b/src/raw_node.rs index f8cf0219b..dcb1150ef 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -32,7 +32,6 @@ use std::mem; -use crate::prost::protobuf_compat::RepeatedField; use prost::Message as ProstMsg; use protobuf::Message as Msg; @@ -283,7 +282,7 @@ impl RawNode { let mut e = Entry::new(); e.set_data(data); e.set_context(context); - m.set_entries(RepeatedField::from_vec(vec![e])); + m.set_entries(vec![e]); self.raft.step(m) } @@ -298,7 +297,7 @@ impl RawNode { e.set_entry_type(EntryType::EntryConfChange); e.set_data(data); e.set_context(context); - m.set_entries(RepeatedField::from_vec(vec![e])); + m.set_entries(vec![e]); self.raft.step(m) } @@ -476,7 +475,7 @@ impl RawNode { m.set_msg_type(MessageType::MsgReadIndex); let mut e = Entry::new(); e.set_data(rctx); - m.set_entries(RepeatedField::from_vec(vec![e])); + m.set_entries(vec![e]); self.raft.step(m).is_ok(); } @@ -507,10 +506,12 @@ impl RawNode { #[cfg(test)] mod test { - use super::is_local_msg; - use crate::eraftpb::MessageType; use harness::setup_for_test; + use crate::eraftpb::MessageType; + + use super::is_local_msg; + #[test] fn test_is_local_msg() { setup_for_test(); diff --git a/tests/integration_cases/test_membership_changes.rs b/tests/integration_cases/test_membership_changes.rs index 528626399..de57bce58 100644 --- a/tests/integration_cases/test_membership_changes.rs +++ b/tests/integration_cases/test_membership_changes.rs @@ -20,7 +20,6 @@ use hashbrown::{HashMap, HashSet}; use prost::Message as ProstMsg; use protobuf; use protobuf::Message as Msg; -use raft::protobuf_compat::RepeatedField; use raft::{ eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, Message, MessageType, Snapshot, @@ -1654,7 +1653,7 @@ fn build_propose_change_message<'a>( message.set_to(recipient); message.set_msg_type(MessageType::MsgPropose); message.set_index(index); - message.set_entries(RepeatedField::from_vec(vec![begin_entry])); + message.set_entries(vec![begin_entry]); message } @@ -1675,6 +1674,6 @@ fn build_propose_add_node_message(recipient: u64, added_id: u64, index: u64) -> message.set_to(recipient); message.set_msg_type(MessageType::MsgPropose); message.set_index(index); - message.set_entries(RepeatedField::from_vec(vec![add_nodes_entry])); + message.set_entries(vec![add_nodes_entry]); message } diff --git a/tests/integration_cases/test_raft.rs b/tests/integration_cases/test_raft.rs index a421268e0..74b948510 100644 --- a/tests/integration_cases/test_raft.rs +++ b/tests/integration_cases/test_raft.rs @@ -35,7 +35,6 @@ use prost::Message as ProstMsg; use protobuf; use protobuf::Message as Msg; use raft::eraftpb::*; -use raft::protobuf_compat::RepeatedField; use raft::storage::MemStorage; use raft::*; @@ -364,7 +363,7 @@ fn test_progress_paused() { m.set_msg_type(MessageType::MsgPropose); let mut e = Entry::new(); e.set_data(b"some_data".to_vec()); - m.set_entries(RepeatedField::from_vec(vec![e])); + m.set_entries(vec![e]); raft.step(m.clone()).expect(""); raft.step(m.clone()).expect(""); raft.step(m.clone()).expect(""); @@ -953,7 +952,7 @@ fn test_candidate_concede() { // send a proposal to 3 to flush out a MsgAppend to 1 let data = "force follower"; let mut m = new_message(3, 3, MessageType::MsgPropose, 0); - m.set_entries(RepeatedField::from_vec(vec![new_entry(0, 0, Some(data))])); + m.set_entries(vec![new_entry(0, 0, Some(data))]); tt.send(vec![m]); // send heartbeat; flush out commit tt.send(vec![new_message(3, 3, MessageType::MsgBeat, 0)]); @@ -997,7 +996,7 @@ fn test_old_messages() { // pretend we're an old leader trying to make progress; this entry is expected to be ignored. let mut m = new_message(2, 1, MessageType::MsgAppend, 0); m.set_term(2); - m.set_entries(RepeatedField::from_vec(vec![empty_entry(2, 3)])); + m.set_entries(vec![empty_entry(2, 3)]); tt.send(vec![m]); // commit a new entry tt.send(vec![new_message(1, 1, MessageType::MsgPropose, 1)]); @@ -1178,9 +1177,7 @@ fn test_handle_msg_append() { m.set_index(index); m.set_commit(commit); if let Some(ets) = ents { - m.set_entries(RepeatedField::from_vec( - ets.iter().map(|&(i, t)| empty_entry(t, i)).collect(), - )); + m.set_entries(ets.iter().map(|&(i, t)| empty_entry(t, i)).collect()); } m }; @@ -1393,7 +1390,7 @@ fn test_msg_append_response_wait_reset() { // A new command is now proposed on node 1. m = new_message(1, 0, MessageType::MsgPropose, 0); - m.set_entries(RepeatedField::from_vec(vec![empty_entry(0, 0)])); + m.set_entries(vec![empty_entry(0, 0)]); sm.step(m).expect(""); // The command is broadcast to all nodes not in the wait state. diff --git a/tests/integration_cases/test_raft_paper.rs b/tests/integration_cases/test_raft_paper.rs index c7fd34473..9ae8bac0c 100644 --- a/tests/integration_cases/test_raft_paper.rs +++ b/tests/integration_cases/test_raft_paper.rs @@ -30,7 +30,6 @@ use harness::*; use protobuf; use protobuf::Message as Msg; use raft::eraftpb::*; -use raft::protobuf_compat::RepeatedField; use raft::storage::MemStorage; use raft::*; @@ -459,7 +458,7 @@ fn test_leader_start_replication() { m.set_index(li); m.set_log_term(1); m.set_commit(li); - m.set_entries(RepeatedField::from_vec(ents)); + m.set_entries(ents); m }; let expect_msgs = vec![ @@ -630,7 +629,7 @@ fn test_follower_commit_entry() { m.set_term(1); m.set_index(1); m.set_commit(commit); - m.set_entries(RepeatedField::from_vec(ents.clone())); + m.set_entries(ents.clone()); r.step(m).expect(""); if r.raft_log.committed != commit { @@ -764,7 +763,7 @@ fn test_follower_append_entries() { m.set_term(2); m.set_log_term(term); m.set_index(index); - m.set_entries(RepeatedField::from_vec(ents)); + m.set_entries(ents); r.step(m).expect(""); let g = r.raft_log.all_entries(); @@ -889,7 +888,7 @@ fn test_leader_sync_follower_log() { n.send(vec![m]); let mut m = new_message(1, 1, MessageType::MsgPropose, 0); - m.set_entries(RepeatedField::from_vec(vec![Entry::new()])); + m.set_entries(vec![Entry::new()]); n.send(vec![m]); let lead_str = ltoa(&n.peers[&1].raft_log); let follower_str = ltoa(&n.peers[&2].raft_log); @@ -918,7 +917,7 @@ fn test_vote_request() { m.set_term(wterm - 1); m.set_log_term(0); m.set_index(1); - m.set_entries(RepeatedField::from_vec(ents.clone())); + m.set_entries(ents.clone()); r.step(m).expect(""); r.read_messages(); diff --git a/tests/test_util/mod.rs b/tests/test_util/mod.rs index d6f8e6dad..9081b7add 100644 --- a/tests/test_util/mod.rs +++ b/tests/test_util/mod.rs @@ -28,7 +28,6 @@ use harness::*; use protobuf::Message as Msg; use raft::eraftpb::*; -use raft::protobuf_compat::RepeatedField; use raft::storage::MemStorage; use raft::*; @@ -135,7 +134,7 @@ pub fn new_message_with_entries(from: u64, to: u64, t: MessageType, ents: Vec Message { for _ in 0..n { ents.push(new_entry(0, 0, SOME_DATA)); } - m.set_entries(RepeatedField::from_vec(ents)); + m.set_entries(ents); } m } From 3b9a8bb63abb1714d66300bb9e80db9b0b5bd010 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 12:23:48 -0400 Subject: [PATCH 33/40] Remove all uses of `protobuf::Message as Msg` Signed-off-by: ice1000 --- src/lib.rs | 2 +- src/log_unstable.rs | 7 +++---- src/raft.rs | 46 ++++++++++++++++++++++----------------------- src/raft_log.rs | 11 +++++------ src/raw_node.rs | 31 +++++++++++++++--------------- src/storage.rs | 16 +++++++--------- src/util.rs | 13 ++++++------- 7 files changed, 59 insertions(+), 67 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1c71755b4..d28a0a665 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -317,7 +317,7 @@ This means it's possible to do: ```rust use raft::{Config, storage::MemStorage, raw_node::RawNode, eraftpb::*}; -use prost::Message as Msg; +use prost::Message as ProstMsg; let mut config = Config { id: 1, ..Default::default() }; let store = MemStorage::new_with_conf_state((vec![1, 2], vec![])); let mut node = RawNode::new(&mut config, store).unwrap(); diff --git a/src/log_unstable.rs b/src/log_unstable.rs index cf91056ca..68a58d29c 100644 --- a/src/log_unstable.rs +++ b/src/log_unstable.rs @@ -186,18 +186,17 @@ mod test { use crate::eraftpb::{Entry, Snapshot, SnapshotMetadata}; use crate::log_unstable::Unstable; use harness::setup_for_test; - use protobuf::Message as Msg; fn new_entry(index: u64, term: u64) -> Entry { - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_term(term); e.set_index(index); e } fn new_snapshot(index: u64, term: u64) -> Snapshot { - let mut snap = Snapshot::new(); - let mut meta = SnapshotMetadata::new(); + let mut snap = Snapshot::new_(); + let mut meta = SnapshotMetadata::new_(); meta.set_index(index); meta.set_term(term); snap.set_metadata(meta); diff --git a/src/raft.rs b/src/raft.rs index c909ec984..5447c602c 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -32,8 +32,6 @@ use crate::eraftpb::{ }; use hashbrown::{HashMap, HashSet}; use prost::Message as ProstMsg; -use protobuf; -use protobuf::Message as Msg; use rand::{self, Rng}; use super::errors::{Error, Result, StorageError}; @@ -213,7 +211,7 @@ trait AssertSend: Send {} impl AssertSend for Raft {} fn new_message(to: u64, field_type: MessageType, from: Option) -> Message { - let mut m = Message::new(); + let mut m = Message::new_(); m.set_to(to); if let Some(id) = from { m.set_from(id); @@ -288,7 +286,7 @@ impl Raft { } } - if raft_state.hard_state != HardState::new() { + if raft_state.hard_state != HardState::new_() { r.load_state(&raft_state.hard_state); } if c.applied > 0 { @@ -363,7 +361,7 @@ impl Raft { /// Returns a value representing the hardstate at the time of calling. pub fn hard_state(&self) -> HardState { - let mut hs = HardState::new(); + let mut hs = HardState::new_(); hs.set_term(self.term); hs.set_vote(self.vote); hs.set_commit(self.raft_log.committed); @@ -594,7 +592,7 @@ impl Raft { } let term = self.raft_log.term(pr.next_idx - 1); let ents = self.raft_log.entries(pr.next_idx, self.max_msg_size); - let mut m = Message::new(); + let mut m = Message::new_(); m.set_to(to); if term.is_err() || ents.is_err() { // send snapshot if we failed to get term or entries @@ -631,7 +629,7 @@ impl Raft { // or it might not have all the committed entries. // The leader MUST NOT forward the follower's commit to // an unmatched index. - let mut m = Message::new(); + let mut m = Message::new_(); m.set_to(to); m.set_msg_type(MessageType::MsgHeartbeat); let commit = cmp::min(pr.matched, self.raft_log.committed); @@ -704,11 +702,11 @@ impl Raft { } fn append_finalize_conf_change_entry(&mut self) { - let mut conf_change = ConfChange::new(); + let mut conf_change = ConfChange::new_(); conf_change.set_change_type(ConfChangeType::FinalizeMembershipChange); - let mut data = Vec::with_capacity(conf_change.compute_size() as usize); + let mut data = Vec::with_capacity(ProstMsg::encoded_len(&conf_change)); conf_change.encode(&mut data).unwrap(); - let mut entry = Entry::new(); + let mut entry = Entry::new_(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); // Index/Term set here. @@ -902,7 +900,7 @@ impl Raft { // could be expensive. self.pending_conf_index = self.raft_log.last_index(); - self.append_entry(&mut [Entry::new()]); + self.append_entry(&mut [Entry::new_()]); // In most cases, we append only a new entry marked with an index and term. // In the specific case of a node recovering while in the middle of a membership change, @@ -1457,7 +1455,7 @@ impl Raft { }; self.read_states.push(rs); } else { - let mut to_send = Message::new(); + let mut to_send = Message::new_(); to_send.set_to(req.get_from()); to_send.set_msg_type(MessageType::MsgReadIndexResp); to_send.set_index(rs.index); @@ -1642,7 +1640,7 @@ impl Raft { configuration [index {}, applied {}]", e, self.pending_conf_index, self.raft_log.applied ); - *e = Entry::new(); + *e = Entry::new_(); e.set_entry_type(EntryType::EntryNormal); } else { self.pending_conf_index = self.raft_log.last_index() + i as u64 + 1; @@ -1683,7 +1681,7 @@ impl Raft { }; self.read_states.push(rs); } else { - let mut to_send = Message::new(); + let mut to_send = Message::new_(); to_send.set_to(m.get_from()); to_send.set_msg_type(MessageType::MsgReadIndexResp); to_send.set_index(read_index); @@ -1919,14 +1917,14 @@ impl Raft { pub fn handle_append_entries(&mut self, m: &Message) { if m.get_index() < self.raft_log.committed { debug!("{} Got message with lower index than committed.", self.tag); - let mut to_send = Message::new(); + let mut to_send = Message::new_(); to_send.set_to(m.get_from()); to_send.set_msg_type(MessageType::MsgAppendResponse); to_send.set_index(self.raft_log.committed); self.send(to_send); return; } - let mut to_send = Message::new(); + let mut to_send = Message::new_(); to_send.set_to(m.get_from()); to_send.set_msg_type(MessageType::MsgAppendResponse); match self.raft_log.maybe_append( @@ -1962,7 +1960,7 @@ impl Raft { /// For a message, commit and send out heartbeat. pub fn handle_heartbeat(&mut self, mut m: Message) { self.raft_log.commit_to(m.get_commit()); - let mut to_send = Message::new(); + let mut to_send = Message::new_(); to_send.set_to(m.get_from()); to_send.set_msg_type(MessageType::MsgHeartbeatResponse); to_send.set_context(m.take_context()); @@ -1979,7 +1977,7 @@ impl Raft { "{} [commit: {}, term: {}] restored snapshot [index: {}, term: {}]", self.tag, self.term, self.raft_log.committed, sindex, sterm ); - let mut to_send = Message::new(); + let mut to_send = Message::new_(); to_send.set_to(m.get_from()); to_send.set_msg_type(MessageType::MsgAppendResponse); to_send.set_index(self.raft_log.last_index()); @@ -1989,7 +1987,7 @@ impl Raft { "{} [commit: {}] ignored snapshot [index: {}, term: {}]", self.tag, self.raft_log.committed, sindex, sterm ); - let mut to_send = Message::new(); + let mut to_send = Message::new_(); to_send.set_to(m.get_from()); to_send.set_msg_type(MessageType::MsgAppendResponse); to_send.set_index(self.raft_log.committed); @@ -2049,7 +2047,7 @@ impl Raft { self.prs = Some(prs); if meta.get_pending_membership_change_index() > 0 { let cs = meta.get_pending_membership_change().clone(); - let mut conf_change = ConfChange::new(); + let mut conf_change = ConfChange::new_(); conf_change.set_change_type(ConfChangeType::BeginMembershipChange); conf_change.set_configuration(cs); conf_change.set_start_index(meta.get_pending_membership_change_index()); @@ -2134,16 +2132,16 @@ impl Raft { ); let destination_index = self.raft_log.last_index() + 1; // Prep a configuration change to append. - let mut conf_change = ConfChange::new(); + let mut conf_change = ConfChange::new_(); conf_change.set_change_type(ConfChangeType::BeginMembershipChange); conf_change.set_configuration(config.into()); conf_change.set_start_index(destination_index); - let mut data = Vec::with_capacity(conf_change.compute_size() as usize); + let mut data = Vec::with_capacity(ProstMsg::encoded_len(&conf_change)); conf_change.encode(&mut data).unwrap(); - let mut entry = Entry::new(); + let mut entry = Entry::new_(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); - let mut message = Message::new(); + let mut message = Message::new_(); message.set_msg_type(MessageType::MsgPropose); message.set_from(self.id); message.set_index(destination_index); diff --git a/src/raft_log.rs b/src/raft_log.rs index 187313eb6..e616c8775 100644 --- a/src/raft_log.rs +++ b/src/raft_log.rs @@ -507,25 +507,24 @@ mod test { use crate::raft_log::{self, RaftLog}; use crate::storage::MemStorage; use harness::setup_for_test; - use protobuf; - use protobuf::Message as Msg; + use prost::Message as ProstMsg; fn new_raft_log(s: MemStorage) -> RaftLog { RaftLog::new(s, String::from("")) } fn new_entry(index: u64, term: u64) -> eraftpb::Entry { - let mut e = eraftpb::Entry::new(); + let mut e = eraftpb::Entry::new_(); e.set_term(term); e.set_index(index); e } fn new_snapshot(meta_index: u64, meta_term: u64) -> eraftpb::Snapshot { - let mut meta = eraftpb::SnapshotMetadata::new(); + let mut meta = eraftpb::SnapshotMetadata::new_(); meta.set_index(meta_index); meta.set_term(meta_term); - let mut snapshot = eraftpb::Snapshot::new(); + let mut snapshot = eraftpb::Snapshot::new_(); snapshot.set_metadata(meta); snapshot } @@ -973,7 +972,7 @@ mod test { let (last, half) = (offset + num, offset + num / 2); let halfe = new_entry(half, half); - let halfe_size = u64::from(protobuf::Message::compute_size(&halfe)); + let halfe_size = ProstMsg::encoded_len(&halfe) as u64; let store = MemStorage::new(); store diff --git a/src/raw_node.rs b/src/raw_node.rs index dcb1150ef..f37b5bb58 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -33,7 +33,6 @@ use std::mem; use prost::Message as ProstMsg; -use protobuf::Message as Msg; use crate::config::Config; use crate::eraftpb::{ @@ -237,7 +236,7 @@ impl RawNode { self.prev_ss = rd.ss.unwrap(); } if let Some(e) = rd.hs { - if e != HardState::new() { + if e != HardState::new_() { self.prev_hs = e; } } @@ -245,7 +244,7 @@ impl RawNode { let e = rd.entries.last().unwrap(); self.raft.raft_log.stable_to(e.get_index(), e.get_term()); } - if rd.snapshot != Snapshot::new() { + if rd.snapshot != Snapshot::new_() { self.raft .raft_log .stable_snap_to(rd.snapshot.get_metadata().get_index()); @@ -269,17 +268,17 @@ impl RawNode { /// Campaign causes this RawNode to transition to candidate state. pub fn campaign(&mut self) -> Result<()> { - let mut m = Message::new(); + let mut m = Message::new_(); m.set_msg_type(MessageType::MsgHup); self.raft.step(m) } /// Propose proposes data be appended to the raft log. pub fn propose(&mut self, context: Vec, data: Vec) -> Result<()> { - let mut m = Message::new(); + let mut m = Message::new_(); m.set_msg_type(MessageType::MsgPropose); m.set_from(self.raft.id); - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_data(data); e.set_context(context); m.set_entries(vec![e]); @@ -289,11 +288,11 @@ impl RawNode { /// ProposeConfChange proposes a config change. #[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))] pub fn propose_conf_change(&mut self, context: Vec, cc: ConfChange) -> Result<()> { - let mut data = Vec::with_capacity(cc.compute_size() as usize); + let mut data = Vec::with_capacity(ProstMsg::encoded_len(&cc)); cc.encode(&mut data)?; - let mut m = Message::new(); + let mut m = Message::new_(); m.set_msg_type(MessageType::MsgPropose); - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_entry_type(EntryType::EntryConfChange); e.set_data(data); e.set_context(context); @@ -313,7 +312,7 @@ impl RawNode { if cc.get_node_id() == INVALID_ID && cc.get_change_type() != ConfChangeType::BeginMembershipChange { - let mut cs = ConfState::new(); + let mut cs = ConfState::new_(); cs.set_nodes(self.raft.prs().voter_ids().iter().cloned().collect()); cs.set_learners(self.raft.prs().learner_ids().iter().cloned().collect()); return Ok(cs); @@ -382,7 +381,7 @@ impl RawNode { return true; } let hs = raft.hard_state(); - if hs != HardState::new() && hs != self.prev_hs { + if hs != HardState::new_() && hs != self.prev_hs { return true; } false @@ -440,7 +439,7 @@ impl RawNode { /// ReportUnreachable reports the given node is not reachable for the last send. pub fn report_unreachable(&mut self, id: u64) { - let mut m = Message::new(); + let mut m = Message::new_(); m.set_msg_type(MessageType::MsgUnreachable); m.set_from(id); // we don't care if it is ok actually @@ -450,7 +449,7 @@ impl RawNode { /// ReportSnapshot reports the status of the sent snapshot. pub fn report_snapshot(&mut self, id: u64, status: SnapshotStatus) { let rej = status == SnapshotStatus::Failure; - let mut m = Message::new(); + let mut m = Message::new_(); m.set_msg_type(MessageType::MsgSnapStatus); m.set_from(id); m.set_reject(rej); @@ -460,7 +459,7 @@ impl RawNode { /// TransferLeader tries to transfer leadership to the given transferee. pub fn transfer_leader(&mut self, transferee: u64) { - let mut m = Message::new(); + let mut m = Message::new_(); m.set_msg_type(MessageType::MsgTransferLeader); m.set_from(transferee); self.raft.step(m).is_ok(); @@ -471,9 +470,9 @@ impl RawNode { /// index, any linearizable read requests issued before the read request can be /// processed safely. The read state will have the same rctx attached. pub fn read_index(&mut self, rctx: Vec) { - let mut m = Message::new(); + let mut m = Message::new_(); m.set_msg_type(MessageType::MsgReadIndex); - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_data(rctx); m.set_entries(vec![e]); self.raft.step(m).is_ok(); diff --git a/src/storage.rs b/src/storage.rs index 9e557d793..88a778a95 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -34,7 +34,6 @@ use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::eraftpb::*; -use protobuf::Message as Msg; use crate::errors::{Error, Result, StorageError}; use crate::util::limit_size; @@ -241,7 +240,7 @@ impl MemStorageCore { } fn snapshot(&self) -> Snapshot { - let mut snapshot = Snapshot::new(); + let mut snapshot = Snapshot::new_(); // Use the latest applied_idx to construct the snapshot. let applied_idx = self.raft_state.hard_state.get_commit(); @@ -478,8 +477,7 @@ mod test { use std::panic::{self, AssertUnwindSafe}; use harness::setup_for_test; - use protobuf; - use protobuf::Message as Msg; + use prost::Message as ProstMsg; use crate::eraftpb::{ConfState, Entry, Snapshot}; use crate::errors::{Error as RaftError, StorageError}; @@ -487,18 +485,18 @@ mod test { use super::{MemStorage, Storage}; fn new_entry(index: u64, term: u64) -> Entry { - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_term(term); e.set_index(index); e } - fn size_of(m: &T) -> u32 { - m.compute_size() + fn size_of(m: &T) -> u32 { + ProstMsg::encoded_len(m) as u32 } fn new_snapshot(index: u64, term: u64, nodes: Vec) -> Snapshot { - let mut s = Snapshot::new(); + let mut s = Snapshot::new_(); s.mut_metadata().set_index(index); s.mut_metadata().set_term(term); s.mut_metadata().mut_conf_state().set_nodes(nodes); @@ -661,7 +659,7 @@ mod test { setup_for_test(); let ents = vec![new_entry(3, 3), new_entry(4, 4), new_entry(5, 5)]; let nodes = vec![1, 2, 3]; - let mut conf_state = ConfState::new(); + let mut conf_state = ConfState::new_(); conf_state.set_nodes(nodes.clone()); let mut tests = vec![ diff --git a/src/util.rs b/src/util.rs index 90034f076..611165629 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,7 +17,7 @@ use std::u64; use crate::eraftpb::{ConfChange, ConfChangeType, ConfState, Entry, Message}; -use protobuf::Message as Msg; +use prost::Message as ProstMsg; /// A number to represent that there is no limit. pub const NO_LIMIT: u64 = u64::MAX; @@ -29,10 +29,9 @@ pub const NO_LIMIT: u64 = u64::MAX; /// /// ``` /// use raft::{util::limit_size, prelude::*}; -/// use protobuf::Message as Msg; /// /// let template = { -/// let mut entry = Entry::new(); +/// let mut entry = Entry::new_(); /// entry.set_data("*".repeat(100).into_bytes()); /// entry /// }; @@ -54,7 +53,7 @@ pub const NO_LIMIT: u64 = u64::MAX; /// limit_size(&mut entries, Some(0)); /// assert_eq!(entries.len(), 1); /// ``` -pub fn limit_size(entries: &mut Vec, max: Option) { +pub fn limit_size(entries: &mut Vec, max: Option) { if entries.len() <= 1 { return; } @@ -68,10 +67,10 @@ pub fn limit_size(entries: &mut Vec, max: Option) { .iter() .take_while(|&e| { if size == 0 { - size += u64::from(Msg::compute_size(e)); + size += ProstMsg::encoded_len(e) as u64; true } else { - size += u64::from(Msg::compute_size(e)); + size += ProstMsg::encoded_len(e) as u64; size <= max } }) @@ -104,7 +103,7 @@ where impl From<(u64, ConfState)> for ConfChange { fn from((start_index, state): (u64, ConfState)) -> Self { - let mut change = ConfChange::new(); + let mut change = ConfChange::new_(); change.set_change_type(ConfChangeType::BeginMembershipChange); change.set_configuration(state); change.set_start_index(start_index); From 28294fa8010efe8558861e2b9d11f7f6a823f77e Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 12:30:18 -0400 Subject: [PATCH 34/40] Remove `Codec` error and remove tests (not added for prost's errors because their constructors are private Signed-off-by: ice1000 --- src/errors.rs | 12 ------------ src/prost.rs | 2 -- src/prost/protobuf_compat.rs | 8 -------- 3 files changed, 22 deletions(-) delete mode 100644 src/prost/protobuf_compat.rs diff --git a/src/errors.rs b/src/errors.rs index 3a3fc8c38..f8e8c3bad 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -16,7 +16,6 @@ use std::error; use std::{cmp, io, result}; use prost::{DecodeError, EncodeError}; -use protobuf::ProtobufError; quick_error! { /// The base error type for raft @@ -50,13 +49,6 @@ quick_error! { ConfigInvalid(desc: String) { description(desc) } - /// A Protobuf message failed in some manner. - Codec(err: ProtobufError) { - from() - cause(err) - description(err.description()) - display("protobuf error {:?}", err) - } /// A Prost message encode failed in some manner. ProstEncode(err: EncodeError) { from() @@ -197,10 +189,6 @@ mod tests { Error::StepPeerNotFound, Error::Store(StorageError::Compacted) ); - assert_ne!( - Error::Codec(ProtobufError::MessageNotInitialized { message: "" }), - Error::StepLocalMsg - ); } #[test] diff --git a/src/prost.rs b/src/prost.rs index b6172921c..2b3dba3d7 100644 --- a/src/prost.rs +++ b/src/prost.rs @@ -5,5 +5,3 @@ pub mod eraftpb { include!("prost/eraftpb.rs"); include!("prost/wrapper_eraftpb.rs"); } - -pub mod protobuf_compat; diff --git a/src/prost/protobuf_compat.rs b/src/prost/protobuf_compat.rs deleted file mode 100644 index 0fd05a634..000000000 --- a/src/prost/protobuf_compat.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub struct RepeatedField; - -impl RepeatedField { - #[inline] - pub fn from_vec(v: Vec) -> Vec { - v - } -} From 64b34976ca490aa21ad747e633781dd17937dea2 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 12:49:10 -0400 Subject: [PATCH 35/40] Remove even more protobuf stuff, apply some minor suggestions by clippy Signed-off-by: ice1000 --- examples/five_mem_node/main.rs | 7 +- src/prost/wrapper_eraftpb.rs | 333 +----------------- .../test_membership_changes.rs | 26 +- tests/integration_cases/test_raft.rs | 40 +-- tests/integration_cases/test_raft_paper.rs | 4 +- tests/integration_cases/test_raw_node.rs | 21 +- tests/test_util/mod.rs | 9 +- 7 files changed, 60 insertions(+), 380 deletions(-) diff --git a/examples/five_mem_node/main.rs b/examples/five_mem_node/main.rs index 909774672..9ee4c68fd 100644 --- a/examples/five_mem_node/main.rs +++ b/examples/five_mem_node/main.rs @@ -13,7 +13,7 @@ #[macro_use] extern crate log; extern crate env_logger; -extern crate protobuf; +extern crate prost; extern crate raft; extern crate regex; @@ -23,7 +23,7 @@ use std::sync::{Arc, Mutex}; use std::time::{Duration, Instant}; use std::{str, thread}; -use protobuf::Message as PbMessage; +use prost::Message as ProstMsg; use raft::eraftpb::ConfState; use raft::storage::MemStorage; use raft::{prelude::*, StateRole}; @@ -223,8 +223,7 @@ fn on_ready( } if let EntryType::EntryConfChange = entry.get_entry_type() { // For conf change messages, make them effective. - let mut cc = ConfChange::new(); - cc.merge_from_bytes(entry.get_data()).unwrap(); + let cc = ConfChange::decode(entry.get_data()).unwrap(); let node_id = cc.get_node_id(); match cc.get_change_type() { ConfChangeType::AddNode => raft_group.raft.add_node(node_id).unwrap(), diff --git a/src/prost/wrapper_eraftpb.rs b/src/prost/wrapper_eraftpb.rs index a18a94e74..5b0c1c71b 100644 --- a/src/prost/wrapper_eraftpb.rs +++ b/src/prost/wrapper_eraftpb.rs @@ -69,52 +69,6 @@ impl Entry { self.sync_log } } -impl ::protobuf::Clear for Entry { - fn clear(&mut self) { - ::prost::Message::clear(self); - } -} -impl ::protobuf::Message for Entry { - fn compute_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn get_cached_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - fn new() -> Self { - Self::new_() - } - fn write_to_with_cached_sizes( - &self, - _os: &mut ::protobuf::CodedOutputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn default_instance() -> &'static Entry { - unimplemented!(); - } - fn is_initialized(&self) -> bool { - true - } - fn merge_from( - &mut self, - _is: &mut ::protobuf::CodedInputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - unimplemented!(); - } - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - unimplemented!(); - } -} impl SnapshotMetadata { pub fn new_() -> SnapshotMetadata { ::std::default::Default::default() @@ -130,7 +84,7 @@ impl SnapshotMetadata { pub fn get_conf_state(&self) -> &ConfState { match self.conf_state.as_ref() { Some(v) => v, - None => ::default_instance(), + None => ConfState::default_instance(), } } pub fn mut_conf_state(&mut self) -> &mut ConfState { @@ -155,7 +109,7 @@ impl SnapshotMetadata { pub fn get_pending_membership_change(&self) -> &ConfState { match self.pending_membership_change.as_ref() { Some(v) => v, - None => ::default_instance(), + None => ConfState::default_instance(), } } pub fn mut_pending_membership_change(&mut self) -> &mut ConfState { @@ -196,55 +150,12 @@ impl SnapshotMetadata { pub fn get_term(&self) -> u64 { self.term } -} -impl ::protobuf::Clear for SnapshotMetadata { - fn clear(&mut self) { - ::prost::Message::clear(self); - } -} -impl ::protobuf::Message for SnapshotMetadata { - fn compute_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn get_cached_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - fn new() -> Self { - Self::new_() - } - fn write_to_with_cached_sizes( - &self, - _os: &mut ::protobuf::CodedOutputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } fn default_instance() -> &'static SnapshotMetadata { static mut INSTANCE: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { lock: ::protobuf::lazy::ONCE_INIT, ptr: 0 as *const SnapshotMetadata, }; - unsafe { INSTANCE.get(SnapshotMetadata::new) } - } - fn is_initialized(&self) -> bool { - true - } - fn merge_from( - &mut self, - _is: &mut ::protobuf::CodedInputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - unimplemented!(); - } - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - unimplemented!(); + unsafe { INSTANCE.get(SnapshotMetadata::new_) } } } impl Snapshot { @@ -277,7 +188,7 @@ impl Snapshot { pub fn get_metadata(&self) -> &SnapshotMetadata { match self.metadata.as_ref() { Some(v) => v, - None => ::default_instance(), + None => SnapshotMetadata::default_instance(), } } pub fn mut_metadata(&mut self) -> &mut SnapshotMetadata { @@ -291,55 +202,12 @@ impl Snapshot { .take() .unwrap_or_else(|| SnapshotMetadata::default()) } -} -impl ::protobuf::Clear for Snapshot { - fn clear(&mut self) { - ::prost::Message::clear(self); - } -} -impl ::protobuf::Message for Snapshot { - fn compute_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn get_cached_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - fn new() -> Self { - Self::new_() - } - fn write_to_with_cached_sizes( - &self, - _os: &mut ::protobuf::CodedOutputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } fn default_instance() -> &'static Snapshot { static mut INSTANCE: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { lock: ::protobuf::lazy::ONCE_INIT, ptr: 0 as *const Snapshot, }; - unsafe { INSTANCE.get(Snapshot::new) } - } - fn is_initialized(&self) -> bool { - true - } - fn merge_from( - &mut self, - _is: &mut ::protobuf::CodedInputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - unimplemented!(); - } - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - unimplemented!(); + unsafe { INSTANCE.get(Snapshot::new_) } } } impl Message { @@ -435,7 +303,7 @@ impl Message { pub fn get_snapshot(&self) -> &Snapshot { match self.snapshot.as_ref() { Some(v) => v, - None => ::default_instance(), + None => Snapshot::default_instance(), } } pub fn mut_snapshot(&mut self) -> &mut Snapshot { @@ -481,52 +349,6 @@ impl Message { ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) } } -impl ::protobuf::Clear for Message { - fn clear(&mut self) { - ::prost::Message::clear(self); - } -} -impl ::protobuf::Message for Message { - fn compute_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn get_cached_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - fn new() -> Self { - Self::new_() - } - fn write_to_with_cached_sizes( - &self, - _os: &mut ::protobuf::CodedOutputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn default_instance() -> &'static Message { - unimplemented!(); - } - fn is_initialized(&self) -> bool { - true - } - fn merge_from( - &mut self, - _is: &mut ::protobuf::CodedInputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - unimplemented!(); - } - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - unimplemented!(); - } -} impl HardState { pub fn new_() -> HardState { ::std::default::Default::default() @@ -559,52 +381,6 @@ impl HardState { self.commit } } -impl ::protobuf::Clear for HardState { - fn clear(&mut self) { - ::prost::Message::clear(self); - } -} -impl ::protobuf::Message for HardState { - fn compute_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn get_cached_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - fn new() -> Self { - Self::new_() - } - fn write_to_with_cached_sizes( - &self, - _os: &mut ::protobuf::CodedOutputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn default_instance() -> &'static HardState { - unimplemented!(); - } - fn is_initialized(&self) -> bool { - true - } - fn merge_from( - &mut self, - _is: &mut ::protobuf::CodedInputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - unimplemented!(); - } - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - unimplemented!(); - } -} impl ConfState { pub fn new_() -> ConfState { ::std::default::Default::default() @@ -639,51 +415,12 @@ impl ConfState { pub fn take_learners(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.learners, ::std::vec::Vec::new()) } -} -impl ::protobuf::Clear for ConfState { - fn clear(&mut self) { - ::prost::Message::clear(self); - } -} -impl ::protobuf::Message for ConfState { - fn compute_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn get_cached_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - fn new() -> Self { - Self::new_() - } - fn write_to_with_cached_sizes( - &self, - _os: &mut ::protobuf::CodedOutputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } fn default_instance() -> &'static ConfState { - unimplemented!(); - } - fn is_initialized(&self) -> bool { - true - } - fn merge_from( - &mut self, - _is: &mut ::protobuf::CodedInputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - unimplemented!(); - } - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - unimplemented!(); + static mut INSTANCE: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ConfState, + }; + unsafe { INSTANCE.get(ConfState::new_) } } } impl ConfChange { @@ -743,7 +480,7 @@ impl ConfChange { pub fn get_configuration(&self) -> &ConfState { match self.configuration.as_ref() { Some(v) => v, - None => ::default_instance(), + None => ConfState::default_instance(), } } pub fn mut_configuration(&mut self) -> &mut ConfState { @@ -767,49 +504,3 @@ impl ConfChange { self.start_index } } -impl ::protobuf::Clear for ConfChange { - fn clear(&mut self) { - ::prost::Message::clear(self); - } -} -impl ::protobuf::Message for ConfChange { - fn compute_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn get_cached_size(&self) -> u32 { - ::prost::Message::encoded_len(self) as u32 - } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - fn new() -> Self { - Self::new_() - } - fn write_to_with_cached_sizes( - &self, - _os: &mut ::protobuf::CodedOutputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn default_instance() -> &'static ConfChange { - unimplemented!(); - } - fn is_initialized(&self) -> bool { - true - } - fn merge_from( - &mut self, - _is: &mut ::protobuf::CodedInputStream, - ) -> ::protobuf::ProtobufResult<()> { - unimplemented!(); - } - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - unimplemented!(); - } - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - unimplemented!(); - } -} diff --git a/tests/integration_cases/test_membership_changes.rs b/tests/integration_cases/test_membership_changes.rs index de57bce58..7b88130c4 100644 --- a/tests/integration_cases/test_membership_changes.rs +++ b/tests/integration_cases/test_membership_changes.rs @@ -18,8 +18,6 @@ use harness::{setup_for_test, Network}; use hashbrown::{HashMap, HashSet}; use prost::Message as ProstMsg; -use protobuf; -use protobuf::Message as Msg; use raft::{ eraftpb::{ ConfChange, ConfChangeType, ConfState, Entry, EntryType, Message, MessageType, Snapshot, @@ -473,8 +471,8 @@ mod remove_leader { scenario.send(messages); let peer_leader = scenario.peer_leaders(); - assert!(peer_leader[&2] != 1); - assert!(peer_leader[&3] != 1); + assert_ne!(peer_leader[&2], 1); + assert_ne!(peer_leader[&3], 1); Ok(()) } } @@ -1602,7 +1600,7 @@ fn conf_state<'a>( ) -> ConfState { let voters = voters.into_iter().cloned().collect::>(); let learners = learners.into_iter().cloned().collect::>(); - let mut conf_state = ConfState::new(); + let mut conf_state = ConfState::new_(); conf_state.set_nodes(voters); conf_state.set_learners(learners); conf_state @@ -1614,7 +1612,7 @@ fn begin_conf_change<'a>( index: u64, ) -> ConfChange { let conf_state = conf_state(voters, learners); - let mut conf_change = ConfChange::new(); + let mut conf_change = ConfChange::new_(); conf_change.set_change_type(ConfChangeType::BeginMembershipChange); conf_change.set_configuration(conf_state); conf_change.set_start_index(index); @@ -1622,7 +1620,7 @@ fn begin_conf_change<'a>( } fn finalize_conf_change<'a>() -> ConfChange { - let mut conf_change = ConfChange::new(); + let mut conf_change = ConfChange::new_(); conf_change.set_change_type(ConfChangeType::FinalizeMembershipChange); conf_change } @@ -1633,9 +1631,9 @@ fn begin_entry<'a>( index: u64, ) -> Entry { let conf_change = begin_conf_change(voters, learners, index); - let mut data = Vec::with_capacity(conf_change.compute_size() as usize); + let mut data = Vec::with_capacity(ProstMsg::encoded_len(&conf_change)); conf_change.encode(&mut data).unwrap(); - let mut entry = Entry::new(); + let mut entry = Entry::new_(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); entry.set_index(index); @@ -1649,7 +1647,7 @@ fn build_propose_change_message<'a>( index: u64, ) -> Message { let begin_entry = begin_entry(voters, learners, index); - let mut message = Message::new(); + let mut message = Message::new_(); message.set_to(recipient); message.set_msg_type(MessageType::MsgPropose); message.set_index(index); @@ -1659,18 +1657,18 @@ fn build_propose_change_message<'a>( fn build_propose_add_node_message(recipient: u64, added_id: u64, index: u64) -> Message { let add_nodes_entry = { - let mut conf_change = ConfChange::new(); + let mut conf_change = ConfChange::new_(); conf_change.set_change_type(ConfChangeType::AddNode); conf_change.set_node_id(added_id); - let mut data = Vec::with_capacity(conf_change.compute_size() as usize); + let mut data = Vec::with_capacity(ProstMsg::encoded_len(&conf_change)); conf_change.encode(&mut data).unwrap(); - let mut entry = Entry::new(); + let mut entry = Entry::new_(); entry.set_entry_type(EntryType::EntryConfChange); entry.set_data(data); entry.set_index(index); entry }; - let mut message = Message::new(); + let mut message = Message::new_(); message.set_to(recipient); message.set_msg_type(MessageType::MsgPropose); message.set_index(index); diff --git a/tests/integration_cases/test_raft.rs b/tests/integration_cases/test_raft.rs index 74b948510..ad756f389 100644 --- a/tests/integration_cases/test_raft.rs +++ b/tests/integration_cases/test_raft.rs @@ -32,8 +32,6 @@ use std::panic::{self, AssertUnwindSafe}; use harness::*; use hashbrown::HashSet; use prost::Message as ProstMsg; -use protobuf; -use protobuf::Message as Msg; use raft::eraftpb::*; use raft::storage::MemStorage; use raft::*; @@ -62,7 +60,7 @@ fn read_messages(raft: &mut Raft) -> Vec { fn ents_with_config(terms: &[u64], pre_vote: bool) -> Interface { let store = MemStorage::new(); for (i, term) in terms.iter().enumerate() { - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_index(i as u64 + 1); e.set_term(*term); store.wl().append(&[e]).expect(""); @@ -77,12 +75,10 @@ fn assert_raft_log( raft_log: &RaftLog, (committed, applied, last): (u64, u64, u64), ) { - assert!( - raft_log.committed == committed, + assert_eq!( + raft_log.committed, committed, "{}committed = {}, want = {}", - prefix, - raft_log.committed, - committed + prefix, raft_log.committed, committed ); assert!( raft_log.applied == applied, @@ -104,7 +100,7 @@ fn assert_raft_log( // to the given value but no log entries (indicating that it voted in // the given term but has not receive any logs). fn voted_with_config(vote: u64, term: u64, pre_vote: bool) -> Interface { - let mut hard_state = HardState::new(); + let mut hard_state = HardState::new_(); hard_state.set_vote(vote); hard_state.set_term(term); let store = MemStorage::new(); @@ -357,11 +353,11 @@ fn test_progress_paused() { let mut raft = new_test_raft(1, vec![1, 2], 5, 1, new_storage()); raft.become_candidate(); raft.become_leader(); - let mut m = Message::new(); + let mut m = Message::new_(); m.set_from(1); m.set_to(1); m.set_msg_type(MessageType::MsgPropose); - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_data(b"some_data".to_vec()); m.set_entries(vec![e]); raft.step(m.clone()).expect(""); @@ -429,7 +425,7 @@ fn test_leader_election_with_config(pre_vote: bool) { ]; for (i, &mut (ref mut network, state, term)) in tests.iter_mut().enumerate() { - let mut m = Message::new(); + let mut m = Message::new_(); m.set_from(1); m.set_to(1); m.set_msg_type(MessageType::MsgHup); @@ -1107,7 +1103,7 @@ fn test_commit() { store.wl().append(&logs).unwrap(); let cfg = new_test_config(1, 10, 1); let mut sm = new_test_raft_with_config(&cfg, store); - let mut hs = HardState::new(); + let mut hs = HardState::new_(); hs.set_term(sm_term); sm.raft_log.store.wl().set_hardstate(hs); sm.term = sm_term; @@ -1170,7 +1166,7 @@ fn test_pass_election_timeout() { fn test_handle_msg_append() { setup_for_test(); let nm = |term, log_term, index, commit, ents: Option>| { - let mut m = Message::new(); + let mut m = Message::new_(); m.set_msg_type(MessageType::MsgAppend); m.set_term(term); m.set_log_term(log_term); @@ -2321,7 +2317,7 @@ fn test_read_only_for_new_leader() { let storage = MemStorage::new_with_conf_state((vec![1, 2, 3], vec![])); let entries = vec![empty_entry(1, 2), empty_entry(1, 3)]; storage.wl().append(&entries).unwrap(); - let mut hs = HardState::new(); + let mut hs = HardState::new_(); hs.set_term(1); hs.set_commit(committed); storage.wl().set_hardstate(hs); @@ -2876,7 +2872,7 @@ fn test_step_config() { r.become_leader(); let index = r.raft_log.last_index(); let mut m = new_message(1, 1, MessageType::MsgPropose, 0); - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_entry_type(EntryType::EntryConfChange); m.mut_entries().push(e); r.step(m).expect(""); @@ -2895,7 +2891,7 @@ fn test_step_ignore_config() { r.become_leader(); assert!(!r.has_pending_conf()); let mut m = new_message(1, 1, MessageType::MsgPropose, 0); - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_entry_type(EntryType::EntryConfChange); m.mut_entries().push(e); assert!(!r.has_pending_conf()); @@ -2920,7 +2916,7 @@ fn test_new_leader_pending_config() { let mut tests = vec![(false, 1), (true, 2)]; for (i, (add_entry, wpending_index)) in tests.drain(..).enumerate() { let mut r = new_test_raft(1, vec![1, 2], 10, 1, new_storage()); - let mut e = Entry::new(); + let mut e = Entry::new_(); if add_entry { e.set_entry_type(EntryType::EntryNormal); r.append_entry(&mut [e]); @@ -3074,12 +3070,12 @@ fn test_commit_after_remove_node() -> Result<()> { // Begin to remove the second node. let mut m = new_message(0, 0, MessageType::MsgPropose, 0); - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_entry_type(EntryType::EntryConfChange); - let mut cc = ConfChange::new(); + let mut cc = ConfChange::new_(); cc.set_change_type(ConfChangeType::RemoveNode); cc.set_node_id(2); - let mut ccdata = Vec::with_capacity(cc.compute_size() as usize); + let mut ccdata = Vec::with_capacity(ProstMsg::encoded_len(&cc)); cc.encode(&mut ccdata).unwrap(); e.set_data(ccdata); m.mut_entries().push(e); @@ -3772,7 +3768,7 @@ fn test_learner_receive_snapshot() { network.peers.get_mut(&1).unwrap().tick(); } - let mut msg = Message::new(); + let mut msg = Message::new_(); msg.set_from(1); msg.set_to(1); msg.set_msg_type(MessageType::MsgBeat); diff --git a/tests/integration_cases/test_raft_paper.rs b/tests/integration_cases/test_raft_paper.rs index 9ae8bac0c..fd31c29da 100644 --- a/tests/integration_cases/test_raft_paper.rs +++ b/tests/integration_cases/test_raft_paper.rs @@ -27,8 +27,6 @@ use crate::test_util::*; use harness::*; -use protobuf; -use protobuf::Message as Msg; use raft::eraftpb::*; use raft::storage::MemStorage; use raft::*; @@ -888,7 +886,7 @@ fn test_leader_sync_follower_log() { n.send(vec![m]); let mut m = new_message(1, 1, MessageType::MsgPropose, 0); - m.set_entries(vec![Entry::new()]); + m.set_entries(vec![Entry::new_()]); n.send(vec![m]); let lead_str = ltoa(&n.peers[&1].raft_log); let follower_str = ltoa(&n.peers[&2].raft_log); diff --git a/tests/integration_cases/test_raw_node.rs b/tests/integration_cases/test_raw_node.rs index 15f015fae..18521fa63 100644 --- a/tests/integration_cases/test_raw_node.rs +++ b/tests/integration_cases/test_raw_node.rs @@ -27,7 +27,6 @@ use harness::*; use prost::Message as ProstMsg; -use protobuf::{self, Message as Msg}; use raft::eraftpb::*; use raft::storage::MemStorage; use raft::*; @@ -35,7 +34,7 @@ use raft::*; use crate::test_util::*; fn conf_change(t: ConfChangeType, node_id: u64) -> ConfChange { - let mut cc = ConfChange::new(); + let mut cc = ConfChange::new_(); cc.set_change_type(t); cc.set_node_id(node_id); cc @@ -121,7 +120,7 @@ fn test_raw_node_read_index_to_old_leader() { // elect r1 as leader nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); - let mut test_entries = Entry::new(); + let mut test_entries = Entry::new_(); test_entries.set_data(b"testdata".to_vec()); // send readindex request to r2(follower) @@ -189,7 +188,7 @@ fn test_raw_node_propose_and_conf_change() { raw_node.propose(vec![], b"somedata".to_vec()).expect(""); let cc = conf_change(ConfChangeType::AddNode, 2); - ccdata.reserve_exact(cc.compute_size() as usize); + ccdata.reserve_exact(ProstMsg::encoded_len(&cc)); cc.encode(&mut ccdata).unwrap(); raw_node.propose_conf_change(vec![], cc).expect(""); @@ -244,7 +243,7 @@ fn test_raw_node_propose_add_duplicate_node() { }; let cc1 = conf_change(ConfChangeType::AddNode, 1); - let mut ccdata1 = Vec::with_capacity(cc1.compute_size() as usize); + let mut ccdata1 = Vec::with_capacity(ProstMsg::encoded_len(&cc1)); cc1.encode(&mut ccdata1).unwrap(); propose_conf_change_and_apply(cc1.clone()); @@ -253,7 +252,7 @@ fn test_raw_node_propose_add_duplicate_node() { // the new node join should be ok let cc2 = conf_change(ConfChangeType::AddNode, 2); - let mut ccdata2 = Vec::with_capacity(cc2.compute_size() as usize); + let mut ccdata2 = Vec::with_capacity(ProstMsg::encoded_len(&cc2)); cc2.encode(&mut ccdata2).unwrap(); propose_conf_change_and_apply(cc2); @@ -436,7 +435,7 @@ fn test_skip_bcast_commit() { nt.send(vec![new_message(1, 1, MessageType::MsgHup, 0)]); // Without bcast commit, followers will not update its commit index immediately. - let mut test_entries = Entry::new(); + let mut test_entries = Entry::new_(); test_entries.set_data(b"testdata".to_vec()); let msg = new_message_with_entries(1, 1, MessageType::MsgPropose, vec![test_entries.clone()]); nt.send(vec![msg.clone()]); @@ -469,13 +468,13 @@ fn test_skip_bcast_commit() { assert_eq!(nt.peers[&3].raft_log.committed, 5); // When committing conf change, leader should always bcast commit. - let mut cc = ConfChange::new(); + let mut cc = ConfChange::new_(); cc.set_change_type(ConfChangeType::RemoveNode); cc.set_node_id(3); - let mut data = Vec::with_capacity(cc.compute_size() as usize); - data.reserve_exact(cc.compute_size() as usize); + let mut data = Vec::with_capacity(ProstMsg::encoded_len(&cc)); + data.reserve_exact(ProstMsg::encoded_len(&cc)); cc.encode(&mut data).unwrap(); - let mut cc_entry = Entry::new(); + let mut cc_entry = Entry::new_(); cc_entry.set_entry_type(EntryType::EntryConfChange); cc_entry.set_data(data); nt.send(vec![new_message_with_entries( diff --git a/tests/test_util/mod.rs b/tests/test_util/mod.rs index 9081b7add..0ee6b17b3 100644 --- a/tests/test_util/mod.rs +++ b/tests/test_util/mod.rs @@ -26,7 +26,6 @@ // limitations under the License. use harness::*; -use protobuf::Message as Msg; use raft::eraftpb::*; use raft::storage::MemStorage; use raft::*; @@ -119,7 +118,7 @@ pub fn new_test_raft_with_config(config: &Config, storage: MemStorage) -> Interf } pub fn hard_state(t: u64, c: u64, v: u64) -> HardState { - let mut hs = HardState::new(); + let mut hs = HardState::new_(); hs.set_term(t); hs.set_commit(c); hs.set_vote(v); @@ -129,7 +128,7 @@ pub fn hard_state(t: u64, c: u64, v: u64) -> HardState { pub const SOME_DATA: Option<&'static str> = Some("somedata"); pub fn new_message_with_entries(from: u64, to: u64, t: MessageType, ents: Vec) -> Message { - let mut m = Message::new(); + let mut m = Message::new_(); m.set_from(from); m.set_to(to); m.set_msg_type(t); @@ -152,7 +151,7 @@ pub fn new_message(from: u64, to: u64, t: MessageType, n: usize) -> Message { } pub fn new_entry(term: u64, index: u64, data: Option<&str>) -> Entry { - let mut e = Entry::new(); + let mut e = Entry::new_(); e.set_index(index); e.set_term(term); if let Some(d) = data { @@ -166,7 +165,7 @@ pub fn empty_entry(term: u64, index: u64) -> Entry { } pub fn new_snapshot(index: u64, term: u64, nodes: Vec) -> Snapshot { - let mut s = Snapshot::new(); + let mut s = Snapshot::new_(); s.mut_metadata().set_index(index); s.mut_metadata().set_term(term); s.mut_metadata().mut_conf_state().set_nodes(nodes); From 651dfd9490b0563b2b6cc73e043075f749918645 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 12:59:50 -0400 Subject: [PATCH 36/40] Clean up build script Signed-off-by: ice1000 --- build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.rs b/build.rs index e81dd5faf..bbe08b4f0 100644 --- a/build.rs +++ b/build.rs @@ -12,10 +12,9 @@ // limitations under the License. use protobuf_build::*; -use std::fs::{read_dir, remove_file, File}; +use std::fs::{read_dir, File}; use std::io::Write; -#[allow(unused_must_use)] fn main() { // This build script creates files in the `src` directory. Since that is // outside Cargo's OUT_DIR it will cause an error when this crate is used From e56bbe7dd00302d75e2579c4cb3b409b59732bc9 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 16:37:18 -0400 Subject: [PATCH 37/40] Fix clippy warnings Signed-off-by: ice1000 --- build.rs | 5 ++++- src/prost.rs | 1 + src/prost/wrapper_eraftpb.rs | 14 +++++--------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.rs b/build.rs index bbe08b4f0..a76e2c4f0 100644 --- a/build.rs +++ b/build.rs @@ -57,7 +57,10 @@ fn main() { } fn generate_prost_rs(mod_names: &[String]) { - let mut text = "#![allow(dead_code)]\n#![allow(missing_docs)]\n\n".to_owned(); + let mut text = "#![allow(dead_code)]\n\ + #![allow(missing_docs)]\n\ + #![allow(clippy::all)]\n\n" + .to_owned(); for mod_name in mod_names { text.push_str("pub mod "); diff --git a/src/prost.rs b/src/prost.rs index 2b3dba3d7..085a2ed96 100644 --- a/src/prost.rs +++ b/src/prost.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] #![allow(missing_docs)] +#![allow(clippy::all)] pub mod eraftpb { include!("prost/eraftpb.rs"); diff --git a/src/prost/wrapper_eraftpb.rs b/src/prost/wrapper_eraftpb.rs index 5b0c1c71b..2bfd206cd 100644 --- a/src/prost/wrapper_eraftpb.rs +++ b/src/prost/wrapper_eraftpb.rs @@ -94,9 +94,7 @@ impl SnapshotMetadata { self.conf_state.as_mut().unwrap() } pub fn take_conf_state(&mut self) -> ConfState { - self.conf_state - .take() - .unwrap_or_else(|| ConfState::default()) + self.conf_state.take().unwrap_or_else(ConfState::default) } pub fn has_pending_membership_change(&self) -> bool { self.pending_membership_change.is_some() @@ -121,7 +119,7 @@ impl SnapshotMetadata { pub fn take_pending_membership_change(&mut self) -> ConfState { self.pending_membership_change .take() - .unwrap_or_else(|| ConfState::default()) + .unwrap_or_else(ConfState::default) } pub fn clear_pending_membership_change_index(&mut self) { self.pending_membership_change_index = 0 @@ -200,7 +198,7 @@ impl Snapshot { pub fn take_metadata(&mut self) -> SnapshotMetadata { self.metadata .take() - .unwrap_or_else(|| SnapshotMetadata::default()) + .unwrap_or_else(SnapshotMetadata::default) } fn default_instance() -> &'static Snapshot { static mut INSTANCE: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { @@ -313,7 +311,7 @@ impl Message { self.snapshot.as_mut().unwrap() } pub fn take_snapshot(&mut self) -> Snapshot { - self.snapshot.take().unwrap_or_else(|| Snapshot::default()) + self.snapshot.take().unwrap_or_else(Snapshot::default) } pub fn clear_reject(&mut self) { self.reject = false @@ -490,9 +488,7 @@ impl ConfChange { self.configuration.as_mut().unwrap() } pub fn take_configuration(&mut self) -> ConfState { - self.configuration - .take() - .unwrap_or_else(|| ConfState::default()) + self.configuration.take().unwrap_or_else(ConfState::default) } pub fn clear_start_index(&mut self) { self.start_index = 0 From cf52151a9b2a5534235b3cd00d06d3f4f6f7c3bf Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 16:43:35 -0400 Subject: [PATCH 38/40] Use `merge` Signed-off-by: ice1000 --- examples/five_mem_node/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/five_mem_node/main.rs b/examples/five_mem_node/main.rs index 9ee4c68fd..074c0694a 100644 --- a/examples/five_mem_node/main.rs +++ b/examples/five_mem_node/main.rs @@ -223,7 +223,8 @@ fn on_ready( } if let EntryType::EntryConfChange = entry.get_entry_type() { // For conf change messages, make them effective. - let cc = ConfChange::decode(entry.get_data()).unwrap(); + let mut cc = ConfChange::new_(); + ProstMsg::merge(&mut cc, entry.get_data()).unwrap(); let node_id = cc.get_node_id(); match cc.get_change_type() { ConfChangeType::AddNode => raft_group.raft.add_node(node_id).unwrap(), From f2c0219cd7b3065cc9f2d8195fdd64734081bdf9 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 16:46:16 -0400 Subject: [PATCH 39/40] Add rust-protobuf codes back Signed-off-by: ice1000 --- Cargo.toml | 1 + src/prost/wrapper_eraftpb.rs | 540 +++++++++++++++++++++++++++++++++-- 2 files changed, 516 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 42eb05ed0..b951af74c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ failpoint = ["fail"] [dependencies] log = ">0.2" protobuf = "~2.1-2.2" +lazy_static = "1.3.0" prost = "0.5" prost-derive = "0.5" bytes = "0.4.11" diff --git a/src/prost/wrapper_eraftpb.rs b/src/prost/wrapper_eraftpb.rs index 2bfd206cd..562a4a694 100644 --- a/src/prost/wrapper_eraftpb.rs +++ b/src/prost/wrapper_eraftpb.rs @@ -69,6 +69,72 @@ impl Entry { self.sync_log } } +impl ::protobuf::Clear for Entry { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for Entry { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static Entry { + ::lazy_static::lazy_static! { + static ref INSTANCE: Entry = Entry::new_(); + } + &*INSTANCE + } + fn is_initialized(&self) -> bool { + true + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } + fn write_to_bytes(&self) -> ::protobuf::ProtobufResult> { + let mut buf = Vec::new(); + if let Err(_) = ::prost::Message::encode(self, &mut buf) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(buf) + } + fn merge_from_bytes(&mut self, bytes: &[u8]) -> ::protobuf::ProtobufResult<()> { + if let Err(_) = ::prost::Message::merge(self, bytes) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(()) + } +} impl SnapshotMetadata { pub fn new_() -> SnapshotMetadata { ::std::default::Default::default() @@ -80,11 +146,12 @@ impl SnapshotMetadata { self.conf_state = ::std::option::Option::None } pub fn set_conf_state(&mut self, v: ConfState) { - self.conf_state = ::std::option::Option::Some(v);; } + self.conf_state = ::std::option::Option::Some(v); + } pub fn get_conf_state(&self) -> &ConfState { match self.conf_state.as_ref() { Some(v) => v, - None => ConfState::default_instance(), + None => ::default_instance(), } } pub fn mut_conf_state(&mut self) -> &mut ConfState { @@ -103,11 +170,12 @@ impl SnapshotMetadata { self.pending_membership_change = ::std::option::Option::None } pub fn set_pending_membership_change(&mut self, v: ConfState) { - self.pending_membership_change = ::std::option::Option::Some(v);; } + self.pending_membership_change = ::std::option::Option::Some(v); + } pub fn get_pending_membership_change(&self) -> &ConfState { match self.pending_membership_change.as_ref() { Some(v) => v, - None => ConfState::default_instance(), + None => ::default_instance(), } } pub fn mut_pending_membership_change(&mut self) -> &mut ConfState { @@ -148,12 +216,71 @@ impl SnapshotMetadata { pub fn get_term(&self) -> u64 { self.term } +} +impl ::protobuf::Clear for SnapshotMetadata { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for SnapshotMetadata { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } fn default_instance() -> &'static SnapshotMetadata { - static mut INSTANCE: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const SnapshotMetadata, - }; - unsafe { INSTANCE.get(SnapshotMetadata::new_) } + ::lazy_static::lazy_static! { + static ref INSTANCE: SnapshotMetadata = SnapshotMetadata::new_(); + } + &*INSTANCE + } + fn is_initialized(&self) -> bool { + true + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } + fn write_to_bytes(&self) -> ::protobuf::ProtobufResult> { + let mut buf = Vec::new(); + if let Err(_) = ::prost::Message::encode(self, &mut buf) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(buf) + } + fn merge_from_bytes(&mut self, bytes: &[u8]) -> ::protobuf::ProtobufResult<()> { + if let Err(_) = ::prost::Message::merge(self, bytes) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(()) } } impl Snapshot { @@ -182,11 +309,12 @@ impl Snapshot { self.metadata = ::std::option::Option::None } pub fn set_metadata(&mut self, v: SnapshotMetadata) { - self.metadata = ::std::option::Option::Some(v);; } + self.metadata = ::std::option::Option::Some(v); + } pub fn get_metadata(&self) -> &SnapshotMetadata { match self.metadata.as_ref() { Some(v) => v, - None => SnapshotMetadata::default_instance(), + None => ::default_instance(), } } pub fn mut_metadata(&mut self) -> &mut SnapshotMetadata { @@ -200,12 +328,71 @@ impl Snapshot { .take() .unwrap_or_else(SnapshotMetadata::default) } +} +impl ::protobuf::Clear for Snapshot { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for Snapshot { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } fn default_instance() -> &'static Snapshot { - static mut INSTANCE: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Snapshot, - }; - unsafe { INSTANCE.get(Snapshot::new_) } + ::lazy_static::lazy_static! { + static ref INSTANCE: Snapshot = Snapshot::new_(); + } + &*INSTANCE + } + fn is_initialized(&self) -> bool { + true + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } + fn write_to_bytes(&self) -> ::protobuf::ProtobufResult> { + let mut buf = Vec::new(); + if let Err(_) = ::prost::Message::encode(self, &mut buf) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(buf) + } + fn merge_from_bytes(&mut self, bytes: &[u8]) -> ::protobuf::ProtobufResult<()> { + if let Err(_) = ::prost::Message::merge(self, bytes) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(()) } } impl Message { @@ -297,11 +484,12 @@ impl Message { self.snapshot = ::std::option::Option::None } pub fn set_snapshot(&mut self, v: Snapshot) { - self.snapshot = ::std::option::Option::Some(v);; } + self.snapshot = ::std::option::Option::Some(v); + } pub fn get_snapshot(&self) -> &Snapshot { match self.snapshot.as_ref() { Some(v) => v, - None => Snapshot::default_instance(), + None => ::default_instance(), } } pub fn mut_snapshot(&mut self) -> &mut Snapshot { @@ -347,6 +535,72 @@ impl Message { ::std::mem::replace(&mut self.context, ::std::vec::Vec::new()) } } +impl ::protobuf::Clear for Message { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for Message { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static Message { + ::lazy_static::lazy_static! { + static ref INSTANCE: Message = Message::new_(); + } + &*INSTANCE + } + fn is_initialized(&self) -> bool { + true + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } + fn write_to_bytes(&self) -> ::protobuf::ProtobufResult> { + let mut buf = Vec::new(); + if let Err(_) = ::prost::Message::encode(self, &mut buf) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(buf) + } + fn merge_from_bytes(&mut self, bytes: &[u8]) -> ::protobuf::ProtobufResult<()> { + if let Err(_) = ::prost::Message::merge(self, bytes) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(()) + } +} impl HardState { pub fn new_() -> HardState { ::std::default::Default::default() @@ -379,6 +633,72 @@ impl HardState { self.commit } } +impl ::protobuf::Clear for HardState { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for HardState { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static HardState { + ::lazy_static::lazy_static! { + static ref INSTANCE: HardState = HardState::new_(); + } + &*INSTANCE + } + fn is_initialized(&self) -> bool { + true + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } + fn write_to_bytes(&self) -> ::protobuf::ProtobufResult> { + let mut buf = Vec::new(); + if let Err(_) = ::prost::Message::encode(self, &mut buf) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(buf) + } + fn merge_from_bytes(&mut self, bytes: &[u8]) -> ::protobuf::ProtobufResult<()> { + if let Err(_) = ::prost::Message::merge(self, bytes) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(()) + } +} impl ConfState { pub fn new_() -> ConfState { ::std::default::Default::default() @@ -413,12 +733,71 @@ impl ConfState { pub fn take_learners(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.learners, ::std::vec::Vec::new()) } +} +impl ::protobuf::Clear for ConfState { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for ConfState { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } fn default_instance() -> &'static ConfState { - static mut INSTANCE: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ConfState, - }; - unsafe { INSTANCE.get(ConfState::new_) } + ::lazy_static::lazy_static! { + static ref INSTANCE: ConfState = ConfState::new_(); + } + &*INSTANCE + } + fn is_initialized(&self) -> bool { + true + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } + fn write_to_bytes(&self) -> ::protobuf::ProtobufResult> { + let mut buf = Vec::new(); + if let Err(_) = ::prost::Message::encode(self, &mut buf) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(buf) + } + fn merge_from_bytes(&mut self, bytes: &[u8]) -> ::protobuf::ProtobufResult<()> { + if let Err(_) = ::prost::Message::merge(self, bytes) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(()) } } impl ConfChange { @@ -474,11 +853,12 @@ impl ConfChange { self.configuration = ::std::option::Option::None } pub fn set_configuration(&mut self, v: ConfState) { - self.configuration = ::std::option::Option::Some(v);; } + self.configuration = ::std::option::Option::Some(v); + } pub fn get_configuration(&self) -> &ConfState { match self.configuration.as_ref() { Some(v) => v, - None => ConfState::default_instance(), + None => ::default_instance(), } } pub fn mut_configuration(&mut self) -> &mut ConfState { @@ -500,3 +880,113 @@ impl ConfChange { self.start_index } } +impl ::protobuf::Clear for ConfChange { + fn clear(&mut self) { + ::prost::Message::clear(self); + } +} +impl ::protobuf::Message for ConfChange { + fn compute_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn get_cached_size(&self) -> u32 { + ::prost::Message::encoded_len(self) as u32 + } + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + fn new() -> Self { + Self::new_() + } + fn write_to_with_cached_sizes( + &self, + _os: &mut ::protobuf::CodedOutputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn default_instance() -> &'static ConfChange { + ::lazy_static::lazy_static! { + static ref INSTANCE: ConfChange = ConfChange::new_(); + } + &*INSTANCE + } + fn is_initialized(&self) -> bool { + true + } + fn merge_from( + &mut self, + _is: &mut ::protobuf::CodedInputStream, + ) -> ::protobuf::ProtobufResult<()> { + unimplemented!(); + } + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + unimplemented!(); + } + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + unimplemented!(); + } + fn write_to_bytes(&self) -> ::protobuf::ProtobufResult> { + let mut buf = Vec::new(); + if let Err(_) = ::prost::Message::encode(self, &mut buf) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(buf) + } + fn merge_from_bytes(&mut self, bytes: &[u8]) -> ::protobuf::ProtobufResult<()> { + if let Err(_) = ::prost::Message::merge(self, bytes) { + return Err(::protobuf::ProtobufError::WireError( + ::protobuf::error::WireError::Other, + )); + } + Ok(()) + } +} +impl EntryType { + pub fn values() -> &'static [Self] { + static VALUES: &'static [EntryType] = &[EntryType::EntryNormal, EntryType::EntryConfChange]; + VALUES + } +} +impl MessageType { + pub fn values() -> &'static [Self] { + static VALUES: &'static [MessageType] = &[ + MessageType::MsgHup, + MessageType::MsgBeat, + MessageType::MsgPropose, + MessageType::MsgAppend, + MessageType::MsgAppendResponse, + MessageType::MsgRequestVote, + MessageType::MsgRequestVoteResponse, + MessageType::MsgSnapshot, + MessageType::MsgHeartbeat, + MessageType::MsgHeartbeatResponse, + MessageType::MsgUnreachable, + MessageType::MsgSnapStatus, + MessageType::MsgCheckQuorum, + MessageType::MsgTransferLeader, + MessageType::MsgTimeoutNow, + MessageType::MsgReadIndex, + MessageType::MsgReadIndexResp, + MessageType::MsgRequestPreVote, + MessageType::MsgRequestPreVoteResponse, + ]; + VALUES + } +} +impl ConfChangeType { + pub fn values() -> &'static [Self] { + static VALUES: &'static [ConfChangeType] = &[ + ConfChangeType::AddNode, + ConfChangeType::RemoveNode, + ConfChangeType::AddLearnerNode, + ConfChangeType::BeginMembershipChange, + ConfChangeType::FinalizeMembershipChange, + ]; + VALUES + } +} From f2dce7691832c81904f4b1e59801b3054ec235e6 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Thu, 4 Apr 2019 17:52:00 -0400 Subject: [PATCH 40/40] Revert unexpected comment changes Signed-off-by: ice1000 --- src/storage.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage.rs b/src/storage.rs index 88a778a95..0718d177a 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -82,7 +82,7 @@ impl RaftState { /// Storage saves all the information about the current Raft implementation, including Raft Log, /// commit index, the leader to vote for, etc. /// -/// If any Storage method returns an error, the raft INSTANCE will +/// If any Storage method returns an error, the raft instance will /// become inoperable and refuse to participate in elections; the /// application is responsible for cleanup and recovery in this case. pub trait Storage { @@ -124,7 +124,7 @@ pub trait Storage { fn snapshot(&self) -> Result; } -/// The Memory Storage Core INSTANCE holds the actual state of the storage struct. To access this +/// The Memory Storage Core instance holds the actual state of the storage struct. To access this /// value, use the `rl` and `wl` functions on the main MemStorage implementation. pub struct MemStorageCore { raft_state: RaftState,