Skip to content

Commit a674173

Browse files
committed
compute block length accounting for compression
Taken from PR #1698 and commit da5f789
1 parent a1e71f3 commit a674173

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

db.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,8 @@ var requestPool = sync.Pool{
758758
}
759759

760760
func (db *DB) writeToLSM(b *request) error {
761+
db.lock.RLock()
762+
defer db.lock.RUnlock()
761763
for i, entry := range b.Entries {
762764
var err error
763765
if entry.skipVlogAndSetThreshold(db.valueThreshold()) {

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
55
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
66
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
77
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
8-
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
98
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
109
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
1110
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=

table/builder.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ func NewTableBuilder(opts Options) *Builder {
157157
return b
158158
}
159159

160+
func maxEncodedLen(ctype options.CompressionType, sz int) int {
161+
switch ctype {
162+
case options.Snappy:
163+
return snappy.MaxEncodedLen(sz)
164+
case options.ZSTD:
165+
return y.ZSTDCompressBound(sz)
166+
}
167+
return sz
168+
}
169+
160170
func (b *Builder) handleBlock() {
161171
defer b.wg.Done()
162172

@@ -179,7 +189,7 @@ func (b *Builder) handleBlock() {
179189
// BlockBuf should always less than or equal to allocated space. If the blockBuf is greater
180190
// than allocated space that means the data from this block cannot be stored in its
181191
// existing location.
182-
allocatedSpace := (item.end) + padding + 1
192+
allocatedSpace := maxEncodedLen(b.opts.Compression, (item.end)) + padding + 1
183193
y.AssertTrue(len(blockBuf) <= allocatedSpace)
184194

185195
// blockBuf was allocated on allocator. So, we don't need to copy it over.

0 commit comments

Comments
 (0)