From 45e1b2dfc681d21fb66b40d380b0c06f3204e6d6 Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Tue, 2 Sep 2014 13:56:35 -0400 Subject: [PATCH] removing gouchstore store impl this implementation didn't really adhere to the contract and now that we have boltdb we have a better pure go impl --- index/store/gouchstore/batch.go | 48 -------- index/store/gouchstore/iterator.go | 110 ------------------ index/store/gouchstore/store.go | 85 -------------- index/store/gouchstore/store_test.go | 27 ----- index/store/gouchstore/util.go | 19 --- .../upside_down/benchmark_gouchstore_test.go | 28 ----- index/upside_down/reader_test.go | 6 +- 7 files changed, 3 insertions(+), 320 deletions(-) delete mode 100644 index/store/gouchstore/batch.go delete mode 100644 index/store/gouchstore/iterator.go delete mode 100644 index/store/gouchstore/store.go delete mode 100644 index/store/gouchstore/store_test.go delete mode 100644 index/store/gouchstore/util.go delete mode 100644 index/upside_down/benchmark_gouchstore_test.go diff --git a/index/store/gouchstore/batch.go b/index/store/gouchstore/batch.go deleted file mode 100644 index 7647b26f..00000000 --- a/index/store/gouchstore/batch.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2014 Couchbase, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file -// except in compliance with the License. You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software distributed under the -// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -// either express or implied. See the License for the specific language governing permissions -// and limitations under the License. - -package gouchstore - -import ( - "github.com/mschoch/gouchstore" -) - -type GouchstoreBatch struct { - store *GouchstoreStore - bulk gouchstore.BulkWriter -} - -func newGouchstoreBatch(store *GouchstoreStore) *GouchstoreBatch { - rv := GouchstoreBatch{ - store: store, - bulk: store.db.Bulk(), - } - return &rv -} - -func (gb *GouchstoreBatch) Set(key, val []byte) { - id := string(key) - doc := gouchstore.Document{ID: id, Body: val} - docInfo := gouchstore.DocumentInfo{ID: id, ContentMeta: gouchstore.DOC_IS_COMPRESSED} - gb.bulk.Set(&docInfo, &doc) -} - -func (gb *GouchstoreBatch) Delete(key []byte) { - id := string(key) - docInfo := &gouchstore.DocumentInfo{ID: id, ContentMeta: gouchstore.DOC_IS_COMPRESSED} - gb.bulk.Delete(docInfo) -} - -func (gb *GouchstoreBatch) Execute() error { - return gb.bulk.Commit() -} - -func (gb *GouchstoreBatch) Close() error { - return gb.bulk.Close() -} diff --git a/index/store/gouchstore/iterator.go b/index/store/gouchstore/iterator.go deleted file mode 100644 index 330b9714..00000000 --- a/index/store/gouchstore/iterator.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2014 Couchbase, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file -// except in compliance with the License. You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software distributed under the -// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -// either express or implied. See the License for the specific language governing permissions -// and limitations under the License. - -package gouchstore - -import ( - "fmt" - - "github.com/mschoch/gouchstore" -) - -type GouchstoreIterator struct { - store *GouchstoreStore - valid bool - curr *gouchstore.DocumentInfo - diChan chan *gouchstore.DocumentInfo - closeChan chan bool -} - -func newGouchstoreIterator(store *GouchstoreStore) *GouchstoreIterator { - rv := GouchstoreIterator{ - store: store, - } - return &rv -} - -func (gi *GouchstoreIterator) cleanupExistingIterator() { - if gi.closeChan != nil { - close(gi.closeChan) - alive := true - for alive { - _, alive = <-gi.diChan - } - gi.closeChan = nil - } -} - -func (gi *GouchstoreIterator) SeekFirst() { - gi.Seek([]byte{}) -} - -func (gi *GouchstoreIterator) Seek(key []byte) { - gi.cleanupExistingIterator() - gi.curr = nil - gi.diChan = make(chan *gouchstore.DocumentInfo) - gi.closeChan = make(chan bool) - - wtCallback := func(gouchstore *gouchstore.Gouchstore, depth int, documentInfo *gouchstore.DocumentInfo, key []byte, subTreeSize uint64, reducedValue []byte, userContext interface{}) error { - - if documentInfo != nil && documentInfo.Deleted == false { - select { - case gi.diChan <- documentInfo: - gi.valid = true - case <-gi.closeChan: - return fmt.Errorf("seek aborted") - } - } - return nil - } - go func() { - gi.store.db.WalkIdTree(string(key), "", wtCallback, nil) - close(gi.diChan) - }() - gi.curr = <-gi.diChan -} - -func (gi *GouchstoreIterator) Current() ([]byte, []byte, bool) { - if gi.Valid() { - return gi.Key(), gi.Value(), true - } - return nil, nil, false -} - -func (gi *GouchstoreIterator) Next() { - gi.curr = <-gi.diChan - if gi.curr == nil { - gi.valid = false - } -} - -func (gi *GouchstoreIterator) Key() []byte { - if gi.curr != nil { - return []byte(gi.curr.ID) - } - return nil -} - -func (gi *GouchstoreIterator) Value() []byte { - if gi.curr != nil { - doc, err := gi.store.db.DocumentByDocumentInfo(gi.curr) - if err == nil { - return doc.Body - } - } - return nil -} - -func (gi *GouchstoreIterator) Valid() bool { - return gi.valid -} - -func (gi *GouchstoreIterator) Close() { - gi.cleanupExistingIterator() -} diff --git a/index/store/gouchstore/store.go b/index/store/gouchstore/store.go deleted file mode 100644 index d2f9a7f6..00000000 --- a/index/store/gouchstore/store.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2014 Couchbase, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file -// except in compliance with the License. You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software distributed under the -// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -// either express or implied. See the License for the specific language governing permissions -// and limitations under the License. - -package gouchstore - -import ( - "github.com/blevesearch/bleve/index/store" - "github.com/mschoch/gouchstore" -) - -type GouchstoreStore struct { - path string - db *gouchstore.Gouchstore -} - -func Open(path string) (*GouchstoreStore, error) { - rv := GouchstoreStore{ - path: path, - } - - var err error - rv.db, err = gouchstore.Open(path, gouchstore.OPEN_CREATE) - if err != nil { - return nil, err - } - - return &rv, nil -} - -func (gs *GouchstoreStore) Get(key []byte) ([]byte, error) { - var docInfo gouchstore.DocumentInfo - err := gs.db.DocumentInfoByIdNoAlloc(string(key), &docInfo) - if err != nil && err.Error() != "document not found" { - return nil, err - } - if err != nil && err.Error() == "document not found" { - return nil, nil - } - var doc gouchstore.Document - if !docInfo.Deleted { - err := gs.db.DocumentByIdNoAlloc(string(key), &doc) - if err != nil { - return nil, err - } - return doc.Body, nil - } - return nil, nil -} - -func (gs *GouchstoreStore) Set(key, val []byte) error { - doc := gouchstore.NewDocument(string(key), val) - docInfo := gouchstore.NewDocumentInfo(string(key)) - return gs.db.SaveDocument(doc, docInfo) -} - -func (gs *GouchstoreStore) Delete(key []byte) error { - doc := gouchstore.NewDocument(string(key), nil) - docInfo := gouchstore.NewDocumentInfo(string(key)) - docInfo.Deleted = true - return gs.db.SaveDocument(doc, docInfo) -} - -func (gs *GouchstoreStore) Commit() error { - return gs.db.Commit() -} - -func (gs *GouchstoreStore) Close() error { - return gs.db.Close() -} - -func (gs *GouchstoreStore) Iterator(key []byte) store.KVIterator { - rv := newGouchstoreIterator(gs) - rv.Seek(key) - return rv -} - -func (gs *GouchstoreStore) NewBatch() store.KVBatch { - return newGouchstoreBatch(gs) -} diff --git a/index/store/gouchstore/store_test.go b/index/store/gouchstore/store_test.go deleted file mode 100644 index 89ca33cd..00000000 --- a/index/store/gouchstore/store_test.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2014 Couchbase, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file -// except in compliance with the License. You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software distributed under the -// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -// either express or implied. See the License for the specific language governing permissions -// and limitations under the License. - -package gouchstore - -import ( - "os" - "testing" - - "github.com/blevesearch/bleve/index/store/test" -) - -func TestGouchstoreStore(t *testing.T) { - s, err := Open("test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll("test") - - store_test.CommonTestKVStore(t, s) -} diff --git a/index/store/gouchstore/util.go b/index/store/gouchstore/util.go deleted file mode 100644 index efada28f..00000000 --- a/index/store/gouchstore/util.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2014 Couchbase, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file -// except in compliance with the License. You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software distributed under the -// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -// either express or implied. See the License for the specific language governing permissions -// and limitations under the License. - -package gouchstore - -import ( - "github.com/mschoch/gouchstore" -) - -func kvToDocDocInfo(key, val []byte) (*gouchstore.Document, *gouchstore.DocumentInfo) { - id := string(key) - return gouchstore.NewDocument(id, val), gouchstore.NewDocumentInfo(id) -} diff --git a/index/upside_down/benchmark_gouchstore_test.go b/index/upside_down/benchmark_gouchstore_test.go deleted file mode 100644 index 9b9d9e24..00000000 --- a/index/upside_down/benchmark_gouchstore_test.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2014 Couchbase, Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file -// except in compliance with the License. You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software distributed under the -// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -// either express or implied. See the License for the specific language governing permissions -// and limitations under the License. - -package upside_down - -import ( - "os" - "testing" - - "github.com/blevesearch/bleve/index/store/gouchstore" -) - -func BenchmarkGouchstoreIndexing(b *testing.B) { - s, err := gouchstore.Open("test") - if err != nil { - b.Fatal(err) - } - defer os.RemoveAll("test") - defer s.Close() - - CommonBenchmarkIndex(b, s) -} diff --git a/index/upside_down/reader_test.go b/index/upside_down/reader_test.go index 94345f2f..c5454705 100644 --- a/index/upside_down/reader_test.go +++ b/index/upside_down/reader_test.go @@ -16,13 +16,13 @@ import ( "github.com/blevesearch/bleve/document" "github.com/blevesearch/bleve/index" - "github.com/blevesearch/bleve/index/store/gouchstore" + "github.com/blevesearch/bleve/index/store/boltdb" ) func TestIndexReader(t *testing.T) { defer os.RemoveAll("test") - store, err := gouchstore.Open("test") + store, err := boltdb.Open("test", "bleve") idx := NewUpsideDownCouch(store) err = idx.Open() if err != nil { @@ -164,7 +164,7 @@ func TestIndexReader(t *testing.T) { func TestIndexDocIdReader(t *testing.T) { defer os.RemoveAll("test") - store, err := gouchstore.Open("test") + store, err := boltdb.Open("test", "bleve") idx := NewUpsideDownCouch(store) err = idx.Open() if err != nil {