ddbsync

package module
v0.0.0-...-e940c2c Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2016 License: BSD-2-Clause Imports: 8 Imported by: 0

README

ddbsync

DynamoDB/sync

This package is designed to emulate the behaviour of pkg/sync on top of Amazon's DynamoDB. If you need a distributed locking mechanism, consider using this package and DynamoDB before standing up paxos or Zookeeper.

GoPkgDoc

Usage

Create a DynamoDB table named Locks.

$ export AWS_ACCESS_KEY=access
$ export AWS_SECRET_KEY=secret
// ./main.go

package main

import(
		"time"
		"github.com/ryandotsmith/ddbsync"
)

func main() {
		m := new(ddbsync.Mutex)
		m.Name = "some-name"
		m.Ttl = 10 * time.Second
		m.Lock()
		defer m.Unlock()
		// do important work here
		return
}
$ go get github.com/ryandotsmith/ddbsync
$ go run main.go

lock-smith

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

type Mutex struct {
	Name string
	Ttl  int64
}

A Mutex is a mutual exclusion lock. Mutexes can be created as part of other structures.

func (*Mutex) Lock

func (m *Mutex) Lock()

Lock will write an item in a DynamoDB table if the item does not exist. Before writing the lock, we will clear any locks that are expired. Calling this function will block until a lock can be acquired.

func (*Mutex) PruneExpired

func (m *Mutex) PruneExpired()

PruneExpired delete all locks that have lived past their TTL. This is to prevent deadlock from processes that have taken locks but never removed them after execution. This commonly happens when a processor experiences network failure.

func (*Mutex) Unlock

func (m *Mutex) Unlock()

Unlock will delete an item in a DynamoDB table.

Jump to

Keyboard shortcuts

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