• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    Clojure
  • License
    Apache License 2.0
  • Created about 13 years ago
  • Updated over 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Knockbox

Build status

Build Status

knockbox is an eventual-consistency toolbox for Clojure, and eventually the JVM in general. It's inspired by statebox and the paper A comprehensive study of Convergent and Commutative Replicated Data Types.

Databases like Riak let you trade consistency for availability. This means that you can have two conflicting values for a particular key. Resolving these conflicts is up to application-logic in the database clients. Certain data-types and operations are suited for automatic conflict-resolution. This project is a collection of these data-types and operations.

There is also a blog post about knockbox here.

Status

knockbox is currently in development and the API will be changing quickly, without notice.

Resolution Protocol

Each of the data type in knockbox implement the knockbox.resolvable/Resolvable protocol, which is currently simply:

(resolve [a b]))

When it comes time to resolve sibling, you can resolve a vector of them like this:

;; notice the namespace difference
(knockbox.core/resolve [a b c d e])

The data types also implement any appropriate Java Interfaces and Clojure Protocols. The different knockbox set implementations, for example, can be used just like Clojure Sets.

Sets

(require 'knockbox.sets)

;; last-write-wins set
(def a (knockbox.sets/lww))
;; => #{}

;; two-phase set
(def b (knockbox.sets/two-phase))
;; => #{}

;; observed-remove set 
(def c (knockbox.sets/observed-remove))
;; => #{}

(disj a :foo)
;; => #{}

(conj b :bar)
;; => #{:bar}

Registers

Registers are simple containers for values. Currently there is one Register implementation with last-write-wins semantics.

(require '(knockbox core registers))

;; the only argument to lww is the value
;; of the register
(def a (knockbox.registers/lww "1"))
(def b (knockbox.registers/lww "2"))
(def c (knockbox.registers/lww "3"))

;; the value can be queried like
(.value a)
;; => "1"

(.value (knockbox.core/resolve [c b a]))
;; => "3"

Maps

Maps are currently a work in progress, and don't yet implement all of the necessary Java intefaces.

Counters

Counters with an unbounded number of actors (ie. each of your JVM's + Pids) are a tough garbage collection problem. I haven't yet figured out a way to deal with this. Finding a way to bound the number of actors, and not doing GC may be another option.

Serialization

knockbox currently supports JSON serialization for the three set types. Usage below:

(require '(knockbox sets core))

(def a (knockbox.sets/lww))

(def b (conj a :foo :bar :baz))

(def j (knockbox.core/to-json b))

(def c (knockbox.core/from-json j))

(= b c)
;; => true

Tests

Tests can be run by typing:

lein deps # this only needs to be done once
lein midje

Documentation

Source documentation can be generated by typing:

lein deps
lein marg

lein deps only needs to be run once.

More Repositories

1

simple-check

QuickCheck for Clojure
Clojure
286
star
2

ordeal

Haskell
75
star
3

sumo

Clojure driver for Riak
Clojure
51
star
4

riak-ec2-cluster-launcher

A Python script to launch an N-node Riak cluster
Python
35
star
5

fn

Function utilities for Erlang
Erlang
24
star
6

distreader

CSS
23
star
7

your-first-chef-recipe

Ruby
18
star
8

clojure-transient-test

Tests demonstrating CLJ-1285
Clojure
11
star
9

tornadowatch

a simple pubsub server written in tornado (python)
Python
8
star
10

freshlinks

Freshlinks checks that the relative links between your markdown pages are correct, and helps keep them that way!
TypeScript
8
star
11

reiddraper.com

HTML
6
star
12

balsa

Haskell
5
star
13

cloud-haskell-sample

A trivial Cloud Haskell sample app
Haskell
4
star
14

crosscram

Clojure
3
star
15

scheme-haskell

code from "write yourself a scheme in 48 hours"
Haskell
2
star
16

learn-c-hard-way

C
2
star
17

data-traceability

2
star
18

project-euler

Haskell
2
star
19

haskell-logic

Fun with propositional logic in Haskell
Haskell
2
star
20

cocktail-recipes

cocktail recipes in drinkdown
2
star
21

operational-transform

Python
2
star
22

haskell-simple-check

Haskell
2
star
23

scribe_log

A simple Python script to send log data to Scribe
2
star
24

erlang-radix-tree

Erlang
1
star
25

array-binary-encoding

Python
1
star
26

figma-selector

TypeScript
1
star
27

hperf

Fun with an iperf-like tool in Haskell
Haskell
1
star
28

.js

dotjs files
JavaScript
1
star
29

issues

Python
1
star
30

stm-performance-test

Haskell
1
star
31

crosscram-sample

Clojure
1
star
32

concurrency-examples

Erlang
1
star
33

haskell-ring-chan

Haskell
1
star
34

haskell-pipes-fun

Haskell
1
star
35

riak-consistency-slides

1
star
36

knockbox-slides

1
star
37

tf-random-tests

Haskell
1
star