nano

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 21 Imported by: 4

README

nano

Godoc Report Tests Coverage Sponsor

High-performance database. Basically network and disk synchronized hashmaps.

Benchmarks

BenchmarkCollectionGet-12               317030264                3.75 ns/op            0 B/op          0 allocs/op
BenchmarkCollectionSet-12               11678318               102 ns/op              32 B/op          2 allocs/op
BenchmarkCollectionDelete-12            123748969                9.50 ns/op            5 B/op          0 allocs/op
BenchmarkCollectionAll-12                1403905               859 ns/op            2144 B/op          2 allocs/op

Features

  • Low latency commands
  • Every command is "local first, sync later"
  • Data is stored in memory
  • Data is synchronized between all nodes in a cluster
  • Data is saved to disk persistently using JSON
  • Timestamp based conflict resolution
  • Uses the extremely fast sync.Map

Terminology

  • Namespace: Contains multiple collections (e.g. "google")
  • Collection: Contains homogeneous data for a data type (e.g. "User")
  • Key: The string that lets you look up a single object in a collection

All of the above require a unique name. Given namespace, collection and key, you can access the data stored for it.

Style

Please take a look at the style guidelines if you'd like to make a pull request.

Sponsors

Cedric Fung Scott Rayapoullé Eduard Urbach
Cedric Fung Scott Rayapoullé Eduard Urbach

Want to see your own name here?

Documentation

Index

Constants

View Source
const ChannelBufferSize = 128

ChannelBufferSize is the size of the channels used to iterate over a whole collection.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

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

Collection is a hash map of data of the same type that is synchronized across network and disk.

func (*Collection) All

func (collection *Collection) All() chan interface{}

All returns a channel of all objects in the collection.

func (*Collection) Clear

func (collection *Collection) Clear()

Clear deletes all objects from the collection.

func (*Collection) Count added in v0.1.8

func (collection *Collection) Count() int64

Count gives you a rough estimate of how many elements are in the collection. It DOES NOT GUARANTEE that the returned number is the actual number of elements. A good use for this function is to preallocate slices with the given capacity. In the future, this function could possibly return the exact number of elements.

func (*Collection) Delete

func (collection *Collection) Delete(key string) bool

Delete deletes a key from the collection.

func (*Collection) Exists

func (collection *Collection) Exists(key string) bool

Exists returns whether or not the key exists.

func (*Collection) Get

func (collection *Collection) Get(key string) (interface{}, error)

Get returns the value for the given key.

func (*Collection) GetMany

func (collection *Collection) GetMany(keys []string) []interface{}

GetMany is the same as Get, except it looks up multiple keys at once.

func (*Collection) Set

func (collection *Collection) Set(key string, value interface{})

Set sets the value for the key.

type Configuration added in v0.3.0

type Configuration struct {
	// Port is the port used by the server and client nodes.
	Port int

	// Directory includes the path to the namespaces stored on the disk.
	Directory string

	// Hosts represents a list of node addresses that this node should connect to.
	Hosts []string
}

Configuration represents the nano configuration which is only read once at node creation time.

type Namespace

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

Namespace combines multiple collections under a single name.

func (*Namespace) All

func (ns *Namespace) All(name string) chan interface{}

All returns a channel of all objects in the collection.

func (*Namespace) Clear

func (ns *Namespace) Clear(collection string)

Clear deletes all objects from the collection.

func (*Namespace) ClearAll

func (ns *Namespace) ClearAll()

ClearAll deletes all objects from all collections, effectively resetting the entire database.

func (*Namespace) Close

func (ns *Namespace) Close()

Close will close all collections in the namespace, forcing them to sync all data to disk before shutting down.

func (*Namespace) Collection

func (ns *Namespace) Collection(name string) *Collection

Collection returns the collection with the given name.

func (*Namespace) Delete

func (ns *Namespace) Delete(collection string, key string) bool

Delete deletes a key from the collection.

func (*Namespace) Exists

func (ns *Namespace) Exists(collection string, key string) bool

Exists returns whether or not the key exists.

func (*Namespace) Get

func (ns *Namespace) Get(collection string, key string) (interface{}, error)

Get returns the value for the given key.

func (*Namespace) GetMany

func (ns *Namespace) GetMany(collection string, keys []string) []interface{}

GetMany is the same as Get, except it looks up multiple keys at once.

func (*Namespace) HasType

func (ns *Namespace) HasType(typeName string) bool

HasType returns true if the given type name has been registered.

func (*Namespace) Node

func (ns *Namespace) Node() *Node

Node returns the cluster node used for this namespace.

func (*Namespace) Prefetch

func (ns *Namespace) Prefetch()

Prefetch loads all the data for this namespace from disk into memory.

func (*Namespace) RegisterTypes

func (ns *Namespace) RegisterTypes(types ...interface{}) *Namespace

RegisterTypes expects a list of pointers and will look up the types of the given pointers. These types will be registered so that collections can store data using the given type. Note that nil pointers are acceptable.

func (*Namespace) Set

func (ns *Namespace) Set(collection string, key string, value interface{})

Set sets the value for the key.

func (*Namespace) Types

func (ns *Namespace) Types() map[string]reflect.Type

Types returns a map of type names mapped to their reflection type.

type Node

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

Node represents a single database node in the cluster.

func New

func New(config Configuration) *Node

New starts up a new database node.

func (*Node) Address

func (node *Node) Address() net.Addr

Address ...

func (*Node) Broadcast

func (node *Node) Broadcast(msg *packet.Packet)

Broadcast ...

func (*Node) Clear

func (node *Node) Clear()

Clear deletes all data in the Node.

func (*Node) Client

func (node *Node) Client() *client.Node

Client ...

func (*Node) Close

func (node *Node) Close()

Close frees up resources used by the node.

func (*Node) IsClosed

func (node *Node) IsClosed() bool

IsClosed ...

func (*Node) IsServer

func (node *Node) IsServer() bool

IsServer ...

func (*Node) Namespace

func (node *Node) Namespace(name string) *Namespace

Namespace ...

func (*Node) Server

func (node *Node) Server() *server.Node

Server ...

Jump to

Keyboard shortcuts

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