Distributed, fault-tolerant key-value storage written in go.

Godown

Build Status Go Report Card GitHub codecov

A simple, distributed, fault-tolerant key-value storage inspired by Redis. It uses Raft protocotol as consensus algorithm. It supports the following data structures: String, Bitmap, Map, List.

asciicast

How to install

Install via binaries

You can find binaries on the Github releases page.

/application/godown/godown-server -dir=/application/godown/data01 -id=01 -listen=127.0.0.1:14001 -raft=127.0.0.1:24001
/application/godown/godown-server -dir=/application/godown/data02 -id=02 -listen=127.0.0.1:14002 -raft=127.0.0.1:24002 -join=127.0.0.1:14001
/application/godown/godown-server -dir=/application/godown/data03 -id=03 -listen=127.0.0.1:14003 -raft=127.0.0.1:24003 -join=127.0.0.1:14001

Install via docker

# creating a network
docker network create godown 

# creating a volume
docker volume create godown 

# bootstrap a cluster with a single node
docker run -it --rm -v godown:/var/lib/godown --name=godown_1 --net=godown -p 5000:5000 \
    namreg/godown-server -id 1 -listen godown_1:5000 -raft godown_1:6000

# join the second node to the cluster
docker run -it --rm -v godown:/var/lib/godown --name=godown_2 --net=godown -p 5001:5001 \
    namreg/godown-server -id 2 -listen godown_2:5001 -join godown_1:5000 -raft godown_2:6001

# join the third node to the cluster
docker run -it --rm -v godown:/var/lib/godown --name=godown_3 --net=godown -p 5002:5002  \
    namreg/godown-server -id 3 -listen godown_3:5001 -join godown_1:5000 -raft godown_3:6002

Available options to run a server:

  -dir string
        Directory where data is stored.
  -gc duration
        Garbage collector interval.
  -id string
        Server unique id.
  -join string
        Server address to join.
  -listen string
        Server address to listen.
  -raft string
        Raft protocol listen address.
  -resp string
        Redis Serialization Protocol listen address.      
  -version
        Show version.

How to connect

You can connect to any godown node. All modifications will be replicated to all nodes.

Connect via any redis client

If you have specified resp address while starting a node, you can connect to the one by any redis client.

package main

import (
	"fmt"
	"net"
	"time"

	"github.com/garyburd/redigo/redis"
)

const connectionTimeout = 100 * time.Millisecond

func main() {
	conn, err := net.Dial("tcp", "6380")
	if err != nil {
		panic(err)
	}
	rconn := redis.NewConn(conn, connectionTimeout, connectionTimeout)

	reply, err := rconn.Do("LRANGE", "list", 0, 100)
	vals, err := redis.Strings(reply, err)

	if err != nil {
		panic(err)
	}

	fmt.Println(vals)
}

Connect via CLI

godown-cli

Available options:

  -host string
    	Host to connect to a server (default "127.0.0.1")
  -port string
    	Port to connect to a server (default "4000")
  -version
    	Show godown version.

Supported commands:

Command Description
HELP command Show the usage of the given command.
TYPE key Returns the type stored at key.
KEYS pattern Find all keys matching the given pattern.
PING [message] Returns PONG if no argument is provided, otherwise return a copy of the argument as a bulk.
EXPIRE key seconds Set a timeout on key. After the timeout has expired, the key will automatically be deleted.
TTL key Returns the remaining time to live of a key. -1 returns if key does not have timeout.
--- ---
SET key value Set key to hold the string value. If key already holds a value, it is overwritten.
GET key Get the value by key. If provided key does not exist NIL will be returned.
STRLEN key Returns length of the given key. If key does not exists, 0 will be returned.
DEL key Delete the given key.
--- ---
SETBIT key offset value Sets or clears the bit at offset in the string value stored at key.
GETBIT key offset Returns the bit value at offset in the string value stored at key.
--- ---
LPUSH key value [value ...] Prepend one or multiple values to a list.
LPOP key Removes and returns the first element of the list stored at key.
RPUSH key value [value ...] Append one or multiple values to a list.
RPOP key Removes and returns the last element of the list stored at key.
LLEN key Returns the length of the list stored at key. If key does not exist, it is interpreted as an empty list and 0 is returned.
LINDEX key index Returns the element at index index in the list stored at key.
The index is zero-based, so 0 means the first element, 1 the second element and so on. Negative indices can be used to designate elements starting at the tail of the list.
LRANGE key start stop Returns the specified elements of the list stored at key.
The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on.
LREM key value Removes all occurrences of elements equal to value from the list stored at key.
--- ---
HSET key field value Sets field in the hash stored at key to value.
HGET key field Returns the value associated with field in the hash stored at key.
HKEYS key Returns all field names in the hash stored at key. Order of fields is not guaranteed.
HVALS key Returns all values in the hash stored at key.
HDEL key field [field ...] Removes the specified fields from the hash stored at key. Returns the number of fields that were removed.

