{"id":13809351,"url":"https://github.com/komamitsu/oraft","last_synced_at":"2025-05-14T08:31:32.873Z","repository":{"id":38416753,"uuid":"236333307","full_name":"komamitsu/oraft","owner":"komamitsu","description":"Library of Raft consensus algorithm implemented in OCaml","archived":false,"fork":false,"pushed_at":"2023-08-18T14:44:22.000Z","size":275,"stargazers_count":30,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T15:45:44.936Z","etag":null,"topics":["consensus-algorithm","ocaml","raft","raft-consensus-algorithm"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/komamitsu.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}},"created_at":"2020-01-26T15:41:13.000Z","updated_at":"2025-02-22T14:29:29.000Z","dependencies_parsed_at":"2024-01-03T01:31:18.012Z","dependency_job_id":"5e5e8f49-83d0-4089-b11f-47900ec99fad","html_url":"https://github.com/komamitsu/oraft","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komamitsu%2Foraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komamitsu%2Foraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komamitsu%2Foraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komamitsu%2Foraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/komamitsu","download_url":"https://codeload.github.com/komamitsu/oraft/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254104658,"owners_count":22015517,"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":["consensus-algorithm","ocaml","raft","raft-consensus-algorithm"],"created_at":"2024-08-04T02:00:19.648Z","updated_at":"2025-05-14T08:31:27.857Z","avatar_url":"https://github.com/komamitsu.png","language":"OCaml","readme":"# ORaft\n\nLibrary of [Raft consensus algorithm](https://raft.github.io/raft.pdf) implemented in OCaml \n\n\u003cimg src=\"https://raw.githubusercontent.com/wiki/komamitsu/oraft/images/oraft-demo.gif\" alt=\"oraft-demo\" width=\"640\"/\u003e\n\n## Current Status\n\n### TODO\n\n- Cluster membership changes\n- Log compaction\n\n## Requirement\n\n- OCaml 4.14 or later\n- opam\n- dune\n\n## Build\n\n```\n$ opam install --deps-only --with-test .\n$ dune build\n```\n\n## Install\n\n```\n$ opam install .\n```\n\n## Test\n\n\n### Unit test\n\n```\n$ dune runtest\n```\n\n### Smoke test\n\nThis repository has an example Raft application that is a simple KVS as described below. The following command runs 5 KVS servers and a verification tool that sequentially restarts at most 2 servers.\n\n```\n$ smoke_test/run.sh\n```\n\n### Chaos test\n\nThis repository has an example Raft application that is a simple KVS as described below. The following command runs 5 KVS servers, a verification tool and [chaos testing tool](https://github.com/alexei-led/pumba) in docker containers. The 5 KVS servers will randomly experience pause and network delay.\n\n```\n$ chaos_test/run.sh\n```\n\n## Usage\n\n### Create a config file for each Raft application\n\n```json\n{\n    \"node_id\": 2,\n    \"nodes\": [\n        {\"id\": 1, \"host\": \"localhost\", \"port\": 7891, \"app_port\": 8181},\n        {\"id\": 2, \"host\": \"localhost\", \"port\": 7892, \"app_port\": 8182},\n        {\"id\": 3, \"host\": \"localhost\", \"port\": 7893, \"app_port\": 8183}\n    ],\n    \"log_file\": \"oraft.log\",\n    \"log_level\": \"INFO\",\n    \"state_dir\": \"state\",\n    \"election_timeout_millis\": 200,\n    \"heartbeat_interval_millis\": 50,\n    \"request_timeout_millis\": 100\n}\n\n```\n\n`node_id` needs to be modified for each node.\n\n### Write an application using ORaft\n\nThe following code is a very simple application that uses ORaft.\n\n```ocaml\nlet main ~conf_file =\n  let oraft =\n    Oraft.start ~conf_file ~apply_log:(fun ~node_id ~log_index ~log_data -\u003e\n        Printf.printf\n          \"[node_id:%d, log_index:%d] %s\\n\"\n          node_id log_index log_data;\n        flush stdout\n    )\n  in\n  let rec loop () =\n    let%lwt s = Lwt_io.read_line Lwt_io.stdin in\n    let%lwt result = oraft.post_command s in\n    let%lwt _ = Lwt_io.printl (if result then \"OK\" else \"ERR\") in\n    loop ()\n  in\n  Lwt.join [ loop (); oraft.process ] |\u003e Lwt_main.run\n\n\nlet () =\n  let open Command.Let_syntax in\n  Command.basic ~summary:\"Simple example application for ORaft\"\n    [%map_open\n      let config =\n        flag \"config\" (required string) ~doc:\"CONFIG Config file path\"\n      in\n      fun () -\u003e main ~conf_file:config]\n  |\u003e Command_unix.run\n```\n\nSee `example-simple` project for details.\n\n## Example\n\nThis repo contains `example-kv` project that is a simple KVS.\n\n### Run a cluster on multi processes\n\nYou can execute the project like this:\n\n```\n$ ./example-kv/run_all.sh\n```\n\n5 Raft application processes will start.\n\n\nAnd then, you can send a request using `curl` command or something\n\n```\n$ curl -X POST --data-binary 'SET a hello' http://localhost:8181/command\n$ curl -X POST --data-binary 'GET a' http://localhost:8182/command\nhello\n$ curl -X POST --data-binary 'SET b 42' http://localhost:8183/command\n$ curl -X POST --data-binary 'GET b' http://localhost:8184/command\n42\n$ curl -X POST --data-binary 'INCR b' http://localhost:8185/command\n$ curl -X POST --data-binary 'GET b' http://localhost:8181/command\n43\n```\n\n## Development\n\n### Pre-commit hook\n\nThis project uses [pre-commit](https://pre-commit.com/) to automate code format and so on as much as possible. Please [install pre-commit](https://pre-commit.com/#installation) and the git hook script as follows.\n\n```\n$ ls -a .pre-commit-config.yaml\n.pre-commit-config.yaml\n$ pre-commit install\n```\n\nThe code formatter is automatically executed when commiting files. A commit will fail and be formatted by the formatter when any invalid code format is detected. Try to commit the change again.\n\n","funding_links":[],"categories":["Algorithms and Data Structures","\u003ca name=\"OCaml\"\u003e\u003c/a\u003eOCaml"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomamitsu%2Foraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkomamitsu%2Foraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomamitsu%2Foraft/lists"}