Browse Source

clean up etcd backing for sequence persistent storage. It uses some OS

specific calls and is not OS-agnostic.
pull/2/head
Chris Lu 11 years ago
parent
commit
2e2f426fe2
  1. 5
      go/metastore/backing_test.go
  2. 53
      go/metastore/etcd_backing.go
  3. 7
      go/sequence/sequence.go
  4. 1
      go/weed/master.go
  5. 4
      go/weed/weed_server/master_server.go

5
go/metastore/backing_test.go

@ -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)

53
go/metastore/etcd_backing.go

@ -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
}

7
go/sequence/sequence.go

@ -34,13 +34,6 @@ func NewFileSequencer(filepath string) (m *SequencerImpl) {
return
}
//func NewEtcdSequencer(etcdCluster string) (m *SequencerImpl) {
// m = &SequencerImpl{fileFullPath: "/weedfs/default/sequence"}
// m.metaStore = &metastore.MetaStore{metastore.NewMetaStoreEtcdBacking(etcdCluster)}
// m.initilize()
// return
//}
func (m *SequencerImpl) initilize() {
if !m.metaStore.Has(m.fileFullPath) {
m.FileIdSequence = FileIdSaveInterval

1
go/weed/master.go

@ -37,7 +37,6 @@ var (
mMaxCpu = cmdMaster.Flag.Int("maxCpu", 0, "maximum number of CPUs. 0 means all available CPUs")
garbageThreshold = cmdMaster.Flag.String("garbageThreshold", "0.3", "threshold to vacuum and reclaim spaces")
masterWhiteListOption = cmdMaster.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.")
//etcdCluster = cmdMaster.Flag.String("etcd", "", "comma separated etcd urls, e.g., http://localhost:4001, See github.com/coreos/go-etcd/etcd")
masterWhiteList []string
)

4
go/weed/weed_server/master_server.go

@ -40,11 +40,7 @@ func NewMasterServer(r *mux.Router, version string, port int, metaFolder string,
garbageThreshold: garbageThreshold,
whiteList: whiteList,
}
//if len(*etcdCluster) == 0 {
seq := sequence.NewFileSequencer(path.Join(metaFolder, "weed.seq"))
//} else {
// seq = sequence.NewEtcdSequencer(*etcdCluster)
//}
var e error
if ms.topo, e = topology.NewTopology("topo", confFile, seq,
uint64(volumeSizeLimitMB)*1024*1024, pulseSeconds); e != nil {

Loading…
Cancel
Save