Connect via go client

package main

import (
	"fmt"

	"github.com/namreg/godown/client"
)

func main() {
	c, err := client.New("127.0.0.1:4000")
	if err != nil {
		panic(err)
	}
	defer c.Close()

	res := c.Get("key")
	if res.Err() != nil {
		panic(res.Err())
	}

	if res.IsNil() {
		fmt.Print("key does not exist")
	} else {
		fmt.Println(res.Int64())
	}
}

Client documentation available at godoc

TODO

  • Write more docs
  • Write more tests
Owner
Igor German
Backend developer (go)
Igor German
Similar Resources

Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.

Olric Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service. With

Jan 4, 2023

GhostDB is a distributed, in-memory, general purpose key-value data store that delivers microsecond performance at any scale.

GhostDB is a distributed, in-memory, general purpose key-value data store that delivers microsecond performance at any scale.

GhostDB is designed to speed up dynamic database or API driven websites by storing data in RAM in order to reduce the number of times an external data source such as a database or API must be read. GhostDB provides a very large hash table that is distributed across multiple machines and stores large numbers of key-value pairs within the hash table.

Jan 6, 2023

Distributed key-value store

Distributed key-value store

Keva Distributed key-value store General Demo Start the server docker-compose up --build Insert data curl -XPOST http://localhost:5555/storage/test1

Nov 15, 2021

Implementation of distributed key-value system based on TiKV

Distributed_key-value_system A naive implementation of distributed key-value system based on TiKV Features Features of this work are listed below: Dis

Mar 7, 2022

Pogreb is an embedded key-value store for read-heavy workloads written in Go.

Pogreb is an embedded key-value store for read-heavy workloads written in Go.

Embedded key-value store for read-heavy workloads written in Go

Dec 29, 2022

ZedisDB - a key-value memory database written in Go

ZedisDB - a key-value memory database written in Go

Sep 4, 2022

NutsDB a simple, fast, embeddable and persistent key/value store written in pure Go.

NutsDB a simple, fast, embeddable and persistent key/value store written in pure Go.

A simple, fast, embeddable, persistent key/value store written in pure Go. It supports fully serializable transactions and many data structures such as list, set, sorted set.

Jan 9, 2023

An embedded key/value database for Go.

Bolt Bolt is a pure Go key/value store inspired by Howard Chu's LMDB project. The goal of the project is to provide a simple, fast, and reliable datab

Dec 30, 2022

A disk-backed key-value store.

What is diskv? Diskv (disk-vee) is a simple, persistent key-value store written in the Go language. It starts with an incredibly simple API for storin

