ovskv

package module
v0.0.0-...-7a8b5d0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

OVSKV

Go library that presents high performance KV interface built on top of OVSDB.

Features

  • Implements generic key-value interface with support for hierarhical searches, e.g. /a/b/c => values
  • Implements Go struct introspection API, e.g. mapping Go struct on top of hierarhical key-value interface
  • Using OVSDB built-in conditional search to speed up key look up
  • Implements native OVSDB Set and Map primitives as key's value

Examples:

  • Hierarhical Key-Value interface
ovs, _ := ovskv.Init(DB_NAME, DB_CONNECT, DB_NAMESPACE, nil)

// create hierarhy of keys
uuid, _ := ovs.SetKV("/a", "a")
uuid, _ := ovs.SetKV("/a/b", "b")
uuid, _ := ovs.SetKV("/a/b/c", "c")
uuid, _ := ovs.SetKV("/a/b/d", "d")

// retrieve /a/b, /a/b/c, /a/b/d
rows, _ := ovs.GetKV("includes", "/a/b")

// delete all
ovs.DeleteKV("includes", "")

ovs.Disconnect()
  • Go struct introspection Save interface
type C struct {
	SubSubField1 string      `ovskv:"subfield1"`
}

type B struct {
	SubField1 string         `ovskv:"subfield1"`
	SubField2 C              `ovskv:"subfield2"`
}

type A struct {
	Field1 string            `ovskv:"field1"`
	Field2 int               `ovskv:"field2"`
	Field3 int64             `ovskv:"field3"`
	Field4 bool              `ovskv:"field4"`
	Field5 B                 `ovskv:"field5"`
	Field6 []B               `ovskv:"field6"`
}

...

a := A{
	Field1: "value1",
	Field2: 0,
	Field3: 123,
	Field4: false,
	Field5: B{
		SubField1: "value1",
		SubField2: C{
			SubSubField1: "value1",
		},
	},
	Field6: []B{
		{
			SubField1: "value1",
			SubField2: C{
				SubSubField1: "value1",
			},
		},
	},
}

ovs, _ := ovskv.Init(DB_NAME, DB_CONNECT, DB_NAMESPACE, &a)

// store the entire structure pointed by &a in key-value hierarhy
ovs.Save()

// modify one field
a.Field1 = "value1 changed3"

// update just one field
ovs.SaveField(&a.Field1)

ovs.Disconnect()
  • Go struct introspection Load interface
ovs, _ := ovskv.Init(DB_NAME, DB_CONNECT, DB_NAMESPACE, &a)

// load &a from existing key-value hierarhy
ovs.Load()

// re-load just one field
ovs.LoadField(&a.Field1, "/field1")

ovs.Disconnect()

Getting started

Steps to get library compiled and execute tests

install deps
go get -u github.com/stretchr/testify/assert github.com/ebay/libovsdb
create db
ovsdb-tool create ./testkv.db ./testkv.ovsschema
start server
ovsdb-server --remote=ptcp:6641 --remote=tcp:127.0.0.1:6641 ./testkv.db &>/tmp/out &
start tests and benchmarks
go test ovskv_test.go -v -bench

=== RUN   TestKV
--- PASS: TestKV (0.00s)
=== RUN   TestSaveAndLoad
Create Go struct, save it and load it back
--- PASS: TestSaveAndLoad (0.01s)
=== RUN   TestSaveField
Create Go struct with just one element, save it, modify it, save again and load it back
--- PASS: TestSaveField (0.00s)
goos: linux
goarch: amd64
BenchmarkStructSave
BenchmarkStructSave-8                854           1882251 ns/op           43223 B/op        863 allocs/op
BenchmarkStructLoad
BenchmarkStructLoad-8               1099           1203485 ns/op           38194 B/op       1019 allocs/op
BenchmarkKVSet
BenchmarkKVSet-8                    6025            307200 ns/op            7718 B/op        150 allocs/op
BenchmarkKVMGet
BenchmarkKVMGet-8                   3574            337058 ns/op            6289 B/op        136 allocs/op
PASS
access it
ovsdb-client list-dbs tcp:127.0.0.1:6641
ovsdb-client dump tcp:127.0.0.1:6641 TestKV
convert existing db to new schema version (bump version first)
ovsdb-tool convert ./testkv.db testkv.ovsschema

Documentation

Index

Constants

View Source
const (
	OP_INSERT   string = "insert"
	OP_UPDATE   string = "update"
	OP_DELETE   string = "delete"
	OP_SELECT   string = "select"
	SEPA        string = "/"
	OVSSET_SEPA string = ";"
	OVSKV_TAG   string = "ovskv"
	OVSKV_UUID  string = "_uuid"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type OvsKV

type OvsKV interface {
	InsertKV(key, val string) (string, error)
	InsertKVM(key string, val map[string]string)
	SetKV(key, val string) (string, error)
	SetKVM(key string, val map[string]string)
	DeleteKV(op, key string) (int, error)
	GetKV(op, key string) (OvsKVRow, error)
	GetKVM(op, key string) (*[]libovsdb.ResultRow, error)
	Save() error
	SaveField(field interface{}) error
	Load() error
	LoadField(data interface{}, prefix string) error
	Disconnect()
}

type OvsKVImpl

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

func Init

func Init(db_name, db_connect, db_namespace string, data interface{}) (*OvsKVImpl, error)

func (*OvsKVImpl) DeleteKV

func (o *OvsKVImpl) DeleteKV(op, key string) (int, error)

func (*OvsKVImpl) Disconnect

func (o *OvsKVImpl) Disconnect()

func (*OvsKVImpl) GetKV

func (o *OvsKVImpl) GetKV(op, key string) (OvsKVRows, error)

func (*OvsKVImpl) GetKVM

func (o *OvsKVImpl) GetKVM(op, key string) (*[]libovsdb.ResultRow, error)

func (*OvsKVImpl) GetKVNodes

func (o *OvsKVImpl) GetKVNodes(op, key string) (*node, error)

func (*OvsKVImpl) InsertKV

func (o *OvsKVImpl) InsertKV(key, val string) (string, error)

func (*OvsKVImpl) InsertKVM

func (o *OvsKVImpl) InsertKVM(key string, val map[string]string) (string, error)

func (*OvsKVImpl) Load

func (o *OvsKVImpl) Load() error

Load retrieves the data from the ovsdb into the given structure. Only attributes with the tag 'ovskv' will be filled.

func (*OvsKVImpl) LoadField

func (o *OvsKVImpl) LoadField(data interface{}, prefix string) error

LoadField retrieves the specific data from the ovsdb into the given structure. Only attributes with the tag 'ovskv' will be filled.

func (*OvsKVImpl) Save

func (o *OvsKVImpl) Save() error

Save stores a structure in ovskv. Only attributes with the tag 'ovskv' are going to be saved.

func (*OvsKVImpl) SaveField

func (o *OvsKVImpl) SaveField(field interface{}) error

SaveField saves a specific field from the configuration structure. Works in the same way of Save, but it can be used to save specific parts of the configuration, avoiding excessive requests to ovsdb cluster

func (*OvsKVImpl) SetKV

func (o *OvsKVImpl) SetKV(key, val string) (string, error)

func (*OvsKVImpl) SetKVM

func (o *OvsKVImpl) SetKVM(key string, val map[string]string) (string, error)

func (*OvsKVImpl) V

func (o *OvsKVImpl) V(v string) map[string]string

type OvsKVMap

type OvsKVMap map[string]string

type OvsKVRow

type OvsKVRow map[string]interface{}

type OvsKVRows

type OvsKVRows []OvsKVMap

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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