2013-12-05 22:09:13 +01: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.
|
|
|
|
#include "table/meta_blocks.h"
|
|
|
|
|
|
|
|
#include <map>
|
2014-02-05 01:21:47 +01:00
|
|
|
#include <string>
|
2013-12-05 22:09:13 +01:00
|
|
|
|
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
|
|
|
#include "db/table_properties_collector.h"
|
2014-01-28 06:58:46 +01:00
|
|
|
#include "rocksdb/table.h"
|
2014-02-05 01:21:47 +01:00
|
|
|
#include "rocksdb/table_properties.h"
|
2015-09-02 22:58:22 +02:00
|
|
|
#include "table/block.h"
|
2013-12-05 22:09:13 +01:00
|
|
|
#include "table/format.h"
|
2015-10-13 00:06:38 +02:00
|
|
|
#include "table/internal_iterator.h"
|
2014-11-13 20:39:30 +01:00
|
|
|
#include "table/table_properties_internal.h"
|
2013-12-05 22:09:13 +01:00
|
|
|
#include "util/coding.h"
|
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
MetaIndexBuilder::MetaIndexBuilder()
|
2014-09-02 20:49:38 +02:00
|
|
|
: meta_index_block_(new BlockBuilder(1 /* restart interval */)) {}
|
2013-12-05 22:09:13 +01:00
|
|
|
|
|
|
|
void MetaIndexBuilder::Add(const std::string& key,
|
|
|
|
const BlockHandle& handle) {
|
|
|
|
std::string handle_encoding;
|
|
|
|
handle.EncodeTo(&handle_encoding);
|
|
|
|
meta_block_handles_.insert({key, handle_encoding});
|
|
|
|
}
|
|
|
|
|
|
|
|
Slice MetaIndexBuilder::Finish() {
|
|
|
|
for (const auto& metablock : meta_block_handles_) {
|
|
|
|
meta_index_block_->Add(metablock.first, metablock.second);
|
|
|
|
}
|
|
|
|
return meta_index_block_->Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyBlockBuilder::PropertyBlockBuilder()
|
2014-09-02 20:49:38 +02:00
|
|
|
: properties_block_(new BlockBuilder(1 /* restart interval */)) {}
|
2013-12-05 22:09:13 +01:00
|
|
|
|
|
|
|
void PropertyBlockBuilder::Add(const std::string& name,
|
|
|
|
const std::string& val) {
|
|
|
|
props_.insert({name, val});
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertyBlockBuilder::Add(const std::string& name, uint64_t val) {
|
|
|
|
assert(props_.find(name) == props_.end());
|
|
|
|
|
|
|
|
std::string dst;
|
|
|
|
PutVarint64(&dst, val);
|
|
|
|
|
|
|
|
Add(name, dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertyBlockBuilder::Add(
|
|
|
|
const UserCollectedProperties& user_collected_properties) {
|
|
|
|
for (const auto& prop : user_collected_properties) {
|
|
|
|
Add(prop.first, prop.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertyBlockBuilder::AddTableProperty(const TableProperties& props) {
|
|
|
|
Add(TablePropertiesNames::kRawKeySize, props.raw_key_size);
|
|
|
|
Add(TablePropertiesNames::kRawValueSize, props.raw_value_size);
|
|
|
|
Add(TablePropertiesNames::kDataSize, props.data_size);
|
|
|
|
Add(TablePropertiesNames::kIndexSize, props.index_size);
|
|
|
|
Add(TablePropertiesNames::kNumEntries, props.num_entries);
|
|
|
|
Add(TablePropertiesNames::kNumDataBlocks, props.num_data_blocks);
|
|
|
|
Add(TablePropertiesNames::kFilterSize, props.filter_size);
|
2013-12-20 18:35:24 +01:00
|
|
|
Add(TablePropertiesNames::kFormatVersion, props.format_version);
|
|
|
|
Add(TablePropertiesNames::kFixedKeyLen, props.fixed_key_len);
|
2013-12-05 22:09:13 +01:00
|
|
|
|
|
|
|
if (!props.filter_policy_name.empty()) {
|
2015-11-07 01:49:38 +01:00
|
|
|
Add(TablePropertiesNames::kFilterPolicy,
|
|
|
|
props.filter_policy_name);
|
2013-12-05 22:09:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Slice PropertyBlockBuilder::Finish() {
|
|
|
|
for (const auto& prop : props_) {
|
|
|
|
properties_block_->Add(prop.first, prop.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties_block_->Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPropertiesCollectionError(
|
|
|
|
Logger* info_log, const std::string& method, const std::string& name) {
|
|
|
|
assert(method == "Add" || method == "Finish");
|
|
|
|
|
|
|
|
std::string msg =
|
2014-10-30 01:55:19 +01:00
|
|
|
"Encountered error when calling TablePropertiesCollector::" +
|
2013-12-05 22:09:13 +01:00
|
|
|
method + "() with collector name: " + name;
|
2014-10-30 01:55:19 +01:00
|
|
|
Log(InfoLogLevel::ERROR_LEVEL, info_log, "%s", msg.c_str());
|
2013-12-05 22:09:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NotifyCollectTableCollectorsOnAdd(
|
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
|
|
|
const Slice& key, const Slice& value, uint64_t file_size,
|
|
|
|
const std::vector<std::unique_ptr<IntTblPropCollector>>& collectors,
|
2013-12-05 22:09:13 +01:00
|
|
|
Logger* info_log) {
|
|
|
|
bool all_succeeded = true;
|
TablePropertiesCollectorFactory
Summary:
This diff addresses task #4296714 and rethinks how users provide us with TablePropertiesCollectors as part of Options.
Here's description of task #4296714:
I'm debugging #4295529 and noticed that our count of user properties kDeletedKeys is wrong. We're sharing one single InternalKeyPropertiesCollector with all Table Builders. In LOG Files, we're outputting number of kDeletedKeys as connected with a single table, while it's actually the total count of deleted keys since creation of the DB.
For example, this table has 3155 entries and 1391828 deleted keys.
The problem with current approach that we call methods on a single TablePropertiesCollector for all the tables we create. Even worse, we could do it from multiple threads at the same time and TablePropertiesCollector has no way of knowing which table we're calling it for.
Good part: Looks like nobody inside Facebook is using Options::table_properties_collectors. This means we should be able to painfully change the API.
In this change, I introduce TablePropertiesCollectorFactory. For every table we create, we call `CreateTablePropertiesCollector`, which creates a TablePropertiesCollector for a single table. We then use it sequentially from a single thread, which means it doesn't have to be thread-safe.
Test Plan:
Added a test in table_properties_collector_test that fails on master (build two tables, assert that kDeletedKeys count is correct for the second one).
Also, all other tests
Reviewers: sdong, dhruba, haobo, kailiu
Reviewed By: kailiu
CC: leveldb
Differential Revision: https://reviews.facebook.net/D18579
2014-05-13 21:30:55 +02:00
|
|
|
for (auto& collector : collectors) {
|
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
|
|
|
Status s = collector->InternalAdd(key, value, file_size);
|
2013-12-05 22:09:13 +01:00
|
|
|
all_succeeded = all_succeeded && s.ok();
|
|
|
|
if (!s.ok()) {
|
2014-02-05 01:21:47 +01:00
|
|
|
LogPropertiesCollectionError(info_log, "Add" /* method */,
|
|
|
|
collector->Name());
|
2013-12-05 22:09:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return all_succeeded;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NotifyCollectTableCollectorsOnFinish(
|
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
|
|
|
const std::vector<std::unique_ptr<IntTblPropCollector>>& collectors,
|
TablePropertiesCollectorFactory
Summary:
This diff addresses task #4296714 and rethinks how users provide us with TablePropertiesCollectors as part of Options.
Here's description of task #4296714:
I'm debugging #4295529 and noticed that our count of user properties kDeletedKeys is wrong. We're sharing one single InternalKeyPropertiesCollector with all Table Builders. In LOG Files, we're outputting number of kDeletedKeys as connected with a single table, while it's actually the total count of deleted keys since creation of the DB.
For example, this table has 3155 entries and 1391828 deleted keys.
The problem with current approach that we call methods on a single TablePropertiesCollector for all the tables we create. Even worse, we could do it from multiple threads at the same time and TablePropertiesCollector has no way of knowing which table we're calling it for.
Good part: Looks like nobody inside Facebook is using Options::table_properties_collectors. This means we should be able to painfully change the API.
In this change, I introduce TablePropertiesCollectorFactory. For every table we create, we call `CreateTablePropertiesCollector`, which creates a TablePropertiesCollector for a single table. We then use it sequentially from a single thread, which means it doesn't have to be thread-safe.
Test Plan:
Added a test in table_properties_collector_test that fails on master (build two tables, assert that kDeletedKeys count is correct for the second one).
Also, all other tests
Reviewers: sdong, dhruba, haobo, kailiu
Reviewed By: kailiu
CC: leveldb
Differential Revision: https://reviews.facebook.net/D18579
2014-05-13 21:30:55 +02:00
|
|
|
Logger* info_log, PropertyBlockBuilder* builder) {
|
2013-12-05 22:09:13 +01:00
|
|
|
bool all_succeeded = true;
|
TablePropertiesCollectorFactory
Summary:
This diff addresses task #4296714 and rethinks how users provide us with TablePropertiesCollectors as part of Options.
Here's description of task #4296714:
I'm debugging #4295529 and noticed that our count of user properties kDeletedKeys is wrong. We're sharing one single InternalKeyPropertiesCollector with all Table Builders. In LOG Files, we're outputting number of kDeletedKeys as connected with a single table, while it's actually the total count of deleted keys since creation of the DB.
For example, this table has 3155 entries and 1391828 deleted keys.
The problem with current approach that we call methods on a single TablePropertiesCollector for all the tables we create. Even worse, we could do it from multiple threads at the same time and TablePropertiesCollector has no way of knowing which table we're calling it for.
Good part: Looks like nobody inside Facebook is using Options::table_properties_collectors. This means we should be able to painfully change the API.
In this change, I introduce TablePropertiesCollectorFactory. For every table we create, we call `CreateTablePropertiesCollector`, which creates a TablePropertiesCollector for a single table. We then use it sequentially from a single thread, which means it doesn't have to be thread-safe.
Test Plan:
Added a test in table_properties_collector_test that fails on master (build two tables, assert that kDeletedKeys count is correct for the second one).
Also, all other tests
Reviewers: sdong, dhruba, haobo, kailiu
Reviewed By: kailiu
CC: leveldb
Differential Revision: https://reviews.facebook.net/D18579
2014-05-13 21:30:55 +02:00
|
|
|
for (auto& collector : collectors) {
|
2013-12-05 22:09:13 +01:00
|
|
|
UserCollectedProperties user_collected_properties;
|
|
|
|
Status s = collector->Finish(&user_collected_properties);
|
|
|
|
|
|
|
|
all_succeeded = all_succeeded && s.ok();
|
|
|
|
if (!s.ok()) {
|
2014-02-05 01:21:47 +01:00
|
|
|
LogPropertiesCollectionError(info_log, "Finish" /* method */,
|
|
|
|
collector->Name());
|
2013-12-05 22:09:13 +01:00
|
|
|
} else {
|
|
|
|
builder->Add(user_collected_properties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return all_succeeded;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
Status ReadProperties(const Slice& handle_value, RandomAccessFileReader* file,
|
|
|
|
const Footer& footer, Env* env, Logger* logger,
|
|
|
|
TableProperties** table_properties) {
|
2013-12-06 01:51:26 +01:00
|
|
|
assert(table_properties);
|
|
|
|
|
|
|
|
Slice v = handle_value;
|
|
|
|
BlockHandle handle;
|
|
|
|
if (!handle.DecodeFrom(&v).ok()) {
|
|
|
|
return Status::InvalidArgument("Failed to decode properties block handle");
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockContents block_contents;
|
2014-02-06 05:56:14 +01:00
|
|
|
ReadOptions read_options;
|
|
|
|
read_options.verify_checksums = false;
|
2014-08-16 00:05:09 +02:00
|
|
|
Status s;
|
|
|
|
s = ReadBlockContents(file, footer, read_options, handle, &block_contents,
|
|
|
|
env, false);
|
2013-12-06 01:51:26 +01:00
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-08-16 00:05:09 +02:00
|
|
|
Block properties_block(std::move(block_contents));
|
2015-10-13 00:06:38 +02:00
|
|
|
std::unique_ptr<InternalIterator> iter(
|
2014-02-05 01:21:47 +01:00
|
|
|
properties_block.NewIterator(BytewiseComparator()));
|
2013-12-06 01:51:26 +01:00
|
|
|
|
2014-02-08 04:26:49 +01:00
|
|
|
auto new_table_properties = new TableProperties();
|
2013-12-06 01:51:26 +01:00
|
|
|
// All pre-defined properties of type uint64_t
|
|
|
|
std::unordered_map<std::string, uint64_t*> predefined_uint64_properties = {
|
2014-02-08 04:26:49 +01:00
|
|
|
{TablePropertiesNames::kDataSize, &new_table_properties->data_size},
|
|
|
|
{TablePropertiesNames::kIndexSize, &new_table_properties->index_size},
|
|
|
|
{TablePropertiesNames::kFilterSize, &new_table_properties->filter_size},
|
|
|
|
{TablePropertiesNames::kRawKeySize, &new_table_properties->raw_key_size},
|
|
|
|
{TablePropertiesNames::kRawValueSize,
|
|
|
|
&new_table_properties->raw_value_size},
|
2014-02-05 01:21:47 +01:00
|
|
|
{TablePropertiesNames::kNumDataBlocks,
|
2014-02-08 04:26:49 +01:00
|
|
|
&new_table_properties->num_data_blocks},
|
|
|
|
{TablePropertiesNames::kNumEntries, &new_table_properties->num_entries},
|
|
|
|
{TablePropertiesNames::kFormatVersion,
|
|
|
|
&new_table_properties->format_version},
|
|
|
|
{TablePropertiesNames::kFixedKeyLen,
|
|
|
|
&new_table_properties->fixed_key_len}, };
|
2013-12-06 01:51:26 +01:00
|
|
|
|
|
|
|
std::string last_key;
|
|
|
|
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
|
|
|
|
s = iter->status();
|
|
|
|
if (!s.ok()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto key = iter->key().ToString();
|
|
|
|
// properties block is strictly sorted with no duplicate key.
|
2014-02-05 01:21:47 +01:00
|
|
|
assert(last_key.empty() ||
|
|
|
|
BytewiseComparator()->Compare(key, last_key) > 0);
|
2013-12-06 01:51:26 +01:00
|
|
|
last_key = key;
|
|
|
|
|
|
|
|
auto raw_val = iter->value();
|
|
|
|
auto pos = predefined_uint64_properties.find(key);
|
|
|
|
|
|
|
|
if (pos != predefined_uint64_properties.end()) {
|
|
|
|
// handle predefined rocksdb properties
|
|
|
|
uint64_t val;
|
|
|
|
if (!GetVarint64(&raw_val, &val)) {
|
|
|
|
// skip malformed value
|
|
|
|
auto error_msg =
|
2014-10-30 01:55:19 +01:00
|
|
|
"Detect malformed value in properties meta-block:"
|
2013-12-06 01:51:26 +01:00
|
|
|
"\tkey: " + key + "\tval: " + raw_val.ToString();
|
2014-10-30 01:55:19 +01:00
|
|
|
Log(InfoLogLevel::ERROR_LEVEL, logger, "%s", error_msg.c_str());
|
2013-12-06 01:51:26 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*(pos->second) = val;
|
|
|
|
} else if (key == TablePropertiesNames::kFilterPolicy) {
|
2014-02-08 04:26:49 +01:00
|
|
|
new_table_properties->filter_policy_name = raw_val.ToString();
|
2013-12-06 01:51:26 +01:00
|
|
|
} else {
|
|
|
|
// handle user-collected properties
|
2014-02-08 04:26:49 +01:00
|
|
|
new_table_properties->user_collected_properties.insert(
|
2014-02-05 01:21:47 +01:00
|
|
|
{key, raw_val.ToString()});
|
2013-12-06 01:51:26 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-08 04:26:49 +01:00
|
|
|
if (s.ok()) {
|
|
|
|
*table_properties = new_table_properties;
|
|
|
|
} else {
|
|
|
|
delete new_table_properties;
|
|
|
|
}
|
2013-12-06 01:51:26 +01:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
Status ReadTableProperties(RandomAccessFileReader* file, uint64_t file_size,
|
2014-02-08 04:26:49 +01:00
|
|
|
uint64_t table_magic_number, Env* env,
|
|
|
|
Logger* info_log, TableProperties** properties) {
|
2013-12-06 01:51:26 +01:00
|
|
|
// -- Read metaindex block
|
2015-01-13 23:33:04 +01:00
|
|
|
Footer footer;
|
|
|
|
auto s = ReadFooterFromFile(file, file_size, &footer, table_magic_number);
|
2013-12-06 01:51:26 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto metaindex_handle = footer.metaindex_handle();
|
|
|
|
BlockContents metaindex_contents;
|
2014-02-06 05:56:14 +01:00
|
|
|
ReadOptions read_options;
|
|
|
|
read_options.verify_checksums = false;
|
2014-09-18 00:08:19 +02:00
|
|
|
s = ReadBlockContents(file, footer, read_options, metaindex_handle,
|
|
|
|
&metaindex_contents, env, false);
|
2013-12-06 01:51:26 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
2014-08-16 00:05:09 +02:00
|
|
|
Block metaindex_block(std::move(metaindex_contents));
|
2015-10-13 00:06:38 +02:00
|
|
|
std::unique_ptr<InternalIterator> meta_iter(
|
2014-02-05 01:21:47 +01:00
|
|
|
metaindex_block.NewIterator(BytewiseComparator()));
|
2013-12-06 01:51:26 +01:00
|
|
|
|
|
|
|
// -- Read property block
|
2014-04-22 02:49:47 +02:00
|
|
|
bool found_properties_block = true;
|
|
|
|
s = SeekToPropertiesBlock(meta_iter.get(), &found_properties_block);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-12-06 01:51:26 +01:00
|
|
|
TableProperties table_properties;
|
2014-04-22 02:49:47 +02:00
|
|
|
if (found_properties_block == true) {
|
2014-05-01 20:09:32 +02:00
|
|
|
s = ReadProperties(meta_iter->value(), file, footer, env, info_log,
|
|
|
|
properties);
|
2013-12-06 01:51:26 +01:00
|
|
|
} else {
|
2014-08-15 21:17:44 +02:00
|
|
|
s = Status::NotFound();
|
2013-12-06 01:51:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-10-13 00:06:38 +02:00
|
|
|
Status FindMetaBlock(InternalIterator* meta_index_iter,
|
2014-05-15 23:09:03 +02:00
|
|
|
const std::string& meta_block_name,
|
|
|
|
BlockHandle* block_handle) {
|
|
|
|
meta_index_iter->Seek(meta_block_name);
|
|
|
|
if (meta_index_iter->status().ok() && meta_index_iter->Valid() &&
|
|
|
|
meta_index_iter->key() == meta_block_name) {
|
|
|
|
Slice v = meta_index_iter->value();
|
|
|
|
return block_handle->DecodeFrom(&v);
|
|
|
|
} else {
|
|
|
|
return Status::Corruption("Cannot find the meta block", meta_block_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
Status FindMetaBlock(RandomAccessFileReader* file, uint64_t file_size,
|
2014-07-19 01:58:13 +02:00
|
|
|
uint64_t table_magic_number, Env* env,
|
|
|
|
const std::string& meta_block_name,
|
|
|
|
BlockHandle* block_handle) {
|
2015-01-13 23:33:04 +01:00
|
|
|
Footer footer;
|
|
|
|
auto s = ReadFooterFromFile(file, file_size, &footer, table_magic_number);
|
2014-07-19 01:58:13 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto metaindex_handle = footer.metaindex_handle();
|
|
|
|
BlockContents metaindex_contents;
|
|
|
|
ReadOptions read_options;
|
|
|
|
read_options.verify_checksums = false;
|
|
|
|
s = ReadBlockContents(file, footer, read_options, metaindex_handle,
|
|
|
|
&metaindex_contents, env, false);
|
|
|
|
if (!s.ok()) {
|
|
|
|
return s;
|
|
|
|
}
|
2014-08-16 00:05:09 +02:00
|
|
|
Block metaindex_block(std::move(metaindex_contents));
|
2014-07-19 01:58:13 +02:00
|
|
|
|
2015-10-13 00:06:38 +02:00
|
|
|
std::unique_ptr<InternalIterator> meta_iter;
|
2014-07-19 01:58:13 +02:00
|
|
|
meta_iter.reset(metaindex_block.NewIterator(BytewiseComparator()));
|
|
|
|
|
|
|
|
return FindMetaBlock(meta_iter.get(), meta_block_name, block_handle);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
Status ReadMetaBlock(RandomAccessFileReader* file, uint64_t file_size,
|
2014-07-19 01:58:13 +02:00
|
|
|
uint64_t table_magic_number, Env* env,
|
|
|
|
const std::string& meta_block_name,
|
|
|
|
BlockContents* contents) {
|
2014-08-16 00:05:09 +02:00
|
|
|
Status status;
|
2015-01-13 23:33:04 +01:00
|
|
|
Footer footer;
|
|
|
|
status = ReadFooterFromFile(file, file_size, &footer, table_magic_number);
|
2014-09-18 00:08:19 +02:00
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
2014-07-19 01:58:13 +02:00
|
|
|
|
|
|
|
// Reading metaindex block
|
|
|
|
auto metaindex_handle = footer.metaindex_handle();
|
|
|
|
BlockContents metaindex_contents;
|
|
|
|
ReadOptions read_options;
|
|
|
|
read_options.verify_checksums = false;
|
2014-08-16 00:05:09 +02:00
|
|
|
status = ReadBlockContents(file, footer, read_options, metaindex_handle,
|
|
|
|
&metaindex_contents, env, false);
|
2014-09-18 00:08:19 +02:00
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
|
|
|
}
|
2014-07-19 01:58:13 +02:00
|
|
|
|
|
|
|
// Finding metablock
|
2014-08-16 00:05:09 +02:00
|
|
|
Block metaindex_block(std::move(metaindex_contents));
|
2014-07-19 01:58:13 +02:00
|
|
|
|
2015-10-13 00:06:38 +02:00
|
|
|
std::unique_ptr<InternalIterator> meta_iter;
|
2014-07-19 01:58:13 +02:00
|
|
|
meta_iter.reset(metaindex_block.NewIterator(BytewiseComparator()));
|
|
|
|
|
|
|
|
BlockHandle block_handle;
|
2014-08-16 00:05:09 +02:00
|
|
|
status = FindMetaBlock(meta_iter.get(), meta_block_name, &block_handle);
|
2014-07-19 01:58:13 +02:00
|
|
|
|
2014-08-16 00:05:09 +02:00
|
|
|
if (!status.ok()) {
|
|
|
|
return status;
|
2014-07-19 01:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reading metablock
|
2014-08-16 00:05:09 +02:00
|
|
|
return ReadBlockContents(file, footer, read_options, block_handle, contents,
|
|
|
|
env, false);
|
2014-07-19 01:58:13 +02:00
|
|
|
}
|
|
|
|
|
2013-12-05 22:09:13 +01:00
|
|
|
} // namespace rocksdb
|