这是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
30 changes: 30 additions & 0 deletions docs/getting_started.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,36 @@ <h2><a class="header" href="#starting-in-standalone-mode-single-node-cluster" id
[2019-11-11T09:28:26Z INFO raft::raft] received MsgRequestVoteResponse from 1 at term 2
[2019-11-11T09:28:26Z INFO raft::raft] became leader at term 2
</code></pre>
<h2><a class="header" href="#getting-schema" id="getting-schema">Getting schema</a></h2>
<p>You can confirm current schema with the following command:</p>
<pre><code class="language-shellscript">./bin/bayard schema | 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;name&quot;: &quot;id&quot;,
&quot;type&quot;: &quot;text&quot;,
&quot;options&quot;: {
&quot;indexing&quot;: {
&quot;record&quot;: &quot;basic&quot;,
&quot;tokenizer&quot;: &quot;raw&quot;
},
&quot;stored&quot;: true
}
},
{
&quot;name&quot;: &quot;text&quot;,
&quot;type&quot;: &quot;text&quot;,
&quot;options&quot;: {
&quot;indexing&quot;: {
&quot;record&quot;: &quot;position&quot;,
&quot;tokenizer&quot;: &quot;en_stem&quot;
},
&quot;stored&quot;: true
}
}
]
</code></pre>
<h2><a class="header" href="#indexing-document" id="indexing-document">Indexing document</a></h2>
<p>You can index documents with the following command:</p>
<pre><code class="language-shellscript">./bin/bayard set 1 '{&quot;text&quot;:&quot;Tantivy is a full-text search engine library inspired by Apache Lucene and written in Rust.&quot;}'
Expand Down
30 changes: 30 additions & 0 deletions docs/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,36 @@ <h2><a class="header" href="#starting-in-standalone-mode-single-node-cluster" id
[2019-11-11T09:28:26Z INFO raft::raft] received MsgRequestVoteResponse from 1 at term 2
[2019-11-11T09:28:26Z INFO raft::raft] became leader at term 2
</code></pre>
<h2><a class="header" href="#getting-schema" id="getting-schema">Getting schema</a></h2>
<p>You can confirm current schema with the following command:</p>
<pre><code class="language-shellscript">./bin/bayard schema | 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;name&quot;: &quot;id&quot;,
&quot;type&quot;: &quot;text&quot;,
&quot;options&quot;: {
&quot;indexing&quot;: {
&quot;record&quot;: &quot;basic&quot;,
&quot;tokenizer&quot;: &quot;raw&quot;
},
&quot;stored&quot;: true
}
},
{
&quot;name&quot;: &quot;text&quot;,
&quot;type&quot;: &quot;text&quot;,
&quot;options&quot;: {
&quot;indexing&quot;: {
&quot;record&quot;: &quot;position&quot;,
&quot;tokenizer&quot;: &quot;en_stem&quot;
},
&quot;stored&quot;: true
}
}
]
</code></pre>
<h2><a class="header" href="#indexing-document" id="indexing-document">Indexing document</a></h2>
<p>You can index documents with the following command:</p>
<pre><code class="language-shellscript">./bin/bayard set 1 '{&quot;text&quot;:&quot;Tantivy is a full-text search engine library inspired by Apache Lucene and written in Rust.&quot;}'
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.

