databend icon indicating copy to clipboard operation
databend copied to clipboard

feat: add table function `fuse_vacuum2()`

Open SkyFan2002 opened this issue 7 months ago โ€ข 2 comments

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

This PR introduces a new table function fuse_vacuum2() aimed at enhancing performance.

Object Key of Snapshot v5, Segment, and Block

  • UUID Version: Use UUID v7
    • Lexicographically ordered
    • Timestamp can be extracted from the object key
  • Prefix: Prefixed with the character 'g', ensuring all keys of v5 are larger than v4's in lexicographical order

For segments/blocks that are newly created in an operation based on snapshot s, the timestamp embedded in their object keys equals s.timestamp. If there is no base snapshot, let ts be 0. For snapshots, the timestamp embedded in their object keys equals to their own timestamp.

New Field lvt in Snapshot v5

For all snapshots v5 (s), the candidate value (lvt_candidate) of s.lvt is calculated as s.timestamp - settings.get_retention_period(). s.lvt may be adjusted to larger values based on lvt_candidate, in cases where the retention period has been tweaked or due to clock skews. For example, if lvt_candidate <= s.prev.lvt, then s.lvt could be set to s.prev.lvt + 1. s.lvt should respect the retention period setting at the time. Decreasing or setting s.lvt equal to the lvt of the previous snapshot is not allowed.

Properties

  • s.lvt <= s.timestamp
  • s.lvt > s.prev.lvt
  • If s is based on another snapshot s': s.lvt <= s'.timestamp (enforced during commitment: transactions with stale base snapshots are not allowed).

Notes

  • Some(_) > None
  • s.prev may not equal s'

Steps of Vacuum2

fn vacuum2(){
  let lvt = set_lvt();
  let snapshots_before_lvt = list_until(snapshot_dir,lvt);
  let gc_root = select_gc_root(snapshots_before_lvt);
  let snapshots_to_gc = &snapshots_before_lvt[..gc_root_idx];
  
  let lvt = gc_root.lvt;
  let segments_before_gc_root = list_until(segment_dir,lvt);
  let segments_to_gc = segments_before_gc_root - gc_root.segments;

  let blocks_before_gc_root = list_until(block_dir,lvt);
  let blocks_to_gc = blocks_before_gc_root - gc_root.blocks;

  remove(snapshots_to_gc,segments_to_gc,blocks_to_gc);
}

Tests

  • [x] Unit Test
  • [x] Logic Test
  • [ ] Benchmark Test
  • [x] Long run

Type of change

  • [ ] Bug Fix (non-breaking change which fixes an issue)
  • [x] New Feature (non-breaking change which adds functionality)
  • [ ] Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • [ ] Documentation Update
  • [ ] Refactoring
  • [ ] Performance Improvement
  • [ ] Other (please describe):

This change isโ€‚Reviewable

SkyFan2002 avatar Jul 15 '24 02:07 SkyFan2002