https://github.com/vadiminshakov/committer
Two-phase (2PC) and three-phase (3PC) protocols implementaion in Golang
https://github.com/vadiminshakov/committer
2pc 3pc distributed-systems three-phase-commit two-phase-commit
Last synced: 5 months ago
JSON representation
Two-phase (2PC) and three-phase (3PC) protocols implementaion in Golang
- Host: GitHub
- URL: https://github.com/vadiminshakov/committer
- Owner: vadiminshakov
- License: apache-2.0
- Created: 2020-08-02T09:50:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-06-21T19:48:33.000Z (5 months ago)
- Last Synced: 2025-06-21T20:31:27.887Z (5 months ago)
- Topics: 2pc, 3pc, distributed-systems, three-phase-commit, two-phase-commit
- Language: Go
- Homepage:
- Size: 9 MB
- Stars: 38
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go-cn - committer
- awesome-go-plus - committer - A distributed transactions management system (2PC/3PC implementation).  (Distributed Systems / Search and Analytic Databases)
- fucking-awesome-go - committer - A distributed transactions management system (2PC/3PC implementation). (Distributed Systems / Search and Analytic Databases)
- awesome-go - committer - A distributed transactions management system (2PC/3PC implementation). (Distributed Systems / Search and Analytic Databases)
- awesome-go-with-stars - committer - A distributed transactions management system (2PC/3PC implementation). (Distributed Systems / Search and Analytic Databases)
- awesome-go - vadiminshakov/committer - phase (2PC) and three-phase (3PC) protocols implementaion in Golang ☆`39` (Distributed Systems / Search and Analytic Databases)
- awesome-go - committer - A distributed transactions management system (2PC/3PC implementation). (Distributed Systems / Search and Analytic Databases)
README

[](https://pkg.go.dev/github.com/vadiminshakov/committer)
[](https://goreportcard.com/report/github.com/vadiminshakov/committer)
[](https://github.com/avelino/awesome-go)
# **Committer**
**Committer** is a Go implementation of the **Two-Phase Commit (2PC)** and **Three-Phase Commit (3PC)** protocols for distributed systems.
## **Architecture**
The system consists of two types of nodes: **Coordinator** and **Followers**.
The **Coordinator** is responsible for initiating and managing the commit protocols (2PC or 3PC), while the **Followers** (or cohorts) participate in the protocol by responding to the coordinator's requests.
The communication between nodes is handled using gRPC, and the state of each node is managed using a state machine.
## **Key Features**
- **2PC and 3PC support**: Implements two widely used consensus protocols for distributed transactions.
- **Persistence**: Uses **BadgerDB** and WAL for reliable data storage and transaction logs.
- **Configurable**: All options can be specified using command-line flags.
- **Hooks for validation**: Custom logic can be injected during **Propose** and **Commit** stages.
- **gRPC-based communication**: Efficient inter-node communication using gRPC.
## **Configuration**
All configuration parameters can be set using command-line flags:
| **Flag** | **Description** | **Default** | **Example** |
|-----------------|---------------------------------------------------------|---------------------|-------------------------------------|
| `role` | Node role: `coordinator` or `follower` | `follower` | `-role=coordinator` |
| `nodeaddr` | Address of the current node | `localhost:3050` | `-nodeaddr=localhost:3051` |
| `coordinator` | Coordinator address (required for followers) | `""` | `-coordinator=localhost:3050` |
| `committype` | Commit protocol: `two-phase` or `three-phase` | `three-phase` | `-committype=two-phase` |
| `timeout` | Timeout (ms) for unacknowledged messages (3PC only) | `1000` | `-timeout=500` |
| `dbpath` | Path to the BadgerDB database on the filesystem | `./badger` | `-dbpath=/tmp/badger` |
| `followers` | Comma-separated list of follower addresses | `""` | `-followers=localhost:3052,3053` |
| `whitelist` | Comma-separated list of allowed hosts | `127.0.0.1` | `-whitelist=192.168.0.1,192.168.0.2`|
## **Usage**
### **Running as a Follower**
```bash
./committer -role=follower -nodeaddr=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=/tmp/badger/follower
```
### **Running as a Coordinator**
```bash
./committer -role=coordinator -nodeaddr=localhost:3000 -followers=localhost:3001 -committype=three-phase -timeout=1000 -dbpath=/tmp/badger/coordinator
```
## **Hooks**
Hooks allow you to add custom validation logic during the **Propose** and **Commit** stages.
A hook is a function that accepts `*pb.ProposeRequest` or `*pb.CommitRequest` and returns a boolean.
Example hook implementation can be found [here](https://github.com/vadiminshakov/committer/blob/master/core/cohort/commitalgo/hooks/hooks.go).
To inject your own logic, replace the code in the hook file or in main.go with your custom validation and compile sources.
## **Testing**
### **Run Functional Tests**
```bash
make tests
```
### **Testing with Example Client**
1. Compile executables:
```bash
make prepare
```
2. Run the coordinator:
```bash
make run-example-coordinator
```
3. Run a follower in another terminal:
```bash
make run-example-follower
```
4. Start the example client:
```bash
go run ./examples/client/client.go
```
## **Contributions**
Contributions are welcome! Feel free to submit a PR or open an issue if you find bugs or have suggestions for improvement.
## **License**
This project is licensed under the [Apache License](LICENSE).