Skip to content

Build a distributed transactional key-value database

Notifications You must be signed in to change notification settings

thoainguyen/mtikv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MTiKV

Mini TiKV: A Distributed transactional key-value database

Architecture

Overall

Mtikv instance

Raft Group

Flow

TxnKV

RawKV

Getting Started

Prerequisites

  • Go: https://golang.org/doc/install

  • RocksDB:

    1. Clone repo Rocksdb:
    $ cd /home/$USER/Downloads
    $ git clone https://github.com/facebook/rocksdb.git
    1. Follow THIS GUIDE to install rocksdb
  • Gorocksdb:

    1. Set CGO variable
    export CGO_CFLAGS="-I/home/$USER/Downloads/rocksdb/include"
    export CGO_LDFLAGS="-L/home/$USER/Downloads/rocksdb  -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd"
    1. Get library
    $ go get github.com/tecbot/gorocksdb

Installing

  • Clone mtikv into workspace:
    $ cd ~/go/src/github.com && mkdir thoainguyen && cd thoainguyen
    $ git clone https://github.com/thoainguyen/mtikv
    $ cd mtikv

Deployment

1. Run PD:

$ cd cmd/pd
$ go run server.go

2. Run Mtikv_cli:

$ cd cmd/mtikv_cli
$ go run server.go

3. Run Mtikv (4 instance):

3.1 Option 1: Run each instance

$ cd cmd/mtikv
$ go run server.go --node 1
$ go run server.go --node 2 // in another shell
$ go run server.go --node 3 // in another shell
$ go run server.go --node 4 // in another shell

3.2 Option 2: Run via goreman

First install goreman, which manages Procfile-based applications.

The Procfile script will set up a local mtikv cluster. Start it with:

$ goreman start

4. Run Client (CLI)

$ cd cmd/client
$ go run client.go

Usage:

$ go run client.go
$ set <key> <value>
$ get <key>
$ del <key>
$ begin    // new transaction
$ commit   // commit transaction
$ rollback // rollback transaction
Ctr+C to exit

Authors

License

Acknowledgments

  • Mentor @thuyenpt