{"id":13630879,"url":"https://github.com/xnnyygn/xraft","last_synced_at":"2026-01-20T02:45:24.352Z","repository":{"id":42690936,"uuid":"137570946","full_name":"xnnyygn/xraft","owner":"xnnyygn","description":"xnnyygn's raft implementation","archived":false,"fork":false,"pushed_at":"2025-02-10T17:42:06.000Z","size":1076,"stargazers_count":234,"open_issues_count":16,"forks_count":109,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-18T06:51:47.026Z","etag":null,"topics":["distributed-systems","raft"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xnnyygn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-06-16T09:58:43.000Z","updated_at":"2025-03-23T14:30:11.000Z","dependencies_parsed_at":"2024-01-14T06:52:58.683Z","dependency_job_id":"8523a803-6575-422c-af59-47cfb85ec303","html_url":"https://github.com/xnnyygn/xraft","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/xnnyygn/xraft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xnnyygn%2Fxraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xnnyygn%2Fxraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xnnyygn%2Fxraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xnnyygn%2Fxraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xnnyygn","download_url":"https://codeload.github.com/xnnyygn/xraft/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xnnyygn%2Fxraft/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28594958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T02:08:49.799Z","status":"ssl_error","status_checked_at":"2026-01-20T02:08:44.148Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-systems","raft"],"created_at":"2024-08-01T22:02:01.887Z","updated_at":"2026-01-20T02:45:24.318Z","avatar_url":"https://github.com/xnnyygn.png","language":"Java","funding_links":[],"categories":["Java","分布式开发"],"sub_categories":[],"readme":"# xraft\n\nA raft implementation of XnnYygn's.\n\nI want to make something with netty framework, and I found raft. Raft is interesting. As the first distributed consensus algorithm I learnt, I read the paper and implemented almost all of the feature of raft including\n\n* Leader election and log replication\n* Membership change(one server change)\n* Log compaction\n\nAll these feature are implemented in xraft-core. And the client interaction in raft, I thought, should be the feature of service based on xraft-core. Until now, I made a simple key value store based on xraft-core, called xraft-kvstore. It supports GET and SET command.\n\n## Demostration\n\nTo test xraft with xraft-kvstore, you can download xraft and run xraft-kvstore, xraft-kvstore-cli.\n\n### Prerequistes\n\nJava 1.8+ is required to run xraft. You can run `java -version` to check the version of java on your computer.\n\n### Download\n\nYou can get complied xraft in releases.\n\n### Run Server\n\n`xraft-kvstore` under the `bin` directory is the command to run xraft kvstore server.\n\nTo demostrate a xraft cluster with 3 nodes(memory log mode), \n\n* node A, host localhost, port raft node 2333, port kvstore 3333\n* node B, host localhost, port raft node 2334, port kvstore 3334\n* node C, host localhost, port raft node 2335, port kvstore 3335\n\nstart servers with commands below\n\nTerminal A\n\n```\n$ bin/xraft-kvstore -gc A,localhost,2333 B,localhost,2334 C,localhost,2335 -m group-member -i A -p2 3333\n```\n\nTerminal B\n\n```\n$ bin/xraft-kvstore -gc A,localhost,2333 B,localhost,2334 C,localhost,2335 -m group-member -i B -p2 3334\n```\n\nTerminal C\n\n```\n$ bin/xraft-kvstore -gc A,localhost,2333 B,localhost,2334 C,localhost,2335 -m group-member -i C -p2 3335\n```\n\nSince the minimum election timeout is 3 seconds, if you cannot execute all 3 commands within 3 seconds, you will get some error like `failed to connect ....`. But after you started all nodes, the error will disapper.\n\nAfter start, you will see something like `become leader`, `current leader is xxx` and it shows the cluster is started and leader election is ok.\n\n### Run Client\n\nRun `xraft-kvstore-cli` with the cluster configuration. The client will not connect to any node in cluster so it is ok to run client before cluster starts.\n\n```\n$ bin/xraft-kvstore-cli -gc A,localhost,3333 B,localhost,3334 C,localhost,3335\n```\n\nIt will run an interative console, press TAB two times and you will get the available commands. For this demostration, firstly run \n\n```\n\u003e kvstore-get x\n```\n\nand you should get the result `null`. Then run\n\n```\n\u003e kvstore-set x 1\n```\n\nnothing will be printed, now you can run get again.\n\n```\n\u003e kvstore-get x\n```\n\n`1` should be printed.\n\n## New Service\n\nHow to create new service based on xraft-core?\n\n* [Node \u0026 NodeBuilder](https://github.com/xnnyygn/xraft/wiki/Node-\u0026-NodeBuilder)\n* [StateMachine](https://github.com/xnnyygn/xraft/wiki/StateMachine)\n\nFor more detailed implementation of new service, see the source code of xraft-kvstore.\n\n## Build\n\nxraft use [Maven](https://maven.apache.org/) as build system.\n\n```\n$ mvn clean compile install\n```\n\nTo package xraft-kvstore\n\n```\n$ cd xraft-kvstore\n$ mvn package assembly:single\n```\n\n## About PreVote\n\nIf you are looking for Raft optimization `PreVote`, please check `develop` branch.\n\n## Consistency in xraft-kvstore\n\nTo make the implmenetation simple, the `xraft-kvstore` just reads the value in the concurrent hash map, which actually could be a stale value. There is an optimiation in `develop` branch called `readindex` to offer consistent read. If you need consistent read or want to know how to implement it, please refer to `develop` branch.\n\n## License\n\nThis project is licensed under the MIT License.\n\n## 关于《分布式一致性算法开发实战》和相关讨论\n\n2020年5月，我出版了一本书，名字叫做[《分布式一致性算法开发实战》](https://book.douban.com/subject/35051108/)。书里面大部分代码都是参考我的这个项目，或者说我是先完成了这个项目然后再写了书。如果你对项目本身的架构，设计选择或者算法本身等有兴趣的话，欢迎阅读《分布式一致性算法开发实战》，我在书里做了很多详细的讲解。\n\n另外，如果你对书籍或者代码设计有疑问的话，或者想要交流的话，欢迎在[豆瓣页面的讨论区](https://book.douban.com/subject/35051108/)内发表话题，我会定期检查并回复。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxnnyygn%2Fxraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxnnyygn%2Fxraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxnnyygn%2Fxraft/lists"}