{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/raft-rs/pulls/comments/177968833","pull_request_review_id":107938981,"id":177968833,"diff_hunk":"@@ -0,0 +1,202 @@\n+// Copyright 2018 PingCAP, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+extern crate raft;\n+\n+use std::sync::mpsc::{self, RecvTimeoutError};\n+use std::time::{Duration, Instant};\n+use std::thread;\n+use std::collections::HashMap;\n+\n+use raft::prelude::*;\n+use raft::storage::MemStorage;\n+\n+type ProposeCallback = Box<Fn() + Send>;\n+\n+enum Msg {\n+    Propose { id: u8, cb: ProposeCallback },\n+    #[allow(dead_code)] Raft(Message),\n+}\n+\n+// A simple example about how to use the raft library in Rust.\n+fn main() {\n+    // Create a storage for Raft, here we just use a simple memory storage.\n+    // You need to build your own persistent storage in your production.\n+    // Please check the Storage trait in src/storage.rs to see how to implement one.\n+    let storage = MemStorage::new();\n+\n+    // Create the configuration for the Raft node.\n+    let cfg = Config {\n+        // The unique ID for the Raft node.\n+        id: 1,\n+        // The Raft node list.\n+        // Mostly, the peers need to be saved in the storage\n+        // and we can get them from Storage::initial_state function, so here\n+        // you need to set empty.\n+        peers: vec![1],\n+        // Election tick is for how long the follower may campaign again after\n+        // it doesn't receive any message from the leader.\n+        election_tick: 10,\n+        // Heartbeat tick is for how long the leader needs to send\n+        // a heartbeat to keepalive.\n+        heartbeat_tick: 3,\n+        // The max size limits the max size of each append message, mostly, 1 MB is enough.\n+        max_size_per_msg: 1024 * 1024 * 1024,\n+        // Max inflight msgs that the leader sends message to follower without\n+        // receiving ACKs.\n+        max_inflight_msgs: 256,\n+        // The Raft applied index.\n+        // You need to save your applied index when you apply the committed Raft logs.\n+        applied: 0,\n+        // Just for log\n+        tag: format!(\"[{}]\", 1),\n+        ..Default::default()\n+    };\n+\n+    // Create the Raft node.\n+    let mut r = RawNode::new(&cfg, storage, vec![]).unwrap();\n+\n+    let (sender, receiver) = mpsc::channel();\n+\n+    // Use another thread to propose a Raft request.\n+    send_propose(sender);\n+\n+    // Loop forever to drive the Raft.\n+    let mut t = Instant::now();\n+    let mut timeout = Duration::from_millis(100);\n+\n+    // Use a HashMap to holde the propose callbacks.","path":"examples/single_mem_node/main.rs","position":78,"original_position":78,"commit_id":"226c1874012376f51b17be1f06796256f2ba03b4","original_commit_id":"226c1874012376f51b17be1f06796256f2ba03b4","user":{"login":"lilin90","id":30922556,"avatar_url":"https://avatars1.githubusercontent.com/u/30922556?v=4","gravatar_id":"","url":"https://api.github.com/users/lilin90","html_url":"https://github.com/lilin90","followers_url":"https://api.github.com/users/lilin90/followers","following_url":"https://api.github.com/users/lilin90/following{/other_user}","gists_url":"https://api.github.com/users/lilin90/gists{/gist_id}","starred_url":"https://api.github.com/users/lilin90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lilin90/subscriptions","organizations_url":"https://api.github.com/users/lilin90/orgs","repos_url":"https://api.github.com/users/lilin90/repos","events_url":"https://api.github.com/users/lilin90/events{/privacy}","received_events_url":"https://api.github.com/users/lilin90/received_events","type":"User","site_admin":false},"body":"holde -> hold\r\npropose -> proposed? (because \"propose\" is a verb)","created_at":"2018-03-29T07:07:48Z","updated_at":"2018-03-29T07:26:33Z","html_url":"https://github.com/pingcap/raft-rs/pull/44#discussion_r177968833","pull_request_url":"https://api.github.com/repos/pingcap/raft-rs/pulls/44","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/pingcap/raft-rs/pulls/comments/177968833"},"html":{"href":"https://github.com/pingcap/raft-rs/pull/44#discussion_r177968833"},"pull_request":{"href":"https://api.github.com/repos/pingcap/raft-rs/pulls/44"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/raft-rs/pulls/44","id":176671657,"html_url":"https://github.com/pingcap/raft-rs/pull/44","diff_url":"https://github.com/pingcap/raft-rs/pull/44.diff","patch_url":"https://github.com/pingcap/raft-rs/pull/44.patch","issue_url":"https://api.github.com/repos/pingcap/raft-rs/issues/44","number":44,"state":"open","locked":false,"title":"add a simple single memory node example","user":{"login":"siddontang","id":1080370,"avatar_url":"https://avatars2.githubusercontent.com/u/1080370?v=4","gravatar_id":"","url":"https://api.github.com/users/siddontang","html_url":"https://github.com/siddontang","followers_url":"https://api.github.com/users/siddontang/followers","following_url":"https://api.github.com/users/siddontang/following{/other_user}","gists_url":"https://api.github.com/users/siddontang/gists{/gist_id}","starred_url":"https://api.github.com/users/siddontang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siddontang/subscriptions","organizations_url":"https://api.github.com/users/siddontang/orgs","repos_url":"https://api.github.com/users/siddontang/repos","events_url":"https://api.github.com/users/siddontang/events{/privacy}","received_events_url":"https://api.github.com/users/siddontang/received_events","type":"User","site_admin":false},"body":"Add a very simple example to let the user know how to use the Raft library basically. \r\n\r\nPTAL @BusyJay @Hoverbear ","created_at":"2018-03-22T04:17:39Z","updated_at":"2018-03-29T07:26:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f1644ae7901bafcd9fa10e6cb1cf7b778300f79e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/raft-rs/pulls/44/commits","review_comments_url":"https://api.github.com/repos/pingcap/raft-rs/pulls/44/comments","review_comment_url":"https://api.github.com/repos/pingcap/raft-rs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/raft-rs/issues/44/comments","statuses_url":"https://api.github.com/repos/pingcap/raft-rs/statuses/226c1874012376f51b17be1f06796256f2ba03b4","head":{"label":"pingcap:siddontang/example","ref":"siddontang/example","sha":"226c1874012376f51b17be1f06796256f2ba03b4","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":114735865,"name":"raft-rs","full_name":"pingcap/raft-rs","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/raft-rs","description":"Raft distributed consensus algorithm implemented in Rust.","fork":false,"url":"https://api.github.com/repos/pingcap/raft-rs","forks_url":"https://api.github.com/repos/pingcap/raft-rs/forks","keys_url":"https://api.github.com/repos/pingcap/raft-rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/raft-rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/raft-rs/teams","hooks_url":"https://api.github.com/repos/pingcap/raft-rs/hooks","issue_events_url":"https://api.github.com/repos/pingcap/raft-rs/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/raft-rs/events","assignees_url":"https://api.github.com/repos/pingcap/raft-rs/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/raft-rs/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/raft-rs/tags","blobs_url":"https://api.github.com/repos/pingcap/raft-rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/raft-rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/raft-rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/raft-rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/raft-rs/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/raft-rs/languages","stargazers_url":"https://api.github.com/repos/pingcap/raft-rs/stargazers","contributors_url":"https://api.github.com/repos/pingcap/raft-rs/contributors","subscribers_url":"https://api.github.com/repos/pingcap/raft-rs/subscribers","subscription_url":"https://api.github.com/repos/pingcap/raft-rs/subscription","commits_url":"https://api.github.com/repos/pingcap/raft-rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/raft-rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/raft-rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/raft-rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/raft-rs/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/raft-rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/raft-rs/merges","archive_url":"https://api.github.com/repos/pingcap/raft-rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/raft-rs/downloads","issues_url":"https://api.github.com/repos/pingcap/raft-rs/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/raft-rs/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/raft-rs/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/raft-rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/raft-rs/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/raft-rs/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/raft-rs/deployments","created_at":"2017-12-19T07:56:10Z","updated_at":"2018-03-29T03:40:07Z","pushed_at":"2018-03-28T14:21:18Z","git_url":"git://github.com/pingcap/raft-rs.git","ssh_url":"git@github.com:pingcap/raft-rs.git","clone_url":"https://github.com/pingcap/raft-rs.git","svn_url":"https://github.com/pingcap/raft-rs","homepage":"","size":714,"stargazers_count":121,"watchers_count":121,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"archived":false,"open_issues_count":16,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":16,"open_issues":16,"watchers":121,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"99fe6050c708f936012305f6006795344680d93a","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":114735865,"name":"raft-rs","full_name":"pingcap/raft-rs","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars3.githubusercontent.com/u/11855343?v=4","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/raft-rs","description":"Raft distributed consensus algorithm implemented in Rust.","fork":false,"url":"https://api.github.com/repos/pingcap/raft-rs","forks_url":"https://api.github.com/repos/pingcap/raft-rs/forks","keys_url":"https://api.github.com/repos/pingcap/raft-rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/raft-rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/raft-rs/teams","hooks_url":"https://api.github.com/repos/pingcap/raft-rs/hooks","issue_events_url":"https://api.github.com/repos/pingcap/raft-rs/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/raft-rs/events","assignees_url":"https://api.github.com/repos/pingcap/raft-rs/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/raft-rs/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/raft-rs/tags","blobs_url":"https://api.github.com/repos/pingcap/raft-rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/raft-rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/raft-rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/raft-rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/raft-rs/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/raft-rs/languages","stargazers_url":"https://api.github.com/repos/pingcap/raft-rs/stargazers","contributors_url":"https://api.github.com/repos/pingcap/raft-rs/contributors","subscribers_url":"https://api.github.com/repos/pingcap/raft-rs/subscribers","subscription_url":"https://api.github.com/repos/pingcap/raft-rs/subscription","commits_url":"https://api.github.com/repos/pingcap/raft-rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/raft-rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/raft-rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/raft-rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/raft-rs/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/raft-rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/raft-rs/merges","archive_url":"https://api.github.com/repos/pingcap/raft-rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/raft-rs/downloads","issues_url":"https://api.github.com/repos/pingcap/raft-rs/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/raft-rs/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/raft-rs/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/raft-rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/raft-rs/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/raft-rs/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/raft-rs/deployments","created_at":"2017-12-19T07:56:10Z","updated_at":"2018-03-29T03:40:07Z","pushed_at":"2018-03-28T14:21:18Z","git_url":"git://github.com/pingcap/raft-rs.git","ssh_url":"git@github.com:pingcap/raft-rs.git","clone_url":"https://github.com/pingcap/raft-rs.git","svn_url":"https://github.com/pingcap/raft-rs","homepage":"","size":714,"stargazers_count":121,"watchers_count":121,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"archived":false,"open_issues_count":16,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":16,"open_issues":16,"watchers":121,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/raft-rs/pulls/44"},"html":{"href":"https://github.com/pingcap/raft-rs/pull/44"},"issue":{"href":"https://api.github.com/repos/pingcap/raft-rs/issues/44"},"comments":{"href":"https://api.github.com/repos/pingcap/raft-rs/issues/44/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/raft-rs/pulls/44/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/raft-rs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/raft-rs/pulls/44/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/raft-rs/statuses/226c1874012376f51b17be1f06796256f2ba03b4"}},"author_association":"OWNER"}}
{"actor":{"display_login":"lilin90"}}