37 changes: 37 additions & 0 deletions docs_src/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,43 @@ You'll see a startup message like following:
[2019-11-11T09:28:26Z INFO raft::raft] became leader at term 2
```

## Getting schema

You can confirm current schema with the following command:

```shell script
./bin/bayard schema | jq .
```

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

```json
[
{
"name": "id",
"type": "text",
"options": {
"indexing": {
"record": "basic",
"tokenizer": "raw"
},
"stored": true
}
},
{
"name": "text",
"type": "text",
"options": {
"indexing": {
"record": "position",
"tokenizer": "en_stem"
},
"stored": true
}
}
]
```

## Indexing document

You can index documents with the following command:
Expand Down
12 changes: 7 additions & 5 deletions proto/indexpb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import "indexrpcpb.proto";
import "eraftpb.proto";

service Index {
rpc Raft (eraftpb.Message) returns (indexrpcpb.RaftDone) {
}
rpc RaftConfChange (indexrpcpb.ConfChangeReq) returns (indexrpcpb.RaftDone) {
}
rpc Peers (indexrpcpb.IndexReq) returns (indexrpcpb.PeersResp) {
}
rpc Get (indexrpcpb.IndexReq) returns (indexrpcpb.GetResp) {
}
rpc Put (indexrpcpb.IndexReq) returns (indexrpcpb.PutResp) {
Expand All @@ -13,10 +19,6 @@ service Index {
}
rpc Search (indexrpcpb.IndexReq) returns (indexrpcpb.SearchResp) {
}
rpc Raft (eraftpb.Message) returns (indexrpcpb.RaftDone) {
}
rpc RaftConfChange (indexrpcpb.ConfChangeReq) returns (indexrpcpb.RaftDone) {
}
rpc Peers (indexrpcpb.IndexReq) returns (indexrpcpb.PeersResp) {
rpc Schema (indexrpcpb.IndexReq) returns (indexrpcpb.SchemaResp) {
}
}
34 changes: 20 additions & 14 deletions proto/indexrpcpb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ enum ReqType {
Put = 1;
Delete = 2;
Search = 3;
Join = 4;
Leave = 5;
Peers = 6;
Schema = 4;
Join = 5;
Leave = 6;
Peers = 7;
}

message IndexReq {
Expand All @@ -30,17 +31,6 @@ message IndexReq {
string query = 8;
}

message ConfChangeReq {
eraftpb.ConfChange cc = 1;
string ip = 2;
uint32 port = 3;
}

message PeersResp {
string value = 1;
RespErr err = 2;
}

message GetResp {
string value = 1;
RespErr err = 2;
Expand All @@ -59,6 +49,22 @@ message SearchResp {
RespErr err = 2;
}

message SchemaResp {
string value = 1;
RespErr err = 2;
}

message ConfChangeReq {
eraftpb.ConfChange cc = 1;
string ip = 2;
uint32 port = 3;
}

message PeersResp {
string value = 1;
RespErr err = 2;
}

message RaftDone {
RespErr err = 1;
}
147 changes: 86 additions & 61 deletions src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use raft::eraftpb::{ConfChange, ConfChangeType};
use crate::proto::indexpb_grpc::IndexClient;
use crate::proto::indexrpcpb::{
ConfChangeReq, DeleteResp, GetResp, IndexReq, PeersResp, PutResp, RaftDone, ReqType, RespErr,
SearchResp,
SchemaResp, SearchResp,
};

pub fn create_client(addr: &str) -> IndexClient {
Expand All @@ -36,6 +36,87 @@ impl Clerk {
}
}

pub fn join(&mut self, id: u64, ip: &str, port: u16) {
let mut cc = ConfChange::new();
cc.set_id(id);
cc.set_node_id(id);
cc.set_change_type(ConfChangeType::AddNode);
let mut req = ConfChangeReq::new();
req.set_cc(cc);
req.set_ip(ip.to_string());
req.set_port(port as u32);

loop {
let reply = self.servers[self.leader_id]
.raft_conf_change(&req)
.unwrap_or_else(|e| {
error!("{:?}", e);
let mut resp = RaftDone::new();
resp.set_err(RespErr::ErrWrongLeader);
resp
});
match reply.err {
RespErr::OK => return,
RespErr::ErrWrongLeader => (),
RespErr::ErrNoKey => return,
}
self.leader_id = (self.leader_id + 1) % self.servers.len();
thread::sleep(Duration::from_millis(100));
}
}

pub fn leave(&mut self, id: u64) {
let mut cc = ConfChange::new();
cc.set_id(id);
cc.set_node_id(id);
cc.set_change_type(ConfChangeType::RemoveNode);
let mut req = ConfChangeReq::new();
req.set_cc(cc);

loop {
let reply = self.servers[self.leader_id]
.raft_conf_change(&req)
.unwrap_or_else(|e| {
error!("{:?}", e);
let mut resp = RaftDone::new();
resp.set_err(RespErr::ErrWrongLeader);
resp
});
match reply.err {
RespErr::OK => return,
RespErr::ErrWrongLeader => (),
RespErr::ErrNoKey => return,
}
self.leader_id = (self.leader_id + 1) % self.servers.len();
thread::sleep(Duration::from_millis(100));
}
}

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

loop {
let reply = self.servers[self.leader_id]
.peers(&req)
.unwrap_or_else(|_e| {
let mut resp = PeersResp::new();
resp.set_err(RespErr::ErrWrongLeader);
resp
});
match reply.err {
RespErr::OK => return reply.value,
RespErr::ErrWrongLeader => (),
RespErr::ErrNoKey => return String::from(""),
}
self.leader_id = (self.leader_id + 1) % self.servers.len();
thread::sleep(Duration::from_millis(100));
}
}

pub fn get(&mut self, key: &str) -> String {
let mut req = IndexReq::new();
req.set_client_id(self.client_id);
Expand Down Expand Up @@ -138,74 +219,18 @@ impl Clerk {
}
}

pub fn join(&mut self, id: u64, ip: &str, port: u16) {
let mut cc = ConfChange::new();
cc.set_id(id);
cc.set_node_id(id);
cc.set_change_type(ConfChangeType::AddNode);
let mut req = ConfChangeReq::new();
req.set_cc(cc);
req.set_ip(ip.to_string());
req.set_port(port as u32);

loop {
let reply = self.servers[self.leader_id]
.raft_conf_change(&req)
.unwrap_or_else(|e| {
error!("{:?}", e);
let mut resp = RaftDone::new();
resp.set_err(RespErr::ErrWrongLeader);
resp
});
match reply.err {
RespErr::OK => return,
RespErr::ErrWrongLeader => (),
RespErr::ErrNoKey => return,
}
self.leader_id = (self.leader_id + 1) % self.servers.len();
thread::sleep(Duration::from_millis(100));
}
}

pub fn leave(&mut self, id: u64) {
let mut cc = ConfChange::new();
cc.set_id(id);
cc.set_node_id(id);
cc.set_change_type(ConfChangeType::RemoveNode);
let mut req = ConfChangeReq::new();
req.set_cc(cc);

loop {
let reply = self.servers[self.leader_id]
.raft_conf_change(&req)
.unwrap_or_else(|e| {
error!("{:?}", e);
let mut resp = RaftDone::new();
resp.set_err(RespErr::ErrWrongLeader);
resp
});
match reply.err {
RespErr::OK => return,
RespErr::ErrWrongLeader => (),
RespErr::ErrNoKey => return,
}
self.leader_id = (self.leader_id + 1) % self.servers.len();
thread::sleep(Duration::from_millis(100));
}
}

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

loop {
let reply = self.servers[self.leader_id]
.peers(&req)
.schema(&req)
.unwrap_or_else(|_e| {
let mut resp = PeersResp::new();
let mut resp = SchemaResp::new();
resp.set_err(RespErr::ErrWrongLeader);
resp
});
Expand Down
1 change: 1 addition & 0 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod delete;
pub mod get;
pub mod leave;
pub mod peers;
pub mod schema;
pub mod search;
pub mod serve;
pub mod set;
Loading