1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
6 // Copyright (c) 2012 Facebook.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file.
12 #ifndef __STDC_FORMAT_MACROS
13 #define __STDC_FORMAT_MACROS
20 #include "db/db_impl.h"
21 #include "db/job_context.h"
22 #include "db/version_set.h"
23 #include "port/port.h"
24 #include "rocksdb/db.h"
25 #include "rocksdb/env.h"
26 #include "util/file_util.h"
27 #include "util/filename.h"
28 #include "util/mutexlock.h"
29 #include "util/sync_point.h"
33 Status
DBImpl::DisableFileDeletions() {
34 InstrumentedMutexLock
l(&mutex_
);
35 ++disable_delete_obsolete_files_
;
36 if (disable_delete_obsolete_files_
== 1) {
37 ROCKS_LOG_INFO(immutable_db_options_
.info_log
, "File Deletions Disabled");
39 ROCKS_LOG_WARN(immutable_db_options_
.info_log
,
40 "File Deletions Disabled, but already disabled. Counter: %d",
41 disable_delete_obsolete_files_
);
46 Status
DBImpl::EnableFileDeletions(bool force
) {
47 // Job id == 0 means that this is not our background process, but rather
49 JobContext
job_context(0);
50 bool should_purge_files
= false;
52 InstrumentedMutexLock
l(&mutex_
);
54 // if force, we need to enable file deletions right away
55 disable_delete_obsolete_files_
= 0;
56 } else if (disable_delete_obsolete_files_
> 0) {
57 --disable_delete_obsolete_files_
;
59 if (disable_delete_obsolete_files_
== 0) {
60 ROCKS_LOG_INFO(immutable_db_options_
.info_log
, "File Deletions Enabled");
61 should_purge_files
= true;
62 FindObsoleteFiles(&job_context
, true);
65 immutable_db_options_
.info_log
,
66 "File Deletions Enable, but not really enabled. Counter: %d",
67 disable_delete_obsolete_files_
);
70 if (should_purge_files
) {
71 PurgeObsoleteFiles(job_context
);
74 LogFlush(immutable_db_options_
.info_log
);
78 int DBImpl::IsFileDeletionsEnabled() const {
79 return disable_delete_obsolete_files_
;
82 Status
DBImpl::GetLiveFiles(std::vector
<std::string
>& ret
,
83 uint64_t* manifest_file_size
,
84 bool flush_memtable
) {
85 *manifest_file_size
= 0;
90 // flush all dirty data to disk.
92 for (auto cfd
: *versions_
->GetColumnFamilySet()) {
93 if (cfd
->IsDropped()) {
98 status
= FlushMemTable(cfd
, FlushOptions());
99 TEST_SYNC_POINT("DBImpl::GetLiveFiles:1");
100 TEST_SYNC_POINT("DBImpl::GetLiveFiles:2");
107 versions_
->GetColumnFamilySet()->FreeDeadColumnFamilies();
111 ROCKS_LOG_ERROR(immutable_db_options_
.info_log
, "Cannot Flush data %s\n",
112 status
.ToString().c_str());
117 // Make a set of all of the live *.sst files
118 std::vector
<FileDescriptor
> live
;
119 for (auto cfd
: *versions_
->GetColumnFamilySet()) {
120 if (cfd
->IsDropped()) {
123 cfd
->current()->AddLiveFiles(&live
);
127 ret
.reserve(live
.size() + 3); // *.sst + CURRENT + MANIFEST + OPTIONS
129 // create names of the live files. The names are not absolute
130 // paths, instead they are relative to dbname_;
131 for (auto live_file
: live
) {
132 ret
.push_back(MakeTableFileName("", live_file
.GetNumber()));
135 ret
.push_back(CurrentFileName(""));
136 ret
.push_back(DescriptorFileName("", versions_
->manifest_file_number()));
137 ret
.push_back(OptionsFileName("", versions_
->options_file_number()));
139 // find length of manifest file while holding the mutex lock
140 *manifest_file_size
= versions_
->manifest_file_size();
146 Status
DBImpl::GetSortedWalFiles(VectorLogPtr
& files
) {
147 return wal_manager_
.GetSortedWalFiles(files
);
152 #endif // ROCKSDB_LITE