2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// 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).
|
2013-10-16 23:59:46 +02:00
|
|
|
//
|
2012-09-15 02:11:35 +02:00
|
|
|
|
2014-04-15 22:39:26 +02:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2016-06-10 04:03:10 +02:00
|
|
|
#include <stdint.h>
|
2021-09-29 13:01:57 +02:00
|
|
|
|
2013-08-06 21:54:37 +02:00
|
|
|
#include <algorithm>
|
2019-09-20 21:00:55 +02:00
|
|
|
#include <cinttypes>
|
2012-09-15 02:11:35 +02:00
|
|
|
#include <string>
|
2021-09-29 13:01:57 +02:00
|
|
|
|
2019-05-31 20:52:59 +02:00
|
|
|
#include "db/db_impl/db_impl.h"
|
2014-11-15 00:43:10 +01:00
|
|
|
#include "db/job_context.h"
|
2012-09-15 02:11:35 +02:00
|
|
|
#include "db/version_set.h"
|
2019-05-30 05:44:08 +02:00
|
|
|
#include "file/file_util.h"
|
|
|
|
#include "file/filename.h"
|
2021-09-29 13:01:57 +02:00
|
|
|
#include "logging/logging.h"
|
2016-06-10 04:03:10 +02:00
|
|
|
#include "port/port.h"
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/env.h"
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/sync_point.h"
|
2019-05-31 02:39:43 +02:00
|
|
|
#include "util/mutexlock.h"
|
2012-09-15 02:11:35 +02:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2012-09-15 02:11:35 +02:00
|
|
|
|
2012-11-29 01:42:36 +01:00
|
|
|
Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,
|
2013-10-03 23:38:32 +02:00
|
|
|
uint64_t* manifest_file_size,
|
|
|
|
bool flush_memtable) {
|
2012-09-24 23:01:01 +02:00
|
|
|
*manifest_file_size = 0;
|
2012-09-15 02:11:35 +02:00
|
|
|
|
2014-02-25 22:16:59 +01:00
|
|
|
mutex_.Lock();
|
|
|
|
|
2013-10-03 23:38:32 +02:00
|
|
|
if (flush_memtable) {
|
|
|
|
// flush all dirty data to disk.
|
2014-02-25 22:16:59 +01:00
|
|
|
Status status;
|
2018-11-12 21:22:10 +01:00
|
|
|
if (immutable_db_options_.atomic_flush) {
|
2018-10-27 00:06:44 +02:00
|
|
|
autovector<ColumnFamilyData*> cfds;
|
|
|
|
SelectColumnFamiliesForAtomicFlush(&cfds);
|
2014-02-25 22:16:59 +01:00
|
|
|
mutex_.Unlock();
|
2018-10-27 00:06:44 +02:00
|
|
|
status = AtomicFlushMemTables(cfds, FlushOptions(),
|
|
|
|
FlushReason::kGetLiveFiles);
|
2020-05-05 02:43:33 +02:00
|
|
|
if (status.IsColumnFamilyDropped()) {
|
|
|
|
status = Status::OK();
|
|
|
|
}
|
2014-02-25 22:16:59 +01:00
|
|
|
mutex_.Lock();
|
2018-10-27 00:06:44 +02:00
|
|
|
} else {
|
|
|
|
for (auto cfd : *versions_->GetColumnFamilySet()) {
|
|
|
|
if (cfd->IsDropped()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cfd->Ref();
|
|
|
|
mutex_.Unlock();
|
|
|
|
status = FlushMemTable(cfd, FlushOptions(), FlushReason::kGetLiveFiles);
|
|
|
|
TEST_SYNC_POINT("DBImpl::GetLiveFiles:1");
|
|
|
|
TEST_SYNC_POINT("DBImpl::GetLiveFiles:2");
|
|
|
|
mutex_.Lock();
|
2019-12-13 04:02:51 +01:00
|
|
|
cfd->UnrefAndTryDelete();
|
2020-05-05 02:43:33 +02:00
|
|
|
if (!status.ok() && !status.IsColumnFamilyDropped()) {
|
2018-10-27 00:06:44 +02:00
|
|
|
break;
|
2020-05-05 02:43:33 +02:00
|
|
|
} else if (status.IsColumnFamilyDropped()) {
|
|
|
|
status = Status::OK();
|
2018-10-27 00:06:44 +02:00
|
|
|
}
|
2014-02-25 22:16:59 +01:00
|
|
|
}
|
|
|
|
}
|
2014-04-07 23:21:25 +02:00
|
|
|
versions_->GetColumnFamilySet()->FreeDeadColumnFamilies();
|
|
|
|
|
2013-10-03 23:38:32 +02:00
|
|
|
if (!status.ok()) {
|
2014-02-25 22:16:59 +01:00
|
|
|
mutex_.Unlock();
|
2017-03-16 03:22:52 +01:00
|
|
|
ROCKS_LOG_ERROR(immutable_db_options_.info_log, "Cannot Flush data %s\n",
|
|
|
|
status.ToString().c_str());
|
2013-10-03 23:38:32 +02:00
|
|
|
return status;
|
|
|
|
}
|
2012-09-15 02:11:35 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 00:05:34 +02:00
|
|
|
// Make a set of all of the live table and blob files
|
|
|
|
std::vector<uint64_t> live_table_files;
|
|
|
|
std::vector<uint64_t> live_blob_files;
|
2014-02-07 23:47:16 +01:00
|
|
|
for (auto cfd : *versions_->GetColumnFamilySet()) {
|
2015-03-20 01:04:29 +01:00
|
|
|
if (cfd->IsDropped()) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-05 00:05:34 +02:00
|
|
|
cfd->current()->AddLiveFiles(&live_table_files, &live_blob_files);
|
2014-02-07 23:47:16 +01:00
|
|
|
}
|
2012-09-15 02:11:35 +02:00
|
|
|
|
2013-08-29 23:30:52 +02:00
|
|
|
ret.clear();
|
2020-05-05 00:05:34 +02:00
|
|
|
ret.reserve(live_table_files.size() + live_blob_files.size() +
|
|
|
|
3); // for CURRENT + MANIFEST + OPTIONS
|
2012-09-15 02:11:35 +02:00
|
|
|
|
|
|
|
// create names of the live files. The names are not absolute
|
|
|
|
// paths, instead they are relative to dbname_;
|
2020-05-05 00:05:34 +02:00
|
|
|
for (const auto& table_file_number : live_table_files) {
|
|
|
|
ret.emplace_back(MakeTableFileName("", table_file_number));
|
2012-09-15 02:11:35 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 00:05:34 +02:00
|
|
|
for (const auto& blob_file_number : live_blob_files) {
|
|
|
|
ret.emplace_back(BlobFileName("", blob_file_number));
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.emplace_back(CurrentFileName(""));
|
|
|
|
ret.emplace_back(DescriptorFileName("", versions_->manifest_file_number()));
|
2021-05-05 21:53:42 +02:00
|
|
|
// The OPTIONS file number is zero in read-write mode when OPTIONS file
|
|
|
|
// writing failed and the DB was configured with
|
|
|
|
// `fail_if_options_file_error == false`. In read-only mode the OPTIONS file
|
|
|
|
// number is zero when no OPTIONS file exist at all. In those cases we do not
|
|
|
|
// record any OPTIONS file in the live file list.
|
|
|
|
if (versions_->options_file_number() != 0) {
|
|
|
|
ret.emplace_back(OptionsFileName("", versions_->options_file_number()));
|
|
|
|
}
|
2012-09-15 02:11:35 +02:00
|
|
|
|
2012-09-24 23:01:01 +02:00
|
|
|
// find length of manifest file while holding the mutex lock
|
2014-11-04 02:45:55 +01:00
|
|
|
*manifest_file_size = versions_->manifest_file_size();
|
2012-09-24 23:01:01 +02:00
|
|
|
|
2014-02-25 22:16:59 +01:00
|
|
|
mutex_.Unlock();
|
2012-09-15 02:11:35 +02:00
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2013-08-06 21:54:37 +02:00
|
|
|
Status DBImpl::GetSortedWalFiles(VectorLogPtr& files) {
|
2018-01-18 02:37:10 +01:00
|
|
|
{
|
|
|
|
// If caller disabled deletions, this function should return files that are
|
|
|
|
// guaranteed not to be deleted until deletions are re-enabled. We need to
|
|
|
|
// wait for pending purges to finish since WalManager doesn't know which
|
|
|
|
// files are going to be purged. Additional purges won't be scheduled as
|
|
|
|
// long as deletions are disabled (so the below loop must terminate).
|
|
|
|
InstrumentedMutexLock l(&mutex_);
|
|
|
|
while (disable_delete_obsolete_files_ > 0 &&
|
2020-09-11 07:34:03 +02:00
|
|
|
(pending_purge_obsolete_files_ > 0 || bg_purge_scheduled_ > 0)) {
|
2018-01-18 02:37:10 +01:00
|
|
|
bg_cv_.Wait();
|
|
|
|
}
|
|
|
|
}
|
2021-07-29 20:50:00 +02:00
|
|
|
|
|
|
|
// Disable deletion in order to avoid the case where a file is deleted in
|
|
|
|
// the middle of the process so IO error is returned.
|
|
|
|
Status s = DisableFileDeletions();
|
|
|
|
bool file_deletion_supported = !s.IsNotSupported();
|
|
|
|
if (s.ok() || !file_deletion_supported) {
|
|
|
|
s = wal_manager_.GetSortedWalFiles(files);
|
|
|
|
if (file_deletion_supported) {
|
|
|
|
Status s2 = EnableFileDeletions(false);
|
|
|
|
if (!s2.ok() && s.ok()) {
|
|
|
|
s = s2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
2013-08-06 21:54:37 +02:00
|
|
|
}
|
2014-11-14 20:38:26 +01:00
|
|
|
|
2019-09-04 21:08:56 +02:00
|
|
|
Status DBImpl::GetCurrentWalFile(std::unique_ptr<LogFile>* current_log_file) {
|
|
|
|
uint64_t current_logfile_number;
|
|
|
|
{
|
|
|
|
InstrumentedMutexLock l(&mutex_);
|
|
|
|
current_logfile_number = logfile_number_;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wal_manager_.GetLiveWalFile(current_logfile_number, current_log_file);
|
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2014-04-15 22:39:26 +02:00
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|