Skip to content

Commit

Permalink
Merge pull request #420 from steveyen/MB-20590
Browse files Browse the repository at this point in the history
index/store/moss KV backend propagates mossStore's Stats()
  • Loading branch information
mschoch authored Sep 12, 2016
2 parents 5cf50ec + e8cc3c6 commit f531835
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
38 changes: 23 additions & 15 deletions index/store/moss/lower.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
}
Expand All @@ -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{
Expand All @@ -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.
}

// ------------------------------------------------
Expand Down Expand Up @@ -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{
Expand All @@ -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}
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions index/store/moss/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
12 changes: 10 additions & 2 deletions index/store/moss/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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,
Expand All @@ -139,7 +144,9 @@ func New(mo store.MergeOperator, config map[string]interface{}) (

options.LowerLevelInit = lowerLevelInit
options.LowerLevelUpdate = lowerLevelUpdate

llStore = lowerLevelStore
llStats = lowerLevelStats
}

// --------------------------------------------------
Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions vendor/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,39 @@
{
"importpath": "github.com/blevesearch/go-porterstemmer",
"repository": "https://github.com/blevesearch/go-porterstemmer",
"vcs": "",
"revision": "23a2c8e5cf1f380f27722c6d2ae8896431dc7d0e",
"branch": "master",
"notests": true
},
{
"importpath": "github.com/blevesearch/segment",
"repository": "https://github.com/blevesearch/segment",
"vcs": "",
"revision": "db70c57796cc8c310613541dfade3dce627d09c7",
"branch": "master",
"notests": true
},
{
"importpath": "github.com/boltdb/bolt",
"repository": "https://github.com/boltdb/bolt",
"vcs": "",
"revision": "144418e1475d8bf7abbdc48583500f1a20c62ea7",
"branch": "master",
"notests": true
},
{
"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",
Expand All @@ -40,27 +45,31 @@
{
"importpath": "github.com/golang/snappy",
"repository": "https://github.com/golang/snappy",
"vcs": "",
"revision": "cef980a12b316c5b7e5bb3a8e168eb43ae999a88",
"branch": "master",
"notests": true
},
{
"importpath": "github.com/rcrowley/go-metrics",
"repository": "https://github.com/rcrowley/go-metrics",
"vcs": "",
"revision": "dee209f2455f101a5e4e593dea94872d2c62d85d",
"branch": "master",
"notests": true
},
{
"importpath": "github.com/steveyen/gtreap",
"repository": "https://github.com/steveyen/gtreap",
"vcs": "",
"revision": "0abe01ef9be25c4aedc174758ec2d917314d6d70",
"branch": "master",
"notests": true
},
{
"importpath": "github.com/syndtr/goleveldb/leveldb",
"repository": "https://github.com/syndtr/goleveldb",
"vcs": "",
"revision": "93fc893f2dadb96ffde441c7546cc67ea290a3a8",
"branch": "master",
"path": "/leveldb",
Expand All @@ -69,13 +78,15 @@
{
"importpath": "github.com/willf/bitset",
"repository": "https://github.com/willf/bitset",
"vcs": "",
"revision": "2e6e8094ef4745224150c88c16191c7dceaad16f",
"branch": "master",
"notests": true
},
{
"importpath": "golang.org/x/net/context",
"repository": "https://go.googlesource.com/net",
"vcs": "",
"revision": "e45385e9b226f570b1f086bf287b25d3d4117776",
"branch": "master",
"path": "/context",
Expand All @@ -84,6 +95,7 @@
{
"importpath": "golang.org/x/text/transform",
"repository": "https://go.googlesource.com/text",
"vcs": "",
"revision": "5ee49cfe751141f8017047bab800d1f528ee3be1",
"branch": "master",
"path": "/transform",
Expand All @@ -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
}
]
}
}

0 comments on commit f531835

Please sign in to comment.