mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-27 02:44:18 +00:00
c67d48c852
Summary: This is a huge diff and it was hectic, but the idea is actually quite simple. Every operation (Put, Get, etc.) done on default column family in DBTest is now forwarded to non-default ("pikachu"). The good news is that we had zero test failures! Column families look stable so far. One interesting test that I adapted for column families is MultiThreadedTest. I replaced every Put() with a WriteBatch writing to all column families concurrently. Every Put in the write batch contains unique_id. Instead of Get() I do a multiget across all column families with the same key. If atomicity holds, I expect to see the same unique_id in all column families. Test Plan: This is a test! Reviewers: dhruba, haobo, kailiu, sdong CC: leveldb Differential Revision: https://reviews.facebook.net/D16149
117 lines
3.3 KiB
C++
117 lines
3.3 KiB
C++
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
//
|
|
// Copyright (c) 2012 Facebook.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include <algorithm>
|
|
#include <string>
|
|
#include <stdint.h>
|
|
#include "db/db_impl.h"
|
|
#include "db/filename.h"
|
|
#include "db/version_set.h"
|
|
#include "rocksdb/db.h"
|
|
#include "rocksdb/env.h"
|
|
#include "port/port.h"
|
|
#include "util/mutexlock.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
Status DBImpl::DisableFileDeletions() {
|
|
MutexLock l(&mutex_);
|
|
++disable_delete_obsolete_files_;
|
|
if (disable_delete_obsolete_files_ == 1) {
|
|
// if not, it has already been disabled, so don't log anything
|
|
Log(options_.info_log, "File Deletions Disabled");
|
|
}
|
|
return Status::OK();
|
|
}
|
|
|
|
Status DBImpl::EnableFileDeletions(bool force) {
|
|
DeletionState deletion_state;
|
|
bool should_purge_files = false;
|
|
{
|
|
MutexLock l(&mutex_);
|
|
if (force) {
|
|
// if force, we need to enable file deletions right away
|
|
disable_delete_obsolete_files_ = 0;
|
|
} else if (disable_delete_obsolete_files_ > 0) {
|
|
--disable_delete_obsolete_files_;
|
|
}
|
|
if (disable_delete_obsolete_files_ == 0) {
|
|
Log(options_.info_log, "File Deletions Enabled");
|
|
should_purge_files = true;
|
|
FindObsoleteFiles(deletion_state, true);
|
|
}
|
|
}
|
|
if (should_purge_files) {
|
|
PurgeObsoleteFiles(deletion_state);
|
|
}
|
|
LogFlush(options_.info_log);
|
|
return Status::OK();
|
|
}
|
|
|
|
Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,
|
|
uint64_t* manifest_file_size,
|
|
bool flush_memtable) {
|
|
|
|
*manifest_file_size = 0;
|
|
|
|
if (flush_memtable) {
|
|
// flush all dirty data to disk.
|
|
Status status = Flush(FlushOptions());
|
|
if (!status.ok()) {
|
|
Log(options_.info_log, "Cannot Flush data %s\n",
|
|
status.ToString().c_str());
|
|
return status;
|
|
}
|
|
}
|
|
|
|
MutexLock l(&mutex_);
|
|
|
|
// Make a set of all of the live *.sst files
|
|
std::set<uint64_t> live;
|
|
for (auto cfd : *versions_->GetColumnFamilySet()) {
|
|
cfd->current()->AddLiveFiles(&live);
|
|
}
|
|
|
|
ret.clear();
|
|
ret.reserve(live.size() + 2); //*.sst + CURRENT + MANIFEST
|
|
|
|
// create names of the live files. The names are not absolute
|
|
// paths, instead they are relative to dbname_;
|
|
for (auto live_file : live) {
|
|
ret.push_back(TableFileName("", live_file));
|
|
}
|
|
|
|
ret.push_back(CurrentFileName(""));
|
|
ret.push_back(DescriptorFileName("", versions_->ManifestFileNumber()));
|
|
|
|
// find length of manifest file while holding the mutex lock
|
|
*manifest_file_size = versions_->ManifestFileSize();
|
|
|
|
return Status::OK();
|
|
}
|
|
|
|
Status DBImpl::GetSortedWalFiles(VectorLogPtr& files) {
|
|
// First get sorted files in archive dir, then append sorted files from main
|
|
// dir to maintain sorted order
|
|
|
|
// list wal files in archive dir.
|
|
Status s;
|
|
std::string archivedir = ArchivalDirectory(options_.wal_dir);
|
|
if (env_->FileExists(archivedir)) {
|
|
s = AppendSortedWalsOfType(archivedir, files, kArchivedLogFile);
|
|
if (!s.ok()) {
|
|
return s;
|
|
}
|
|
}
|
|
// list wal files in main db dir.
|
|
return AppendSortedWalsOfType(options_.wal_dir, files, kAliveLogFile);
|
|
}
|
|
|
|
}
|