From b48b1df25646e51ec365188d8f953e7ce5173353 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Wed, 13 Dec 2023 09:41:28 -0800 Subject: [PATCH] db: don't allow table overlaps in compaction tests 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. --- compaction_picker_test.go | 19 +++++++ testdata/compaction_expand_inputs | 53 ----------------- testdata/compaction_setup_inputs | 57 ------------------- ...mpaction_setup_inputs_multilevel_write_amp | 49 ---------------- 4 files changed, 19 insertions(+), 159 deletions(-) diff --git a/compaction_picker_test.go b/compaction_picker_test.go index 85db2a9cdb..d43efc5c07 100644 --- a/compaction_picker_test.go +++ b/compaction_picker_test.go @@ -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 } @@ -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": @@ -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()) +} diff --git a/testdata/compaction_expand_inputs b/testdata/compaction_expand_inputs index 86035f1a80..80e8676934 100644 --- a/testdata/compaction_expand_inputs +++ b/testdata/compaction_expand_inputs @@ -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 diff --git a/testdata/compaction_setup_inputs b/testdata/compaction_setup_inputs index 6755a8f4a9..c973d0a987 100644 --- a/testdata/compaction_setup_inputs +++ b/testdata/compaction_setup_inputs @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/testdata/compaction_setup_inputs_multilevel_write_amp b/testdata/compaction_setup_inputs_multilevel_write_amp index beb31e9dc8..c42ccc9f24 100644 --- a/testdata/compaction_setup_inputs_multilevel_write_amp +++ b/testdata/compaction_setup_inputs_multilevel_write_amp @@ -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 @@ -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