Migrate from libkv to valkeyrie library
This commit is contained in:
parent
a91080b060
commit
563a0bd274
33 changed files with 109 additions and 115 deletions
|
@ -10,9 +10,9 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/abronan/valkeyrie"
|
||||
"github.com/abronan/valkeyrie/store"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/docker/libkv"
|
||||
"github.com/docker/libkv/store"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -34,7 +34,7 @@ type BoltDB struct {
|
|||
dbIndex uint64
|
||||
path string
|
||||
timeout time.Duration
|
||||
// By default libkv opens and closes the bolt DB connection for every
|
||||
// By default valkeyrie opens and closes the bolt DB connection for every
|
||||
// get/put operation. This allows multiple apps to use a Bolt DB at the
|
||||
// same time.
|
||||
// PersistConnection flag provides an option to override ths behavior.
|
||||
|
@ -44,13 +44,13 @@ type BoltDB struct {
|
|||
}
|
||||
|
||||
const (
|
||||
libkvmetadatalen = 8
|
||||
metadatalen = 8
|
||||
transientTimeout = time.Duration(10) * time.Second
|
||||
)
|
||||
|
||||
// Register registers boltdb to libkv
|
||||
// Register registers boltdb to valkeyrie
|
||||
func Register() {
|
||||
libkv.AddStore(store.BOLTDB, New)
|
||||
valkeyrie.AddStore(store.BOLTDB, New)
|
||||
}
|
||||
|
||||
// New opens a new BoltDB connection to the specified path and bucket
|
||||
|
@ -126,7 +126,7 @@ func (b *BoltDB) releaseDBhandle() {
|
|||
}
|
||||
|
||||
// Get the value at "key". BoltDB doesn't provide an inbuilt last modified index with every kv pair. Its implemented by
|
||||
// by a atomic counter maintained by the libkv and appened to the value passed by the client.
|
||||
// by a atomic counter maintained by the valkeyrie and appened to the value passed by the client.
|
||||
func (b *BoltDB) Get(key string, opts *store.ReadOptions) (*store.KVPair, error) {
|
||||
var (
|
||||
val []byte
|
||||
|
@ -161,8 +161,8 @@ func (b *BoltDB) Get(key string, opts *store.ReadOptions) (*store.KVPair, error)
|
|||
return nil, err
|
||||
}
|
||||
|
||||
dbIndex := binary.LittleEndian.Uint64(val[:libkvmetadatalen])
|
||||
val = val[libkvmetadatalen:]
|
||||
dbIndex := binary.LittleEndian.Uint64(val[:metadatalen])
|
||||
val = val[metadatalen:]
|
||||
|
||||
return &store.KVPair{Key: key, Value: val, LastIndex: (dbIndex)}, nil
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ func (b *BoltDB) Put(key string, value []byte, opts *store.WriteOptions) error {
|
|||
b.Lock()
|
||||
defer b.Unlock()
|
||||
|
||||
dbval := make([]byte, libkvmetadatalen)
|
||||
dbval := make([]byte, metadatalen)
|
||||
|
||||
if db, err = b.getDBhandle(); err != nil {
|
||||
return err
|
||||
|
@ -287,8 +287,8 @@ func (b *BoltDB) List(keyPrefix string, opts *store.ReadOptions) ([]*store.KVPai
|
|||
|
||||
for key, v := cursor.Seek(prefix); bytes.HasPrefix(key, prefix); key, v = cursor.Next() {
|
||||
hasResult = true
|
||||
dbIndex := binary.LittleEndian.Uint64(v[:libkvmetadatalen])
|
||||
v = v[libkvmetadatalen:]
|
||||
dbIndex := binary.LittleEndian.Uint64(v[:metadatalen])
|
||||
v = v[metadatalen:]
|
||||
val := make([]byte, len(v))
|
||||
copy(val, v)
|
||||
|
||||
|
@ -338,7 +338,7 @@ func (b *BoltDB) AtomicDelete(key string, previous *store.KVPair) (bool, error)
|
|||
if val == nil {
|
||||
return store.ErrKeyNotFound
|
||||
}
|
||||
dbIndex := binary.LittleEndian.Uint64(val[:libkvmetadatalen])
|
||||
dbIndex := binary.LittleEndian.Uint64(val[:metadatalen])
|
||||
if dbIndex != previous.LastIndex {
|
||||
return store.ErrKeyModified
|
||||
}
|
||||
|
@ -363,7 +363,7 @@ func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair, opt
|
|||
b.Lock()
|
||||
defer b.Unlock()
|
||||
|
||||
dbval := make([]byte, libkvmetadatalen)
|
||||
dbval := make([]byte, metadatalen)
|
||||
|
||||
if db, err = b.getDBhandle(); err != nil {
|
||||
return false, nil, err
|
||||
|
@ -392,7 +392,7 @@ func (b *BoltDB) AtomicPut(key string, value []byte, previous *store.KVPair, opt
|
|||
if len(val) == 0 {
|
||||
return store.ErrKeyNotFound
|
||||
}
|
||||
dbIndex = binary.LittleEndian.Uint64(val[:libkvmetadatalen])
|
||||
dbIndex = binary.LittleEndian.Uint64(val[:metadatalen])
|
||||
if dbIndex != previous.LastIndex {
|
||||
return store.ErrKeyModified
|
||||
}
|
|
@ -8,8 +8,8 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/libkv"
|
||||
"github.com/docker/libkv/store"
|
||||
"github.com/abronan/valkeyrie"
|
||||
"github.com/abronan/valkeyrie/store"
|
||||
api "github.com/hashicorp/consul/api"
|
||||
)
|
||||
|
||||
|
@ -55,9 +55,9 @@ type consulLock struct {
|
|||
renewCh chan struct{}
|
||||
}
|
||||
|
||||
// Register registers consul to libkv
|
||||
// Register registers consul to valkeyrie
|
||||
func Register() {
|
||||
libkv.AddStore(store.CONSUL, New)
|
||||
valkeyrie.AddStore(store.CONSUL, New)
|
||||
}
|
||||
|
||||
// New creates a new Consul client given a list
|
|
@ -12,9 +12,9 @@ import (
|
|||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/abronan/valkeyrie"
|
||||
"github.com/abronan/valkeyrie/store"
|
||||
etcd "github.com/coreos/etcd/client"
|
||||
"github.com/docker/libkv"
|
||||
"github.com/docker/libkv/store"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -53,9 +53,9 @@ const (
|
|||
defaultUpdateTime = 5 * time.Second
|
||||
)
|
||||
|
||||
// Register registers etcd to libkv
|
||||
// Register registers etcd to valkeyrie
|
||||
func Register() {
|
||||
libkv.AddStore(store.ETCD, New)
|
||||
valkeyrie.AddStore(store.ETCD, New)
|
||||
}
|
||||
|
||||
// New creates a new Etcd client given a list
|
|
@ -7,10 +7,10 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/abronan/valkeyrie"
|
||||
"github.com/abronan/valkeyrie/store"
|
||||
etcd "github.com/coreos/etcd/clientv3"
|
||||
"github.com/coreos/etcd/clientv3/concurrency"
|
||||
"github.com/docker/libkv"
|
||||
"github.com/docker/libkv/store"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -38,9 +38,9 @@ type etcdLock struct {
|
|||
ttl time.Duration
|
||||
}
|
||||
|
||||
// Register registers etcd to libkv
|
||||
// Register registers etcd to valkeyrie
|
||||
func Register() {
|
||||
libkv.AddStore(store.ETCDV3, New)
|
||||
valkeyrie.AddStore(store.ETCDV3, New)
|
||||
}
|
||||
|
||||
// New creates a new Etcd client given a list
|
|
@ -25,7 +25,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
// ErrBackendNotSupported is thrown when the backend k/v store is not supported by libkv
|
||||
// ErrBackendNotSupported is thrown when the backend k/v store is not supported by valkeyrie
|
||||
ErrBackendNotSupported = errors.New("Backend storage not supported yet, please choose one of")
|
||||
// ErrCallNotSupported is thrown when a method is not implemented/supported by the current backend
|
||||
ErrCallNotSupported = errors.New("The current call is not supported with this backend")
|
||||
|
@ -66,7 +66,7 @@ type ClientTLSConfig struct {
|
|||
// Store represents the backend K/V storage
|
||||
// Each store should support every call listed
|
||||
// here. Or it couldn't be implemented as a K/V
|
||||
// backend for libkv
|
||||
// backend for valkeyrie
|
||||
type Store interface {
|
||||
// Put a value at the specified key
|
||||
Put(key string, value []byte, options *WriteOptions) error
|
|
@ -4,8 +4,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/libkv"
|
||||
"github.com/docker/libkv/store"
|
||||
"github.com/abronan/valkeyrie"
|
||||
"github.com/abronan/valkeyrie/store"
|
||||
zk "github.com/samuel/go-zookeeper/zk"
|
||||
)
|
||||
|
||||
|
@ -32,9 +32,9 @@ type zookeeperLock struct {
|
|||
value []byte
|
||||
}
|
||||
|
||||
// Register registers zookeeper to libkv
|
||||
// Register registers zookeeper to valkeyrie
|
||||
func Register() {
|
||||
libkv.AddStore(store.ZK, New)
|
||||
valkeyrie.AddStore(store.ZK, New)
|
||||
}
|
||||
|
||||
// New creates a new Zookeeper client given a
|
||||
|
@ -485,7 +485,7 @@ func (s *Zookeeper) get(key string) ([]byte, *zk.Stat, error) {
|
|||
var meta *zk.Stat
|
||||
var err error
|
||||
|
||||
// To guard against older versions of libkv
|
||||
// To guard against older versions of valkeyrie
|
||||
// creating and writing to znodes non-atomically,
|
||||
// We try to resync few times if we read SOH or
|
||||
// an empty string
|
||||
|
@ -518,7 +518,7 @@ func (s *Zookeeper) getW(key string) ([]byte, *zk.Stat, <-chan zk.Event, error)
|
|||
var ech <-chan zk.Event
|
||||
var err error
|
||||
|
||||
// To guard against older versions of libkv
|
||||
// To guard against older versions of valkeyrie
|
||||
// creating and writing to znodes non-atomically,
|
||||
// We try to resync few times if we read SOH or
|
||||
// an empty string
|
|
@ -1,11 +1,11 @@
|
|||
package libkv
|
||||
package valkeyrie
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/libkv/store"
|
||||
"github.com/abronan/valkeyrie/store"
|
||||
)
|
||||
|
||||
// Initialize creates a new Store object, initializing the client
|
||||
|
@ -34,7 +34,7 @@ func NewStore(backend store.Backend, addrs []string, options *store.Config) (sto
|
|||
return nil, fmt.Errorf("%s %s", store.ErrBackendNotSupported.Error(), supportedBackend)
|
||||
}
|
||||
|
||||
// AddStore adds a new store backend to libkv
|
||||
// AddStore adds a new store backend to valkeyrie
|
||||
func AddStore(store store.Backend, init Initialize) {
|
||||
initializers[store] = init
|
||||
}
|
8
vendor/github.com/containous/staert/kv.go
generated
vendored
8
vendor/github.com/containous/staert/kv.go
generated
vendored
|
@ -10,9 +10,9 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/abronan/valkeyrie"
|
||||
"github.com/abronan/valkeyrie/store"
|
||||
"github.com/containous/flaeg"
|
||||
"github.com/docker/libkv"
|
||||
"github.com/docker/libkv/store"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
|
@ -27,11 +27,11 @@ type KvSource struct {
|
|||
|
||||
// NewKvSource creates a new KvSource
|
||||
func NewKvSource(backend store.Backend, addrs []string, options *store.Config, prefix string) (*KvSource, error) {
|
||||
kvStore, err := libkv.NewStore(backend, addrs, options)
|
||||
kvStore, err := valkeyrie.NewStore(backend, addrs, options)
|
||||
return &KvSource{Store: kvStore, Prefix: prefix}, err
|
||||
}
|
||||
|
||||
// Parse uses libkv and mapstructure to fill the structure
|
||||
// Parse uses valkeyrie and mapstructure to fill the structure
|
||||
func (kv *KvSource) Parse(cmd *flaeg.Command) (*flaeg.Command, error) {
|
||||
err := kv.LoadConfig(cmd.Config)
|
||||
if err != nil {
|
||||
|
|
13
vendor/github.com/containous/staert/staert.go
generated
vendored
13
vendor/github.com/containous/staert/staert.go
generated
vendored
|
@ -105,14 +105,8 @@ func (ts *TomlSource) ConfigFileUsed() string {
|
|||
|
||||
func preprocessDir(dirIn string) (string, error) {
|
||||
dirOut := dirIn
|
||||
if strings.HasPrefix(dirIn, "$") {
|
||||
end := strings.Index(dirIn, string(os.PathSeparator))
|
||||
if end == -1 {
|
||||
end = len(dirIn)
|
||||
}
|
||||
dirOut = os.Getenv(dirIn[1:end]) + dirIn[end:]
|
||||
}
|
||||
dirOut, err := filepath.Abs(dirOut)
|
||||
expanded := os.ExpandEnv(dirIn)
|
||||
dirOut, err := filepath.Abs(expanded)
|
||||
return dirOut, err
|
||||
}
|
||||
|
||||
|
@ -123,7 +117,8 @@ func findFile(filename string, dirNfile []string) string {
|
|||
if fileInfo, err := os.Stat(fullPath); err == nil && !fileInfo.IsDir() {
|
||||
return fullPath
|
||||
}
|
||||
fullPath = fullPath + "/" + filename + ".toml"
|
||||
|
||||
fullPath = filepath.Join(fullPath, filename+".toml")
|
||||
if fileInfo, err := os.Stat(fullPath); err == nil && !fileInfo.IsDir() {
|
||||
return fullPath
|
||||
}
|
||||
|
|
2
vendor/github.com/docker/leadership/candidate.go
generated
vendored
2
vendor/github.com/docker/leadership/candidate.go
generated
vendored
|
@ -4,7 +4,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/libkv/store"
|
||||
"github.com/abronan/valkeyrie/store"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
2
vendor/github.com/docker/leadership/follower.go
generated
vendored
2
vendor/github.com/docker/leadership/follower.go
generated
vendored
|
@ -3,7 +3,7 @@ package leadership
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/docker/libkv/store"
|
||||
"github.com/abronan/valkeyrie/store"
|
||||
)
|
||||
|
||||
// Follower can follow an election in real-time and push notifications whenever
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue