Skip to content

Commit

Permalink
*: Log info about read compactions
Browse files Browse the repository at this point in the history
This change, which is *not* meant for merging into a release
or master branch, is solely to add logging events when
a read compaction is appended to the db's slice, and when
a read compaction is picked off of the slice. This is to help
inform cockroachdb#1143.
  • Loading branch information
itsbilal committed May 17, 2021
1 parent 0be98f9 commit 85e0b39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,9 @@ type readCompaction struct {
level int
// Key ranges are used instead of file handles as versions could change
// between the read sampling and scheduling a compaction.
start []byte
end []byte
start []byte
end []byte
tableInfo manifest.TableInfo
}

func (d *DB) addInProgressCompaction(c *compaction) {
Expand Down
6 changes: 6 additions & 0 deletions compaction_picker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,9 @@ func pickReadTriggeredCompactionHelper(
) (pc *pickedCompaction) {
cmp := p.opts.Comparer.Compare
overlapSlice := p.vers.Overlaps(rc.level, cmp, rc.start, rc.end)
p.opts.Logger.Infof("pickReadTriggeredCompactionHelper: L%d [%s] (%s - %s)",
rc.level, rc.tableInfo.FileNum, rc.tableInfo.Smallest.Pretty(p.opts.Comparer.FormatKey),
rc.tableInfo.Largest.Pretty(p.opts.Comparer.FormatKey))
if overlapSlice.Empty() {
var shouldCompact bool
// If the file for the given key range has moved levels since the compaction
Expand All @@ -1367,9 +1370,12 @@ func pickReadTriggeredCompactionHelper(
if !shouldCompact {
return nil
}
p.opts.Logger.Infof("pickReadTriggeredCompactionHelper: updated level to L%d",
rc.level)
}
pc = newPickedCompaction(p.opts, p.vers, rc.level, p.baseLevel)
pc.startLevel.files = overlapSlice
p.opts.Logger.Infof("pickReadTriggeredCompactionHelper: overlaps %s", overlapSlice.String())
if !pc.setupInputs() {
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ func (i *Iterator) sampleRead() {
start: topFile.Smallest.UserKey,
end: topFile.Largest.UserKey,
level: topLevel,
tableInfo: topFile.TableInfo(),
}
i.readSampling.pendingCompactions = append(i.readSampling.pendingCompactions, read)
}
Expand Down Expand Up @@ -1021,6 +1022,12 @@ func (i *Iterator) Close() error {
i.readState.db.mu.Lock()
i.readState.db.mu.compact.readCompactions = append(i.readState.db.mu.compact.readCompactions, i.readSampling.pendingCompactions...)
i.readState.db.mu.Unlock()
for j := range i.readSampling.pendingCompactions {
i.readState.db.opts.Logger.Infof("read compaction appended: %s", LevelInfo{
Level: i.readSampling.pendingCompactions[j].level,
Tables: []TableInfo{i.readSampling.pendingCompactions[j].tableInfo},
})
}
}

i.readState.unref()
Expand Down

0 comments on commit 85e0b39

Please sign in to comment.