Git Product home page Git Product logo

kvdb's Introduction

kvdb

GoDoc Travis branch Go Report Card Code Coverage

Key Value Store abstraction library.

The kvdb library abstracts the caller from the specific key-value database implementation. The main goal of the kvdb library is to provide simple APIs to deal with only keys and values, and abstract away the intricate details of a specific key value stores. It also provides support for complex APIs like Snapshot, Watch and Lock which are built using the basic APIs.

Supported key value stores

  • Etcd v2
  • Etcd v3
  • Consul
  • In-memory store (local to the node)
  • Bolt DB (local to the node)
  • Zookeeper

Usage

The kvdb library is easy to use and requires you to create a new instance of the Kvdb object

package main

import (
  "github.com/portworx/kvdb"
  "github.com/portworx/kvdb/etcd/v3"
  "github.com/libopenstorage/openstorage/pkg/dbg"
)

func getKvdb(
  kvdbName string, // Use one of the kv store implementation names
  basePath string, // The path under which all the keys will be created by this kv instance
  discoveryEndpoints []string,  // A list of kv store endpoints
  options map[string]string, // Options that need to be passed to the kv store
  panicHandler kvdb.FatalErrorCB, // A callback function to execute when the library needs to panic
) (kvdb.Kvdb, error) {

	kv, err := kvdb.New(
		kvdbName,
		basePath,
		discoveryEndpoints,
		options,
		panicHandler,
	)
  return kv, err

}

type A struct {
   a1 string
   a2 int
}

func main() {

  // An example kvdb using etcd v3 as a key value store
  kv, err := getKvdb(
    v3.Name,
    "root/",
    []{"127.0.0.1:2379"},
    nil,
    dbg.Panicf,
  )
  if err != nil {
    fmt.Println("Failed to create a kvdb instance: ", err)
    return
  }

  // Put a key value pair foo=bar
  a := &A{"bar", 1}
  _, err = kv.Put("foo", &a, 0)
  if err != nil {
    fmt.Println("Failed to put a key in kvdb: ", err)
    return
  }

  // Get a key
  value := A{}
  _, err = kv.GetVal("foo", &value)
  if err != nil {
    fmt.Println("Failed to get a key from kvdb: ", err)
    return
  }
}

Contributing

We are always looking for contributions from the open source community. Send out a PR and we will review it.

Sign your work

The sign-off is a simple line at the end of the explanation for the patch, which certifies that you wrote it or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify the below (from developercertificate.org):

Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
660 York Street, Suite 102,
San Francisco, CA 94110 USA

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

then you just add a line to every git commit message:

Signed-off-by: Joe Smith <[email protected]>

using your real name (sorry, no pseudonyms or anonymous contributions.)

You can add the sign off when creating the git commit via git commit -s.

License

kvdb library is licensed under the Apache License 2.0

replace google.golang.org/grpc/naming => github.com/xiegeo/grpc-naming v1.29.1-alpha

kvdb's People

Contributors

adityadani avatar baopx avatar bufdev avatar disrani-px avatar glitchfix avatar gourao avatar jrivera-px avatar jvinod avatar multani avatar nrevanna avatar piyush-nimbalkar avatar pure-adamukaapan avatar pureneelesh avatar saheienko avatar sangleganesh avatar sdeoras avatar sharma-tapas avatar vinayakshnd avatar vlaxman-px avatar zoxpx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kvdb's Issues

Stop using global variables aka rm kvdb_mgr.go

The concept of having a global kvdb.KVDB instance, and other libraries relying on this, seems not only a dangerous pattern, but unnecessary. This is really messing with the refactor work on openstorage, we should talk.

How to test?

There should be some way to test this easily - one way to do this would be to use docker-compose to set up containers for consul and etcd, and then we can add continuous integration testing too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.