0
0

Merge pull request #420 from steveyen/MB-20590

index/store/moss KV backend propagates mossStore's Stats()
This commit is contained in:
Marty Schoch 2016-09-11 20:28:29 -04:00 committed by GitHub
commit f531835d5c
4 changed files with 53 additions and 19 deletions

View File

@ -32,7 +32,7 @@ func initLowerLevelStore(
lowerLevelStoreConfig map[string]interface{},
lowerLevelMaxBatchSize uint64,
options moss.CollectionOptions,
) (moss.Snapshot, moss.LowerLevelUpdate, store.KVStore, error) {
) (moss.Snapshot, moss.LowerLevelUpdate, store.KVStore, statsFunc, error) {
if lowerLevelStoreConfig == nil {
lowerLevelStoreConfig = map[string]interface{}{}
}
@ -50,13 +50,13 @@ func initLowerLevelStore(
constructor := registry.KVStoreConstructorByName(lowerLevelStoreName)
if constructor == nil {
return nil, nil, nil, fmt.Errorf("moss store, initLowerLevelStore,"+
return nil, nil, nil, nil, fmt.Errorf("moss store, initLowerLevelStore,"+
" could not find lower level store: %s", lowerLevelStoreName)
}
kvStore, err := constructor(options.MergeOperator, lowerLevelStoreConfig)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}
llStore := &llStore{
@ -74,10 +74,10 @@ func initLowerLevelStore(
llSnapshot, err := llUpdate(nil)
if err != nil {
_ = kvStore.Close()
return nil, nil, nil, err
return nil, nil, nil, nil, err
}
return llSnapshot, llUpdate, kvStore, nil // llStore.refs is now 1.
return llSnapshot, llUpdate, kvStore, nil, nil // llStore.refs is now 1.
}
// ------------------------------------------------
@ -410,16 +410,16 @@ func (lli *llIterator) CurrentEx() (
// ------------------------------------------------
func InitMossStore(config map[string]interface{}, options moss.CollectionOptions) (
moss.Snapshot, moss.LowerLevelUpdate, store.KVStore, error) {
moss.Snapshot, moss.LowerLevelUpdate, store.KVStore, statsFunc, error) {
path, ok := config["path"].(string)
if !ok {
return nil, nil, nil, fmt.Errorf("lower: missing path for InitMossStore config")
return nil, nil, nil, nil, fmt.Errorf("lower: missing path for InitMossStore config")
}
err := os.MkdirAll(path, 0700)
if err != nil {
return nil, nil, nil, fmt.Errorf("lower: InitMossStore mkdir, path: %s, err: %v",
path, err)
return nil, nil, nil, nil, fmt.Errorf("lower: InitMossStore mkdir,"+
" path: %s, err: %v", path, err)
}
storeOptions := moss.StoreOptions{
@ -429,19 +429,19 @@ func InitMossStore(config map[string]interface{}, options moss.CollectionOptions
if ok {
b, err := json.Marshal(v) // Convert from map[string]interface{}.
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}
err = json.Unmarshal(b, &storeOptions)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}
}
s, err := moss.OpenStore(path, storeOptions)
if err != nil {
return nil, nil, nil, fmt.Errorf("lower: moss.OpenStore, path: %s, err: %v",
path, err)
return nil, nil, nil, nil, fmt.Errorf("lower: moss.OpenStore,"+
" path: %s, err: %v", path, err)
}
sw := &mossStoreWrapper{s: s}
@ -461,10 +461,18 @@ func InitMossStore(config map[string]interface{}, options moss.CollectionOptions
llSnapshot, err := llUpdate(nil)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}
return llSnapshot, llUpdate, nil, nil
llStats := func() map[string]interface{} {
stats, err := s.Stats()
if err != nil {
return nil
}
return stats
}
return llSnapshot, llUpdate, nil, llStats, nil
}
type mossStoreWrapper struct {

View File

@ -34,6 +34,11 @@ func (s *stats) statsMap() map[string]interface{} {
}
}
_, exists := ms["kv"]
if !exists && s.s.llstats != nil {
ms["kv"] = s.s.llstats()
}
return ms
}

View File

@ -35,11 +35,14 @@ type Store struct {
m sync.Mutex
ms moss.Collection
mo store.MergeOperator
llstore store.KVStore
llstore store.KVStore // May be nil (ex: when using mossStore).
llstats statsFunc // May be nil.
s *stats
}
type statsFunc func() map[string]interface{}
// New initializes a moss storage with values from the optional
// config["mossCollectionOptions"] (a JSON moss.CollectionOptions).
// Next, values from the RegistryCollectionOptions, named by the
@ -102,6 +105,8 @@ func New(mo store.MergeOperator, config map[string]interface{}) (
}
var llStore store.KVStore
var llStats statsFunc
if options.LowerLevelInit == nil &&
options.LowerLevelUpdate == nil &&
mossLowerLevelStoreName != "" {
@ -127,7 +132,7 @@ func New(mo store.MergeOperator, config map[string]interface{}) (
mossLowerLevelMaxBatchSize = uint64(mossLowerLevelMaxBatchSizeF)
}
lowerLevelInit, lowerLevelUpdate, lowerLevelStore, err :=
lowerLevelInit, lowerLevelUpdate, lowerLevelStore, lowerLevelStats, err :=
initLowerLevelStore(config,
mossLowerLevelStoreName,
mossLowerLevelStoreConfig,
@ -139,7 +144,9 @@ func New(mo store.MergeOperator, config map[string]interface{}) (
options.LowerLevelInit = lowerLevelInit
options.LowerLevelUpdate = lowerLevelUpdate
llStore = lowerLevelStore
llStats = lowerLevelStats
}
// --------------------------------------------------
@ -156,6 +163,7 @@ func New(mo store.MergeOperator, config map[string]interface{}) (
ms: ms,
mo: mo,
llstore: llStore,
llstats: llStats,
}
rv.s = &stats{s: &rv}
return &rv, nil

17
vendor/manifest vendored
View File

@ -4,6 +4,7 @@
{
"importpath": "github.com/blevesearch/go-porterstemmer",
"repository": "https://github.com/blevesearch/go-porterstemmer",
"vcs": "",
"revision": "23a2c8e5cf1f380f27722c6d2ae8896431dc7d0e",
"branch": "master",
"notests": true
@ -11,6 +12,7 @@
{
"importpath": "github.com/blevesearch/segment",
"repository": "https://github.com/blevesearch/segment",
"vcs": "",
"revision": "db70c57796cc8c310613541dfade3dce627d09c7",
"branch": "master",
"notests": true
@ -18,6 +20,7 @@
{
"importpath": "github.com/boltdb/bolt",
"repository": "https://github.com/boltdb/bolt",
"vcs": "",
"revision": "144418e1475d8bf7abbdc48583500f1a20c62ea7",
"branch": "master",
"notests": true
@ -25,13 +28,15 @@
{
"importpath": "github.com/couchbase/moss",
"repository": "https://github.com/couchbase/moss",
"revision": "e013f5f973e5b094ecf61e08ae9aa3754bd22d15",
"vcs": "git",
"revision": "564bdbc09ecc32cb398b56b855a5a6dc9fd7cce5",
"branch": "master",
"notests": true
},
{
"importpath": "github.com/golang/protobuf/proto",
"repository": "https://github.com/golang/protobuf",
"vcs": "",
"revision": "655cdfa588ea190e901bc5590e65d5621688847c",
"branch": "master",
"path": "/proto",
@ -40,6 +45,7 @@
{
"importpath": "github.com/golang/snappy",
"repository": "https://github.com/golang/snappy",
"vcs": "",
"revision": "cef980a12b316c5b7e5bb3a8e168eb43ae999a88",
"branch": "master",
"notests": true
@ -47,6 +53,7 @@
{
"importpath": "github.com/rcrowley/go-metrics",
"repository": "https://github.com/rcrowley/go-metrics",
"vcs": "",
"revision": "dee209f2455f101a5e4e593dea94872d2c62d85d",
"branch": "master",
"notests": true
@ -54,6 +61,7 @@
{
"importpath": "github.com/steveyen/gtreap",
"repository": "https://github.com/steveyen/gtreap",
"vcs": "",
"revision": "0abe01ef9be25c4aedc174758ec2d917314d6d70",
"branch": "master",
"notests": true
@ -61,6 +69,7 @@
{
"importpath": "github.com/syndtr/goleveldb/leveldb",
"repository": "https://github.com/syndtr/goleveldb",
"vcs": "",
"revision": "93fc893f2dadb96ffde441c7546cc67ea290a3a8",
"branch": "master",
"path": "/leveldb",
@ -69,6 +78,7 @@
{
"importpath": "github.com/willf/bitset",
"repository": "https://github.com/willf/bitset",
"vcs": "",
"revision": "2e6e8094ef4745224150c88c16191c7dceaad16f",
"branch": "master",
"notests": true
@ -76,6 +86,7 @@
{
"importpath": "golang.org/x/net/context",
"repository": "https://go.googlesource.com/net",
"vcs": "",
"revision": "e45385e9b226f570b1f086bf287b25d3d4117776",
"branch": "master",
"path": "/context",
@ -84,6 +95,7 @@
{
"importpath": "golang.org/x/text/transform",
"repository": "https://go.googlesource.com/text",
"vcs": "",
"revision": "5ee49cfe751141f8017047bab800d1f528ee3be1",
"branch": "master",
"path": "/transform",
@ -92,10 +104,11 @@
{
"importpath": "golang.org/x/text/unicode/norm",
"repository": "https://go.googlesource.com/text",
"vcs": "",
"revision": "5ee49cfe751141f8017047bab800d1f528ee3be1",
"branch": "master",
"path": "/unicode/norm",
"notests": true
}
]
}
}