]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/db/blob/blob_file_completion_callback.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / db / blob / blob_file_completion_callback.h
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 : event_logger_(event_logger), listeners_(listeners), dbname_(dbname) {
26 #ifndef ROCKSDB_LITE
27 sst_file_manager_ = sst_file_manager;
28 mutex_ = mutex;
29 error_handler_ = error_handler;
30 #else
31 (void)sst_file_manager;
32 (void)mutex;
33 (void)error_handler;
34 #endif // ROCKSDB_LITE
35 }
36
37 void OnBlobFileCreationStarted(const std::string& file_name,
38 const std::string& column_family_name,
39 int job_id,
40 BlobFileCreationReason creation_reason) {
41 #ifndef ROCKSDB_LITE
42 // Notify the listeners.
43 EventHelpers::NotifyBlobFileCreationStarted(listeners_, dbname_,
44 column_family_name, file_name,
45 job_id, creation_reason);
46 #else
47 (void)file_name;
48 (void)column_family_name;
49 (void)job_id;
50 (void)creation_reason;
51 #endif
52 }
53
54 Status OnBlobFileCompleted(const std::string& file_name,
55 const std::string& column_family_name, int job_id,
56 uint64_t file_number,
57 BlobFileCreationReason creation_reason,
58 const Status& report_status,
59 const std::string& checksum_value,
60 const std::string& checksum_method,
61 uint64_t blob_count, uint64_t blob_bytes) {
62 Status s;
63
64 #ifndef ROCKSDB_LITE
65 auto sfm = static_cast<SstFileManagerImpl*>(sst_file_manager_);
66 if (sfm) {
67 // Report new blob files to SstFileManagerImpl
68 s = sfm->OnAddFile(file_name);
69 if (sfm->IsMaxAllowedSpaceReached()) {
70 s = Status::SpaceLimit("Max allowed space was reached");
71 TEST_SYNC_POINT(
72 "BlobFileCompletionCallback::CallBack::MaxAllowedSpaceReached");
73 InstrumentedMutexLock l(mutex_);
74 error_handler_->SetBGError(s, BackgroundErrorReason::kFlush);
75 }
76 }
77 #endif // !ROCKSDB_LITE
78
79 // Notify the listeners.
80 EventHelpers::LogAndNotifyBlobFileCreationFinished(
81 event_logger_, listeners_, dbname_, column_family_name, file_name,
82 job_id, file_number, creation_reason,
83 (!report_status.ok() ? report_status : s),
84 (checksum_value.empty() ? kUnknownFileChecksum : checksum_value),
85 (checksum_method.empty() ? kUnknownFileChecksumFuncName
86 : checksum_method),
87 blob_count, blob_bytes);
88 return s;
89 }
90
91 private:
92 #ifndef ROCKSDB_LITE
93 SstFileManager* sst_file_manager_;
94 InstrumentedMutex* mutex_;
95 ErrorHandler* error_handler_;
96 #endif // ROCKSDB_LITE
97 EventLogger* event_logger_;
98 std::vector<std::shared_ptr<EventListener>> listeners_;
99 std::string dbname_;
100 };
101 } // namespace ROCKSDB_NAMESPACE