2018-08-27 17:56:28 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
|
|
|
|
|
2019-05-30 03:44:08 +00:00
|
|
|
#include "file/filename.h"
|
2019-06-01 00:19:43 +00:00
|
|
|
#include "logging/logging.h"
|
2020-07-03 02:24:25 +00:00
|
|
|
#include "util/cast_util.h"
|
2018-08-27 17:56:28 +00:00
|
|
|
#include "util/mutexlock.h"
|
2020-07-03 02:24:25 +00:00
|
|
|
#include "utilities/blob_db/blob_db_impl.h"
|
2018-08-27 17:56:28 +00:00
|
|
|
|
|
|
|
// BlobDBImpl methods to get snapshot of files, e.g. for replication.
|
|
|
|
|
2024-03-04 18:08:32 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE::blob_db {
|
2018-08-27 17:56:28 +00:00
|
|
|
|
|
|
|
Status BlobDBImpl::DisableFileDeletions() {
|
|
|
|
// Disable base DB file deletions.
|
|
|
|
Status s = db_impl_->DisableFileDeletions();
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
{
|
|
|
|
// Hold delete_file_mutex_ to make sure no DeleteObsoleteFiles job
|
|
|
|
// is running.
|
|
|
|
MutexLock l(&delete_file_mutex_);
|
|
|
|
count = ++disable_file_deletions_;
|
|
|
|
}
|
|
|
|
|
|
|
|
ROCKS_LOG_INFO(db_options_.info_log,
|
2020-02-28 22:10:51 +00:00
|
|
|
"Disabled blob file deletions. count: %d", count);
|
2018-08-27 17:56:28 +00:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2024-02-14 02:36:25 +00:00
|
|
|
Status BlobDBImpl::EnableFileDeletions() {
|
2018-08-27 17:56:28 +00:00
|
|
|
// Enable base DB file deletions.
|
2024-02-14 02:36:25 +00:00
|
|
|
Status s = db_impl_->EnableFileDeletions();
|
2018-08-27 17:56:28 +00:00
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
{
|
|
|
|
MutexLock l(&delete_file_mutex_);
|
2024-02-14 02:36:25 +00:00
|
|
|
if (disable_file_deletions_ > 0) {
|
2018-08-27 17:56:28 +00:00
|
|
|
count = --disable_file_deletions_;
|
|
|
|
}
|
|
|
|
assert(count >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ROCKS_LOG_INFO(db_options_.info_log, "Enabled blob file deletions. count: %d",
|
|
|
|
count);
|
|
|
|
// Consider trigger DeleteobsoleteFiles once after re-enabled, if we are to
|
|
|
|
// make DeleteobsoleteFiles re-run interval configuration.
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
Status BlobDBImpl::GetLiveFiles(std::vector<std::string>& ret,
|
|
|
|
uint64_t* manifest_file_size,
|
|
|
|
bool flush_memtable) {
|
2018-08-31 18:59:49 +00:00
|
|
|
if (!bdb_options_.path_relative) {
|
|
|
|
return Status::NotSupported(
|
|
|
|
"Not able to get relative blob file path from absolute blob_dir.");
|
|
|
|
}
|
2018-08-27 17:56:28 +00:00
|
|
|
// Hold a lock in the beginning to avoid updates to base DB during the call
|
|
|
|
ReadLock rl(&mutex_);
|
|
|
|
Status s = db_->GetLiveFiles(ret, manifest_file_size, flush_memtable);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
ret.reserve(ret.size() + blob_files_.size());
|
2024-03-04 18:08:32 +00:00
|
|
|
for (const auto& bfile_pair : blob_files_) {
|
2018-08-27 17:56:28 +00:00
|
|
|
auto blob_file = bfile_pair.second;
|
2018-08-31 18:59:49 +00:00
|
|
|
// Path should be relative to db_name, but begin with slash.
|
|
|
|
ret.emplace_back(
|
|
|
|
BlobFileName("", bdb_options_.blob_dir, blob_file->BlobFileNumber()));
|
2018-08-27 17:56:28 +00:00
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlobDBImpl::GetLiveFilesMetaData(std::vector<LiveFileMetaData>* metadata) {
|
2018-08-31 18:59:49 +00:00
|
|
|
// Path should be relative to db_name.
|
|
|
|
assert(bdb_options_.path_relative);
|
2018-08-27 17:56:28 +00:00
|
|
|
// Hold a lock in the beginning to avoid updates to base DB during the call
|
|
|
|
ReadLock rl(&mutex_);
|
|
|
|
db_->GetLiveFilesMetaData(metadata);
|
2024-03-04 18:08:32 +00:00
|
|
|
for (const auto& bfile_pair : blob_files_) {
|
2018-08-27 17:56:28 +00:00
|
|
|
auto blob_file = bfile_pair.second;
|
|
|
|
LiveFileMetaData filemetadata;
|
2022-03-29 21:36:35 +00:00
|
|
|
filemetadata.size = blob_file->GetFileSize();
|
2019-11-07 22:02:16 +00:00
|
|
|
const uint64_t file_number = blob_file->BlobFileNumber();
|
2018-08-31 18:59:49 +00:00
|
|
|
// Path should be relative to db_name, but begin with slash.
|
2019-11-07 22:02:16 +00:00
|
|
|
filemetadata.name = BlobFileName("", bdb_options_.blob_dir, file_number);
|
|
|
|
filemetadata.file_number = file_number;
|
2020-09-10 18:32:02 +00:00
|
|
|
if (blob_file->HasTTL()) {
|
|
|
|
filemetadata.oldest_ancester_time = blob_file->GetExpirationRange().first;
|
|
|
|
}
|
2020-07-03 02:24:25 +00:00
|
|
|
auto cfh =
|
|
|
|
static_cast_with_check<ColumnFamilyHandleImpl>(DefaultColumnFamily());
|
2018-08-27 17:56:28 +00:00
|
|
|
filemetadata.column_family_name = cfh->GetName();
|
|
|
|
metadata->emplace_back(filemetadata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-04 18:08:32 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE::blob_db
|