Documentation ¶
Overview ¶
Package dmutex is a distributed mutex package written in Go. It takes a quorum based approach to managing shared locks across n distributed nodes. Dmutex is initialized with the local node's address(it can be either the IP address or even the hostname), the addresses of the entire cluster, and a timeout for the gRPC calls. For simplicity it uses port 7070 for all nodes in the cluster. Optional file locations of a TLS certificate and key can be passed in order to secure cluster traffic.
Example ¶
Example initializing and using dmutex
package main import ( "time" "github.com/bparli/dmutex" log "github.com/sirupsen/logrus" ) func main() { nodes := []string{"192.168.1.12", "192.168.1.13", "192.168.1.14", "192.168.1.15", "192.168.1.16"} dm := dmutex.NewDMutex("192.168.1.12", nodes, 3*time.Second, "server.crt", "server.key") if err := dm.Lock(); err != nil { log.Errorln("Lock error", err) } else { log.Debugln("Acquired Lock") time.Sleep(time.Duration(100) * time.Millisecond) dm.UnLock() log.Debugln("Released Lock") } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dmutex ¶
Dmutex is the main struct encompassing everything the local node needs to request and release the distributed shared lock
func NewDMutex ¶
func NewDMutex(nodeAddr string, nodeAddrs []string, timeout time.Duration, tlsCrtFile string, tlsKeyFile string) *Dmutex
NewDMutex is the public function for initializing the distributed lock from the local node's perspective. It takes as arguments:
- the local node's address (in either hotname or IP address form)
- the entire cluster's individual addresses, again in either hostname or IP address form
- a timeout specifying grpc timeouts
- optional Certificate and Key files for encrypting connections between nodes
It calculates the tree, quorums, initializes grpc client and server and returns the initialized distributed mutex
Directories ¶
Path | Synopsis |
---|---|
Package bintree creates a binary tree of Ip Addresses for use in the distributed mutex algorithm.
|
Package bintree creates a binary tree of Ip Addresses for use in the distributed mutex algorithm. |
Package client is a package for the grpc calls to other nodes in the cluster.
|
Package client is a package for the grpc calls to other nodes in the cluster. |
Package queue implements the heap interface in order to implement a request queue of distributed lock requests.
|
Package queue implements the heap interface in order to implement a request queue of distributed lock requests. |
Package quorums is a package for initializing and maintaining the distribted mutex's quorums from the local node's perspective.
|
Package quorums is a package for initializing and maintaining the distribted mutex's quorums from the local node's perspective. |
Package server is the grpc server for processing distributed lock requests.
|
Package server is the grpc server for processing distributed lock requests. |