seaweedfs/go/metastore/metastore.go
Chris Lu 5cb6590eae add metastore, switching sequence to use it
metastore is for storing metadata. This will be used later when moving
to distributed master mode.
2013-11-05 01:59:00 -08:00

36 lines
694 B
Go

package metastore
import (
"code.google.com/p/weed-fs/go/util"
"errors"
"path"
)
type MetaStoreBacking interface {
Get(elem ...string) ([]byte, error)
Set(val []byte, elem ...string) error
Has(elem ...string) bool
}
type MetaStore struct {
MetaStoreBacking
}
func (m *MetaStore) SetUint64(val uint64, elem ...string) error {
b := make([]byte, 8)
util.Uint64toBytes(b, val)
return m.Set(b, elem...)
}
func (m *MetaStore) GetUint64(elem ...string) (val uint64, err error) {
if b, e := m.Get(elem...); e == nil && len(b) == 8 {
val = util.BytesToUint64(b)
} else {
if e != nil {
return 0, e
}
err = errors.New("Not found value for " + path.Join(elem...))
}
return
}