Coverage Report

Created: 2026-04-10 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/db/blob/blob_file_completion_callback.h
Line
Count
Source
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under both the GPLv2 (found in the
3
//  COPYING file in the root directory) and Apache 2.0 License
4
//  (found in the LICENSE.Apache file in the root directory).
5
//
6
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7
// Use of this source code is governed by a BSD-style license that can be
8
// found in the LICENSE file. See the AUTHORS file for names of contributors.
9
#pragma once
10
11
#include "db/error_handler.h"
12
#include "db/event_helpers.h"
13
#include "file/sst_file_manager_impl.h"
14
#include "rocksdb/status.h"
15
16
namespace ROCKSDB_NAMESPACE {
17
18
class BlobFileCompletionCallback {
19
 public:
20
  BlobFileCompletionCallback(
21
      SstFileManager* sst_file_manager, InstrumentedMutex* mutex,
22
      ErrorHandler* error_handler, EventLogger* event_logger,
23
      const std::vector<std::shared_ptr<EventListener>>& listeners,
24
      const std::string& dbname)
25
42.2k
      : event_logger_(event_logger), listeners_(listeners), dbname_(dbname) {
26
42.2k
    sst_file_manager_ = sst_file_manager;
27
42.2k
    mutex_ = mutex;
28
42.2k
    error_handler_ = error_handler;
29
42.2k
  }
30
31
  void OnBlobFileCreationStarted(const std::string& file_name,
32
                                 const std::string& column_family_name,
33
                                 int job_id,
34
0
                                 BlobFileCreationReason creation_reason) {
35
    // Notify the listeners.
36
0
    EventHelpers::NotifyBlobFileCreationStarted(listeners_, dbname_,
37
0
                                                column_family_name, file_name,
38
0
                                                job_id, creation_reason);
39
0
  }
40
41
  Status OnBlobFileCompleted(const std::string& file_name,
42
                             const std::string& column_family_name, int job_id,
43
                             uint64_t file_number,
44
                             BlobFileCreationReason creation_reason,
45
                             const Status& report_status,
46
                             const std::string& checksum_value,
47
                             const std::string& checksum_method,
48
0
                             uint64_t blob_count, uint64_t blob_bytes) {
49
0
    Status s;
50
51
0
    auto sfm = static_cast<SstFileManagerImpl*>(sst_file_manager_);
52
0
    if (sfm) {
53
      // Report new blob files to SstFileManagerImpl
54
0
      s = sfm->OnAddFile(file_name);
55
0
      if (sfm->IsMaxAllowedSpaceReached()) {
56
0
        s = Status::SpaceLimit("Max allowed space was reached");
57
0
        TEST_SYNC_POINT(
58
0
            "BlobFileCompletionCallback::CallBack::MaxAllowedSpaceReached");
59
0
        InstrumentedMutexLock l(mutex_);
60
0
        error_handler_->SetBGError(s, BackgroundErrorReason::kFlush);
61
0
      }
62
0
    }
63
64
    // Notify the listeners.
65
0
    EventHelpers::LogAndNotifyBlobFileCreationFinished(
66
0
        event_logger_, listeners_, dbname_, column_family_name, file_name,
67
0
        job_id, file_number, creation_reason,
68
0
        (!report_status.ok() ? report_status : s),
69
0
        (checksum_value.empty() ? kUnknownFileChecksum : checksum_value),
70
0
        (checksum_method.empty() ? kUnknownFileChecksumFuncName
71
0
                                 : checksum_method),
72
0
        blob_count, blob_bytes);
73
0
    return s;
74
0
  }
75
76
 private:
77
  SstFileManager* sst_file_manager_;
78
  InstrumentedMutex* mutex_;
79
  ErrorHandler* error_handler_;
80
  EventLogger* event_logger_;
81
  std::vector<std::shared_ptr<EventListener>> listeners_;
82
  std::string dbname_;
83
};
84
}  // namespace ROCKSDB_NAMESPACE