@@ -1589,24 +1589,22 @@ func WriteSyncNoop(eng Engine) error {
1589
1589
// either write a Pebble range tombstone or clear individual keys. If it uses
1590
1590
// a range tombstone, it will tighten the span to the first encountered key.
1591
1591
//
1592
- // pointKeyThreshold and rangeKeyThreshold specify the number of point/range
1593
- // keys respectively where it will switch from clearing individual keys to
1594
- // Pebble range tombstones (RANGEDEL or RANGEKEYDEL respectively). A threshold
1595
- // of 0 disables checking for and clearing that key type.
1592
+ // The pointKeyThreshold parameter specifies the number of point keys where it
1593
+ // will switch from clearing individual keys using point tombstones to clearing
1594
+ // the entire range using Pebble range tombstones (RANGEDELs). The
1595
+ // pointKeyThreshold value must be at least 1. NB: An initial scan will be done
1596
+ // to determine the type of clear, so a large threshold will potentially involve
1597
+ // scanning a large number of keys.
1596
1598
//
1597
- // NB: An initial scan will be done to determine the type of clear, so a large
1598
- // threshold will potentially involve scanning a large number of keys twice.
1599
- //
1600
- // TODO(erikgrinaker): Consider tightening the end of the range tombstone span
1601
- // too, by doing a SeekLT when we reach the threshold. It's unclear whether it's
1602
- // really worth it.
1599
+ // ClearRangeWithHeuristic will also check for the existence of range keys, and
1600
+ // if any exist, it will write a RANGEKEYDEL clearing all range keys in the span.
1603
1601
func ClearRangeWithHeuristic (
1604
- ctx context.Context ,
1605
- r Reader ,
1606
- w Writer ,
1607
- start , end roachpb.Key ,
1608
- pointKeyThreshold , rangeKeyThreshold int ,
1602
+ ctx context.Context , r Reader , w Writer , start , end roachpb.Key , pointKeyThreshold int ,
1609
1603
) error {
1604
+ if pointKeyThreshold < 1 {
1605
+ return errors .AssertionFailedf ("pointKeyThreshold must be at least 1" )
1606
+ }
1607
+
1610
1608
clearPointKeys := func (r Reader , w Writer , start , end roachpb.Key , threshold int ) error {
1611
1609
iter , err := r .NewEngineIterator (ctx , IterOptions {
1612
1610
KeyTypes : IterKeyTypePointsOnly ,
@@ -1655,7 +1653,7 @@ func ClearRangeWithHeuristic(
1655
1653
return err
1656
1654
}
1657
1655
1658
- clearRangeKeys := func (r Reader , w Writer , start , end roachpb.Key , threshold int ) error {
1656
+ clearRangeKeys := func (r Reader , w Writer , start , end roachpb.Key ) error {
1659
1657
iter , err := r .NewEngineIterator (ctx , IterOptions {
1660
1658
KeyTypes : IterKeyTypeRangesOnly ,
1661
1659
LowerBound : start ,
@@ -1666,51 +1664,29 @@ func ClearRangeWithHeuristic(
1666
1664
}
1667
1665
defer iter .Close ()
1668
1666
1669
- // Scan, and drop a RANGEKEYDEL if we reach the threshold.
1670
- var ok bool
1671
- var count int
1672
- var firstKey roachpb.Key
1673
- for ok , err = iter .SeekEngineKeyGE (EngineKey {Key : start }); ok ; ok , err = iter .NextEngineKey () {
1674
- count += len (iter .EngineRangeKeys ())
1675
- if len (firstKey ) == 0 {
1676
- bounds , err := iter .EngineRangeBounds ()
1677
- if err != nil {
1678
- return err
1679
- }
1680
- firstKey = bounds .Key .Clone ()
1681
- }
1682
- if count >= threshold {
1683
- return w .ClearRawRange (firstKey , end , false /* pointKeys */ , true /* rangeKeys */ )
1684
- }
1685
- }
1686
- if err != nil || count == 0 {
1667
+ ok , err := iter .SeekEngineKeyGE (EngineKey {Key : start })
1668
+ if err != nil {
1687
1669
return err
1688
1670
}
1689
- // Clear individual range keys.
1690
- for ok , err = iter .SeekEngineKeyGE (EngineKey {Key : start }); ok ; ok , err = iter .NextEngineKey () {
1691
- bounds , err := iter .EngineRangeBounds ()
1692
- if err != nil {
1693
- return err
1694
- }
1695
- for _ , v := range iter .EngineRangeKeys () {
1696
- if err := w .ClearEngineRangeKey (bounds .Key , bounds .EndKey , v .Version ); err != nil {
1697
- return err
1698
- }
1699
- }
1671
+ if ! ok {
1672
+ // No range keys in the span.
1673
+ return nil
1700
1674
}
1701
- return err
1702
- }
1703
-
1704
- if pointKeyThreshold > 0 {
1705
- if err := clearPointKeys (r , w , start , end , pointKeyThreshold ); err != nil {
1675
+ bounds , err := iter .EngineRangeBounds ()
1676
+ if err != nil {
1706
1677
return err
1707
1678
}
1679
+ // TODO(erikgrinaker): Consider tightening the end of the range
1680
+ // tombstone span too, by doing a SeekLT when we reach the threshold.
1681
+ // It's unclear whether it's really worth it.
1682
+ return w .ClearRawRange (bounds .Key , end , false /* pointKeys */ , true /* rangeKeys */ )
1708
1683
}
1709
1684
1710
- if rangeKeyThreshold > 0 {
1711
- if err := clearRangeKeys (r , w , start , end , rangeKeyThreshold ); err != nil {
1712
- return err
1713
- }
1685
+ if err := clearPointKeys (r , w , start , end , pointKeyThreshold ); err != nil {
1686
+ return err
1687
+ }
1688
+ if err := clearRangeKeys (r , w , start , end ); err != nil {
1689
+ return err
1714
1690
}
1715
1691
1716
1692
return nil
0 commit comments