0
0

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
This commit is contained in:
Steve Yen 2016-11-18 10:34:27 -08:00
parent c351931701
commit 37490864ce
2 changed files with 26 additions and 2 deletions

View File

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

View File

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