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).
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.
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"
16 namespace ROCKSDB_NAMESPACE
{
18 class BlobFileCompletionCallback
{
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
) {
27 sst_file_manager_
= sst_file_manager
;
29 error_handler_
= error_handler
;
31 (void)sst_file_manager
;
34 #endif // ROCKSDB_LITE
37 void OnBlobFileCreationStarted(const std::string
& file_name
,
38 const std::string
& column_family_name
,
40 BlobFileCreationReason creation_reason
) {
42 // Notify the listeners.
43 EventHelpers::NotifyBlobFileCreationStarted(listeners_
, dbname_
,
44 column_family_name
, file_name
,
45 job_id
, creation_reason
);
48 (void)column_family_name
;
50 (void)creation_reason
;
54 Status
OnBlobFileCompleted(const std::string
& file_name
,
55 const std::string
& column_family_name
, int job_id
,
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
) {
65 auto sfm
= static_cast<SstFileManagerImpl
*>(sst_file_manager_
);
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");
72 "BlobFileCompletionCallback::CallBack::MaxAllowedSpaceReached");
73 InstrumentedMutexLock
l(mutex_
);
74 error_handler_
->SetBGError(s
, BackgroundErrorReason::kFlush
);
77 #endif // !ROCKSDB_LITE
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
87 blob_count
, blob_bytes
);
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_
;
101 } // namespace ROCKSDB_NAMESPACE