Skip to content

Instantly share code, notes, and snippets.

@ajkr
Created December 16, 2018 23:10
Show Gist options
  • Save ajkr/9619663ad7dc5586ac79b29bbc06921f to your computer and use it in GitHub Desktop.
Save ajkr/9619663ad7dc5586ac79b29bbc06921f to your computer and use it in GitHub Desktop.
diff --git a/compaction_test.go b/compaction_test.go
index e1e4107..f703f3e 100644
--- a/compaction_test.go
+++ b/compaction_test.go
@@ -747,14 +747,7 @@ func TestManualCompaction(t *testing.T) {
return b.String()
case "compact":
- if len(td.CmdArgs) != 1 {
- return fmt.Sprintf("%s expects 1 argument", td.Cmd)
- }
- parts := strings.Split(td.CmdArgs[0].Key, "-")
- if len(parts) != 2 {
- return fmt.Sprintf("malformed test case: %s", td.Input)
- }
- if err := d.Compact([]byte(parts[0]), []byte(parts[1])); err != nil {
+ if err := runCompactCommand(td, d); err != nil {
return err.Error()
}
diff --git a/data_test.go b/data_test.go
index 1efaf0e..a842cc4 100644
--- a/data_test.go
+++ b/data_test.go
@@ -150,15 +150,61 @@ func runBatchDefineCmd(d *datadriven.TestData, b *Batch) error {
return nil
}
+func runCompactCommand(td *datadriven.TestData, d *DB) error {
+ if len(td.CmdArgs) > 2 {
+ return fmt.Errorf("%s expects at most two arguments", td.Cmd)
+ }
+ parts := strings.Split(td.CmdArgs[0].Key, "-")
+ if len(parts) != 2 {
+ return fmt.Errorf("expected <begin>-<end>: %s", td.Input)
+ }
+ if len(td.CmdArgs) == 2 {
+ levelString := td.CmdArgs[1].String()
+ iStart := db.MakeInternalKey([]byte(parts[0]), db.InternalKeySeqNumMax, db.InternalKeyKindMax)
+ iEnd := db.MakeInternalKey([]byte(parts[1]), 0, 0)
+ if levelString[0] != 'L' {
+ return fmt.Errorf("expected L<n>: %s", levelString)
+ }
+ level, err := strconv.Atoi(levelString[1:])
+ if err != nil {
+ return err
+ }
+ return d.manualCompact(&manualCompaction{
+ done: make(chan error, 1),
+ level: level,
+ start: iStart,
+ end: iEnd,
+ })
+ } else {
+ return d.Compact([]byte(parts[0]), []byte(parts[1]))
+ }
+}
+
func runDBDefineCmd(td *datadriven.TestData) (*DB, error) {
if td.Input == "" {
return nil, fmt.Errorf("empty test input")
}
fs := storage.NewMem()
- d, err := Open("", &db.Options{
+ opts := db.Options{
Storage: fs,
- })
+ }
+ for _, arg := range td.CmdArgs {
+ switch arg.Key {
+ case "TargetFileSizes":
+ opts.Levels = make([]db.LevelOptions, len(arg.Vals))
+ for i := range arg.Vals {
+ size, err := strconv.ParseInt(arg.Vals[i], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ opts.Levels[i].TargetFileSize = size
+ }
+ default:
+ return nil, fmt.Errorf("%s: unknown arg: %s", td.Cmd, arg.Key)
+ }
+ }
+ d, err := Open("", &opts)
if err != nil {
return nil, err
}
diff --git a/range_del_test.go b/range_del_test.go
index 05970ac..d86ce61 100644
--- a/range_del_test.go
+++ b/range_del_test.go
@@ -34,6 +34,15 @@ func TestRangeDel(t *testing.T) {
d.mu.Unlock()
return s
+ case "compact":
+ if err := runCompactCommand(td, d); err != nil {
+ return err.Error()
+ }
+ d.mu.Lock()
+ s := d.mu.versions.currentVersion().String()
+ d.mu.Unlock()
+ return s
+
case "get":
snap := Snapshot{
db: d,
diff --git a/testdata/range_del b/testdata/range_del
index 757cf86..940374b 100644
--- a/testdata/range_del
+++ b/testdata/range_del
@@ -1127,3 +1127,76 @@ get seq=3
a
----
pebble: not found
+
+# A range tombstone straddles two SSTs. One is compacted to a lower level. Its
+# keys that are newer than the range tombstone should not disappear.
+
+define TargetFileSizes=(100, 1)
+L0
+ a.RANGEDEL.1:e
+L0
+ a.SET.2:v
+L0
+ c.SET.3:v
+----
+mem: 1
+0: a-e a-a c-c
+
+compact a-e
+----
+1: a-c c-e
+
+compact d-e
+----
+1: a-c
+2: c-e
+
+iter seq=4
+seek-ge b
+next
+----
+a:v
+.
+
+# A range tombstone straddles two SSTs. One is compacted two levels lower. The
+# other is compacted one level lower. The one that is compacted one level lower
+# should not delete more keys via the file's key-range expanding.
+
+define TargetFileSizes=(100, 1)
+L0
+ a.RANGEDEL.1:e
+L0
+ a.SET.2:v
+L0
+ c.SET.3:v
+L2
+ d.SET.0:v
+----
+mem: 1
+0: a-e a-a c-c
+2: d-d
+
+compact a-b
+----
+1: a-c c-e
+2: d-d
+
+compact d-e
+----
+1: a-c
+3: c-e
+
+get seq=4
+c
+----
+v
+
+compact a-b L1
+----
+2: a-e
+3: c-e
+
+get seq=4
+c
+----
+v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment