Merge pull request #63 from mingnus/v0.7-devel-fix

Minor fixes for new dev-tools
This commit is contained in:
Joe Thornber 2016-05-23 09:15:56 +01:00
commit 39c6f3d6ea
5 changed files with 29 additions and 27 deletions

View File

@ -6,11 +6,11 @@ using persistent_data::btree_detail::btree_node_checker;
//---------------------------------------------------------------- //----------------------------------------------------------------
btree_node_checker::error_type btree_node_checker::get_last_error() { btree_node_checker::error_type btree_node_checker::get_last_error() const {
return last_error_; return last_error_;
} }
std::string btree_node_checker::get_last_error_string() { std::string btree_node_checker::get_last_error_string() const {
switch (last_error_) { switch (last_error_) {
case BLOCK_NR_MISMATCH: case BLOCK_NR_MISMATCH:
return block_nr_mismatch_string(); return block_nr_mismatch_string();
@ -39,7 +39,7 @@ void btree_node_checker::reset() {
last_error_ = NO_ERROR; last_error_ = NO_ERROR;
} }
std::string btree_node_checker::block_nr_mismatch_string() { std::string btree_node_checker::block_nr_mismatch_string() const {
std::ostringstream out; std::ostringstream out;
out << "block number mismatch: actually " out << "block number mismatch: actually "
<< error_location_ << error_location_
@ -48,7 +48,7 @@ std::string btree_node_checker::block_nr_mismatch_string() {
return out.str(); return out.str();
} }
std::string btree_node_checker::value_sizes_mismatch_string() { std::string btree_node_checker::value_sizes_mismatch_string() const {
std::ostringstream out; std::ostringstream out;
out << "value size mismatch: expected " << error_value_sizes_[1] out << "value size mismatch: expected " << error_value_sizes_[1]
<< ", but got " << error_value_sizes_[0] << ", but got " << error_value_sizes_[0]
@ -58,7 +58,7 @@ std::string btree_node_checker::value_sizes_mismatch_string() {
return out.str(); return out.str();
} }
std::string btree_node_checker::max_entries_too_large_string() { std::string btree_node_checker::max_entries_too_large_string() const {
std::ostringstream out; std::ostringstream out;
out << "max entries too large: " << error_max_entries_ out << "max entries too large: " << error_max_entries_
<< " (block " << error_location_ << ")"; << " (block " << error_location_ << ")";
@ -66,7 +66,7 @@ std::string btree_node_checker::max_entries_too_large_string() {
return out.str(); return out.str();
} }
std::string btree_node_checker::max_entries_not_divisible_string() { std::string btree_node_checker::max_entries_not_divisible_string() const {
std::ostringstream out; std::ostringstream out;
out << "max entries is not divisible by 3: " << error_max_entries_ out << "max entries is not divisible by 3: " << error_max_entries_
<< " (block " << error_location_ << ")"; << " (block " << error_location_ << ")";
@ -74,7 +74,7 @@ std::string btree_node_checker::max_entries_not_divisible_string() {
return out.str(); return out.str();
} }
std::string btree_node_checker::nr_entries_too_large_string() { std::string btree_node_checker::nr_entries_too_large_string() const {
std::ostringstream out; std::ostringstream out;
out << "bad nr_entries: " out << "bad nr_entries: "
<< error_nr_entries_ << " < " << error_nr_entries_ << " < "
@ -84,7 +84,7 @@ std::string btree_node_checker::nr_entries_too_large_string() {
return out.str(); return out.str();
} }
std::string btree_node_checker::nr_entries_too_small_string() { std::string btree_node_checker::nr_entries_too_small_string() const {
std::ostringstream out; std::ostringstream out;
out << "too few entries in btree_node: " out << "too few entries in btree_node: "
<< error_nr_entries_ << error_nr_entries_
@ -96,7 +96,7 @@ std::string btree_node_checker::nr_entries_too_small_string() {
return out.str(); return out.str();
} }
std::string btree_node_checker::keys_out_of_order_string() { std::string btree_node_checker::keys_out_of_order_string() const {
std::ostringstream out; std::ostringstream out;
out << "keys are out of order, " out << "keys are out of order, "
<< error_keys_[0] << " <= " << error_keys_[1] << error_keys_[0] << " <= " << error_keys_[1]
@ -105,7 +105,7 @@ std::string btree_node_checker::keys_out_of_order_string() {
return out.str(); return out.str();
} }
std::string btree_node_checker::parent_key_mismatch_string() { std::string btree_node_checker::parent_key_mismatch_string() const {
std::ostringstream out; std::ostringstream out;
out << "parent key mismatch: parent was " << error_keys_[1] out << "parent key mismatch: parent was " << error_keys_[1]
<< ", but lowest in node was " << error_keys_[0] << ", but lowest in node was " << error_keys_[0]
@ -114,7 +114,7 @@ std::string btree_node_checker::parent_key_mismatch_string() {
return out.str(); return out.str();
} }
std::string btree_node_checker::leaf_key_overlapped_string() { std::string btree_node_checker::leaf_key_overlapped_string() const {
std::ostringstream out; std::ostringstream out;
out << "the last key of the previous leaf was " << error_keys_[1] out << "the last key of the previous leaf was " << error_keys_[1]
<< " and the first key of this leaf is " << error_keys_[0] << " and the first key of this leaf is " << error_keys_[0]

View File

@ -41,6 +41,8 @@ namespace persistent_data {
error_keys_{0, 0} { error_keys_{0, 0} {
} }
virtual ~btree_node_checker() {}
template <typename ValueTraits> template <typename ValueTraits>
bool check_block_nr(btree_detail::node_ref<ValueTraits> const &n) { bool check_block_nr(btree_detail::node_ref<ValueTraits> const &n) {
if (n.get_location() != n.get_block_nr()) { if (n.get_location() != n.get_block_nr()) {
@ -175,20 +177,20 @@ namespace persistent_data {
return true; return true;
} }
error_type get_last_error(); error_type get_last_error() const;
std::string get_last_error_string(); std::string get_last_error_string() const;
void reset(); void reset();
private: private:
std::string block_nr_mismatch_string(); std::string block_nr_mismatch_string() const;
std::string value_sizes_mismatch_string(); std::string value_sizes_mismatch_string() const;
std::string max_entries_too_large_string(); std::string max_entries_too_large_string() const;
std::string max_entries_not_divisible_string(); std::string max_entries_not_divisible_string() const;
std::string nr_entries_too_large_string(); std::string nr_entries_too_large_string() const;
std::string nr_entries_too_small_string(); std::string nr_entries_too_small_string() const;
std::string keys_out_of_order_string(); std::string keys_out_of_order_string() const;
std::string parent_key_mismatch_string(); std::string parent_key_mismatch_string() const;
std::string leaf_key_overlapped_string(); std::string leaf_key_overlapped_string() const;
error_type last_error_; error_type last_error_;
block_address error_location_; block_address error_location_;

View File

@ -330,7 +330,7 @@ thin_ll_dump_cmd::run(int argc, char **argv)
boost::optional<string> output; boost::optional<string> output;
flags f; flags f;
char c; int c;
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch(c) { switch(c) {
case 'h': case 'h':

View File

@ -87,7 +87,7 @@ namespace {
device_tree_detail::device_details details; device_tree_detail::device_details details;
device_tree::ptr details_tree; device_tree::ptr details_tree;
boost::optional<uint32_t> details_root = get_opt_attr<uint32_t>(attr, "blocknr"); boost::optional<uint64_t> details_root = get_opt_attr<uint64_t>(attr, "blocknr");
if (details_root) if (details_root)
details_tree = device_tree::ptr(new device_tree(*md->tm_, *details_root, details_tree = device_tree::ptr(new device_tree(*md->tm_, *details_root,
device_tree_detail::device_details_traits::ref_counter())); device_tree_detail::device_details_traits::ref_counter()));
@ -112,7 +112,7 @@ namespace {
} }
void parse_node(metadata::ptr md, emitter::ptr e, attributes const &attr) { void parse_node(metadata::ptr md, emitter::ptr e, attributes const &attr) {
metadata_dump_subtree(md, e, true, get_attr<uint32_t>(attr, "blocknr")); metadata_dump_subtree(md, e, true, get_attr<uint64_t>(attr, "blocknr"));
} }
void start_tag(void *data, char const *el, char const **attr) { void start_tag(void *data, char const *el, char const **attr) {
@ -216,7 +216,7 @@ thin_ll_restore_cmd::run(int argc, char **argv) {
string output; string output;
string input_metadata; string input_metadata;
flags f; flags f;
char c; int c;
const char shortopts[] = "hi:o:E:V"; const char shortopts[] = "hi:o:E:V";
const struct option longopts[] = { const struct option longopts[] = {

View File

@ -383,7 +383,7 @@ thin_scan_cmd::run(int argc, char **argv)
boost::optional<string> output; boost::optional<string> output;
flags f; flags f;
char c; int c;
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch(c) { switch(c) {
case 'h': case 'h':