compaction_merging_iterator.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. //
  3. // This source code is licensed under both the GPLv2 (found in the
  4. // COPYING file in the root directory) and Apache 2.0 License
  5. // (found in the LICENSE.Apache file in the root directory).
  6. #pragma once
  7. #include "db/range_del_aggregator.h"
  8. #include "rocksdb/slice.h"
  9. #include "rocksdb/types.h"
  10. #include "table/merging_iterator.h"
  11. namespace ROCKSDB_NAMESPACE {
  12. /*
  13. * This is a simplified version of MergingIterator and is specifically used for
  14. * compaction. It merges the input `children` iterators into a sorted stream of
  15. * keys. Range tombstone start keys are also emitted to prevent oversize
  16. * compactions. For example, consider an L1 file with content [a, b), y, z,
  17. * where [a, b) is a range tombstone and y and z are point keys. This could
  18. * cause an oversize compaction as it can overlap with a wide range of key space
  19. * in L2.
  20. *
  21. * CompactionMergingIterator emits range tombstone start keys from each LSM
  22. * level's range tombstone iterator, and for each range tombstone
  23. * [start,end)@seqno, the key will be start@seqno with op_type
  24. * kTypeRangeDeletion unless truncated at file boundary (see detail in
  25. * TruncatedRangeDelIterator::start_key()).
  26. *
  27. * Caller should use CompactionMergingIterator::IsDeleteRangeSentinelKey() to
  28. * check if the current key is a range tombstone key.
  29. * TODO(cbi): IsDeleteRangeSentinelKey() is used for two kinds of keys at
  30. * different layers: file boundary and range tombstone keys. Separate them into
  31. * two APIs for clarity.
  32. */
  33. class CompactionMergingIterator;
  34. class InternalStats;
  35. InternalIterator* NewCompactionMergingIterator(
  36. const InternalKeyComparator* comparator, InternalIterator** children, int n,
  37. std::vector<std::pair<std::unique_ptr<TruncatedRangeDelIterator>,
  38. std::unique_ptr<TruncatedRangeDelIterator>**>>&
  39. range_tombstone_iters,
  40. Arena* arena = nullptr, InternalStats* stats = nullptr);
  41. } // namespace ROCKSDB_NAMESPACE