dlock - Easy to use, Distributed lock manager, written in Go.
'dlock' provides command line tool to use for acquire distributed lock.
Focused on..
- Easy to use. One binary, No deploy, Only cloud.
- Configuration free.
- Almost ZERO pricing. (based on DynamoDB free tier)
- Scalable in the future.
Startup projects, microserivces or etc, Some times we write a small batch program.
In essence, we know it needs lock
. But most case, it is enough lite and no time to make distributed lock.
In early release, it will not causes problem, because programs takes enough short time. But it causes problem when we forget.
So, I write Easy to Use
distributed lock.
AWS account only.
$ ./dlock
NAME:
dlock - acquire 'lock' to following commands.
USAGE:
dlock [global options] command [command options] [arguments...]
VERSION:
0.0.0
COMMANDS:
create-table Create table then exit
run run command in distributed lock
GLOBAL OPTIONS:
--region value, -r value Specify Region name (default: "ap-northeast-1")
--table value, -t value Specify Table name
--aws_access_key_id value [$AWS_ACCESS_KEY_ID]
--aws_secret_access_key value [$AWS_SECRET_ACCESS_KEY]
--help, -h show help
--version, -v print the version
$ curl -L https://github.com/unacowa/dlock/releases/download/pre-release/linux_amd64_dlock -o dlock
$ chmod +x dlock
$ sudo cp dlock /usr/local/bin
$ export AWS_ACCESS_KEY_ID=AKIxxxxxxxxxxxxxxxxx
$ export AWS_SECRET_ACCESS_KEY=Kxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$ ./dlock --table dynamodb_go_lock create-table
$ ./dlock --table dynamodb_go_lock run --domain example bash -c 'sleep 3; echo One' & ./dlock --table dynamodb_go_lock run --domain example bash -c 'sleep 3; echo Two'
failed acquire. transaction:fea09f48-c94b-4cb0-8b82-2479dee26564 running and not expires
One
Uses AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
for access to AWS DynamoDB.
Both are passed from ENVIRONMENT
or GLOBAL OPTION
.
docker run -itd --name dynamodb_lock_go-gopath -v /go busybox
docker run --rm --volumes-from dynamodb_lock_go-gopath -v $PWD:/go/src/app -w /go/src/app golang:1.6 go-wrapper download
docker run --rm --volumes-from dynamodb_lock_go-gopath -v $PWD:/go/src/app -w /go/src/app golang:1.6 go build -o 'dlock'
Test uses 'REAL' dynamoDB. Create database as following, Before run.
docker run --rm --volumes-from dynamodb_lock_go-gopath -v $PWD:/go/src/app -w /go/src/app -e AWS_ACCESS_KEY_ID=AKIxxxxxxxxx -e AWS_SECRET_ACCESS_KEY=KVxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx golang:1.6 go run lock.go -t dynamodb_go_lock create-table
docker run --rm --volumes-from dynamodb_lock_go-gopath -v $PWD:/go/src/app -w /go/src/app -e AWS_ACCESS_KEY_ID=AKIxxxxxxxxx -e AWS_SECRET_ACCESS_KEY=KVxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx golang:1.6 go test .