@@ -1150,6 +1150,37 @@ func runCompactionTest(
1150
1150
}
1151
1151
return describeLSM (d , verbose )
1152
1152
1153
+ case "run-virtual-rewrite-compaction" :
1154
+ err := func () error {
1155
+ d .mu .Lock ()
1156
+ defer d .mu .Unlock ()
1157
+ d .mu .versions .logLock ()
1158
+ env := d .makeCompactionEnvLocked ()
1159
+ require .NotNil (t , env )
1160
+ picker := d .mu .versions .picker .(* compactionPickerByScore )
1161
+ pc := picker .pickVirtualRewriteCompaction (* env )
1162
+ if pc == nil {
1163
+ d .mu .versions .logUnlock ()
1164
+ return errors .New ("no virtual rewrite compaction" )
1165
+ }
1166
+ d .mu .versions .logUnlock ()
1167
+ d .runPickedCompaction (pc , noopGrantHandle {})
1168
+ for d .mu .compact .compactingCount > 0 {
1169
+ d .mu .compact .cond .Wait ()
1170
+ }
1171
+ return nil
1172
+ }()
1173
+ if err != nil {
1174
+ return err .Error ()
1175
+ }
1176
+ return describeLSM (d , verbose )
1177
+
1178
+ case "virtual-backings" :
1179
+ d .mu .Lock ()
1180
+ s := d .mu .versions .latest .virtualBackings .String ()
1181
+ d .mu .Unlock ()
1182
+ return s
1183
+
1153
1184
case "validate-blob-reference-index-block" :
1154
1185
var inputTables []* manifest.TableMetadata
1155
1186
for _ , line := range crstrings .Lines (td .Input ) {
@@ -1550,6 +1581,11 @@ func TestCompaction(t *testing.T) {
1550
1581
verbose : true ,
1551
1582
cmp : DefaultComparer ,
1552
1583
},
1584
+ "virtual_rewrite" : {
1585
+ minVersion : FormatNewest ,
1586
+ maxVersion : FormatNewest ,
1587
+ verbose : true ,
1588
+ },
1553
1589
}
1554
1590
datadriven .Walk (t , "testdata/compaction" , func (t * testing.T , path string ) {
1555
1591
filename := filepath .Base (path )
@@ -1608,24 +1644,21 @@ func TestCompactionDeleteOnlyHints(t *testing.T) {
1608
1644
}
1609
1645
}()
1610
1646
1611
- var compactInfo * CompactionInfo // protected by d.mu
1647
+ var compactInfo [] CompactionInfo
1612
1648
reset := func () (* Options , error ) {
1613
1649
if d != nil {
1614
- compactInfo = nil
1615
1650
if err := closeAllSnapshots (d ); err != nil {
1616
1651
return nil , err
1617
1652
}
1618
1653
if err := d .Close (); err != nil {
1619
1654
return nil , err
1620
1655
}
1621
1656
}
1657
+ compactInfo = nil
1622
1658
el := TeeEventListener (
1623
1659
EventListener {
1624
1660
CompactionEnd : func (info CompactionInfo ) {
1625
- if compactInfo != nil {
1626
- return
1627
- }
1628
- compactInfo = & info
1661
+ compactInfo = append (compactInfo , info )
1629
1662
},
1630
1663
},
1631
1664
MakeLoggingEventListener (testutils.Logger {T : t }),
@@ -1653,21 +1686,29 @@ func TestCompactionDeleteOnlyHints(t *testing.T) {
1653
1686
return opts , nil
1654
1687
}
1655
1688
1689
+ compactInfo = nil
1656
1690
compactionString := func () string {
1657
1691
for d .mu .compact .compactingCount > 0 {
1658
1692
d .mu .compact .cond .Wait ()
1659
1693
}
1694
+ slices .SortFunc (compactInfo , func (a , b CompactionInfo ) int {
1695
+ return cmp .Compare (a .String (), b .String ())
1696
+ })
1660
1697
1661
- s := "(none)"
1662
- if compactInfo != nil {
1698
+ var b strings.Builder
1699
+ if len (compactInfo ) == 0 {
1700
+ return "(none)\n "
1701
+ }
1702
+
1703
+ for _ , c := range compactInfo {
1663
1704
// Fix the job ID and durations for determinism.
1664
- compactInfo .JobID = 100
1665
- compactInfo .Duration = time .Second
1666
- compactInfo .TotalDuration = 2 * time .Second
1667
- s = compactInfo .String ()
1668
- compactInfo = nil
1705
+ c .JobID = 100
1706
+ c .Duration = time .Second
1707
+ c .TotalDuration = 2 * time .Second
1708
+ b .WriteString (fmt .Sprintf ("%s\n " , c .String ()))
1669
1709
}
1670
- return s
1710
+ compactInfo = nil
1711
+ return b .String ()
1671
1712
}
1672
1713
1673
1714
var err error
@@ -1768,12 +1809,14 @@ func TestCompactionDeleteOnlyHints(t *testing.T) {
1768
1809
1769
1810
// NB: collectTableStats attempts to acquire the lock. Temporarily
1770
1811
// unlock here to avoid a deadlock.
1771
- d .mu .Unlock ()
1772
- if didRun := d .collectTableStats (); ! didRun {
1773
- // If a job was already running, wait for the results.
1774
- d .waitTableStats ()
1775
- }
1776
- d .mu .Lock ()
1812
+ func () {
1813
+ d .mu .Unlock ()
1814
+ defer d .mu .Lock ()
1815
+ if didRun := d .collectTableStats (); ! didRun {
1816
+ // If a job was already running, wait for the results.
1817
+ d .waitTableStats ()
1818
+ }
1819
+ }()
1777
1820
1778
1821
hints := d .mu .compact .deletionHints
1779
1822
if len (hints ) == 0 {
@@ -1914,6 +1957,13 @@ func TestCompactionTombstones(t *testing.T) {
1914
1957
for i := range c .Output .Tables {
1915
1958
c .Output .Tables [i ].FileNum = 0
1916
1959
}
1960
+ if c .Reason == "virtual-sst-rewrite" {
1961
+ for i := range c .Input {
1962
+ for j := range c .Input [i ].Tables {
1963
+ c .Input [i ].Tables [j ].FileNum = 0
1964
+ }
1965
+ }
1966
+ }
1917
1967
}
1918
1968
}
1919
1969
// Sort for determinism. We use the negative value of cmp.Compare to sort
0 commit comments