{"id":30249184,"url":"https://github.com/flowerinthenight/hedge-rs","last_synced_at":"2025-08-15T08:38:55.341Z","repository":{"id":283047356,"uuid":"950508768","full_name":"flowerinthenight/hedge-rs","owner":"flowerinthenight","description":"A cluster membership library built on spindle-rs.","archived":false,"fork":false,"pushed_at":"2025-04-11T06:45:25.000Z","size":339,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-20T07:39:57.032Z","etag":null,"topics":["cluster","distributed-systems","memberlist","rust","spanner","truetime"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/flowerinthenight.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":"2025-03-18T09:19:36.000Z","updated_at":"2025-06-14T03:16:19.000Z","dependencies_parsed_at":"2025-03-18T10:28:26.988Z","dependency_job_id":"8c740eea-2919-4936-be3d-b2cae04a3229","html_url":"https://github.com/flowerinthenight/hedge-rs","commit_stats":null,"previous_names":["flowerinthenight/hedge-rs"],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/flowerinthenight/hedge-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fhedge-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fhedge-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fhedge-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fhedge-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flowerinthenight","download_url":"https://codeload.github.com/flowerinthenight/hedge-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fhedge-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270546174,"owners_count":24604455,"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","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cluster","distributed-systems","memberlist","rust","spanner","truetime"],"created_at":"2025-08-15T08:38:50.750Z","updated_at":"2025-08-15T08:38:55.332Z","avatar_url":"https://github.com/flowerinthenight.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![main](https://github.com/flowerinthenight/hedge-rs/actions/workflows/main.yml/badge.svg)](https://github.com/flowerinthenight/hedge-rs/actions/workflows/main.yml)\n[![crates.io](https://img.shields.io/crates/v/hedge_rs)](https://crates.io/crates/hedge_rs)\n[![docs-rs](https://img.shields.io/docsrs/hedge_rs)](https://docs.rs/hedge_rs/latest/hedge_rs/)\n\n## hedge-rs\n\nA cluster membership Rust library. It is built on [spindle-rs](https://github.com/flowerinthenight/spindle-rs), a distributed locking library built on [Cloud Spanner](https://cloud.google.com/spanner/) and [TrueTime](https://cloud.google.com/spanner/docs/true-time-external-consistency). It is a port (subset only) of the original [hedge](https://github.com/flowerinthenight/hedge), which is written in Go. Ported features include:\n\n* Tracking of member nodes - good for clusters with sizes that can change dynamically overtime, such as [GCP MIGs](https://cloud.google.com/compute/docs/instance-groups#managed_instance_groups), and [Kubernetes Deployments](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/);\n* Leader election - the cluster elects and maintains a single leader node at all times;\n* List of members - get a list of all member nodes at any time;\n* Send - any member node can send messages to the leader at any time; and\n* Broadcast - any member node can broadcast messages to all nodes at any time.\n\n## Running the sample\n\nFirst, create the Spanner table for [spindle-rs](https://github.com/flowerinthenight/spindle-rs):\n\n```sql\nCREATE TABLE locktable (\n    name STRING(MAX) NOT NULL,\n    heartbeat TIMESTAMP OPTIONS (allow_commit_timestamp=true),\n    token TIMESTAMP OPTIONS (allow_commit_timestamp=true),\n    writer STRING(MAX),\n) PRIMARY KEY (name)\n```\n\nThen you can run the sample like so:\n\n```bash\n# Clone and build:\n$ git clone https://github.com/flowerinthenight/hedge-rs/\n$ cd hedge-rs/\n$ cargo build\n\n# Run the first instance. The first host:port is for hedge-rs'\n# internal server; the last host:port is for main's test TCP.\n# (Use your actual Spanner values.)\n$ RUST_LOG=info ./target/debug/example \\\n  projects/p/instances/i/databases/db \\\n  locktable \\\n  0.0.0.0:8080 \\\n  0.0.0.0:9090\n\n# Run this 2nd instance on a different terminal. The first\n# host:port is for hedge-rs' internal server; the last\n# host:port is for main's test TCP.\n# (Use your actual Spanner values.)\n$ RUST_LOG=info ./target/debug/example \\\n  projects/p/instances/i/databases/db \\\n  locktable \\\n  0.0.0.0:8081 \\\n  0.0.0.0:9091\n\n# Run this 3rd instance on a different terminal. The first\n# host:port is for hedge-rs' internal server; the last\n# host:port is for main's test TCP.\n# (Use your actual Spanner values.)\n$ RUST_LOG=info ./target/debug/example \\\n  projects/p/instances/i/databases/db \\\n  locktable \\\n  0.0.0.0:8082 \\\n  0.0.0.0:9092\n```\n\nYou can play around by adding more processes, killing the leader process, killing a non-leader process, restarting an existing process, etc.\n\nTo test the `send()` and `broadcast()` APIs, you can do something like:\n\n```bash\n# Messages starting with 'send' will use the send() API.\n$ echo 'send this message to leader' | nc localhost 9091\n\n# Messages starting with 'broadcast' will use the broadcast() API.\n$ echo 'broadcast hello all nodes!' | nc localhost 9092\n```\n\n## Runing the sample on a GCP MIG\n\nA sample cloud-init [startup script](./startup-gcp-mig.sh) is provided for spinning up a [Managed Instance Group](https://cloud.google.com/compute/docs/instance-groups#managed_instance_groups) with the sample code running as a systemd service. You need to update the `ExecStart` section first with your actual Spanner connection URL and table name.\n\n```bash\n# Create a launch template. The provided --service-account\n# will provide access to Spanner.\n$ gcloud compute instance-templates create hedge-tmpl \\\n  --machine-type e2-micro \\\n  --service-account=name@project.iam.gserviceaccount.com \\\n  --scopes=cloud-platform \\\n  --metadata=startup-script=''\"$(cat startup-gcp-mig.sh)\"''\n\n# Create the MIG. Update {target-region} with actual value.\n$ gcloud compute instance-groups managed create hedge-mig \\\n  --template hedge-tmpl --size 3 --region {target-region}\n\n# Let's use 'https://github.com/flowerinthenight/g-ssh-cmd'\n# to tail the logs from all three VMs.\n$ brew install flowerinthenight/tap/g-ssh-cmd\n\n# Assuming your 'gcloud' is configured properly:\n$ g-ssh-cmd mig hedge-mig 'journalctl -f'\n\n# On a different terminal, SSH to one of the VMs and try:\n$ echo 'broadcast hello all nodes!' | \\\n  nc $(cat /etc/hedge/internal-ip) 9090\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowerinthenight%2Fhedge-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflowerinthenight%2Fhedge-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowerinthenight%2Fhedge-rs/lists"}