Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions leveldb/opt/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
DefaultWriteBuffer = 4 * MiB
DefaultWriteL0PauseTrigger = 12
DefaultWriteL0SlowdownTrigger = 8
DefaultFilterBaseLg = 11
)

// Cacher is a caching algorithm.
Expand Down Expand Up @@ -373,6 +374,11 @@ type Options struct {
//
// The default value is 8.
WriteL0SlowdownTrigger int

// FilterBaseLg is the log size for filter block to create a bloom filter.
//
// The default value is 11(as well as 2KB)
FilterBaseLg int
}

func (o *Options) GetAltFilters() []filter.Filter {
Expand Down Expand Up @@ -641,6 +647,13 @@ func (o *Options) GetWriteL0SlowdownTrigger() int {
return o.WriteL0SlowdownTrigger
}

func (o *Options) GetFilterBaseLg() int {
if o == nil || o.FilterBaseLg == 0 {
return DefaultFilterBaseLg
}
return o.FilterBaseLg
}

// ReadOptions holds the optional parameters for 'read operation'. The
// 'read operation' includes Get, Find and NewIterator.
type ReadOptions struct {
Expand Down
4 changes: 0 additions & 4 deletions leveldb/table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ const (
// These constants are part of the file format and should not be changed.
blockTypeNoCompression = 0
blockTypeSnappyCompression = 1

// Generate new filter every 2KB of data
filterBaseLg = 11
filterBase = 1 << filterBaseLg
)

type blockHandle struct {
Expand Down
6 changes: 4 additions & 2 deletions leveldb/table/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type filterWriter struct {
buf util.Buffer
nKeys int
offsets []uint32
baseLg int
}

func (w *filterWriter) add(key []byte) {
Expand All @@ -103,7 +104,7 @@ func (w *filterWriter) flush(offset uint64) {
if w.generator == nil {
return
}
for x := int(offset / filterBase); x > len(w.offsets); {
for x := int(offset / uint64(1<<w.baseLg)); x > len(w.offsets); {
w.generate()
}
}
Expand All @@ -122,7 +123,7 @@ func (w *filterWriter) finish() {
buf4 := w.buf.Alloc(4)
binary.LittleEndian.PutUint32(buf4, x)
}
w.buf.WriteByte(filterBaseLg)
w.buf.WriteByte(byte(w.baseLg))
}

func (w *filterWriter) generate() {
Expand Down Expand Up @@ -369,6 +370,7 @@ func NewWriter(f io.Writer, o *opt.Options) *Writer {
// filter block
if w.filter != nil {
w.filterBlock.generator = w.filter.NewGenerator()
w.filterBlock.baseLg = o.GetFilterBaseLg()
w.filterBlock.flush(0)
}
return w
Expand Down
2 changes: 2 additions & 0 deletions manualtest/dbstress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/filter"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/storage"
"github.com/syndtr/goleveldb/leveldb/table"
Expand Down Expand Up @@ -350,6 +351,7 @@ func main() {
DisableBlockCache: !enableBlockCache,
ErrorIfExist: true,
Compression: opt.NoCompression,
Filter: filter.NewBloomFilter(10),
}
if enableCompression {
o.Compression = opt.DefaultCompression
Expand Down