Skip to content

Commit

Permalink
db: don't allow table overlaps in compaction tests
Browse files Browse the repository at this point in the history
With all formats that tolerate split keys deprecated, we no longer
have to deal with tables overlapping in terms of user keys.

This commit adds a check to disallow any key overlap between tables in
compaction tests and removes offending test cases.
  • Loading branch information
RaduBerinde committed Dec 14, 2023
1 parent 6e9f783 commit b48b1df
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 159 deletions.
19 changes: 19 additions & 0 deletions compaction_picker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,14 @@ func TestPickedCompactionSetupInputs(t *testing.T) {
}
}

for _, levelFiles := range files {
for i := 1; i < len(levelFiles); i++ {
if !checkTableBoundary(levelFiles[i-1], levelFiles[i], opts.Comparer.Compare) {
d.Fatalf(t, "overlapping tables: %s and %s", levelFiles[i-1], levelFiles[i])
}
}
}

if pc.outputLevel.level == -1 {
pc.outputLevel.level = pc.startLevel.level + 1
}
Expand Down Expand Up @@ -1133,6 +1141,12 @@ func TestPickedCompactionExpandInputs(t *testing.T) {
files = append(files, meta)
}
manifest.SortBySmallest(files, cmp)
// Verify that the tables have no user key overlap.
for i := 1; i < len(files); i++ {
if !checkTableBoundary(files[i-1], files[i], cmp) {
d.Fatalf(t, "overlapping tables: %s and %s", files[i-1], files[i])
}
}
return ""

case "expand-inputs":
Expand Down Expand Up @@ -1590,3 +1604,8 @@ func checkClone(t *testing.T, pc *pickedCompaction) {
}
}
}

func checkTableBoundary(a, b *fileMetadata, cmp base.Compare) (ok bool) {
c := cmp(a.LargestPointKey.UserKey, b.SmallestPointKey.UserKey)
return c < 0 || (c == 0 && a.LargestPointKey.IsExclusiveSentinel())
}
53 changes: 0 additions & 53 deletions testdata/compaction_expand_inputs
Original file line number Diff line number Diff line change
Expand Up @@ -23,56 +23,3 @@ expand-inputs 1
expand-inputs 2
----
2: e#5,1-f#6,1

define
a.SET.1-b.SET.2
b.SET.1-d.SET.4
e.SET.5-f.SET.6
----

expand-inputs 0
----
0: a#1,1-b#2,1
1: b#1,1-d#4,1

expand-inputs 1
----
0: a#1,1-b#2,1
1: b#1,1-d#4,1

expand-inputs 2
----
2: e#5,1-f#6,1

define
a.SET.1-b.SET.2
b.SET.1-d.SET.4
d.SET.2-f.SET.6
----

expand-inputs 0
----
0: a#1,1-b#2,1
1: b#1,1-d#4,1
2: d#2,1-f#6,1

expand-inputs 1
----
0: a#1,1-b#2,1
1: b#1,1-d#4,1
2: d#2,1-f#6,1

define
a.SET.1-b.RANGEDEL.72057594037927935
b.SET.1-d.SET.4
d.SET.2-f.SET.6
----

expand-inputs 0
----
0: a#1,1-b#72057594037927935,15

expand-inputs 1
----
1: b#1,1-d#4,1
2: d#2,1-f#6,1
57 changes: 0 additions & 57 deletions testdata/compaction_setup_inputs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ L0
a.SET.1-b.SET.2
----

