2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2013-10-16 23:59:46 +02:00
|
|
|
// 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 23:37:00 +01: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.
|
|
|
|
//
|
2015-04-10 01:11:15 +02:00
|
|
|
// Repairer does best effort recovery to recover as much data as possible after
|
|
|
|
// a disaster without compromising consistency. It does not guarantee bringing
|
|
|
|
// the database to a time consistent state.
|
|
|
|
//
|
|
|
|
// Repair process is broken into 4 phases:
|
|
|
|
// (a) Find files
|
|
|
|
// (b) Convert logs to tables
|
|
|
|
// (c) Extract metadata
|
|
|
|
// (d) Write Descriptor
|
|
|
|
//
|
|
|
|
// (a) Find files
|
|
|
|
//
|
|
|
|
// The repairer goes through all the files in the directory, and classifies them
|
|
|
|
// based on their file name. Any file that cannot be identified by name will be
|
|
|
|
// ignored.
|
|
|
|
//
|
|
|
|
// (b) Convert logs to table
|
|
|
|
//
|
|
|
|
// Every log file that is active is replayed. All sections of the file where the
|
|
|
|
// checksum does not match is skipped over. We intentionally give preference to
|
|
|
|
// data consistency.
|
|
|
|
//
|
|
|
|
// (c) Extract metadata
|
|
|
|
//
|
|
|
|
// We scan every table to compute
|
|
|
|
// (1) smallest/largest for the table
|
|
|
|
// (2) largest sequence number in the table
|
|
|
|
//
|
|
|
|
// If we are unable to scan the file, then we ignore the table.
|
|
|
|
//
|
|
|
|
// (d) Write Descriptor
|
|
|
|
//
|
|
|
|
// 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
|
2011-03-18 23:37:00 +01:00
|
|
|
//
|
|
|
|
// 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.
|
2015-04-10 01:11:15 +02:00
|
|
|
// (d) We can provide options for time consistent recovery and unsafe recovery
|
|
|
|
// (ignore checksum failure when applicable)
|
2011-03-18 23:37:00 +01:00
|
|
|
// Possible optimization 2:
|
2011-04-21 00:48:11 +02:00
|
|
|
// Store per-table metadata (smallest, largest, largest-seq#, ...)
|
|
|
|
// in the table's meta section to speed up ScanTable.
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2014-04-15 22:39:26 +02:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
2014-09-05 08:14:37 +02:00
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
2014-06-28 01:01:59 +02:00
|
|
|
#define __STDC_FORMAT_MACROS
|
2014-09-05 08:14:37 +02:00
|
|
|
#endif
|
|
|
|
|
2014-06-28 01:01:59 +02:00
|
|
|
#include <inttypes.h>
|
2011-03-18 23:37:00 +01: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"
|
2014-12-02 21:09:20 +01:00
|
|
|
#include "db/writebuffer.h"
|
2011-03-18 23:37:00 +01:00
|
|
|
#include "db/write_batch_internal.h"
|
2013-08-23 17:38:13 +02:00
|
|
|
#include "rocksdb/comparator.h"
|
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/env.h"
|
2014-09-05 01:18:36 +02:00
|
|
|
#include "rocksdb/options.h"
|
|
|
|
#include "rocksdb/immutable_options.h"
|
2015-10-13 00:06:38 +02:00
|
|
|
#include "table/scoped_arena_iterator.h"
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
#include "util/file_reader_writer.h"
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class Repairer {
|
|
|
|
public:
|
|
|
|
Repairer(const std::string& dbname, const Options& options)
|
|
|
|
: dbname_(dbname),
|
|
|
|
env_(options.env),
|
|
|
|
icmp_(options.comparator),
|
2014-08-25 23:22:05 +02:00
|
|
|
options_(SanitizeOptions(dbname, &icmp_, options)),
|
2014-09-05 01:18:36 +02:00
|
|
|
ioptions_(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 18:07:55 +01:00
|
|
|
raw_table_cache_(
|
|
|
|
// TableCache can be small since we expect each table to be opened
|
|
|
|
// once.
|
2015-03-17 23:04:37 +01:00
|
|
|
NewLRUCache(10, options_.table_cache_numshardbits)),
|
2011-03-18 23:37:00 +01:00
|
|
|
next_file_number_(1) {
|
A new call back to TablePropertiesCollector to allow users know the entry is add, delete or merge
Summary:
Currently users have no idea a key is add, delete or merge from TablePropertiesCollector call back. Add a new function to add it.
Also refactor the codes so that
(1) make table property collector and internal table property collector two separate data structures with the later one now exposed
(2) table builders only receive internal table properties
Test Plan: Add cases in table_properties_collector_test to cover both of old and new ways of using TablePropertiesCollector.
Reviewers: yhchiang, igor.sugak, rven, igor
Reviewed By: rven, igor
Subscribers: meyering, yoshinorim, maykov, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D35373
2015-04-06 19:04:30 +02:00
|
|
|
GetIntTblPropCollectorFactory(options, &int_tbl_prop_collector_factories_);
|
|
|
|
|
2014-07-02 18:54:20 +02:00
|
|
|
table_cache_ =
|
2014-09-05 01:18:36 +02:00
|
|
|
new TableCache(ioptions_, env_options_, raw_table_cache_.get());
|
2014-01-15 00:27:09 +01:00
|
|
|
edit_ = new VersionEdit();
|
2011-03-18 23:37:00 +01: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 18:07:55 +01:00
|
|
|
raw_table_cache_.reset();
|
2012-06-23 04:30:03 +02:00
|
|
|
delete edit_;
|
2011-03-18 23:37:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Status Run() {
|
|
|
|
Status status = FindFiles();
|
|
|
|
if (status.ok()) {
|
|
|
|
ConvertLogFilesToTables();
|
|
|
|
ExtractMetaData();
|
|
|
|
status = WriteDescriptor();
|
|
|
|
}
|
|
|
|
if (status.ok()) {
|
2014-06-28 01:01:59 +02:00
|
|
|
uint64_t bytes = 0;
|
2011-04-21 00:48:11 +02:00
|
|
|
for (size_t i = 0; i < tables_.size(); i++) {
|
2014-06-14 00:54:19 +02:00
|
|
|
bytes += tables_[i].meta.fd.GetFileSize();
|
2011-03-18 23:37:00 +01:00
|
|
|
}
|
2014-10-29 23:12:50 +01:00
|
|
|
Log(InfoLogLevel::WARN_LEVEL, options_.info_log,
|
2013-10-05 07:32:05 +02:00
|
|
|
"**** Repaired rocksdb %s; "
|
2015-07-02 01:13:49 +02:00
|
|
|
"recovered %" ROCKSDB_PRIszt " files; %" PRIu64
|
2014-06-28 01:01:59 +02:00
|
|
|
"bytes. "
|
2011-03-18 23:37:00 +01:00
|
|
|
"Some data may have been lost. "
|
|
|
|
"****",
|
2014-06-28 01:01:59 +02:00
|
|
|
dbname_.c_str(), tables_.size(), bytes);
|
2011-03-18 23:37:00 +01:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct TableInfo {
|
|
|
|
FileMetaData meta;
|
2013-06-14 07:09:08 +02:00
|
|
|
SequenceNumber min_sequence;
|
2011-03-18 23:37:00 +01:00
|
|
|
SequenceNumber max_sequence;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string const dbname_;
|
|
|
|
Env* const env_;
|
2014-09-05 01:18:36 +02:00
|
|
|
const InternalKeyComparator icmp_;
|
A new call back to TablePropertiesCollector to allow users know the entry is add, delete or merge
Summary:
Currently users have no idea a key is add, delete or merge from TablePropertiesCollector call back. Add a new function to add it.
Also refactor the codes so that
(1) make table property collector and internal table property collector two separate data structures with the later one now exposed
(2) table builders only receive internal table properties
Test Plan: Add cases in table_properties_collector_test to cover both of old and new ways of using TablePropertiesCollector.
Reviewers: yhchiang, igor.sugak, rven, igor
Reviewed By: rven, igor
Subscribers: meyering, yoshinorim, maykov, leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D35373
2015-04-06 19:04:30 +02:00
|
|
|
std::vector<std::unique_ptr<IntTblPropCollectorFactory>>
|
|
|
|
int_tbl_prop_collector_factories_;
|
2014-09-05 01:18:36 +02:00
|
|
|
const Options options_;
|
|
|
|
const ImmutableCFOptions ioptions_;
|
[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 18:07:55 +01:00
|
|
|
std::shared_ptr<Cache> raw_table_cache_;
|
2011-03-18 23:37:00 +01:00
|
|
|
TableCache* table_cache_;
|
2012-06-23 04:30:03 +02:00
|
|
|
VersionEdit* edit_;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
std::vector<std::string> manifests_;
|
2014-07-02 18:54:20 +02:00
|
|
|
std::vector<FileDescriptor> table_fds_;
|
2011-03-18 23:37:00 +01:00
|
|
|
std::vector<uint64_t> logs_;
|
|
|
|
std::vector<TableInfo> tables_;
|
|
|
|
uint64_t next_file_number_;
|
2014-09-05 01:18:36 +02:00
|
|
|
const EnvOptions env_options_;
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
Status FindFiles() {
|
|
|
|
std::vector<std::string> filenames;
|
2014-07-02 18:54:20 +02:00
|
|
|
bool found_file = false;
|
2015-12-16 00:26:20 +01:00
|
|
|
for (size_t path_id = 0; path_id < options_.db_paths.size(); path_id++) {
|
2014-07-15 00:34:30 +02:00
|
|
|
Status status =
|
|
|
|
env_->GetChildren(options_.db_paths[path_id].path, &filenames);
|
2014-07-02 18:54:20 +02:00
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
if (!filenames.empty()) {
|
|
|
|
found_file = true;
|
|
|
|
}
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2014-07-02 18:54:20 +02:00
|
|
|
uint64_t number;
|
|
|
|
FileType type;
|
|
|
|
for (size_t i = 0; i < filenames.size(); i++) {
|
|
|
|
if (ParseFileName(filenames[i], &number, &type)) {
|
|
|
|
if (type == kDescriptorFile) {
|
|
|
|
assert(path_id == 0);
|
|
|
|
manifests_.push_back(filenames[i]);
|
2011-03-18 23:37:00 +01:00
|
|
|
} else {
|
2014-07-02 18:54:20 +02:00
|
|
|
if (number + 1 > next_file_number_) {
|
|
|
|
next_file_number_ = number + 1;
|
|
|
|
}
|
|
|
|
if (type == kLogFile) {
|
|
|
|
assert(path_id == 0);
|
|
|
|
logs_.push_back(number);
|
|
|
|
} else if (type == kTableFile) {
|
2015-12-28 23:28:19 +01:00
|
|
|
table_fds_.emplace_back(number, static_cast<uint32_t>(path_id),
|
|
|
|
0);
|
2014-07-02 18:54:20 +02:00
|
|
|
} else {
|
|
|
|
// Ignore other files
|
|
|
|
}
|
2011-03-18 23:37:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-02 18:54:20 +02:00
|
|
|
if (!found_file) {
|
|
|
|
return Status::Corruption(dbname_, "repair found no files");
|
|
|
|
}
|
|
|
|
return Status::OK();
|
2011-03-18 23:37:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConvertLogFilesToTables() {
|
2011-04-21 00:48:11 +02:00
|
|
|
for (size_t i = 0; i < logs_.size(); i++) {
|
2011-03-18 23:37:00 +01:00
|
|
|
std::string logname = LogFileName(dbname_, logs_[i]);
|
|
|
|
Status status = ConvertLogToTable(logs_[i]);
|
|
|
|
if (!status.ok()) {
|
2014-10-29 23:12:50 +01:00
|
|
|
Log(InfoLogLevel::WARN_LEVEL, options_.info_log,
|
2014-06-28 01:01:59 +02:00
|
|
|
"Log #%" PRIu64 ": ignoring conversion error: %s", logs_[i],
|
2011-03-18 23:37:00 +01:00
|
|
|
status.ToString().c_str());
|
|
|
|
}
|
|
|
|
ArchiveFile(logname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status ConvertLogToTable(uint64_t log) {
|
|
|
|
struct LogReporter : public log::Reader::Reporter {
|
|
|
|
Env* env;
|
2013-01-20 11:07:13 +01:00
|
|
|
std::shared_ptr<Logger> info_log;
|
2011-03-18 23:37:00 +01:00
|
|
|
uint64_t lognum;
|
2015-02-26 20:28:41 +01:00
|
|
|
virtual void Corruption(size_t bytes, const Status& s) override {
|
2011-03-18 23:37:00 +01:00
|
|
|
// We print error messages for corruption, but continue repairing.
|
2014-10-29 23:12:50 +01:00
|
|
|
Log(InfoLogLevel::ERROR_LEVEL, info_log,
|
|
|
|
"Log #%" PRIu64 ": dropping %d bytes; %s", lognum,
|
2014-06-28 01:01:59 +02:00
|
|
|
static_cast<int>(bytes), s.ToString().c_str());
|
2011-03-18 23:37:00 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Open the log file
|
|
|
|
std::string logname = LogFileName(dbname_, log);
|
2013-01-20 11:07:13 +01:00
|
|
|
unique_ptr<SequentialFile> lfile;
|
2014-09-05 01:18:36 +02:00
|
|
|
Status status = env_->NewSequentialFile(logname, &lfile, env_options_);
|
2011-03-18 23:37:00 +01:00
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
unique_ptr<SequentialFileReader> lfile_reader(
|
|
|
|
new SequentialFileReader(std::move(lfile)));
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// 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).
|
2015-10-08 19:06:16 +02:00
|
|
|
log::Reader reader(options_.info_log, std::move(lfile_reader), &reporter,
|
|
|
|
true /*enable checksum*/, 0 /*initial_offset*/, log);
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
// Read all the records and add to a memtable
|
|
|
|
std::string scratch;
|
|
|
|
Slice record;
|
|
|
|
WriteBatch batch;
|
2014-12-02 21:09:20 +01:00
|
|
|
WriteBuffer wb(options_.db_write_buffer_size);
|
2015-05-29 23:36:35 +02:00
|
|
|
MemTable* mem =
|
|
|
|
new MemTable(icmp_, ioptions_, MutableCFOptions(options_, ioptions_),
|
|
|
|
&wb, kMaxSequenceNumber);
|
2014-11-18 19:20:10 +01:00
|
|
|
auto cf_mems_default = new ColumnFamilyMemTablesDefault(mem);
|
2011-05-21 04:17:43 +02:00
|
|
|
mem->Ref();
|
2011-03-18 23:37:00 +01: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);
|
support for concurrent adds to memtable
Summary:
This diff adds support for concurrent adds to the skiplist memtable
implementations. Memory allocation is made thread-safe by the addition of
a spinlock, with small per-core buffers to avoid contention. Concurrent
memtable writes are made via an additional method and don't impose a
performance overhead on the non-concurrent case, so parallelism can be
selected on a per-batch basis.
Write thread synchronization is an increasing bottleneck for higher levels
of concurrency, so this diff adds --enable_write_thread_adaptive_yield
(default off). This feature causes threads joining a write batch
group to spin for a short time (default 100 usec) using sched_yield,
rather than going to sleep on a mutex. If the timing of the yield calls
indicates that another thread has actually run during the yield then
spinning is avoided. This option improves performance for concurrent
situations even without parallel adds, although it has the potential to
increase CPU usage (and the heuristic adaptation is not yet mature).
Parallel writes are not currently compatible with
inplace updates, update callbacks, or delete filtering.
Enable it with --allow_concurrent_memtable_write (and
--enable_write_thread_adaptive_yield). Parallel memtable writes
are performance neutral when there is no actual parallelism, and in
my experiments (SSD server-class Linux and varying contention and key
sizes for fillrandom) they are always a performance win when there is
more than one thread.
Statistics are updated earlier in the write path, dropping the number
of DB mutex acquisitions from 2 to 1 for almost all cases.
This diff was motivated and inspired by Yahoo's cLSM work. It is more
conservative than cLSM: RocksDB's write batch group leader role is
preserved (along with all of the existing flush and write throttling
logic) and concurrent writers are blocked until all memtable insertions
have completed and the sequence number has been advanced, to preserve
linearizability.
My test config is "db_bench -benchmarks=fillrandom -threads=$T
-batch_size=1 -memtablerep=skip_list -value_size=100 --num=1000000/$T
-level0_slowdown_writes_trigger=9999 -level0_stop_writes_trigger=9999
-disable_auto_compactions --max_write_buffer_number=8
-max_background_flushes=8 --disable_wal --write_buffer_size=160000000
--block_size=16384 --allow_concurrent_memtable_write" on a two-socket
Xeon E5-2660 @ 2.2Ghz with lots of memory and an SSD hard drive. With 1
thread I get ~440Kops/sec. Peak performance for 1 socket (numactl
-N1) is slightly more than 1Mops/sec, at 16 threads. Peak performance
across both sockets happens at 30 threads, and is ~900Kops/sec, although
with fewer threads there is less performance loss when the system has
background work.
Test Plan:
1. concurrent stress tests for InlineSkipList and DynamicBloom
2. make clean; make check
3. make clean; DISABLE_JEMALLOC=1 make valgrind_check; valgrind db_bench
4. make clean; COMPILE_WITH_TSAN=1 make all check; db_bench
5. make clean; COMPILE_WITH_ASAN=1 make all check; db_bench
6. make clean; OPT=-DROCKSDB_LITE make check
7. verify no perf regressions when disabled
Reviewers: igor, sdong
Reviewed By: sdong
Subscribers: MarkCallaghan, IslamAbdelRahman, anthony, yhchiang, rven, sdong, guyg8, kradhakrishnan, dhruba
Differential Revision: https://reviews.facebook.net/D50589
2015-08-15 01:59:07 +02:00
|
|
|
status = WriteBatchInternal::InsertInto(&batch, cf_mems_default, nullptr);
|
2011-03-18 23:37:00 +01:00
|
|
|
if (status.ok()) {
|
|
|
|
counter += WriteBatchInternal::Count(&batch);
|
|
|
|
} else {
|
2014-10-29 23:12:50 +01:00
|
|
|
Log(InfoLogLevel::WARN_LEVEL,
|
|
|
|
options_.info_log, "Log #%" PRIu64 ": ignoring %s", log,
|
2011-03-18 23:37:00 +01:00
|
|
|
status.ToString().c_str());
|
|
|
|
status = Status::OK(); // Keep going with rest of file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-22 04:36:45 +02:00
|
|
|
// Do not record a version edit for this conversion to a Table
|
2011-03-18 23:37:00 +01:00
|
|
|
// since ExtractMetaData() will also generate edits.
|
|
|
|
FileMetaData meta;
|
2014-07-02 18:54:20 +02:00
|
|
|
meta.fd = FileDescriptor(next_file_number_++, 0, 0);
|
2014-09-05 02:40:41 +02:00
|
|
|
{
|
|
|
|
ReadOptions ro;
|
|
|
|
ro.total_order_seek = true;
|
|
|
|
Arena arena;
|
|
|
|
ScopedArenaIterator iter(mem->NewIterator(ro, &arena));
|
2015-10-09 01:57:35 +02:00
|
|
|
status = BuildTable(
|
|
|
|
dbname_, env_, ioptions_, env_options_, table_cache_, iter.get(),
|
|
|
|
&meta, icmp_, &int_tbl_prop_collector_factories_,
|
|
|
|
TablePropertiesCollectorFactory::Context::kUnknownColumnFamily, {},
|
Use SST files for Transaction conflict detection
Summary:
Currently, transactions can fail even if there is no actual write conflict. This is due to relying on only the memtables to check for write-conflicts. Users have to tune memtable settings to try to avoid this, but it's hard to figure out exactly how to tune these settings.
With this diff, TransactionDB will use both memtables and SST files to determine if there are any write conflicts. This relies on the fact that BlockBasedTable stores sequence numbers for all writes that happen after any open snapshot. Also, D50295 is needed to prevent SingleDelete from disappearing writes (the TODOs in this test code will be fixed once the other diff is approved and merged).
Note that Optimistic transactions will still rely on tuning memtable settings as we do not want to read from SST while on the write thread. Also, memtable settings can still be used to reduce how often TransactionDB needs to read SST files.
Test Plan: unit tests, db bench
Reviewers: rven, yhchiang, kradhakrishnan, IslamAbdelRahman, sdong
Reviewed By: sdong
Subscribers: dhruba, leveldb, yoshinorim
Differential Revision: https://reviews.facebook.net/D50475
2015-10-16 01:37:15 +02:00
|
|
|
kMaxSequenceNumber, kNoCompression, CompressionOptions(), false,
|
|
|
|
nullptr);
|
2014-09-05 02:40:41 +02:00
|
|
|
}
|
2013-11-27 23:56:20 +01:00
|
|
|
delete mem->Unref();
|
2014-02-06 01:02:48 +01:00
|
|
|
delete cf_mems_default;
|
2013-03-01 03:04:58 +01:00
|
|
|
mem = nullptr;
|
2011-03-18 23:37:00 +01:00
|
|
|
if (status.ok()) {
|
2014-06-14 00:54:19 +02:00
|
|
|
if (meta.fd.GetFileSize() > 0) {
|
2014-07-02 18:54:20 +02:00
|
|
|
table_fds_.push_back(meta.fd);
|
2011-03-18 23:37:00 +01:00
|
|
|
}
|
|
|
|
}
|
2014-10-29 23:12:50 +01:00
|
|
|
Log(InfoLogLevel::INFO_LEVEL, options_.info_log,
|
|
|
|
"Log #%" PRIu64 ": %d ops saved to Table #%" PRIu64 " %s",
|
|
|
|
log, counter, meta.fd.GetNumber(), status.ToString().c_str());
|
2011-03-18 23:37:00 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtractMetaData() {
|
2014-07-02 18:54:20 +02:00
|
|
|
for (size_t i = 0; i < table_fds_.size(); i++) {
|
2011-03-18 23:37:00 +01:00
|
|
|
TableInfo t;
|
2014-07-02 18:54:20 +02:00
|
|
|
t.meta.fd = table_fds_[i];
|
2011-03-18 23:37:00 +01:00
|
|
|
Status status = ScanTable(&t);
|
|
|
|
if (!status.ok()) {
|
2014-07-02 18:54:20 +02:00
|
|
|
std::string fname = TableFileName(
|
|
|
|
options_.db_paths, t.meta.fd.GetNumber(), t.meta.fd.GetPathId());
|
2014-08-13 20:57:40 +02:00
|
|
|
char file_num_buf[kFormatFileNumberBufSize];
|
|
|
|
FormatFileNumber(t.meta.fd.GetNumber(), t.meta.fd.GetPathId(),
|
|
|
|
file_num_buf, sizeof(file_num_buf));
|
2014-10-29 23:12:50 +01:00
|
|
|
Log(InfoLogLevel::WARN_LEVEL, options_.info_log,
|
|
|
|
"Table #%s: ignoring %s", file_num_buf,
|
2014-07-02 18:54:20 +02:00
|
|
|
status.ToString().c_str());
|
2011-03-18 23:37:00 +01:00
|
|
|
ArchiveFile(fname);
|
|
|
|
} else {
|
|
|
|
tables_.push_back(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status ScanTable(TableInfo* t) {
|
2014-07-02 18:54:20 +02:00
|
|
|
std::string fname = TableFileName(options_.db_paths, t->meta.fd.GetNumber(),
|
|
|
|
t->meta.fd.GetPathId());
|
2011-03-18 23:37:00 +01:00
|
|
|
int counter = 0;
|
2014-07-02 18:54:20 +02:00
|
|
|
uint64_t file_size;
|
|
|
|
Status status = env_->GetFileSize(fname, &file_size);
|
|
|
|
t->meta.fd = FileDescriptor(t->meta.fd.GetNumber(), t->meta.fd.GetPathId(),
|
|
|
|
file_size);
|
2011-03-18 23:37:00 +01:00
|
|
|
if (status.ok()) {
|
2015-10-13 00:06:38 +02:00
|
|
|
InternalIterator* iter = table_cache_->NewIterator(
|
2014-09-05 01:18:36 +02:00
|
|
|
ReadOptions(), env_options_, icmp_, t->meta.fd);
|
2011-03-18 23:37:00 +01:00
|
|
|
bool empty = true;
|
|
|
|
ParsedInternalKey parsed;
|
2013-06-14 07:09:08 +02:00
|
|
|
t->min_sequence = 0;
|
2011-03-18 23:37:00 +01:00
|
|
|
t->max_sequence = 0;
|
|
|
|
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
|
|
|
Slice key = iter->key();
|
|
|
|
if (!ParseInternalKey(key, &parsed)) {
|
2014-10-29 23:12:50 +01:00
|
|
|
Log(InfoLogLevel::ERROR_LEVEL,
|
|
|
|
options_.info_log, "Table #%" PRIu64 ": unparsable key %s",
|
2014-06-28 01:01:59 +02:00
|
|
|
t->meta.fd.GetNumber(), EscapeString(key).c_str());
|
2011-03-18 23:37:00 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
counter++;
|
|
|
|
if (empty) {
|
|
|
|
empty = false;
|
|
|
|
t->meta.smallest.DecodeFrom(key);
|
|
|
|
}
|
|
|
|
t->meta.largest.DecodeFrom(key);
|
2013-06-14 07:09:08 +02:00
|
|
|
if (parsed.sequence < t->min_sequence) {
|
|
|
|
t->min_sequence = parsed.sequence;
|
|
|
|
}
|
2011-03-18 23:37:00 +01:00
|
|
|
if (parsed.sequence > t->max_sequence) {
|
|
|
|
t->max_sequence = parsed.sequence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!iter->status().ok()) {
|
|
|
|
status = iter->status();
|
|
|
|
}
|
|
|
|
delete iter;
|
|
|
|
}
|
2014-10-29 23:12:50 +01:00
|
|
|
Log(InfoLogLevel::INFO_LEVEL,
|
|
|
|
options_.info_log, "Table #%" PRIu64 ": %d entries %s",
|
2014-06-28 01:01:59 +02:00
|
|
|
t->meta.fd.GetNumber(), counter, status.ToString().c_str());
|
2011-03-18 23:37:00 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status WriteDescriptor() {
|
|
|
|
std::string tmp = TempFileName(dbname_, 1);
|
2013-01-20 11:07:13 +01:00
|
|
|
unique_ptr<WritableFile> file;
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
EnvOptions env_options = env_->OptimizeForManifestWrite(env_options_);
|
|
|
|
Status status = env_->NewWritableFile(tmp, &file, env_options);
|
2011-03-18 23:37:00 +01:00
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
SequenceNumber max_sequence = 0;
|
2011-04-21 00:48:11 +02:00
|
|
|
for (size_t i = 0; i < tables_.size(); i++) {
|
2011-03-18 23:37:00 +01:00
|
|
|
if (max_sequence < tables_[i].max_sequence) {
|
|
|
|
max_sequence = tables_[i].max_sequence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-23 04:30:03 +02:00
|
|
|
edit_->SetComparatorName(icmp_.user_comparator()->Name());
|
|
|
|
edit_->SetLogNumber(0);
|
|
|
|
edit_->SetNextFile(next_file_number_);
|
|
|
|
edit_->SetLastSequence(max_sequence);
|
2011-03-18 23:37:00 +01:00
|
|
|
|
2011-04-21 00:48:11 +02:00
|
|
|
for (size_t i = 0; i < tables_.size(); i++) {
|
2011-03-18 23:37:00 +01:00
|
|
|
// TODO(opt): separate out into multiple levels
|
|
|
|
const TableInfo& t = tables_[i];
|
2014-07-02 18:54:20 +02:00
|
|
|
edit_->AddFile(0, t.meta.fd.GetNumber(), t.meta.fd.GetPathId(),
|
|
|
|
t.meta.fd.GetFileSize(), t.meta.smallest, t.meta.largest,
|
2015-06-04 21:03:40 +02:00
|
|
|
t.min_sequence, t.max_sequence,
|
|
|
|
t.meta.marked_for_compaction);
|
2011-03-18 23:37:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//fprintf(stderr, "NewDescriptor:\n%s\n", edit_.DebugString().c_str());
|
|
|
|
{
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-18 01:16:11 +02:00
|
|
|
unique_ptr<WritableFileWriter> file_writer(
|
|
|
|
new WritableFileWriter(std::move(file), env_options));
|
2015-10-08 19:07:15 +02:00
|
|
|
log::Writer log(std::move(file_writer), 0, false);
|
2011-03-18 23:37:00 +01:00
|
|
|
std::string record;
|
2012-06-23 04:30:03 +02:00
|
|
|
edit_->EncodeTo(&record);
|
2011-03-18 23:37:00 +01:00
|
|
|
status = log.AddRecord(record);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!status.ok()) {
|
|
|
|
env_->DeleteFile(tmp);
|
|
|
|
} else {
|
|
|
|
// Discard older manifests
|
2011-04-21 00:48:11 +02:00
|
|
|
for (size_t i = 0; i < manifests_.size(); i++) {
|
2011-03-18 23:37:00 +01:00
|
|
|
ArchiveFile(dbname_ + "/" + manifests_[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Install new manifest
|
|
|
|
status = env_->RenameFile(tmp, DescriptorFileName(dbname_, 1));
|
|
|
|
if (status.ok()) {
|
2014-05-06 23:51:33 +02:00
|
|
|
status = SetCurrentFile(env_, dbname_, 1, nullptr);
|
2011-03-18 23:37:00 +01:00
|
|
|
} 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 03:04:58 +01:00
|
|
|
if (slash != nullptr) {
|
2011-03-18 23:37:00 +01: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 03:04:58 +01:00
|
|
|
new_file.append((slash == nullptr) ? fname.c_str() : slash + 1);
|
2011-03-18 23:37:00 +01:00
|
|
|
Status s = env_->RenameFile(fname, new_file);
|
2014-10-29 23:12:50 +01:00
|
|
|
Log(InfoLogLevel::INFO_LEVEL,
|
|
|
|
options_.info_log, "Archiving %s: %s\n",
|
2011-03-18 23:37:00 +01:00
|
|
|
fname.c_str(), s.ToString().c_str());
|
|
|
|
}
|
|
|
|
};
|
2011-10-31 18:22:06 +01:00
|
|
|
} // namespace
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
Status RepairDB(const std::string& dbname, const Options& options) {
|
|
|
|
Repairer repairer(dbname, options);
|
|
|
|
return repairer.Run();
|
|
|
|
}
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
} // namespace rocksdb
|
2014-04-15 22:39:26 +02:00
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|