Jan 1, 2023
Comments
  • test(marshaler): add tests and benches on MarshalJSON

    test(marshaler): add tests and benches on MarshalJSON

    I added some tests on MarshalJSON to responds the TODO list in the README.md.

    I detected something weird during the marshaling of a BitMap Value.

    this value object:

    &Value{
      dataType: BitMapDataType,
      data: []uint64{1, 2, 3, 4}
    }
    

    is marshaled as:

    {
      "ttl": 0,
      "type": "bitmap",
      "value": [1, 12, 123, 1234]
    }
    

    But I was thinking that this simple BitMap Value would be marshaled as:

    {
      "ttl": 0,
      "type": "bitmap",
      "value": [1, 2, 3, 4]
    }
    

    am I missing something ?

  • Add gRPC-based API (?)

    Add gRPC-based API (?)

    Hi,

    I'm really impressed with this effort. I understand the main goal is to provide a transparent REDIS client API but would you consider an addition of a gRPC API in addition to the REDIS API? The benefits would be improved RPC semantics, speed and throughput (binary protocol).

    Would you accept contributions to that effect? (maintaining the API cleanly separated, of course)

  • lpush, rpush api inconsistent.

    lpush, rpush api inconsistent.

    I found lpush, rpush api inconsistent.

    // RPush appends a new value(s) to the list stored at the given key.
    func (c *Client) RPush(key, value string, values ...string) StatusResult
    
    //LPush prepends a new value to the list stored at the given key.
    func (c *Client) LPush(key, value string) StatusResult
    

    I think setting the api this way will make it more comfortable to use.

    func (c *Client) RPush(key, values ...string) StatusResult

    Originally posted by @fangpianqi in https://github.com/namreg/godown/issues/5#issuecomment-443554022

  • func (c *Client) RPush(key, value string, values ...string) StatusResult

    func (c *Client) RPush(key, value string, values ...string) StatusResult

    I seem to have found a new problem. In my application scenario, I need to use the rpush command to send 9000000 data entries. I started three instances to form a cluster, but in the end I found that the data in the list became 27000000 after the program was completed.

    Here is my test code

    package main
    
    import (
    	"fmt"
    	"github.com/namreg/godown/client"
    	"time"
    )
    
    const data = `
    	ow9sif3W+Of+dqe2xoII1QJ2OoZFS5zjz4NtdQ49BhPOUdSlQtHVfStNlyLBxD7kxU/BV9h6PjDen2VSIbbV69jEAamcQtT4r8MTtghMC+9H/dgfNUQJQmtvHkJPqHTho1rBSRFseOpmhR9SW2CJL+0tfKGK6hziwTlbdi40qUDy905zbteLCxf2RiNDLkmwQTx+KfPVFvNPHzDOBrgvA52ZgivGlIur6r2djaAqp0XbLQN+3pw5bR1AtB/GL9x56MU+BVDg/IOQH15klpmR+EEsABF3vNo6FBL7i+JDu6ri9z9jEjMxL+UZ/lFvTkzQSiyNsigps8GnDtjuyq2ZWmdh02HMgCfNZyz9BvVZlU9PE4SgFPBtW49V080iX5t8/qlppMcRRBmOiShjmo54uTT4r+48fKMu3qX2p6F9n4jxMBbQxUDPzCq7xmNS5g4f7sH7XLTKc/W7XI2V4TNYXXxqH0YATMjz7Jyo3fOkQtUN50WPBW5fNj8soW+52q4gQqdfJcEa34HiAEo3axX5Q5LO0giLdBF/zNiM0K0leQEfgEjoGviD9s1+t214FyoKnHBQgrrFf2HxGZnuMfiDVTtUEG5UqN+dRL5VD0ZTMzY/YEJ1Fn1NIy1R7vBfhKfZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA=
    	`
    
    func main() {
    
    	c, err := client.New("10.2.1.246:14001")
    
    	if err != nil {
    		fmt.Println(err)
    		return
    	}
    
    	start := time.Now()
    	for i := 0; i < 90; i ++ {
    		x := make([]string, 999)
    		for j := 0; j < 999; j++ {
    			x[j] = data
    		}
    		c.RPush("t13", data, x...)
    	}
    	fmt.Println(time.Since(start))
    }
    
    

    The amount of data has tripled, which is equivalent to the amount of data multiplied by the number of clusters.

Golang-key-value-store - Key Value Store API Service with Go DDD Architecture

This document specifies the tools used in the Key-Value store and reorganizes how to use them. In this created service, In-Memory Key-Value Service was created and how to use the API is specified in the HTML file in the folder named "doc"

Jul 31, 2022
A key-value db api with multiple storage engines and key generation
A key-value db api with multiple storage engines and key generation

Jet is a deadly-simple key-value api. The main goals of this project are : Making a simple KV tool for our other projects. Learn tests writing and git

Apr 5, 2022
Distributed reliable key-value store for the most critical data of a distributed system

etcd Note: The master branch may be in an unstable or even broken state during development. Please use releases instead of the master branch in order

Dec 28, 2022
Keyval - A simple key-value storage library written in Go

keyval keyval is a simple key-value storage library written in Go and its back c

Sep 16, 2022
Simple Distributed key-value database (in-memory/disk) written with Golang.

Kallbaz DB Simple Distributed key-value store (in-memory/disk) written with Golang. Installation go get github.com/msam1r/kallbaz-db Usage API // Get

Jan 18, 2022
The TinyKV course builds a key-value storage system with the Raft consensus algorithm.
The TinyKV course builds a key-value storage system with the Raft consensus algorithm.

The TinyKV Course The TinyKV course builds a key-value storage system with the Raft consensus algorithm. It is inspired by MIT 6.824 and TiKV Project.

Jan 4, 2022
A key-value storage transaction interpretator.

kv-txn-interpreter A key-value storage transaction interpreter, which provides an etcd-like transaction interface to help you build a transaction over

Feb 22, 2022
The TinyKV course builds a key-value storage system with the Raft consensus algorithm
The TinyKV course builds a key-value storage system with the Raft consensus algorithm

The TinyKV Course The TinyKV course builds a key-value storage system with the Raft consensus algorithm. It is inspired by MIT 6.824 and TiKV Project.

Jul 26, 2022
rosedb is a fast, stable and embedded key-value (k-v) storage engine based on bitcask.
rosedb is a fast, stable and embedded key-value (k-v) storage engine based on bitcask.

rosedb is a fast, stable and embedded key-value (k-v) storage engine based on bitcask. Its on-disk files are organized as WAL(Write Ahead Log) in LSM trees, optimizing for write throughput.

Dec 28, 2022
Tinykv - The TinyKV course builds a key-value storage system with the Raft consensus algorithm
Tinykv - The TinyKV course builds a key-value storage system with the Raft consensus algorithm

The TinyKV Course The TinyKV course builds a key-value storage system with the R

Dec 7, 2022