# Verify we expand the start level inputs to a clean cut.
setup-inputs a a
L1
a.SET.1-b.SET.2
b.SET.1-c.SET.2
----
L1
000001:[a#1,1-b#2,1]
000002:[b#1,1-c#2,1]

# The range deletion sentinel acts as a clean cut boundary.
setup-inputs a a
L1
Expand All @@ -29,20 +19,6 @@ L1
L1
000001:[a#1,1-b#72057594037927935,15]

# Verify we expand the output level inputs to a clean cut.
setup-inputs a a
L1
a.SET.5-b.SET.6
L2
a.SET.3-c.SET.4
c.SET.3-d.SET.2
----
L1
000001:[a#5,1-b#6,1]
L2
000002:[a#3,1-c#4,1]
000003:[c#3,1-d#2,1]

# Verify we expand the output level inputs to a clean cut.
setup-inputs a a
L1
Expand Down Expand Up @@ -85,22 +61,6 @@ L1
L2
000003:[a#3,1-d#4,1]

# Verify the available disk capacity limit doesn't affect the
# output level clean-cut expansion.
setup-inputs avail-bytes=10 a a
L1
a.SET.5-b.SET.6 size=5
c.SET.4-e.SET.3 size=10
L2
a.SET.3-d.SET.4 size=5
d.SET.2-e.SET.2 size=5
----
L1
000001:[a#5,1-b#6,1]
L2
000003:[a#3,1-d#4,1]
000004:[d#2,1-e#2,1]

# We won't grow the start level inputs if doing so would grow the
# output level inputs.
setup-inputs a a
Expand All @@ -116,23 +76,6 @@ L1
L2
000003:[a#3,1-d#4,1]

# Verify setup inputs can identify compacting files in range
setup-inputs a a
L1
a.SET.5-b.SET.6
L2
a.SET.3-c.SET.4
c.SET.3-d.SET.2 compacting
d.SET.3-e.SET.6
----
L1
000001:[a#5,1-b#6,1]
L2
000002:[a#3,1-c#4,1]
000003:[c#3,1-d#2,1]
000004:[d#3,1-e#6,1]
is-compacting

# Verify when there is one file in range and it is compacting
setup-inputs a a
L2
Expand Down
49 changes: 0 additions & 49 deletions testdata/compaction_setup_inputs_multilevel_write_amp
Original file line number Diff line number Diff line change
Expand Up @@ -180,29 +180,6 @@ init-multi-level(1,2,3)
Original WriteAmp 2.00; ML WriteAmp 1.50
Original OverlappingRatio 1.00; ML OverlappingRatio 0.50

# Verify an expansion of the output level in the initial setupInputs will init a multi-level
# compaction. i.e. without the initial expansion, the multil level compaction would not have
# occurred.
setup-inputs a a
L1
a.SET.5-b.SET.6 size=1
L2
a.SET.3-c.SET.4 size=1
c.SET.3-d.SET.2 size=1
L3
c.SET.4-d.SET.4 size=3
----
L1
000001:[a#5,1-b#6,1]
L2
000002:[a#3,1-c#4,1]
000003:[c#3,1-d#2,1]
L3
000004:[c#4,1-d#4,1]
init-multi-level(1,2,3)
Original WriteAmp 3.00; ML WriteAmp 2.00
Original OverlappingRatio 2.00; ML OverlappingRatio 1.00

setup-inputs a a
L1
a.SET.5-b.SET.6 size=1
Expand Down Expand Up @@ -274,32 +251,6 @@ L1
L2
000002:[a#5,1-b#6,1]

# During second setupInputs call, allow output level expansion even if max size
# limit is exceeded, but not conduct intermediate level expansion.
#
# TODO(msbutler): If second setup inputs exceeds maxSize limits, should the first compaction get
# returned?
setup-inputs avail-bytes=20 a a
L1
a.SET.1-b.SET.2 size=4
L2
a.SET.5-b.SET.6 size=5
c.SET.4-e.SET.3 size=8
L3
a.SET.3-d.SET.4 size=2
d.SET.2-e.SET.2 size=2
----
L1
000001:[a#1,1-b#2,1]
L2
000002:[a#5,1-b#6,1]
L3
000004:[a#3,1-d#4,1]
000005:[d#2,1-e#2,1]
init-multi-level(1,2,3)
Original WriteAmp 2.25; ML WriteAmp 1.44
Original OverlappingRatio 1.25; ML OverlappingRatio 0.44

# Don't init a multi-level compaction if the start level is L5.
setup-inputs a a
L5
Expand Down

0 comments on commit b48b1df

Please sign in to comment.