这是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
14 changes: 4 additions & 10 deletions docs/cluster_mode.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ <h2><a class="header" href="#starting-in-cluster-mode-3-node-cluster" id="starti
--host=0.0.0.0 \
--port=5001 \
--id=1 \
--peers=&quot;1=0.0.0.0:5001&quot; \
--data-directory=./data/1 \
--schema-file=./etc/schema.json \
--unique-key-field-name=id
Expand All @@ -166,8 +165,7 @@ <h2><a class="header" href="#starting-in-cluster-mode-3-node-cluster" id="starti
--host=0.0.0.0 \
--port=5002 \
--id=2 \
--peers=&quot;1=0.0.0.0:5001,2=0.0.0.0:5002&quot; \
--leader-id=1 \
--peers=&quot;1=0.0.0.0:5001&quot; \
--data-directory=./data/2 \
--schema-file=./etc/schema.json \
--unique-key-field-name=id
Expand All @@ -176,8 +174,7 @@ <h2><a class="header" href="#starting-in-cluster-mode-3-node-cluster" id="starti
--host=0.0.0.0 \
--port=5003 \
--id=3 \
--peers=&quot;1=0.0.0.0:5001,2=0.0.0.0:5002,3=0.0.0.0:5003&quot; \
--leader-id=1 \
--peers=&quot;1=0.0.0.0:5001,2=0.0.0.0:5002&quot; \
--data-directory=./data/3 \
--schema-file=./etc/schema.json \
--unique-key-field-name=id
Expand All @@ -201,11 +198,8 @@ <h2><a class="header" href="#remove-a-server-from-a-cluster" id="remove-a-server
If you want the server to join the cluster again, you must remove it from the cluster.<br />
The following command deletes the server with <code>id=3</code> from the cluster:</p>
<pre><code class="language-shellscript">./bin/bayard leave \
--host=127.0.0.1 \
--port=5001 \
--id=3 \
--peers=&quot;1=0.0.0.0:5001,2=0.0.0.0:5002&quot; \
--leader-id=1
--servers=127.0.0.1:5001 \
--id=3
</code></pre>

</main>
Expand Down
14 changes: 4 additions & 10 deletions docs/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ <h2><a class="header" href="#starting-in-cluster-mode-3-node-cluster" id="starti
--host=0.0.0.0 \
--port=5001 \
--id=1 \
--peers=&quot;1=0.0.0.0:5001&quot; \
--data-directory=./data/1 \
--schema-file=./etc/schema.json \
--unique-key-field-name=id
Expand All @@ -337,8 +336,7 @@ <h2><a class="header" href="#starting-in-cluster-mode-3-node-cluster" id="starti
--host=0.0.0.0 \
--port=5002 \
--id=2 \
--peers=&quot;1=0.0.0.0:5001,2=0.0.0.0:5002&quot; \
--leader-id=1 \
--peers=&quot;1=0.0.0.0:5001&quot; \
--data-directory=./data/2 \
--schema-file=./etc/schema.json \
--unique-key-field-name=id
Expand All @@ -347,8 +345,7 @@ <h2><a class="header" href="#starting-in-cluster-mode-3-node-cluster" id="starti
--host=0.0.0.0 \
--port=5003 \
--id=3 \
--peers=&quot;1=0.0.0.0:5001,2=0.0.0.0:5002,3=0.0.0.0:5003&quot; \
--leader-id=1 \
--peers=&quot;1=0.0.0.0:5001,2=0.0.0.0:5002&quot; \
--data-directory=./data/3 \
--schema-file=./etc/schema.json \
--unique-key-field-name=id
Expand All @@ -372,11 +369,8 @@ <h2><a class="header" href="#remove-a-server-from-a-cluster" id="remove-a-server
If you want the server to join the cluster again, you must remove it from the cluster.<br />
The following command deletes the server with <code>id=3</code> from the cluster:</p>
<pre><code class="language-shellscript">./bin/bayard leave \
--host=127.0.0.1 \
--port=5001 \
--id=3 \
--peers=&quot;1=0.0.0.0:5001,2=0.0.0.0:5002&quot; \
--leader-id=1
--servers=127.0.0.1:5001 \
--id=3
</code></pre>
<h1><a class="header" href="#running-on-docker" id="running-on-docker">Running on Docker</a></h1>
<p>See the available Docker container image version at the following URL:</p>
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.

