Skip to content

Commit 5babbee

Browse files
committed
metamorphic: add a missing simulated excise
We weren't simulating the excise when the batch wasn't empty but it yielded an empty sst (e.g. it only contained a `LogData`). Fix that and refactor the code a bit to avoid three copies of this code. Informs #3448
1 parent 9c2da6d commit 5babbee

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

metamorphic/ops.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -898,19 +898,14 @@ func (o *ingestAndExciseOp) run(t *Test, h historyRecorder) {
898898
}
899899
db := t.getDB(o.dbID)
900900
if b.Empty() {
901-
// Ingestion will be a no-op. But still do a DeleteRange and RangeKeyDelete
902-
// as the generator/key manager expect this to succeed regardless.
903-
//
904-
// TODO(bilal): Take out this case when we support standalone Excises with
905-
// no ingestions.
906-
err = firstError(err, db.DeleteRange(o.exciseStart, o.exciseEnd, t.writeOpts))
907-
err = firstError(err, db.RangeKeyDelete(o.exciseStart, o.exciseEnd, t.writeOpts))
908-
h.Recordf("%s // %v", o, err)
901+
h.Recordf("%s // %v", o, o.simulateExcise(db, t))
909902
return
910903
}
904+
911905
if o.sstContainsExciseTombstone {
912906
// Add a rangedel and rangekeydel to the batch. This ensures it'll end up
913-
// inside the sstable.
907+
// inside the sstable. Note that all entries in the sstable will have the
908+
// same sequence number, so the ordering within the batch doesn't matter.
914909
err = firstError(err, b.DeleteRange(o.exciseStart, o.exciseEnd, t.writeOpts))
915910
err = firstError(err, b.RangeKeyDelete(o.exciseStart, o.exciseEnd, t.writeOpts))
916911
}
@@ -919,38 +914,39 @@ func (o *ingestAndExciseOp) run(t *Test, h historyRecorder) {
919914
h.Recordf("Build(%s) // %v", o.batchID, err2)
920915
return
921916
}
922-
err = firstError(err, err2)
923917
err = firstError(err, b.Close())
924918

925919
if writerMeta.Properties.NumEntries == 0 && writerMeta.Properties.NumRangeKeys() == 0 {
926-
// No-op.
927-
h.Recordf("%s // %v", o, err)
920+
h.Recordf("%s // %v", o, o.simulateExcise(db, t))
928921
return
929922
}
930-
if !t.testOpts.useExcise {
931-
// Do a rangedel and rangekeydel before the ingestion. This mimics the
932-
// behaviour of an excise.
933-
err = firstError(err, db.DeleteRange(o.exciseStart, o.exciseEnd, t.writeOpts))
934-
err = firstError(err, db.RangeKeyDelete(o.exciseStart, o.exciseEnd, t.writeOpts))
935-
}
936923

937924
if t.testOpts.useExcise {
938925
err = firstError(err, t.withRetries(func() error {
939-
_, err := t.getDB(o.dbID).IngestAndExcise([]string{path}, nil /* shared */, nil /* external */, pebble.KeyRange{
926+
_, err := db.IngestAndExcise([]string{path}, nil /* shared */, nil /* external */, pebble.KeyRange{
940927
Start: o.exciseStart,
941928
End: o.exciseEnd,
942929
}, o.sstContainsExciseTombstone)
943930
return err
944931
}))
945932
} else {
933+
err = firstError(err, o.simulateExcise(db, t))
946934
err = firstError(err, t.withRetries(func() error {
947-
return t.getDB(o.dbID).Ingest([]string{path})
935+
return db.Ingest([]string{path})
948936
}))
949937
}
950938

951939
h.Recordf("%s // %v", o, err)
952940
}
953941

942+
func (o *ingestAndExciseOp) simulateExcise(db *pebble.DB, t *Test) error {
943+
// Simulate the excise using a DeleteRange and RangeKeyDelete.
944+
return errors.CombineErrors(
945+
db.DeleteRange(o.exciseStart, o.exciseEnd, t.writeOpts),
946+
db.RangeKeyDelete(o.exciseStart, o.exciseEnd, t.writeOpts),
947+
)
948+
}
949+
954950
func (o *ingestAndExciseOp) receiver() objID { return o.dbID }
955951
func (o *ingestAndExciseOp) syncObjs() objIDSlice {
956952
// Ingest should not be concurrent with mutating the batches that will be

0 commit comments

Comments
 (0)