0
0

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
This commit is contained in:
Marty Schoch 2014-09-02 13:56:35 -04:00
parent 7a7eb2e94c
commit 45e1b2dfc6
7 changed files with 3 additions and 320 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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