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).
8 #include "file/filename.h"
9 #include "logging/logging.h"
10 #include "util/cast_util.h"
11 #include "util/mutexlock.h"
12 #include "utilities/blob_db/blob_db_impl.h"
14 // BlobDBImpl methods to get snapshot of files, e.g. for replication.
16 namespace ROCKSDB_NAMESPACE
{
19 Status
BlobDBImpl::DisableFileDeletions() {
20 // Disable base DB file deletions.
21 Status s
= db_impl_
->DisableFileDeletions();
28 // Hold delete_file_mutex_ to make sure no DeleteObsoleteFiles job
30 MutexLock
l(&delete_file_mutex_
);
31 count
= ++disable_file_deletions_
;
34 ROCKS_LOG_INFO(db_options_
.info_log
,
35 "Disabled blob file deletions. count: %d", count
);
39 Status
BlobDBImpl::EnableFileDeletions(bool force
) {
40 // Enable base DB file deletions.
41 Status s
= db_impl_
->EnableFileDeletions(force
);
48 MutexLock
l(&delete_file_mutex_
);
50 disable_file_deletions_
= 0;
51 } else if (disable_file_deletions_
> 0) {
52 count
= --disable_file_deletions_
;
57 ROCKS_LOG_INFO(db_options_
.info_log
, "Enabled blob file deletions. count: %d",
59 // Consider trigger DeleteobsoleteFiles once after re-enabled, if we are to
60 // make DeleteobsoleteFiles re-run interval configuration.
64 Status
BlobDBImpl::GetLiveFiles(std::vector
<std::string
>& ret
,
65 uint64_t* manifest_file_size
,
66 bool flush_memtable
) {
67 if (!bdb_options_
.path_relative
) {
68 return Status::NotSupported(
69 "Not able to get relative blob file path from absolute blob_dir.");
71 // Hold a lock in the beginning to avoid updates to base DB during the call
73 Status s
= db_
->GetLiveFiles(ret
, manifest_file_size
, flush_memtable
);
77 ret
.reserve(ret
.size() + blob_files_
.size());
78 for (auto bfile_pair
: blob_files_
) {
79 auto blob_file
= bfile_pair
.second
;
80 // Path should be relative to db_name, but begin with slash.
82 BlobFileName("", bdb_options_
.blob_dir
, blob_file
->BlobFileNumber()));
87 void BlobDBImpl::GetLiveFilesMetaData(std::vector
<LiveFileMetaData
>* metadata
) {
88 // Path should be relative to db_name.
89 assert(bdb_options_
.path_relative
);
90 // Hold a lock in the beginning to avoid updates to base DB during the call
92 db_
->GetLiveFilesMetaData(metadata
);
93 for (auto bfile_pair
: blob_files_
) {
94 auto blob_file
= bfile_pair
.second
;
95 LiveFileMetaData filemetadata
;
96 filemetadata
.size
= static_cast<size_t>(blob_file
->GetFileSize());
97 const uint64_t file_number
= blob_file
->BlobFileNumber();
98 // Path should be relative to db_name, but begin with slash.
99 filemetadata
.name
= BlobFileName("", bdb_options_
.blob_dir
, file_number
);
100 filemetadata
.file_number
= file_number
;
101 if (blob_file
->HasTTL()) {
102 filemetadata
.oldest_ancester_time
= blob_file
->GetExpirationRange().first
;
105 static_cast_with_check
<ColumnFamilyHandleImpl
>(DefaultColumnFamily());
106 filemetadata
.column_family_name
= cfh
->GetName();
107 metadata
->emplace_back(filemetadata
);
111 } // namespace blob_db
112 } // namespace ROCKSDB_NAMESPACE
113 #endif // !ROCKSDB_LITE