lockd

command module
v0.0.0-...-385ea26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2020 License: MIT Imports: 13 Imported by: 0

README

lockd

Build Status

A distributed lock service.

Development

Run using:

go mod download
go run main.go -cluster integtests/config/1node.json -id 1

In another terminal, run the following:

curl -i -X POST http://localhost:2081/lock/foo
Multi-Node Cluster

To run a multi-node cluster in development, run the following in separate terminals:

# 1st terminal
go build && ./lockd -cluster integtests/config/3nodes.json -id 101

# 2nd terminal
./lockd -cluster integtests/config/3nodes.json -id 102

# 3rd terminal
./lockd -cluster integtests/config/3nodes.json -id 103

# 4th terminal
go run integtests/main.go

Lock API

The lock service has a REST-ful interface: every lock is a resource at the path /lock/:name:

GET /lock/:name

Check if the given entry is locked.

This will return one of the following status codes:

  • 200 OK - Entry is locked.
  • 404 Not Found - Entry is unlocked.
  • 503 Service Unavailable - Node is not the leader of the cluster.

Example:

curl -i http://localhost:2081/lock/foo
POST /lock/:name

Lock the given entry.

This will return one of the following status codes:

  • 200 OK - Success - entry is now locked.
  • 409 Conflict - Failed - entry is locked.
  • 503 Service Unavailable - Node is not the leader of the cluster.

Example:

curl -i -X POST http://localhost:2081/lock/foo
DELETE /lock/:name

Unlock the given entry.

This will return one of the following status codes:

  • 200 OK - Success - entry is now locked.
  • 409 Conflict - Failed - entry is locked.
  • 503 Service Unavailable - Node is not the leader of the cluster.

Example:

curl -i -X DELETE http://localhost:2081/lock/foo

TODO

Basic Daemon:

  • command line param: server listen address
  • logging setup
  • gin logging to golang standard logging bridge

Basic Single-Node Locking:

  • Lock & Unlock API endpoints
  • Lock state persistence API
  • In-memory state persistence
  • Implement single-node locking service
  • Refactor to use raft as single-node cluster
  • Lock wait for raft commit

Lock Features:

  • Lock status query API
  • Lock request/client id field
  • Request/client id override
  • Lock acquire wait time

Error Handling:

  • Internal error shows original stack trace
  • API timeouts
  • Field content and size limit checks
  • Avoid/delay panic where possible

Integration Testing:

  • External test script
  • Travis runs server and test script

Lock State Persistence:

  • Boltdb state persistence
  • Command line param: choice of persistence mode
  • Command line param: Boltdb state file name

Lock TTL:

  • Lock TTL params
  • Expired Lock Unlocker

Lock Admin:

  • List Locks API
  • Web UI: basic assets
  • Web UI: list locks
  • Web UI: lock
  • Web UI: unlock

Multi-Node Locking:

  • raft consensus module
  • cluster support
  • listen port using cluster info
  • raft rpc endpoints
  • peer rpc service
  • change default port back to 2080
  • default port when port not specified
  • easy single node option
  • clients support for cluster
  • proxy Lock & Unlock API calls to raft leader
  • raft snapshotting

Clients:

  • Ruby client
  • Python client
  • Java/Scala client

Servers:

  • Homebrew installable binary
  • Linux binary

Misc:

  • Add metrics & logging
  • Expose raft details e.g. leader, term
  • Stop -help from showing "-httptest.serve"
  • Vendorize dependencies

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL