clean up etcd backing for sequence persistent storage. It uses some OS
specific calls and is not OS-agnostic.
This commit is contained in:
@@ -14,11 +14,6 @@ func TestFileBacking(t *testing.T) {
|
||||
verifySetGet(t, ms)
|
||||
}
|
||||
|
||||
func TestEtcdBacking(t *testing.T) {
|
||||
ms := &MetaStore{NewMetaStoreEtcdBacking("http://localhost:4001")}
|
||||
verifySetGet(t, ms)
|
||||
}
|
||||
|
||||
func verifySetGet(t *testing.T, ms *MetaStore) {
|
||||
data := uint64(234234)
|
||||
ms.SetUint64("/tmp/sequence", data)
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
// +build ignore
|
||||
|
||||
package metastore
|
||||
|
||||
import (
|
||||
"code.google.com/p/weed-fs/go/glog"
|
||||
"errors"
|
||||
"github.com/coreos/go-etcd/etcd"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// store data on etcd
|
||||
|
||||
type MetaStoreEtcdBacking struct {
|
||||
client *etcd.Client
|
||||
}
|
||||
|
||||
func NewMetaStoreEtcdBacking(etcdCluster string) *MetaStoreEtcdBacking {
|
||||
m := &MetaStoreEtcdBacking{}
|
||||
m.client = etcd.NewClient(strings.Split(etcdCluster, ","))
|
||||
return m
|
||||
}
|
||||
|
||||
func (m MetaStoreEtcdBacking) Set(path, val string) error {
|
||||
res, e := m.client.Set(path, val, 0)
|
||||
glog.V(2).Infof("etcd set response: %+v\n", res)
|
||||
return e
|
||||
}
|
||||
|
||||
func (m MetaStoreEtcdBacking) Get(path string) (string, error) {
|
||||
results, err := m.client.Get(path)
|
||||
for i, res := range results {
|
||||
glog.V(2).Infof("[%d] get response: %+v\n", i, res)
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if results[0].Key != path {
|
||||
return "", errors.New("Key Not Found:" + path)
|
||||
}
|
||||
return results[0].Value, nil
|
||||
}
|
||||
|
||||
func (m MetaStoreEtcdBacking) Has(path string) (ok bool) {
|
||||
results, err := m.client.Get(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if results[0].Key != path {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user