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).
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
|
|
|
#include "utilities/blob_db/blob_db_impl.h"
|
|
|
|
|
2019-05-30 03:44:08 +00:00
|
|
|
#include "file/filename.h"
|
2019-06-01 00:19:43 +00:00
|
|
|
#include "logging/logging.h"
|
2018-08-27 17:56:28 +00:00
|
|
|
#include "util/mutexlock.h"
|
|
|
|
|
|
|
|
// BlobDBImpl methods to get snapshot of files, e.g. for replication.
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2018-08-27 17:56:28 +00:00
|
|
|
namespace blob_db {
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
Status BlobDBImpl::EnableFileDeletions(bool force) {
|
|
|
|
// Enable base DB file deletions.
|
|
|
|
Status s = db_impl_->EnableFileDeletions(force);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
{
|
|
|
|
MutexLock l(&delete_file_mutex_);
|
|
|
|
if (force) {
|
|
|
|
disable_file_deletions_ = 0;
|
|
|
|
} else if (disable_file_deletions_ > 0) {
|
|
|
|
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());
|
|
|
|
for (auto bfile_pair : blob_files_) {
|
|
|
|
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);
|
|
|
|
for (auto bfile_pair : blob_files_) {
|
|
|
|
auto blob_file = bfile_pair.second;
|
|
|
|
LiveFileMetaData filemetadata;
|
2018-09-06 01:07:53 +00:00
|
|
|
filemetadata.size = static_cast<size_t>(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;
|
2018-08-27 17:56:28 +00:00
|
|
|
auto cfh = reinterpret_cast<ColumnFamilyHandleImpl*>(DefaultColumnFamily());
|
|
|
|
filemetadata.column_family_name = cfh->GetName();
|
|
|
|
metadata->emplace_back(filemetadata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace blob_db
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2018-08-27 17:56:28 +00:00
|
|
|
#endif // !ROCKSDB_LITE
|