compaction_state.cc 1.5 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. //
  7. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  8. // Use of this source code is governed by a BSD-style license that can be
  9. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  10. #include "db/compaction/compaction_state.h"
  11. namespace ROCKSDB_NAMESPACE {
  12. Slice CompactionState::SmallestUserKey() {
  13. for (const auto& sub_compact_state : sub_compact_states) {
  14. Slice smallest = sub_compact_state.SmallestUserKey();
  15. if (!smallest.empty()) {
  16. return smallest;
  17. }
  18. }
  19. // If there is no finished output, return an empty slice.
  20. return Slice{nullptr, 0};
  21. }
  22. Slice CompactionState::LargestUserKey() {
  23. for (auto it = sub_compact_states.rbegin(); it < sub_compact_states.rend();
  24. ++it) {
  25. Slice largest = it->LargestUserKey();
  26. if (!largest.empty()) {
  27. return largest;
  28. }
  29. }
  30. // If there is no finished output, return an empty slice.
  31. return Slice{nullptr, 0};
  32. }
  33. void CompactionState::AggregateCompactionStats(
  34. InternalStats::CompactionStatsFull& internal_stats,
  35. CompactionJobStats& job_stats) {
  36. for (const auto& sc : sub_compact_states) {
  37. sc.AggregateCompactionOutputStats(internal_stats);
  38. job_stats.Add(sc.compaction_job_stats);
  39. }
  40. }
  41. } // namespace ROCKSDB_NAMESPACE