这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/cluster_mode.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ <h2><a class="header" href="#starting-in-cluster-mode-3-node-cluster" id="starti
<p>The above commands run servers on the same host, so each server must listen on a different port. This would not be necessary if each server runs on a different host.
Recommend 3 or more odd number of servers in the cluster to avoid split-brain.<br />
When deploying to a single host, if that host goes down due to hardware failure, all of the servers in the cluster will be stopped, so recommend deploying to a different host.</p>
<h2><a class="header" href="#cluster-peers" id="cluster-peers">Cluster peers</a></h2>
<p>You can check the peers in the cluster with the following command:</p>
<pre><code class="language-shellscript">./bin/bayard peers --servers localhost:5001 | jq .
</code></pre>
<p>You'll see the result in JSON format. The result of the above command is:</p>
<pre><code class="language-json">{
&quot;1&quot;: &quot;0.0.0.0:5001&quot;,
&quot;2&quot;: &quot;0.0.0.0:5002&quot;,
&quot;3&quot;: &quot;0.0.0.0:5003&quot;
}
</code></pre>
<h2><a class="header" href="#remove-a-server-from-a-cluster" id="remove-a-server-from-a-cluster">Remove a server from a cluster</a></h2>
<p>If one of the servers in a cluster goes down due to a hardware failure and raft logs and metadata is lost, that server cannot join the cluster again.<br />
If you want the server to join the cluster again, you must remove it from the cluster.<br />
Expand Down
11 changes: 11 additions & 0 deletions docs/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ <h2><a class="header" href="#starting-in-cluster-mode-3-node-cluster" id="starti
<p>The above commands run servers on the same host, so each server must listen on a different port. This would not be necessary if each server runs on a different host.
Recommend 3 or more odd number of servers in the cluster to avoid split-brain.<br />
When deploying to a single host, if that host goes down due to hardware failure, all of the servers in the cluster will be stopped, so recommend deploying to a different host.</p>
<h2><a class="header" href="#cluster-peers" id="cluster-peers">Cluster peers</a></h2>
<p>You can check the peers in the cluster with the following command:</p>
<pre><code class="language-shellscript">./bin/bayard peers --servers localhost:5001 | jq .
</code></pre>
<p>You'll see the result in JSON format. The result of the above command is:</p>
<pre><code class="language-json">{
&quot;1&quot;: &quot;0.0.0.0:5001&quot;,
&quot;2&quot;: &quot;0.0.0.0:5002&quot;,
&quot;3&quot;: &quot;0.0.0.0:5003&quot;
}
</code></pre>
<h2><a class="header" href="#remove-a-server-from-a-cluster" id="remove-a-server-from-a-cluster">Remove a server from a cluster</a></h2>
<p>If one of the servers in a cluster goes down due to a hardware failure and raft logs and metadata is lost, that server cannot join the cluster again.<br />
If you want the server to join the cluster again, you must remove it from the cluster.<br />
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/searchindex.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions docs_src/cluster_mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ The above commands run servers on the same host, so each server must listen on a
Recommend 3 or more odd number of servers in the cluster to avoid split-brain.
When deploying to a single host, if that host goes down due to hardware failure, all of the servers in the cluster will be stopped, so recommend deploying to a different host.

## Cluster peers

You can check the peers in the cluster with the following command:

```shell script
./bin/bayard peers --servers localhost:5001 | jq .
```

You'll see the result in JSON format. The result of the above command is:

```json
{
"1": "0.0.0.0:5001",
"2": "0.0.0.0:5002",
"3": "0.0.0.0:5003"
}
```

## Remove a server from a cluster

If one of the servers in a cluster goes down due to a hardware failure and raft logs and metadata is lost, that server cannot join the cluster again.
Expand Down
2 changes: 1 addition & 1 deletion proto/indexpb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ service Index {
}
rpc RaftConfChange (indexrpcpb.ConfChangeReq) returns (indexrpcpb.RaftDone) {
}
rpc Status (indexrpcpb.IndexReq) returns (indexrpcpb.StatusResp) {
rpc Peers (indexrpcpb.IndexReq) returns (indexrpcpb.PeersResp) {
}
}
4 changes: 2 additions & 2 deletions proto/indexrpcpb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum ReqType {
Search = 3;
Join = 4;
Leave = 5;
Status = 6;
Peers = 6;
}

