Distributed lock manager. Warning: very hard to use it properly. Not because it's broken, but because distributed systems are hard. If in doubt, do not use this.

What

Dlock is a distributed lock manager [1]. It is designed after flock utility but for multiple machines. When client disconnects, all his locks are lost. TCP keep alive probes and optional protocol level heart beat ensure connection problems are detected in time.

dlock-server manages locks in memory, no persistence. dlock client connects to server, sends a lock acquiring request, optionally waits if locks are being held by someone else.

How

Client-server speak very simple protocol built on Protocol Buffers [2] frames on top of TCP. Pipelining many requests before reading response is perfectly fine. Responses come in the order of requests.

Protocol:

Length-prefixed protocol buffers. Length prefix is 4 bytes, big endian binary encoding.

message Request {
    uint32 version = 1 [default = 2];
    uint64 id = 2;
    string access_token = 3;
    RequestType type = 4;

    // Ping is empty
    RequestLock lock = 51;
    // RequestUnlock unlock = 52;
}

message Response {
    uint32 version = 1 [default = 2];
    uint64 request_id = 2;
    ResponseStatus status = 3;
    string error_text = 4;
    repeated string keys = 5;
    int64 server_unix_time = 6; // Unix timestamp
}

As of 2013-05-28, API version is 2.

Lock request:

`type = Lock`

message RequestLock {
    uint64 wait_micro = 1;
    uint64 release_micro = 2;
    repeated string keys = 3;
}

Supplied keys are locked until client disconnects or for release_micro microseconds. If release timeout is supplied, disconnect does not do anything. If some of specified keys are already locked, this command will block for at most wait_micro microseconds before returning response with AcquireTimeout status.

Ping request:

`type = Ping`

Response is always Ok. Clients should send pings periodically to inform server they are alive. Otherwise the server will disconnect them with suspection of failure and release their locks.

enum RequestType {
    Ping = 1;
    Lock = 2;
//  Unlock = 3;
}

enum ResponseStatus {
    // Error codes:
    // 1-99: protocol level errors
    // 100-119: [lock] input validation errors
    // 120-139: [lock] response errors for valid input
    Ok = 0;
    General = 1; // generic error, read message for details
    Version = 2; // incompatible request version
    InvalidType = 3; // unknown request type

    // Lock 100-199
    TooManyKeys = 100;
    AcquireTimeout = 120;
}

References

[1] http://en.wikipedia.org/wiki/Distributed_lock_manager

[2] https://code.google.com/p/protobuf/

Flair

https://travis-ci.org/temoto/dlock.svg?branch=master
Owner
Similar Resources

Labs, solutions and related materials from the MIT 6.824 Distributed Systems course.

Labs, solutions and related materials from the MIT 6.824 Distributed Systems course.

MIT 6.824 Distributed Systems Labs, solutions and related materials from the MIT 6.824 Distributed Systems course. Overview From the official website:

Nov 5, 2022

MIT6.824 Distributed Systems

MIT6.824-Distributed-Systems My Solutions for MIT6.824

Jan 28, 2022

Distributed reliable key-value store for the most critical data of a distributed system

etcd Note: The main branch may be in an unstable or even broken state during development. For stable versions, see releases. etcd is a distributed rel

Dec 30, 2022

Easy to use Raft library to make your app distributed, highly available and fault-tolerant

Easy to use Raft library to make your app distributed, highly available and fault-tolerant

An easy to use customizable library to make your Go application Distributed, Highly available, Fault Tolerant etc... using Hashicorp's Raft library wh

Nov 16, 2022

distributed data sync with operational transformation/transforms

DOT The DOT project is a blend of operational transformation, CmRDT, persistent/immutable datastructures and reactive stream processing. This is an im

Dec 16, 2022

High performance, distributed and low latency publish-subscribe platform.

High performance, distributed and low latency publish-subscribe platform.

Emitter: Distributed Publish-Subscribe Platform Emitter is a distributed, scalable and fault-tolerant publish-subscribe platform built with MQTT proto

Jan 2, 2023

Fast, efficient, and scalable distributed map/reduce system, DAG execution, in memory or on disk, written in pure Go, runs standalone or distributedly.

Gleam Gleam is a high performance and efficient distributed execution system, and also simple, generic, flexible and easy to customize. Gleam is built

Jan 1, 2023
Comments
  • Deadlock

    Deadlock

    I was browsing the code, and happened to notice a lock that was never unlocked when an error occurs: https://github.com/temoto/dlock/blob/master/dlock-server/server.go#L101

Distributed-Services - Distributed Systems with Golang to consequently build a fully-fletched distributed service

Distributed-Services This project is essentially a result of my attempt to under

Jun 1, 2022
A distributed lock service in Go using etcd

locker A distributed lock service client for etcd. What? Why? A distributed lock service is somewhat self-explanatory. Locking (mutexes) as a service

Sep 27, 2022
Lockgate is a cross-platform locking library for Go with distributed locks using Kubernetes or lockgate HTTP lock server as well as the OS file locks support.

Lockgate Lockgate is a locking library for Go. Classical interface: 2 types of locks: shared and exclusive; 2 modes of locking: blocking and non-block

Dec 16, 2022
Collection of high performance, thread-safe, lock-free go data structures

Garr - Go libs in a Jar Collection of high performance, thread-safe, lock-free go data structures. adder - Data structure to perform highly-performant

Dec 26, 2022
Go Micro is a framework for distributed systems development

Go Micro Go Micro is a framework for distributed systems development. Overview Go Micro provides the core requirements for distributed systems develop

Jan 8, 2023
Go Micro is a standalone framework for distributed systems development

Go Micro Go Micro is a framework for distributed systems development. Overview Go Micro provides the core requirements for distributed systems develop

Dec 31, 2022
Tarmac is a unique framework designed for the next generation of distributed systems
Tarmac is a unique framework designed for the next generation of distributed systems

Framework for building distributed services with Web Assembly

Dec 31, 2022
A distributed systems library for Kubernetes deployments built on top of spindle and Cloud Spanner.

hedge A library built on top of spindle and Cloud Spanner that provides rudimentary distributed computing facilities to Kubernetes deployments. Featur

Nov 9, 2022
MIT 6.824: Distributed Systems

MIT 6.824 is a core 12-unit graduate subject with lectures, readings, programming labs, an optional project, a mid-term exam, and a final exam.

Jul 6, 2022
Distributed Systems 2021 - Miniproject 3

Distributed Systems 2021 -- Miniproject 3 Hand-in Date: 1 December 2021 (at 23:59) What to submit on learnit: a single zip-compressed file containing:

Dec 11, 2021