From edf16f59c73e50f73591ed16f5f23521b1a0a7d6 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 2 May 2013 12:59:42 +0100 Subject: [PATCH] [restorer] Mappings only get inserted when the device is completed. This saves looking up the device mapping tree for every insert. --- thin-provisioning/restore_emitter.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/thin-provisioning/restore_emitter.cc b/thin-provisioning/restore_emitter.cc index b471578..587137a 100644 --- a/thin-provisioning/restore_emitter.cc +++ b/thin-provisioning/restore_emitter.cc @@ -77,15 +77,17 @@ namespace { md_->details_->insert(key, details); // Insert an empty mapping tree - single_mapping_tree::ptr new_tree( - new single_mapping_tree(md_->tm_, - block_time_ref_counter(md_->data_sm_))); - md_->mappings_top_level_->insert(key, new_tree->get_root()); - md_->mappings_->set_root(md_->mappings_top_level_->get_root()); // FIXME: ugly + current_mapping_.reset(new single_mapping_tree(md_->tm_, + block_time_ref_counter(md_->data_sm_))); current_device_ = optional(dev); } virtual void end_device() { + uint64_t key[1] = {*current_device_}; + + md_->mappings_top_level_->insert(key, current_mapping_->get_root()); + md_->mappings_->set_root(md_->mappings_top_level_->get_root()); // FIXME: ugly + current_device_ = optional(); } @@ -110,17 +112,16 @@ namespace { if (!current_device_) throw runtime_error("not in device"); - uint64_t key[2] = {*current_device_, origin_block}; + uint64_t key[1] = {origin_block}; block_time bt; bt.block_ = data_block; bt.time_ = time; - md_->mappings_->insert(key, bt); - md_->mappings_top_level_->set_root(md_->mappings_->get_root()); + current_mapping_->insert(key, bt); md_->data_sm_->inc(data_block); } private: - bool device_exists(thin_dev_t dev) const { + bool device_exists(thin_dev_t dev) const { uint64_t key[1] = {dev}; detail_tree::maybe_value v = md_->details_->lookup(key); return v; @@ -129,6 +130,7 @@ namespace { metadata::ptr md_; bool in_superblock_; optional current_device_; + single_mapping_tree::ptr current_mapping_; }; }