14 changes: 4 additions & 10 deletions docs_src/cluster_mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ You can start servers in cluster mode with the following command:
--host=0.0.0.0 \
--port=5001 \
--id=1 \
--peers="1=0.0.0.0:5001" \
--data-directory=./data/1 \
--schema-file=./etc/schema.json \
--unique-key-field-name=id
Expand All @@ -24,8 +23,7 @@ You can start servers in cluster mode with the following command:
--host=0.0.0.0 \
--port=5002 \
--id=2 \
--peers="1=0.0.0.0:5001,2=0.0.0.0:5002" \
--leader-id=1 \
--peers="1=0.0.0.0:5001" \
--data-directory=./data/2 \
--schema-file=./etc/schema.json \
--unique-key-field-name=id
Expand All @@ -36,8 +34,7 @@ You can start servers in cluster mode with the following command:
--host=0.0.0.0 \
--port=5003 \
--id=3 \
--peers="1=0.0.0.0:5001,2=0.0.0.0:5002,3=0.0.0.0:5003" \
--leader-id=1 \
--peers="1=0.0.0.0:5001,2=0.0.0.0:5002" \
--data-directory=./data/3 \
--schema-file=./etc/schema.json \
--unique-key-field-name=id
Expand Down Expand Up @@ -73,9 +70,6 @@ The following command deletes the server with `id=3` from the cluster:

```shell script
./bin/bayard leave \
--host=127.0.0.1 \
--port=5001 \
--id=3 \
--peers="1=0.0.0.0:5001,2=0.0.0.0:5002" \
--leader-id=1
--servers=127.0.0.1:5001 \
--id=3
```
7 changes: 1 addition & 6 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn run_serve_cli(matches: &ArgMatches) -> Result<(), String> {
let port = matches.value_of("PORT").unwrap().parse::<u16>().unwrap();
let id = matches.value_of("ID").unwrap().parse::<u64>().unwrap();
let mut peers = HashMap::new();
peers.insert(id, create_client(&format!("{}:{}", host, port)));
if let Some(peers_vec) = matches.values_of("PEERS") {
peers_vec
.map(|s| {
Expand All @@ -30,11 +31,6 @@ pub fn run_serve_cli(matches: &ArgMatches) -> Result<(), String> {
})
.count();
}
let leader_id = matches
.value_of("LEADER_ID")
.unwrap()
.parse::<u64>()
.unwrap();
let data_directory = matches.value_of("DATA_DIRECTORY").unwrap();
let schema_file = matches.value_of("SCHEMA_FILE").unwrap();
let unique_key_field_name = matches.value_of("UNIQUE_KEY_FIELD_NAME").unwrap();
Expand Down Expand Up @@ -67,7 +63,6 @@ pub fn run_serve_cli(matches: &ArgMatches) -> Result<(), String> {
id,
host,
port,
leader_id,
peers,
Arc::new(index),
unique_key_field_name,
Expand Down
30 changes: 10 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ fn main() {
.version(crate_version!())
.author(crate_authors!())
.about("Start server")
.arg(
Arg::with_name("ID")
.help("The node ID")
.short("i")
.long("id")
.value_name("ID")
.default_value("1")
.takes_value(true),
)
.arg(
Arg::with_name("HOST")
.help("The node address")
Expand All @@ -46,37 +55,18 @@ fn main() {
.default_value("5000")
.takes_value(true),
)
.arg(
Arg::with_name("ID")
.help("The node ID")
.short("i")
.long("id")
.value_name("ID")
.default_value("1")
.takes_value(true),
)
.arg(
Arg::with_name("PEERS")
.help("Set raft peers address separated by `,`")
.help("Set peers address separated by `,`, if join to a cluster")
.short("p")
.long("peers")
.value_name("ID=IP:PORT")
.default_value("1=0.0.0.0:5000")
.multiple(true)
.takes_value(true)
.use_delimiter(true)
.require_delimiter(true)
.value_delimiter(","),
)
.arg(
Arg::with_name("LEADER_ID")
.help("The leader node ID")
.short("l")
.long("leader-id")
.value_name("LEADER_ID")
.default_value("1")
.takes_value(true),
)
.arg(
Arg::with_name("DATA_DIRECTORY")
.help("The data directory")
Expand Down
20 changes: 6 additions & 14 deletions src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl IndexServer {
id: u64,
host: &str,
port: u16,
leader_id: u64,
peers: HashMap<u64, IndexClient>,
index: Arc<Index>,
unique_key_field: &str,
Expand Down Expand Up @@ -95,20 +94,13 @@ impl IndexServer {
let peer = peer::Peer::new(id, apply_sender, peers_id);
peer::Peer::activate(peer, rpc_sender, rf_receiver);

debug!("leader_id: {}", leader_id);
let mut leaders: Vec<IndexClient> = Vec::new();
leaders.push(
index_server
.peers
.clone()
.lock()
.unwrap()
.get(&leader_id)
.unwrap()
.clone(),
);
let mut servers: Vec<IndexClient> = Vec::new();
for (_, value) in index_server.peers.clone().lock().unwrap().iter() {
servers.push(value.clone());
}

let client_id = rand::random();
let mut client = Clerk::new(&leaders, client_id);
let mut client = Clerk::new(&servers, client_id);
client.join(id, host, port);

// Wait for signals for termination (SIGINT, SIGTERM).
Expand Down