Skip to content

Commit

Permalink
search: fully fleshed out leveldb store for bleve
Browse files Browse the repository at this point in the history
Issue: HOTPOT-1262
  • Loading branch information
strib committed Dec 4, 2019
1 parent 90d6031 commit 70485d6
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 61 deletions.
45 changes: 39 additions & 6 deletions go/kbfs/search/bleve_leveldb_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package search
import (
"github.com/blevesearch/bleve/index/store"
"github.com/keybase/client/go/kbfs/libfs"
"github.com/pkg/errors"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/iterator"
"github.com/syndtr/goleveldb/leveldb/util"
Expand Down Expand Up @@ -108,6 +109,32 @@ func (bldbr *bleveLevelDBReader) Close() error {
return nil
}

type bleveLevelDBBatch struct {
b *leveldb.Batch
}

var _ store.KVBatch = (*bleveLevelDBBatch)(nil)

func (bldbb *bleveLevelDBBatch) Set(key, val []byte) {
bldbb.b.Put(key, val)
}

func (bldbb *bleveLevelDBBatch) Delete(key []byte) {
bldbb.b.Delete(key)
}

func (bldbb *bleveLevelDBBatch) Merge(key, val []byte) {
panic("Merge called")
}

func (bldbb *bleveLevelDBBatch) Reset() {
bldbb.b.Reset()
}

func (bldbb *bleveLevelDBBatch) Close() error {
return nil
}

type bleveLevelDBWriter struct {
db *leveldb.DB
}
Expand All @@ -116,22 +143,28 @@ var _ store.KVWriter = (*bleveLevelDBWriter)(nil)

// NewBatch implements the store.KVReader interface for bleveLevelDBWriter.
func (bldbw *bleveLevelDBWriter) NewBatch() store.KVBatch {
return nil
return &bleveLevelDBBatch{b: leveldb.MakeBatch(0)}
}

// NewBatchEx implements the store.KVReader interface for bleveLevelDBWriter.
func (bldbw *bleveLevelDBWriter) NewBatchEx(store.KVBatchOptions) (
func (bldbw *bleveLevelDBWriter) NewBatchEx(opts store.KVBatchOptions) (
[]byte, store.KVBatch, error) {
return nil, nil, nil
b := &bleveLevelDBBatch{b: leveldb.MakeBatch(opts.TotalBytes)}
return b.b.Dump(), b, nil
}

// ExecuteBatch implements the store.KVReader interface for bleveLevelDBWriter.
func (bldbw *bleveLevelDBWriter) ExecuteBatch(batch store.KVBatch) error {
return nil
b, ok := batch.(*bleveLevelDBBatch)
if !ok {
return errors.Errorf("Unexpected batch type: %T", batch)
}
return bldbw.db.Write(b.b, nil)
}

// Close implements the store.KVReader interface for bleveLevelDBWriter.
func (bldbw *bleveLevelDBWriter) Close() error {
// Does this need to close outstanding batches allocated by this writer?
return nil
}

Expand All @@ -156,7 +189,7 @@ func newBleveLevelDBStore(bfs billy.Filesystem, readOnly bool) (

// Writer implements the store.KVStore interface for bleveLevelDBStore.
func (bldbs *bleveLevelDBStore) Writer() (store.KVWriter, error) {
return nil, nil
return &bleveLevelDBWriter{db: bldbs.db}, nil
}

// Writer implements the store.KVStore interface for bleveLevelDBStore.
Expand All @@ -170,5 +203,5 @@ func (bldbs *bleveLevelDBStore) Reader() (store.KVReader, error) {

// close implements the store.KVStore interface for bleveLevelDBStore.
func (bldbs *bleveLevelDBStore) Close() error {
return nil
return bldbs.db.Close()
}
5 changes: 5 additions & 0 deletions go/vendor/github.com/syndtr/goleveldb/leveldb/batch.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion go/vendor/github.com/syndtr/goleveldb/leveldb/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions go/vendor/github.com/syndtr/goleveldb/leveldb/db_compaction.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 26 additions & 17 deletions go/vendor/github.com/syndtr/goleveldb/leveldb/db_iter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions go/vendor/github.com/syndtr/goleveldb/leveldb/db_transaction.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion go/vendor/github.com/syndtr/goleveldb/leveldb/opt/options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 70485d6

Please sign in to comment.