March 2021
Intermediate to advanced
260 pages
5h 45m
English
We have a log that can write and read records on one computer. We want a distributed log that’s replicated on multiple computers, so let’s implement Raft in our service to get that.
Install Raft by running this command:
| | $ go get github.com/hashicorp/raft@v1.1.1 |
| | $ # use etcd's fork of Ben Johnson's Bolt key/value store, |
| | $ # which includes fixes for Go 1.14+ |
| | $ go mod edit -replace github.com/hashicorp/raft-boltdb=\ |
| | github.com/travisjeffery/raft-boltdb@v1.0.0 |
In the internal/log directory, create a distributed.go file, beginning with this snippet:
| | package log |
| | |
| | import ( |
| | "bytes" |
| | "crypto/tls" |
| | "fmt" |
| | "io" |
| | "net" |
| | "os" |
| | "path/filepath" ... |
Read now
Unlock full access