Skip to content

Commit

Permalink
options: enable read based compactions
Browse files Browse the repository at this point in the history
This change enables read based compactions by default and sets the read
sampling threshold. This is based on the findings in
cockroachdb#29.
  • Loading branch information
aadityasondhi committed Dec 22, 2020
1 parent 4c4e043 commit 23ad85a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (i *Iterator) maybeSampleRead() {
return
}
samplingPeriod := readBytesPeriod * i.readState.db.opts.Experimental.ReadSamplingMultiplier
if samplingPeriod == 0 {
if samplingPeriod <= 0 {
return
}
if i.readSampling.rand == nil || i.readSampling.randvar == nil {
Expand Down
9 changes: 3 additions & 6 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,12 @@ type Options struct {
// conservative and allow approximately one seek for every 16KB
// of data before triggering a compaction.
// ```
// TODO(aadityasondhi): Experiment with this to find a good value
ReadCompactionRate int64

// ReadSamplingMultiplier is a multiplier for the readSamplingPeriod in
// iterator.maybeSampleRead() to control the frequency of read sampling
// to trigger a read triggered compaction. A value of 0 prevents sampling
// to trigger a read triggered compaction. A value of -1 prevents sampling
// and disables read triggered compactions.
//
// TODO(aadityasondhi): Experiment with this to find a good value
ReadSamplingMultiplier uint64
}

Expand Down Expand Up @@ -600,8 +597,8 @@ func (o *Options) EnsureDefaults() *Options {
if o.Experimental.ReadCompactionRate == 0 {
o.Experimental.ReadCompactionRate = 16000
}
if o.Experimental.ReadSamplingMultiplier != 0 {
o.Experimental.ReadSamplingMultiplier = 0
if o.Experimental.ReadSamplingMultiplier == 0 {
o.Experimental.ReadSamplingMultiplier = 1
}

o.initMaps()
Expand Down

0 comments on commit 23ad85a

Please sign in to comment.