message IndexReq {
Expand All @@ -36,7 +36,7 @@ message ConfChangeReq {
uint32 port = 3;
}

message StatusResp {
message PeersResp {
string value = 1;
RespErr err = 2;
}
Expand Down
12 changes: 6 additions & 6 deletions src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use raft::eraftpb::{ConfChange, ConfChangeType};

use crate::proto::indexpb_grpc::IndexClient;
use crate::proto::indexrpcpb::{
ConfChangeReq, DeleteResp, GetResp, IndexReq, PutResp, RaftDone, ReqType, RespErr, SearchResp,
StatusResp,
ConfChangeReq, DeleteResp, GetResp, IndexReq, PeersResp, PutResp, RaftDone, ReqType, RespErr,
SearchResp,
};

pub fn create_client(addr: &str) -> IndexClient {
Expand Down Expand Up @@ -194,18 +194,18 @@ impl Clerk {
}
}

pub fn status(&mut self) -> String {
pub fn peers(&mut self) -> String {
let mut req = IndexReq::new();
req.set_client_id(self.client_id);
req.set_req_type(ReqType::Status);
req.set_req_type(ReqType::Peers);
req.set_seq(self.request_seq);
self.request_seq += 1;

loop {
let reply = self.servers[self.leader_id]
.status(&req)
.peers(&req)
.unwrap_or_else(|_e| {
let mut resp = StatusResp::new();
let mut resp = PeersResp::new();
resp.set_err(RespErr::ErrWrongLeader);
resp
});
Expand Down
2 changes: 1 addition & 1 deletion src/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod delete;
pub mod get;
pub mod leave;
pub mod peers;
pub mod search;
pub mod serve;
pub mod set;
pub mod status;
4 changes: 2 additions & 2 deletions src/cmd/status.rs → src/cmd/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::ArgMatches;
use crate::client::client::{create_client, Clerk};
use crate::util::log::set_logger;

pub fn run_status_cli(matches: &ArgMatches) -> Result<(), String> {
pub fn run_peers_cli(matches: &ArgMatches) -> Result<(), String> {
set_logger();

let servers: Vec<_> = matches
Expand All @@ -15,7 +15,7 @@ pub fn run_status_cli(matches: &ArgMatches) -> Result<(), String> {
let client_id = rand::random();

let mut client = Clerk::new(&servers, client_id);
let value = client.status();
let value = client.peers();
print!("{}", value);

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use serde_json;
use tantivy::schema::Schema;
use tantivy::Index;

use crate::client::client::{create_client, Clerk};
use crate::proto::indexpb_grpc::IndexClient;
use crate::client::client::create_client;
use crate::server::server::IndexServer;
use crate::util::log::set_logger;

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use clap::{App, AppSettings, Arg, SubCommand};
use bayard::cmd::delete::run_delete_cli;
use bayard::cmd::get::run_get_cli;
use bayard::cmd::leave::run_leave_cli;
use bayard::cmd::peers::run_peers_cli;
use bayard::cmd::search::run_search_cli;
use bayard::cmd::serve::run_serve_cli;
use bayard::cmd::set::run_set_cli;
use bayard::cmd::status::run_status_cli;

fn main() {
let app = App::new(crate_name!())
Expand Down Expand Up @@ -105,12 +105,12 @@ fn main() {
)
)
.subcommand(
SubCommand::with_name("status")
.name("status")
SubCommand::with_name("peers")
.name("peers")
.setting(AppSettings::DeriveDisplayOrder)
.version(crate_version!())
.author(crate_authors!())
.about("Get cluster status")
.about("Get cluster peers")
.arg(
Arg::with_name("SERVERS")
.help("The server addresses. Use `,` to separate address. Example: `127.0.0.1:5000,127.0.0.1:5001`")
Expand Down Expand Up @@ -304,7 +304,7 @@ fn main() {
let options = some_options.unwrap();
let run_cli = match subcommand {
"serve" => run_serve_cli,
"status" => run_status_cli,
"peers" => run_peers_cli,
"leave" => run_leave_cli,
"set" => run_set_cli,
"get" => run_get_cli,
Expand Down
52 changes: 26 additions & 26 deletions src/proto/indexpb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@ const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_0;

static file_descriptor_proto_data: &'static [u8] = b"\
\n\rindexpb.proto\x12\x07indexpb\x1a\x10indexrpcpb.proto\x1a\reraftpb.pr\
oto2\x94\x03\n\x05Index\x122\n\x03Get\x12\x14.indexrpcpb.IndexReq\x1a\
oto2\x92\x03\n\x05Index\x122\n\x03Get\x12\x14.indexrpcpb.IndexReq\x1a\
\x13.indexrpcpb.GetResp\"\0\x122\n\x03Put\x12\x14.indexrpcpb.IndexReq\
\x1a\x13.indexrpcpb.PutResp\"\0\x128\n\x06Delete\x12\x14.indexrpcpb.Inde\
xReq\x1a\x16.indexrpcpb.DeleteResp\"\0\x128\n\x06Search\x12\x14.indexrpc\
pb.IndexReq\x1a\x16.indexrpcpb.SearchResp\"\0\x120\n\x04Raft\x12\x10.era\
ftpb.Message\x1a\x14.indexrpcpb.RaftDone\"\0\x12C\n\x0eRaftConfChange\
\x12\x19.indexrpcpb.ConfChangeReq\x1a\x14.indexrpcpb.RaftDone\"\0\x128\n\
\x06Status\x12\x14.indexrpcpb.IndexReq\x1a\x16.indexrpcpb.StatusResp\"\0\
J\xd2\x03\n\x06\x12\x04\0\0\x15\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\
\x08\n\x01\x02\x12\x03\x01\0\x10\n\t\n\x02\x03\0\x12\x03\x03\0\x1a\n\t\n\
\x02\x03\x01\x12\x03\x04\0\x17\n\n\n\x02\x06\0\x12\x04\x06\0\x15\x01\n\n\
\n\x03\x06\0\x01\x12\x03\x06\x08\r\n\x0c\n\x04\x06\0\x02\0\x12\x04\x07\
\x04\x08\x05\n\x0c\n\x05\x06\0\x02\0\x01\x12\x03\x07\x08\x0b\n\x0c\n\x05\
\x06\0\x02\0\x02\x12\x03\x07\r\x20\n\x0c\n\x05\x06\0\x02\0\x03\x12\x03\
\x07+=\n\x0c\n\x04\x06\0\x02\x01\x12\x04\t\x04\n\x05\n\x0c\n\x05\x06\0\
\x02\x01\x01\x12\x03\t\x08\x0b\n\x0c\n\x05\x06\0\x02\x01\x02\x12\x03\t\r\
\x20\n\x0c\n\x05\x06\0\x02\x01\x03\x12\x03\t+=\n\x0c\n\x04\x06\0\x02\x02\
\x12\x04\x0b\x04\x0c\x05\n\x0c\n\x05\x06\0\x02\x02\x01\x12\x03\x0b\x08\
\x0e\n\x0c\n\x05\x06\0\x02\x02\x02\x12\x03\x0b\x10#\n\x0c\n\x05\x06\0\
\x02\x02\x03\x12\x03\x0b.C\n\x0c\n\x04\x06\0\x02\x03\x12\x04\r\x04\x0e\
\x05\n\x0c\n\x05\x06\0\x02\x03\x01\x12\x03\r\x08\x0e\n\x0c\n\x05\x06\0\
\x02\x03\x02\x12\x03\r\x10#\n\x0c\n\x05\x06\0\x02\x03\x03\x12\x03\r.C\n\
\x0c\n\x04\x06\0\x02\x04\x12\x04\x0f\x04\x10\x05\n\x0c\n\x05\x06\0\x02\
\x04\x01\x12\x03\x0f\x08\x0c\n\x0c\n\x05\x06\0\x02\x04\x02\x12\x03\x0f\
\x0e\x1d\n\x0c\n\x05\x06\0\x02\x04\x03\x12\x03\x0f(;\n\x0c\n\x04\x06\0\
\x02\x05\x12\x04\x11\x04\x12\x05\n\x0c\n\x05\x06\0\x02\x05\x01\x12\x03\
\x11\x08\x16\n\x0c\n\x05\x06\0\x02\x05\x02\x12\x03\x11\x180\n\x0c\n\x05\
\x06\0\x02\x05\x03\x12\x03\x11;N\n\x0c\n\x04\x06\0\x02\x06\x12\x04\x13\
\x04\x14\x05\n\x0c\n\x05\x06\0\x02\x06\x01\x12\x03\x13\x08\x0e\n\x0c\n\
\x05\x06\0\x02\x06\x02\x12\x03\x13\x10#\n\x0c\n\x05\x06\0\x02\x06\x03\
\x12\x03\x13.Cb\x06proto3\
\x12\x19.indexrpcpb.ConfChangeReq\x1a\x14.indexrpcpb.RaftDone\"\0\x126\n\
\x05Peers\x12\x14.indexrpcpb.IndexReq\x1a\x15.indexrpcpb.PeersResp\"\0J\
\xd2\x03\n\x06\x12\x04\0\0\x15\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\x08\
\n\x01\x02\x12\x03\x01\0\x10\n\t\n\x02\x03\0\x12\x03\x03\0\x1a\n\t\n\x02\
\x03\x01\x12\x03\x04\0\x17\n\n\n\x02\x06\0\x12\x04\x06\0\x15\x01\n\n\n\
\x03\x06\0\x01\x12\x03\x06\x08\r\n\x0c\n\x04\x06\0\x02\0\x12\x04\x07\x04\
\x08\x05\n\x0c\n\x05\x06\0\x02\0\x01\x12\x03\x07\x08\x0b\n\x0c\n\x05\x06\
\0\x02\0\x02\x12\x03\x07\r\x20\n\x0c\n\x05\x06\0\x02\0\x03\x12\x03\x07+=\
\n\x0c\n\x04\x06\0\x02\x01\x12\x04\t\x04\n\x05\n\x0c\n\x05\x06\0\x02\x01\
\x01\x12\x03\t\x08\x0b\n\x0c\n\x05\x06\0\x02\x01\x02\x12\x03\t\r\x20\n\
\x0c\n\x05\x06\0\x02\x01\x03\x12\x03\t+=\n\x0c\n\x04\x06\0\x02\x02\x12\
\x04\x0b\x04\x0c\x05\n\x0c\n\x05\x06\0\x02\x02\x01\x12\x03\x0b\x08\x0e\n\
\x0c\n\x05\x06\0\x02\x02\x02\x12\x03\x0b\x10#\n\x0c\n\x05\x06\0\x02\x02\
\x03\x12\x03\x0b.C\n\x0c\n\x04\x06\0\x02\x03\x12\x04\r\x04\x0e\x05\n\x0c\
\n\x05\x06\0\x02\x03\x01\x12\x03\r\x08\x0e\n\x0c\n\x05\x06\0\x02\x03\x02\
\x12\x03\r\x10#\n\x0c\n\x05\x06\0\x02\x03\x03\x12\x03\r.C\n\x0c\n\x04\
\x06\0\x02\x04\x12\x04\x0f\x04\x10\x05\n\x0c\n\x05\x06\0\x02\x04\x01\x12\
\x03\x0f\x08\x0c\n\x0c\n\x05\x06\0\x02\x04\x02\x12\x03\x0f\x0e\x1d\n\x0c\
\n\x05\x06\0\x02\x04\x03\x12\x03\x0f(;\n\x0c\n\x04\x06\0\x02\x05\x12\x04\
\x11\x04\x12\x05\n\x0c\n\x05\x06\0\x02\x05\x01\x12\x03\x11\x08\x16\n\x0c\
\n\x05\x06\0\x02\x05\x02\x12\x03\x11\x180\n\x0c\n\x05\x06\0\x02\x05\x03\
\x12\x03\x11;N\n\x0c\n\x04\x06\0\x02\x06\x12\x04\x13\x04\x14\x05\n\x0c\n\
\x05\x06\0\x02\x06\x01\x12\x03\x13\x08\r\n\x0c\n\x05\x06\0\x02\x06\x02\
\x12\x03\x13\x0f\"\n\x0c\n\x05\x06\0\x02\x06\x03\x12\x03\x13-Ab\x06proto\
3\
";

static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy {
Expand Down
26 changes: 13 additions & 13 deletions src/proto/indexpb_grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const METHOD_INDEX_RAFT_CONF_CHANGE: ::grpcio::Method<super::indexrpcpb::ConfCha
resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de },
};

const METHOD_INDEX_STATUS: ::grpcio::Method<super::indexrpcpb::IndexReq, super::indexrpcpb::StatusResp> = ::grpcio::Method {
const METHOD_INDEX_PEERS: ::grpcio::Method<super::indexrpcpb::IndexReq, super::indexrpcpb::PeersResp> = ::grpcio::Method {
ty: ::grpcio::MethodType::Unary,
name: "/indexpb.Index/Status",
name: "/indexpb.Index/Peers",
req_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de },
resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pb_ser, de: ::grpcio::pb_de },
};
Expand Down Expand Up @@ -175,20 +175,20 @@ impl IndexClient {
self.raft_conf_change_async_opt(req, ::grpcio::CallOption::default())
}

pub fn status_opt(&self, req: &super::indexrpcpb::IndexReq, opt: ::grpcio::CallOption) -> ::grpcio::Result<super::indexrpcpb::StatusResp> {
self.client.unary_call(&METHOD_INDEX_STATUS, req, opt)
pub fn peers_opt(&self, req: &super::indexrpcpb::IndexReq, opt: ::grpcio::CallOption) -> ::grpcio::Result<super::indexrpcpb::PeersResp> {
self.client.unary_call(&METHOD_INDEX_PEERS, req, opt)
}

pub fn status(&self, req: &super::indexrpcpb::IndexReq) -> ::grpcio::Result<super::indexrpcpb::StatusResp> {
self.status_opt(req, ::grpcio::CallOption::default())
pub fn peers(&self, req: &super::indexrpcpb::IndexReq) -> ::grpcio::Result<super::indexrpcpb::PeersResp> {
self.peers_opt(req, ::grpcio::CallOption::default())
}

pub fn status_async_opt(&self, req: &super::indexrpcpb::IndexReq, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::indexrpcpb::StatusResp>> {
self.client.unary_call_async(&METHOD_INDEX_STATUS, req, opt)
pub fn peers_async_opt(&self, req: &super::indexrpcpb::IndexReq, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::indexrpcpb::PeersResp>> {
self.client.unary_call_async(&METHOD_INDEX_PEERS, req, opt)
}

pub fn status_async(&self, req: &super::indexrpcpb::IndexReq) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::indexrpcpb::StatusResp>> {
self.status_async_opt(req, ::grpcio::CallOption::default())
pub fn peers_async(&self, req: &super::indexrpcpb::IndexReq) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<super::indexrpcpb::PeersResp>> {
self.peers_async_opt(req, ::grpcio::CallOption::default())
}
pub fn spawn<F>(&self, f: F) where F: ::futures::Future<Item = (), Error = ()> + Send + 'static {
self.client.spawn(f)
Expand All @@ -202,7 +202,7 @@ pub trait Index {
fn search(&mut self, ctx: ::grpcio::RpcContext, req: super::indexrpcpb::IndexReq, sink: ::grpcio::UnarySink<super::indexrpcpb::SearchResp>);
fn raft(&mut self, ctx: ::grpcio::RpcContext, req: super::eraftpb::Message, sink: ::grpcio::UnarySink<super::indexrpcpb::RaftDone>);
fn raft_conf_change(&mut self, ctx: ::grpcio::RpcContext, req: super::indexrpcpb::ConfChangeReq, sink: ::grpcio::UnarySink<super::indexrpcpb::RaftDone>);
fn status(&mut self, ctx: ::grpcio::RpcContext, req: super::indexrpcpb::IndexReq, sink: ::grpcio::UnarySink<super::indexrpcpb::StatusResp>);
fn peers(&mut self, ctx: ::grpcio::RpcContext, req: super::indexrpcpb::IndexReq, sink: ::grpcio::UnarySink<super::indexrpcpb::PeersResp>);
}

pub fn create_index<S: Index + Send + Clone + 'static>(s: S) -> ::grpcio::Service {
Expand Down Expand Up @@ -232,8 +232,8 @@ pub fn create_index<S: Index + Send + Clone + 'static>(s: S) -> ::grpcio::Servic
instance.raft_conf_change(ctx, req, resp)
});
let mut instance = s.clone();
builder = builder.add_unary_handler(&METHOD_INDEX_STATUS, move |ctx, req, resp| {
instance.status(ctx, req, resp)
builder = builder.add_unary_handler(&METHOD_INDEX_PEERS, move |ctx, req, resp| {
instance.peers(ctx, req, resp)
});
builder.build()
}
Loading