Skip to content
Open
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
14 changes: 13 additions & 1 deletion bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,11 @@ func (b *Bucket) node(pgId common.Pgid, parent *node) *node {
})
}

// If the page is compressed, decompress it before reading.
if p.IsCompressed() {
p = b.tx.decompressedPage(p)
}

// Read the page into the node and cache it.
n.read(p)
b.nodes[pgId] = n
Expand Down Expand Up @@ -945,7 +950,14 @@ func (b *Bucket) pageNode(id common.Pgid) (*common.Page, *node) {
}

// Finally lookup the page from the transaction if no node is materialized.
return b.tx.page(id), nil
p := b.tx.page(id)

// If the page is compressed, decompress it transparently.
if p.IsCompressed() {
p = b.tx.decompressedPage(p)
}

return p, nil
}

// BucketStats records statistics about resources used by a bucket.
Expand Down
3 changes: 3 additions & 0 deletions cmd/bbolt/command/command_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type benchOptions struct {
pageSize int
initialMmapSize int
deleteFraction float64 // Fraction of keys of last tx to delete during writes. works only with "seq-del" write mode.
compression bool
}

func (o *benchOptions) AddFlags(fs *pflag.FlagSet) {
Expand All @@ -61,6 +62,7 @@ func (o *benchOptions) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&o.goBenchOutput, "gobench-output", false, "")
fs.IntVar(&o.pageSize, "page-size", common.DefaultPageSize, "Set page size in bytes.")
fs.IntVar(&o.initialMmapSize, "initial-mmap-size", 0, "Set initial mmap size in bytes for database file.")
fs.BoolVar(&o.compression, "compression", false, "Enables compression.")
}

// Returns an error if `bench` options are not valid.
Expand Down Expand Up @@ -145,6 +147,7 @@ func benchFunc(cmd *cobra.Command, options *benchOptions) error {
dbOptions := *bolt.DefaultOptions
dbOptions.PageSize = options.pageSize
dbOptions.InitialMmapSize = options.initialMmapSize
dbOptions.Compression = options.compression
db, err := bolt.Open(options.path, 0600, &dbOptions)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/bbolt/command/command_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ func TestBenchCommand_Run(t *testing.T) {
tests := map[string]struct {
args []string
}{
"no-args": {},
"100k count": {[]string{"--count", "100000"}},
"no-args": {},
"100k count": {[]string{"--count", "100000"}},
"compression": {[]string{"--compression"}},
}

for name, test := range tests {
Expand Down
Loading
Loading