Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manifest: unref files with range keys when version refcnt is zero #2022

Merged
merged 1 commit into from
Oct 20, 2022
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
7 changes: 7 additions & 0 deletions compaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,13 @@ func TestCompactionTombstones(t *testing.T) {
d.mu.Unlock()
return str

case "close":
if err := d.Close(); err != nil {
return err.Error()
}
d = nil
return ""

case "version":
d.mu.Lock()
s := d.mu.versions.currentVersion().String()
Expand Down
6 changes: 6 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,12 @@ func (d *DB) Close() error {
d.compactionSchedulers.Wait()
d.mu.Lock()

// As a sanity check, ensure that there are no zombie tables. A non-zero count
// hints at a reference count leak.
if ztbls := len(d.mu.versions.zombieTables); ztbls > 0 {
err = firstError(err, errors.Errorf("non-zero zombie file count: %d", ztbls))
}

// If the options include a closer to 'close' the filesystem, close it.
if d.opts.private.fsCloser != nil {
d.opts.private.fsCloser.Close()
Expand Down
3 changes: 3 additions & 0 deletions internal/manifest/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ func (v *Version) unrefFiles() []*FileMetadata {
for _, lm := range v.Levels {
obsolete = append(obsolete, lm.release()...)
}
for _, lm := range v.RangeKeyLevels {
obsolete = append(obsolete, lm.release()...)
}
return obsolete
}

Expand Down
37 changes: 37 additions & 0 deletions testdata/compaction_tombstones
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,40 @@ range-deletions-bytes-estimate: 0
maybe-compact
----
(none)

# Regression test for cockroachdb/cockroach#90149, exercising reference counting
# on tables that contain a mixture of point, range dels and range keys.
#
# Place a table in L6 that contains a RANGEKEYDEL. Because this table is in the
# bottom of the LSM, and there are no range keys below it, the RANGEKEYDEL is
# eligible for elision (the RANGEDEL too). After the elision, the input table
# should be deleted. In #90149, the table still had a reference count, and
# therefore could not be deleted from the filesystem.

define
L6
rangekey:a-b:{(#1,RANGEKEYDEL)}
a.SET.2:a
b.SET.3:b
c.SET.4:c
c.RANGEDEL.5:z
----
6:
000004:[a#2,SET-z#72057594037927935,RANGEDEL]

wait-pending-table-stats
000004
----
num-entries: 3
num-deletions: 1
num-range-key-sets: 0
point-deletions-bytes-estimate: 0
range-deletions-bytes-estimate: 39

maybe-compact
----
[JOB 100] compacted(elision-only) L6 [000004] (1001 B) + L6 [] (0 B) -> L6 [000005] (778 B), in 1.0s (2.0s total), output rate 778 B/s

# Close the DB, asserting that the reference counts balance.
close
----