From 04d428656ecd18b7c9d52eea3af57ba750ffd04b Mon Sep 17 00:00:00 2001 From: Sundar Sridharan Date: Mon, 20 Feb 2017 14:44:35 -0800 Subject: [PATCH 1/2] Add Snapshot interface methods for moss child collections feature --- index/store/moss/lower.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/index/store/moss/lower.go b/index/store/moss/lower.go index 6f1b1dcf..ed742026 100644 --- a/index/store/moss/lower.go +++ b/index/store/moss/lower.go @@ -105,8 +105,9 @@ type llSnapshot struct { llStore *llStore // Holds 1 refs on the llStore. kvReader store.KVReader - m sync.Mutex // Protects fields that follow. - refs int + m sync.Mutex // Protects fields that follow. + refs int + childSnapshots map[string]*llSnapshot } // llIterator represents a lower-level iterator, wrapping a bleve @@ -316,6 +317,29 @@ func (llss *llSnapshot) decRef() { llss.m.Unlock() } +// ChildCollectionNames returns an array of child collection name strings. +func (llss *llSnapshot) ChildCollectionNames() ([]string, error) { + var childCollections = make([]string, len(llss.childSnapshots)) + idx := 0 + for name, _ := range llss.childSnapshots { + childCollections[idx] = name + idx++ + } + return childCollections, nil +} + +// ChildCollectionSnapshot returns a Snapshot on a given child +// collection by its name. +func (llss *llSnapshot) ChildCollectionSnapshot(childCollectionName string) ( + moss.Snapshot, error) { + childSnapshot, exists := llss.childSnapshots[childCollectionName] + if !exists { + return nil, nil + } + childSnapshot.addRef() + return childSnapshot, nil +} + func (llss *llSnapshot) Close() error { llss.decRef() From 74c7de0dcf01df1367d926d22fcef51f3333f3e5 Mon Sep 17 00:00:00 2001 From: Sundar Sridharan Date: Tue, 21 Feb 2017 15:54:04 -0800 Subject: [PATCH 2/2] re-order childSnapshot declaration --- index/store/moss/lower.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index/store/moss/lower.go b/index/store/moss/lower.go index ed742026..2aff2aea 100644 --- a/index/store/moss/lower.go +++ b/index/store/moss/lower.go @@ -102,12 +102,12 @@ type llStore struct { // llSnapshot represents a lower-level snapshot, wrapping a bleve // store.KVReader, and implements the moss.Snapshot interface. type llSnapshot struct { - llStore *llStore // Holds 1 refs on the llStore. - kvReader store.KVReader - - m sync.Mutex // Protects fields that follow. - refs int + llStore *llStore // Holds 1 refs on the llStore. + kvReader store.KVReader childSnapshots map[string]*llSnapshot + + m sync.Mutex // Protects fields that follow. + refs int } // llIterator represents a lower-level iterator, wrapping a bleve