2013-10-16 21:59:46 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2011-03-18 22:37:00 +00:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
//
|
|
|
|
// We recover the contents of the descriptor from the other files we find.
|
|
|
|
// (1) Any log files are first converted to tables
|
|
|
|
// (2) We scan every table to compute
|
|
|
|
// (a) smallest/largest for the table
|
2011-04-20 22:48:11 +00:00
|
|
|
// (b) largest sequence number in the table
|
2011-03-18 22:37:00 +00:00
|
|
|
// (3) We generate descriptor contents:
|
|
|
|
// - log number is set to zero
|
|
|
|
// - next-file-number is set to 1 + largest file number we found
|
|
|
|
// - last-sequence-number is set to largest sequence# found across
|
|
|
|
// all tables (see 2c)
|
|
|
|
// - compaction pointers are cleared
|
|
|
|
// - every table file is added at level 0
|
|
|
|
//
|
|
|
|
// Possible optimization 1:
|
|
|
|
// (a) Compute total size and use to pick appropriate max-level M
|
|
|
|
// (b) Sort tables by largest sequence# in the table
|
|
|
|
// (c) For each table: if it overlaps earlier table, place in level-0,
|
|
|
|
// else place in level-M.
|
|
|
|
// Possible optimization 2:
|
2011-04-20 22:48:11 +00:00
|
|
|
// Store per-table metadata (smallest, largest, largest-seq#, ...)
|
|
|
|
// in the table's meta section to speed up ScanTable.
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2014-04-15 20:39:26 +00:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
#include "db/builder.h"
|
|
|
|
#include "db/db_impl.h"
|
|
|
|
#include "db/dbformat.h"
|
|
|
|
#include "db/filename.h"
|
|
|
|
#include "db/log_reader.h"
|
|
|
|
#include "db/log_writer.h"
|
|
|
|
#include "db/memtable.h"
|
|
|
|
#include "db/table_cache.h"
|
|
|
|
#include "db/version_edit.h"
|
|
|
|
#include "db/write_batch_internal.h"
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/comparator.h"
|
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/env.h"
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class Repairer {
|
|
|
|
public:
|
|
|
|
Repairer(const std::string& dbname, const Options& options)
|
|
|
|
: dbname_(dbname),
|
|
|
|
env_(options.env),
|
|
|
|
icmp_(options.comparator),
|
2012-04-17 15:36:46 +00:00
|
|
|
ipolicy_(options.filter_policy),
|
|
|
|
options_(SanitizeOptions(dbname, &icmp_, &ipolicy_, options)),
|
[CF] Rethink table cache
Summary:
Adapting table cache to column families is interesting. We want table cache to be global LRU, so if some column families are use not as often as others, we want them to be evicted from cache. However, current TableCache object also constructs tables on its own. If table is not found in the cache, TableCache automatically creates new table. We want each column family to be able to specify different table factory.
To solve the problem, we still have a single LRU, but we provide the LRUCache object to TableCache on construction. We have one TableCache per column family, but the underyling cache is shared by all TableCache objects.
This allows us to have a global LRU, but still be able to support different table factories for different column families. Also, in the future it will also be able to support different directories for different column families.
Test Plan: make check
Reviewers: dhruba, haobo, kailiu, sdong
CC: leveldb
Differential Revision: https://reviews.facebook.net/D15915
2014-02-05 17:07:55 +00:00
|
|
|
raw_table_cache_(
|
|
|
|
// TableCache can be small since we expect each table to be opened
|
|
|
|
// once.
|
|
|
|
NewLRUCache(10, options_.table_cache_numshardbits,
|
|
|
|
options_.table_cache_remove_scan_count_limit)),
|
2011-03-18 22:37:00 +00:00
|
|
|
next_file_number_(1) {
|
2014-02-05 20:20:40 +00:00
|
|
|
table_cache_ = new TableCache(dbname_, &options_, storage_options_,
|
|
|
|
raw_table_cache_.get());
|
2014-01-14 23:27:09 +00:00
|
|
|
edit_ = new VersionEdit();
|
2011-03-18 22:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Repairer() {
|
|
|
|
delete table_cache_;
|
[CF] Rethink table cache
Summary:
Adapting table cache to column families is interesting. We want table cache to be global LRU, so if some column families are use not as often as others, we want them to be evicted from cache. However, current TableCache object also constructs tables on its own. If table is not found in the cache, TableCache automatically creates new table. We want each column family to be able to specify different table factory.
To solve the problem, we still have a single LRU, but we provide the LRUCache object to TableCache on construction. We have one TableCache per column family, but the underyling cache is shared by all TableCache objects.
This allows us to have a global LRU, but still be able to support different table factories for different column families. Also, in the future it will also be able to support different directories for different column families.
Test Plan: make check
Reviewers: dhruba, haobo, kailiu, sdong
CC: leveldb
Differential Revision: https://reviews.facebook.net/D15915
2014-02-05 17:07:55 +00:00
|
|
|
raw_table_cache_.reset();
|
2012-06-23 02:30:03 +00:00
|
|
|
delete edit_;
|
2011-03-18 22:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status Run() {
|
|
|
|
Status status = FindFiles();
|
|
|
|
if (status.ok()) {
|
|
|
|
ConvertLogFilesToTables();
|
|
|
|
ExtractMetaData();
|
|
|
|
status = WriteDescriptor();
|
|
|
|
}
|
|
|
|
if (status.ok()) {
|
|
|
|
unsigned long long bytes = 0;
|
2011-04-20 22:48:11 +00:00
|
|
|
for (size_t i = 0; i < tables_.size(); i++) {
|
2011-03-18 22:37:00 +00:00
|
|
|
bytes += tables_[i].meta.file_size;
|
|
|
|
}
|
2011-07-21 02:40:18 +00:00
|
|
|
Log(options_.info_log,
|
2013-10-05 05:32:05 +00:00
|
|
|
"**** Repaired rocksdb %s; "
|
2011-03-18 22:37:00 +00:00
|
|
|
"recovered %d files; %llu bytes. "
|
|
|
|
"Some data may have been lost. "
|
|
|
|
"****",
|
|
|
|
dbname_.c_str(),
|
|
|
|
static_cast<int>(tables_.size()),
|
|
|
|
bytes);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct TableInfo {
|
|
|
|
FileMetaData meta;
|
2013-06-14 05:09:08 +00:00
|
|
|
SequenceNumber min_sequence;
|
2011-03-18 22:37:00 +00:00
|
|
|
SequenceNumber max_sequence;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string const dbname_;
|
|
|
|
Env* const env_;
|
|
|
|
InternalKeyComparator const icmp_;
|
2012-04-17 15:36:46 +00:00
|
|
|
InternalFilterPolicy const ipolicy_;
|
2011-03-18 22:37:00 +00:00
|
|
|
Options const options_;
|
[CF] Rethink table cache
Summary:
Adapting table cache to column families is interesting. We want table cache to be global LRU, so if some column families are use not as often as others, we want them to be evicted from cache. However, current TableCache object also constructs tables on its own. If table is not found in the cache, TableCache automatically creates new table. We want each column family to be able to specify different table factory.
To solve the problem, we still have a single LRU, but we provide the LRUCache object to TableCache on construction. We have one TableCache per column family, but the underyling cache is shared by all TableCache objects.
This allows us to have a global LRU, but still be able to support different table factories for different column families. Also, in the future it will also be able to support different directories for different column families.
Test Plan: make check
Reviewers: dhruba, haobo, kailiu, sdong
CC: leveldb
Differential Revision: https://reviews.facebook.net/D15915
2014-02-05 17:07:55 +00:00
|
|
|
std::shared_ptr<Cache> raw_table_cache_;
|
2011-03-18 22:37:00 +00:00
|
|
|
TableCache* table_cache_;
|
2012-06-23 02:30:03 +00:00
|
|
|
VersionEdit* edit_;
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
std::vector<std::string> manifests_;
|
|
|
|
std::vector<uint64_t> table_numbers_;
|
|
|
|
std::vector<uint64_t> logs_;
|
|
|
|
std::vector<TableInfo> tables_;
|
|
|
|
uint64_t next_file_number_;
|
2013-06-07 22:35:17 +00:00
|
|
|
const EnvOptions storage_options_;
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
Status FindFiles() {
|
|
|
|
std::vector<std::string> filenames;
|
|
|
|
Status status = env_->GetChildren(dbname_, &filenames);
|
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
if (filenames.empty()) {
|
2014-02-12 19:42:54 +00:00
|
|
|
return Status::Corruption(dbname_, "repair found no files");
|
2011-03-18 22:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t number;
|
|
|
|
FileType type;
|
2011-04-20 22:48:11 +00:00
|
|
|
for (size_t i = 0; i < filenames.size(); i++) {
|
|
|
|
if (ParseFileName(filenames[i], &number, &type)) {
|
|
|
|
if (type == kDescriptorFile) {
|
2011-03-18 22:37:00 +00:00
|
|
|
manifests_.push_back(filenames[i]);
|
|
|
|
} else {
|
|
|
|
if (number + 1 > next_file_number_) {
|
|
|
|
next_file_number_ = number + 1;
|
|
|
|
}
|
|
|
|
if (type == kLogFile) {
|
|
|
|
logs_.push_back(number);
|
|
|
|
} else if (type == kTableFile) {
|
|
|
|
table_numbers_.push_back(number);
|
|
|
|
} else {
|
|
|
|
// Ignore other files
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertLogFilesToTables() {
|
2011-04-20 22:48:11 +00:00
|
|
|
for (size_t i = 0; i < logs_.size(); i++) {
|
2011-03-18 22:37:00 +00:00
|
|
|
std::string logname = LogFileName(dbname_, logs_[i]);
|
|
|
|
Status status = ConvertLogToTable(logs_[i]);
|
|
|
|
if (!status.ok()) {
|
2011-07-21 02:40:18 +00:00
|
|
|
Log(options_.info_log, "Log #%llu: ignoring conversion error: %s",
|
2011-03-18 22:37:00 +00:00
|
|
|
(unsigned long long) logs_[i],
|
|
|
|
status.ToString().c_str());
|
|
|
|
}
|
|
|
|
ArchiveFile(logname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status ConvertLogToTable(uint64_t log) {
|
|
|
|
struct LogReporter : public log::Reader::Reporter {
|
|
|
|
Env* env;
|
2013-01-20 10:07:13 +00:00
|
|
|
std::shared_ptr<Logger> info_log;
|
2011-03-18 22:37:00 +00:00
|
|
|
uint64_t lognum;
|
|
|
|
virtual void Corruption(size_t bytes, const Status& s) {
|
|
|
|
// We print error messages for corruption, but continue repairing.
|
2011-07-21 02:40:18 +00:00
|
|
|
Log(info_log, "Log #%llu: dropping %d bytes; %s",
|
2011-03-18 22:37:00 +00:00
|
|
|
(unsigned long long) lognum,
|
|
|
|
static_cast<int>(bytes),
|
|
|
|
s.ToString().c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Open the log file
|
|
|
|
std::string logname = LogFileName(dbname_, log);
|
2013-01-20 10:07:13 +00:00
|
|
|
unique_ptr<SequentialFile> lfile;
|
2013-03-15 00:00:04 +00:00
|
|
|
Status status = env_->NewSequentialFile(logname, &lfile, storage_options_);
|
2011-03-18 22:37:00 +00:00
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the log reader.
|
|
|
|
LogReporter reporter;
|
|
|
|
reporter.env = env_;
|
|
|
|
reporter.info_log = options_.info_log;
|
|
|
|
reporter.lognum = log;
|
|
|
|
// We intentially make log::Reader do checksumming so that
|
|
|
|
// corruptions cause entire commits to be skipped instead of
|
|
|
|
// propagating bad information (like overly large sequence
|
|
|
|
// numbers).
|
2013-01-20 10:07:13 +00:00
|
|
|
log::Reader reader(std::move(lfile), &reporter, false/*do not checksum*/,
|
2011-05-21 02:17:43 +00:00
|
|
|
0/*initial_offset*/);
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
// Read all the records and add to a memtable
|
|
|
|
std::string scratch;
|
|
|
|
Slice record;
|
|
|
|
WriteBatch batch;
|
2014-01-14 23:27:09 +00:00
|
|
|
MemTable* mem = new MemTable(icmp_, options_);
|
2014-02-06 00:02:48 +00:00
|
|
|
auto cf_mems_default = new ColumnFamilyMemTablesDefault(mem, &options_);
|
2011-05-21 02:17:43 +00:00
|
|
|
mem->Ref();
|
2011-03-18 22:37:00 +00:00
|
|
|
int counter = 0;
|
|
|
|
while (reader.ReadRecord(&record, &scratch)) {
|
|
|
|
if (record.size() < 12) {
|
|
|
|
reporter.Corruption(
|
|
|
|
record.size(), Status::Corruption("log record too small"));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
WriteBatchInternal::SetContents(&batch, record);
|
2014-02-06 00:02:48 +00:00
|
|
|
status = WriteBatchInternal::InsertInto(&batch, cf_mems_default);
|
2011-03-18 22:37:00 +00:00
|
|
|
if (status.ok()) {
|
|
|
|
counter += WriteBatchInternal::Count(&batch);
|
|
|
|
} else {
|
2011-07-21 02:40:18 +00:00
|
|
|
Log(options_.info_log, "Log #%llu: ignoring %s",
|
2011-03-18 22:37:00 +00:00
|
|
|
(unsigned long long) log,
|
|
|
|
status.ToString().c_str());
|
|
|
|
status = Status::OK(); // Keep going with rest of file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-22 02:36:45 +00:00
|
|
|
// Do not record a version edit for this conversion to a Table
|
2011-03-18 22:37:00 +00:00
|
|
|
// since ExtractMetaData() will also generate edits.
|
|
|
|
FileMetaData meta;
|
|
|
|
meta.number = next_file_number_++;
|
2014-04-25 19:21:34 +00:00
|
|
|
ReadOptions ro;
|
|
|
|
Iterator* iter = mem->NewIterator(ro, true /* enforce_total_order */);
|
2014-01-27 21:53:22 +00:00
|
|
|
status = BuildTable(dbname_, env_, options_, storage_options_, table_cache_,
|
|
|
|
iter, &meta, icmp_, 0, 0, kNoCompression);
|
2011-03-18 22:37:00 +00:00
|
|
|
delete iter;
|
2013-11-27 22:56:20 +00:00
|
|
|
delete mem->Unref();
|
2014-02-06 00:02:48 +00:00
|
|
|
delete cf_mems_default;
|
2013-03-01 02:04:58 +00:00
|
|
|
mem = nullptr;
|
2011-03-18 22:37:00 +00:00
|
|
|
if (status.ok()) {
|
|
|
|
if (meta.file_size > 0) {
|
|
|
|
table_numbers_.push_back(meta.number);
|
|
|
|
}
|
|
|
|
}
|
2011-07-21 02:40:18 +00:00
|
|
|
Log(options_.info_log, "Log #%llu: %d ops saved to Table #%llu %s",
|
2011-03-18 22:37:00 +00:00
|
|
|
(unsigned long long) log,
|
|
|
|
counter,
|
|
|
|
(unsigned long long) meta.number,
|
|
|
|
status.ToString().c_str());
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtractMetaData() {
|
2011-04-20 22:48:11 +00:00
|
|
|
for (size_t i = 0; i < table_numbers_.size(); i++) {
|
2011-03-18 22:37:00 +00:00
|
|
|
TableInfo t;
|
|
|
|
t.meta.number = table_numbers_[i];
|
|
|
|
Status status = ScanTable(&t);
|
|
|
|
if (!status.ok()) {
|
|
|
|
std::string fname = TableFileName(dbname_, table_numbers_[i]);
|
2011-07-21 02:40:18 +00:00
|
|
|
Log(options_.info_log, "Table #%llu: ignoring %s",
|
2011-03-18 22:37:00 +00:00
|
|
|
(unsigned long long) table_numbers_[i],
|
|
|
|
status.ToString().c_str());
|
|
|
|
ArchiveFile(fname);
|
|
|
|
} else {
|
|
|
|
tables_.push_back(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status ScanTable(TableInfo* t) {
|
|
|
|
std::string fname = TableFileName(dbname_, t->meta.number);
|
|
|
|
int counter = 0;
|
|
|
|
Status status = env_->GetFileSize(fname, &t->meta.file_size);
|
|
|
|
if (status.ok()) {
|
2014-01-07 04:29:17 +00:00
|
|
|
FileMetaData dummy_meta(t->meta.number, t->meta.file_size);
|
2011-03-18 22:37:00 +00:00
|
|
|
Iterator* iter = table_cache_->NewIterator(
|
2014-01-27 21:53:22 +00:00
|
|
|
ReadOptions(), storage_options_, icmp_, dummy_meta);
|
2011-03-18 22:37:00 +00:00
|
|
|
bool empty = true;
|
|
|
|
ParsedInternalKey parsed;
|
2013-06-14 05:09:08 +00:00
|
|
|
t->min_sequence = 0;
|
2011-03-18 22:37:00 +00:00
|
|
|
t->max_sequence = 0;
|
|
|
|
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
|
|
|
Slice key = iter->key();
|
|
|
|
if (!ParseInternalKey(key, &parsed)) {
|
2011-07-21 02:40:18 +00:00
|
|
|
Log(options_.info_log, "Table #%llu: unparsable key %s",
|
2011-03-18 22:37:00 +00:00
|
|
|
(unsigned long long) t->meta.number,
|
|
|
|
EscapeString(key).c_str());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
if (empty) {
|
|
|
|
empty = false;
|
|
|
|
t->meta.smallest.DecodeFrom(key);
|
|
|
|
}
|
|
|
|
t->meta.largest.DecodeFrom(key);
|
2013-06-14 05:09:08 +00:00
|
|
|
if (parsed.sequence < t->min_sequence) {
|
|
|
|
t->min_sequence = parsed.sequence;
|
|
|
|
}
|
2011-03-18 22:37:00 +00:00
|
|
|
if (parsed.sequence > t->max_sequence) {
|
|
|
|
t->max_sequence = parsed.sequence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!iter->status().ok()) {
|
|
|
|
status = iter->status();
|
|
|
|
}
|
|
|
|
delete iter;
|
|
|
|
}
|
2011-07-21 02:40:18 +00:00
|
|
|
Log(options_.info_log, "Table #%llu: %d entries %s",
|
2011-03-18 22:37:00 +00:00
|
|
|
(unsigned long long) t->meta.number,
|
|
|
|
counter,
|
|
|
|
status.ToString().c_str());
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status WriteDescriptor() {
|
|
|
|
std::string tmp = TempFileName(dbname_, 1);
|
2013-01-20 10:07:13 +00:00
|
|
|
unique_ptr<WritableFile> file;
|
2014-03-18 04:52:14 +00:00
|
|
|
Status status = env_->NewWritableFile(
|
|
|
|
tmp, &file, env_->OptimizeForManifestWrite(storage_options_));
|
2011-03-18 22:37:00 +00:00
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
SequenceNumber max_sequence = 0;
|
2011-04-20 22:48:11 +00:00
|
|
|
for (size_t i = 0; i < tables_.size(); i++) {
|
2011-03-18 22:37:00 +00:00
|
|
|
if (max_sequence < tables_[i].max_sequence) {
|
|
|
|
max_sequence = tables_[i].max_sequence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-23 02:30:03 +00:00
|
|
|
edit_->SetComparatorName(icmp_.user_comparator()->Name());
|
|
|
|
edit_->SetLogNumber(0);
|
|
|
|
edit_->SetNextFile(next_file_number_);
|
|
|
|
edit_->SetLastSequence(max_sequence);
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2011-04-20 22:48:11 +00:00
|
|
|
for (size_t i = 0; i < tables_.size(); i++) {
|
2011-03-18 22:37:00 +00:00
|
|
|
// TODO(opt): separate out into multiple levels
|
|
|
|
const TableInfo& t = tables_[i];
|
2012-06-23 02:30:03 +00:00
|
|
|
edit_->AddFile(0, t.meta.number, t.meta.file_size,
|
2013-06-14 05:09:08 +00:00
|
|
|
t.meta.smallest, t.meta.largest,
|
|
|
|
t.min_sequence, t.max_sequence);
|
2011-03-18 22:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//fprintf(stderr, "NewDescriptor:\n%s\n", edit_.DebugString().c_str());
|
|
|
|
{
|
2013-01-20 10:07:13 +00:00
|
|
|
log::Writer log(std::move(file));
|
2011-03-18 22:37:00 +00:00
|
|
|
std::string record;
|
2012-06-23 02:30:03 +00:00
|
|
|
edit_->EncodeTo(&record);
|
2011-03-18 22:37:00 +00:00
|
|
|
status = log.AddRecord(record);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status.ok()) {
|
|
|
|
env_->DeleteFile(tmp);
|
|
|
|
} else {
|
|
|
|
// Discard older manifests
|
2011-04-20 22:48:11 +00:00
|
|
|
for (size_t i = 0; i < manifests_.size(); i++) {
|
2011-03-18 22:37:00 +00:00
|
|
|
ArchiveFile(dbname_ + "/" + manifests_[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Install new manifest
|
|
|
|
status = env_->RenameFile(tmp, DescriptorFileName(dbname_, 1));
|
|
|
|
if (status.ok()) {
|
|
|
|
status = SetCurrentFile(env_, dbname_, 1);
|
|
|
|
} else {
|
|
|
|
env_->DeleteFile(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArchiveFile(const std::string& fname) {
|
|
|
|
// Move into another directory. E.g., for
|
|
|
|
// dir/foo
|
|
|
|
// rename to
|
|
|
|
// dir/lost/foo
|
|
|
|
const char* slash = strrchr(fname.c_str(), '/');
|
|
|
|
std::string new_dir;
|
2013-03-01 02:04:58 +00:00
|
|
|
if (slash != nullptr) {
|
2011-03-18 22:37:00 +00:00
|
|
|
new_dir.assign(fname.data(), slash - fname.data());
|
|
|
|
}
|
|
|
|
new_dir.append("/lost");
|
|
|
|
env_->CreateDir(new_dir); // Ignore error
|
|
|
|
std::string new_file = new_dir;
|
|
|
|
new_file.append("/");
|
2013-03-01 02:04:58 +00:00
|
|
|
new_file.append((slash == nullptr) ? fname.c_str() : slash + 1);
|
2011-03-18 22:37:00 +00:00
|
|
|
Status s = env_->RenameFile(fname, new_file);
|
2011-07-21 02:40:18 +00:00
|
|
|
Log(options_.info_log, "Archiving %s: %s\n",
|
2011-03-18 22:37:00 +00:00
|
|
|
fname.c_str(), s.ToString().c_str());
|
|
|
|
}
|
|
|
|
};
|
2011-10-31 17:22:06 +00:00
|
|
|
} // namespace
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
Status RepairDB(const std::string& dbname, const Options& options) {
|
|
|
|
Repairer repairer(dbname, options);
|
|
|
|
return repairer.Run();
|
|
|
|
}
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
} // namespace rocksdb
|
2014-04-15 20:39:26 +00:00
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|