kvdroid

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

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

Go to latest
Published: May 9, 2019 License: MIT Imports: 10 Imported by: 0

README

kvdroid

This project is experimental and not actively maintained.

kvdroid is a simple experimental distributed key-value store in memory. It's primary purpose is to store large byte arrays chunked between multiple kvdroid-server instances and allow (userspace) zero-copy reads in client.

Features:

  • type-safe client API (value types are []byte and Uint32 only)
  • clients ring API with consistent hashing

Missing features:

  • client pool
  • high level API to manage byte array chunking

Server set up

Clone the repo and build the server:

$ git clone https://github.com/JCapul/kvdroid
$ cd kvdroid
$ make

This will produce the executables kvdroid-server and kvdroid-stop in the build/bin directory.

To launch the server on localhost and default port (8001):

$ build/bin/kvdroid-server

Launch a daemonized server:

$ build/bin/kvdroid-server -daemonize

To stop the server:

$ build/bin/kvdroid-stop

Client API basics

Get the go package:

$ go get github.com/JCapul/kvdroid

Create a client:

package main

import "github.com/JCapul/kvdroid"

func main() {
    kvdroid := kvdroid.NewClient([]byte(":8001")

Use SetBytes and GetBytes to store bytes.

    kvdroid.SetBytes("foo", []byte("bar"))
    b, err := kvdroid.GetBytes("foo")
    ...

Use GetBytesInto to read bytes directly into a user-defined byte slice, the call returns the number of bytes read:

    dst := make([]byte, 20, 20)
    n, err = client.GetBytesInto("foo", recv)

A set of API calls handle range of bytes similar to Redis SETRANGE/GETRANGE commands: SetBytesRange, GetBytesRange, SetBytesRangeInto.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is raised when the key requested by the client is not found
	ErrKeyNotFound = errors.New("key not found")
)

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	// contains filtered or unexported fields
}

Bucket stores data

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client ...

func NewClient

func NewClient(addr string) *Client

NewClient ...

func (*Client) Close

func (c *Client) Close() error

Close ...

func (*Client) DelBytes

func (c *Client) DelBytes(key string) error

DelBytes ...

func (*Client) DelUint

func (c *Client) DelUint(key string) error

DelUint ...

func (*Client) GetBytes

func (c *Client) GetBytes(key string) ([]byte, error)

GetBytes ...

func (*Client) GetBytesInto

func (c *Client) GetBytesInto(key string, dst []byte) (uint32, error)

GetBytesInto ...

func (*Client) GetBytesRange

func (c *Client) GetBytesRange(key string, start, end uint32) ([]byte, error)

GetBytesRange ...

func (*Client) GetBytesRangeInto

func (c *Client) GetBytesRangeInto(key string, start, end uint32, dst []byte) (uint32, error)

GetBytesRangeInto ...

func (*Client) GetUint

func (c *Client) GetUint(key string) (uint32, error)

GetUint ...

func (*Client) SetBytes

func (c *Client) SetBytes(key string, data []byte)

SetBytes ...

func (*Client) SetBytesRange

func (c *Client) SetBytesRange(key string, start uint32, data []byte)

SetBytesRange ...

func (*Client) SetUint

func (c *Client) SetUint(key string, val uint32)

SetUint ...

func (*Client) SetUintIfMax

func (c *Client) SetUintIfMax(key string, val uint32)

SetUintIfMax ...

func (*Client) Shutdown

func (c *Client) Shutdown()

Shutdown ...

func (*Client) TruncateBytes

func (c *Client) TruncateBytes(key string, size uint32) error

TruncateBytes ...

type ConsistentHash

type ConsistentHash struct {
	// contains filtered or unexported fields
}

ConsistentHash ...

func NewConsistentHash

func NewConsistentHash(replicas int, fn Hash) *ConsistentHash

NewConsistentHash ...

func (*ConsistentHash) Add

func (m *ConsistentHash) Add(keys ...string)

Add some keys to the hash.

func (*ConsistentHash) Get

func (m *ConsistentHash) Get(key string) string

Get the closest item in the hash to the provided key.

func (*ConsistentHash) IsEmpty

func (m *ConsistentHash) IsEmpty() bool

