From 37490864ce97f263d1e01edbe658f75e7d81c3b1 Mon Sep 17 00:00:00 2001 From: Steve Yen Date: Fri, 18 Nov 2016 10:34:27 -0800 Subject: [PATCH] bleve/index/store/moss - accessor for underlying mossStore This change adds methods that provide access to the actual, underlying mossStore instance in the bleve/index/store/moss KVStore adaptor. This enables applications to utilize advanced, mossStore-specific features (such as partial rollback of indexes). See also https://issues.couchbase.com/browse/MB-17805 --- index/store/moss/lower.go | 22 +++++++++++++++++++++- index/store/moss/store.go | 6 +++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/index/store/moss/lower.go b/index/store/moss/lower.go index 05f0fbf1..6f1b1dcf 100644 --- a/index/store/moss/lower.go +++ b/index/store/moss/lower.go @@ -473,6 +473,7 @@ func InitMossStore(config map[string]interface{}, options moss.CollectionOptions llSnapshot, err := llUpdate(nil) if err != nil { + _ = s.Close() return nil, nil, nil, nil, err } @@ -484,9 +485,13 @@ func InitMossStore(config map[string]interface{}, options moss.CollectionOptions return stats } - return llSnapshot, llUpdate, nil, llStats, nil + return llSnapshot, llUpdate, sw, llStats, nil } +// mossStoreWrapper implements the bleve.index.store.KVStore +// interface, but only barely enough to allow it to be passed around +// as a lower-level store. Advanced apps will likely cast the +// mossStoreWrapper to access the Actual() method. type mossStoreWrapper struct { m sync.Mutex refs int @@ -509,3 +514,18 @@ func (w *mossStoreWrapper) Close() (err error) { w.m.Unlock() return err } + +func (w *mossStoreWrapper) Reader() (store.KVReader, error) { + return nil, fmt.Errorf("unexpected") +} + +func (w *mossStoreWrapper) Writer() (store.KVWriter, error) { + return nil, fmt.Errorf("unexpected") +} + +func (w *mossStoreWrapper) Actual() *moss.Store { + w.m.Lock() + rv := w.s + w.m.Unlock() + return rv +} diff --git a/index/store/moss/store.go b/index/store/moss/store.go index ef5e4415..3e153d3a 100644 --- a/index/store/moss/store.go +++ b/index/store/moss/store.go @@ -38,7 +38,7 @@ type Store struct { m sync.Mutex ms moss.Collection mo store.MergeOperator - llstore store.KVStore // May be nil (ex: when using mossStore). + llstore store.KVStore // May be nil. llstats statsFunc // May be nil. s *stats @@ -203,6 +203,10 @@ func (s *Store) StatsMap() map[string]interface{} { return s.s.statsMap() } +func (s *Store) LowerLevelStore() store.KVStore { + return s.llstore +} + func init() { registry.RegisterKVStore(Name, New) }