{"id":13630417,"url":"https://github.com/eliben/raft","last_synced_at":"2025-05-14T19:05:38.573Z","repository":{"id":40560071,"uuid":"237623237","full_name":"eliben/raft","owner":"eliben","description":":rowboat: Raft implementation in Go","archived":false,"fork":false,"pushed_at":"2025-01-29T13:45:29.000Z","size":437,"stargazers_count":1134,"open_issues_count":0,"forks_count":188,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-13T13:19:07.875Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eliben.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}},"created_at":"2020-02-01T14:03:08.000Z","updated_at":"2025-04-13T10:08:34.000Z","dependencies_parsed_at":"2024-12-12T20:24:10.039Z","dependency_job_id":"ec8574c3-ae8b-40c2-87db-f88ee45e966a","html_url":"https://github.com/eliben/raft","commit_stats":{"total_commits":174,"total_committers":6,"mean_commits":29.0,"dds":"0.028735632183908066","last_synced_commit":"72bac57a75991f0635177e2bc8823cc7b6e03fa0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eliben","download_url":"https://codeload.github.com/eliben/raft/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717239,"owners_count":21150390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-08-01T22:01:41.809Z","updated_at":"2025-04-13T13:19:14.786Z","avatar_url":"https://github.com/eliben.png","language":"Go","funding_links":[],"categories":["开源类库","Go","Open source library"],"sub_categories":["算法","Algorithm"],"readme":"# :rowboat: Raft\n\nThis is an instructional implementation of the Raft distributed consensus\nalgorithm in Go. It's accompanied by a series of blog posts:\n\n* [Part 0: Introduction](https://eli.thegreenplace.net/2020/implementing-raft-part-0-introduction/)\n* [Part 1: Elections](https://eli.thegreenplace.net/2020/implementing-raft-part-1-elections/)\n* [Part 2: Commands and log replication](https://eli.thegreenplace.net/2020/implementing-raft-part-2-commands-and-log-replication/)\n* [Part 3: Persistence and optimizations](https://eli.thegreenplace.net/2020/implementing-raft-part-3-persistence-and-optimizations/)\n* [Part 4: Key/Value database](https://eli.thegreenplace.net/2024/implementing-raft-part-4-keyvalue-database/)\n* [Part 5: exactly-once delivery](https://eli.thegreenplace.net/2024/implementing-raft-part-5-exactly-once-delivery/)\n\nEach of the `partN` directories in this repository is the complete source code\nfor Part N of the blog post series (except Part 0, which is introductory and has\nno code). There is a lot of duplicated code between the different `partN`\ndirectories - this is a conscious design decision. Rather than abstracting and\nreusing parts of the implementation, I opted for keeping the code as simple\nas possible. Each directory is completely self contained and can be read and\nunderstood in isolation. Using a graphical diff tool to see the deltas between\nthe parts can be instructional.\n\n`part4kv` and `part5kv` contain the code of a Key/Value DB that uses `part3`\nas its Raft implementation.\n\n## How to use this repository\n\nYou can read the code, but I'd also encourage you to run tests and observe the\nlogs they print out. The repository contains a useful tool for visualizing\noutput. Here's a complete usage example:\n\n```\n$ cd part1\n$ go test -v -race -run TestElectionFollowerComesBack |\u0026 tee /tmp/raftlog\n... logging output\n... test should PASS\n$ go run ../tools/raft-testlog-viz/main.go \u003c /tmp/raftlog\nPASS TestElectionFollowerComesBack map[0:true 1:true 2:true TEST:true] ; entries: 150\n... Emitted file:///tmp/TestElectionFollowerComesBack.html\n\nPASS\n```\n\nNow open `file:///tmp/TestElectionFollowerComesBack.html` in your browser.\nYou should see something like this:\n\n![Image of log browser](https://github.com/eliben/raft/blob/main/raftlog-screenshot.png)\n\nScroll and read the logs from the servers, noticing state changes (highlighted\nwith colors). Feel free to add your own `cm.dlog(...)` calls to the code to\nexperiment and print out more details.\n\n## Changing and testing the code\n\nEach `partN` directory is completely independent of the others, and is its own\nGo module. The Raft code itself has no external dependencies; the only `require`\nin its `go.mod` is for a package that enables goroutine leak testing - it's only\nused in tests.\n\nTo work on `part2`, for example:\n\n```\n$ cd part2\n... make code changes\n$ go test -race ./...\n```\n\nDepending on the part and your machine, the tests can take up to a minute to\nrun. Feel free to enable verbose logging with `-v`, and/or used the provided\n`dotest.sh` script to run specific tests with log visualization.\n\nNote: for part3, the actual Raft code is in a `part3/raft` subdirectory, to\nbe importable from future parts. All the instructions discussed so far work\nwith part3 as well - you just have to `cd` one directory deeper.\n\n## Contributing\n\nI'm interested in hearing your opinion or suggestions for the code in this\nrepository. Feel free to open an issue if something is unclear, or if you think\nyou found a bug. Code contributions through PRs are welcome as well.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliben%2Fraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feliben%2Fraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliben%2Fraft/lists"}