IsEmpty returns true if there are no items available.

type Hash

type Hash func(data []byte) uint32

Hash ...

type Message

type Message byte

Message enum

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring ...

func NewRing

func NewRing(addrs []string) *Ring

NewRing ...

func (*Ring) Close

func (r *Ring) Close() error

Close ...

func (*Ring) DelBytes

func (r *Ring) DelBytes(key string) error

DelBytes ...

func (*Ring) DelUint

func (r *Ring) DelUint(key string) error

DelUint ...

func (*Ring) GetBytes

func (r *Ring) GetBytes(key string) ([]byte, error)

GetBytes ...

func (*Ring) GetBytesRange

func (r *Ring) GetBytesRange(key string, start, end uint32) ([]byte, error)

GetBytesRange ...

func (*Ring) GetBytesRangeUinto

func (r *Ring) GetBytesRangeUinto(key string, start, end uint32, dst []byte) (uint32, error)

GetBytesRangeUinto ...

func (*Ring) GetBytesUinto

func (r *Ring) GetBytesUinto(key string, dst []byte) (uint32, error)

GetBytesUinto ...

func (*Ring) GetClient

func (r *Ring) GetClient(key string) *Client

GetClient ...

func (*Ring) GetUint

func (r *Ring) GetUint(key string) (uint32, error)

GetUint ...

func (*Ring) SetBytes

func (r *Ring) SetBytes(key string, data []byte)

SetBytes ...

func (*Ring) SetBytesRange

func (r *Ring) SetBytesRange(key string, start uint32, data []byte)

SetBytesRange ...

func (*Ring) SetUint

func (r *Ring) SetUint(key string, val uint32)

SetUint ...

func (*Ring) SetUintIfMax

func (r *Ring) SetUintIfMax(key string, val uint32)

SetUintIfMax ...

func (*Ring) TruncateBytes

func (r *Ring) TruncateBytes(key string, size uint32) error

TruncateBytes ...

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server ...

func NewServer

func NewServer(opt *ServerOptions) *Server

NewServer ...

func (Server) Addr

func (s Server) Addr() string

Addr ...

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown ...

func (*Server) Start

func (s *Server) Start()

Start ...

type ServerOptions

type ServerOptions struct {
	Bind    string
	Port    int
	Buckets int
}

ServerOptions ...

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages requests and buckets

func NewStore

func NewStore(n int, stopChan chan bool) *Store

NewStore ...

func (*Store) DelBytes

func (s *Store) DelBytes(bucket *Bucket, key string, conn net.Conn)

DelBytes ...

func (*Store) DelUint

func (s *Store) DelUint(bucket *Bucket, key string, conn net.Conn)

DelUint ...

func (*Store) GetBytes

func (s *Store) GetBytes(bucket *Bucket, key string, conn net.Conn)

GetBytes ...

func (*Store) GetBytesInto

func (s *Store) GetBytesInto(bucket *Bucket, key string, conn net.Conn)

GetBytesInto ...

func (*Store) GetBytesRange

func (s *Store) GetBytesRange(bucket *Bucket, key string, conn net.Conn)

GetBytesRange ...

func (*Store) GetBytesRangeInto

func (s *Store) GetBytesRangeInto(bucket *Bucket, key string, conn net.Conn)

GetBytesRangeInto ...

func (*Store) GetUint

func (s *Store) GetUint(bucket *Bucket, key string, conn net.Conn)

GetUint ...

func (*Store) SetBytes

func (s *Store) SetBytes(bucket *Bucket, key string, conn net.Conn)

SetBytes ...

func (*Store) SetBytesRange

func (s *Store) SetBytesRange(bucket *Bucket, key string, conn net.Conn)

SetBytesRange ...

func (*Store) SetUint

func (s *Store) SetUint(bucket *Bucket, key string, conn net.Conn)

SetUint ...

func (*Store) SetUintIfMax

func (s *Store) SetUintIfMax(bucket *Bucket, key string, conn net.Conn)

SetUintIfMax ...

func (*Store) TruncateBytes

func (s *Store) TruncateBytes(bucket *Bucket, key string, conn net.Conn)

TruncateBytes ...

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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