kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [2/3] incubator-kudu git commit: Remove use of boost::ptr_vector in non-test code
Date Mon, 22 Feb 2016 23:53:07 GMT
Remove use of boost::ptr_vector in non-test code

We no longer need this class, since a vector<unique_ptr<>> works fine
in C++11.

Change-Id: Ifb9b704cb3e65b8d1dc2605767c1eb29847b366d
Reviewed-on: http://gerrit.cloudera.org:8080/2243
Tested-by: Kudu Jenkins
Reviewed-by: Dan Burkert <dan@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/6737d78e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/6737d78e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/6737d78e

Branch: refs/heads/master
Commit: 6737d78e8e8d294af21d31ab46e92e91d7466dd8
Parents: 6a6a9c2
Author: Todd Lipcon <todd@apache.org>
Authored: Thu Feb 18 21:11:04 2016 -0800
Committer: Todd Lipcon <todd@apache.org>
Committed: Mon Feb 22 23:52:09 2016 +0000

----------------------------------------------------------------------
 src/kudu/cfile/bloomfile.cc   | 15 ++++++-------
 src/kudu/cfile/bloomfile.h    |  4 ++--
 src/kudu/cfile/index_btree.cc | 44 +++++++++++++++++++-------------------
 src/kudu/cfile/index_btree.h  |  8 +++----
 4 files changed, 34 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/6737d78e/src/kudu/cfile/bloomfile.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/bloomfile.cc b/src/kudu/cfile/bloomfile.cc
index b3059bc..f7a9af2 100644
--- a/src/kudu/cfile/bloomfile.cc
+++ b/src/kudu/cfile/bloomfile.cc
@@ -196,7 +196,7 @@ Status BloomFileReader::InitOnce() {
   // stack-allocate these things more smartly!
   int n_cpus = base::MaxCPUIndex() + 1;
   for (int i = 0; i < n_cpus; i++) {
-    index_iters_.push_back(
+    index_iters_.emplace_back(
       IndexTreeIterator::Create(reader_.get(), validx_root));
   }
   iter_locks_.reset(new padded_spinlock[n_cpus]);
@@ -258,7 +258,7 @@ Status BloomFileReader::CheckKeyPresent(const BloomKeyProbe &probe,
       cpu = (cpu + 1) % index_iters_.size();
     }
 
-    cfile::IndexTreeIterator *index_iter = &index_iters_[cpu];
+    cfile::IndexTreeIterator *index_iter = index_iters_[cpu].get();
 
     Status s = index_iter->SeekAtOrBefore(probe.key());
     if (PREDICT_FALSE(s.IsNotFound())) {
@@ -291,14 +291,13 @@ size_t BloomFileReader::memory_footprint_excluding_reader() const {
 
   size += init_once_.memory_footprint_excluding_this();
 
-  // This seems to be the easiest way to get a heap pointer to the ptr_vector.
-  //
   // TODO: Track the iterators' memory footprint? May change with every seek;
   // not clear if it's worth doing.
-  size += kudu_malloc_usable_size(
-      const_cast<BloomFileReader*>(this)->index_iters_.c_array());
-  for (int i = 0; i < index_iters_.size(); i++) {
-    size += kudu_malloc_usable_size(&index_iters_[i]);
+  if (!index_iters_.empty()) {
+    size += kudu_malloc_usable_size(index_iters_.data());
+    for (int i = 0; i < index_iters_.size(); i++) {
+      size += kudu_malloc_usable_size(index_iters_[i].get());
+    }
   }
 
   if (iter_locks_) {

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/6737d78e/src/kudu/cfile/bloomfile.h
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/bloomfile.h b/src/kudu/cfile/bloomfile.h
index 540ad55..7040b03 100644
--- a/src/kudu/cfile/bloomfile.h
+++ b/src/kudu/cfile/bloomfile.h
@@ -17,7 +17,7 @@
 #ifndef KUDU_CFILE_BLOOMFILE_H
 #define KUDU_CFILE_BLOOMFILE_H
 
-#include <boost/ptr_container/ptr_vector.hpp>
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -128,7 +128,7 @@ class BloomFileReader {
   // We need a big per-thread object which gets passed around so as
   // to avoid this... Instead we'll use a per-CPU iterator as a
   // lame hack.
-  boost::ptr_vector<cfile::IndexTreeIterator> index_iters_;
+  std::vector<std::unique_ptr<cfile::IndexTreeIterator>> index_iters_;
   gscoped_ptr<padded_spinlock[]> iter_locks_;
 
   KuduOnceDynamic init_once_;

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/6737d78e/src/kudu/cfile/index_btree.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/index_btree.cc b/src/kudu/cfile/index_btree.cc
index 1265695..f9065eb 100644
--- a/src/kudu/cfile/index_btree.cc
+++ b/src/kudu/cfile/index_btree.cc
@@ -32,7 +32,7 @@ IndexTreeBuilder::IndexTreeBuilder(
   CFileWriter *writer) :
   options_(options),
   writer_(writer) {
-  idx_blocks_.push_back(CreateBlockBuilder(true));
+  idx_blocks_.emplace_back(CreateBlockBuilder(true));
 }
 
 
@@ -54,15 +54,15 @@ Status IndexTreeBuilder::Append(
       "trying to create level " << level << " but size is only "
                                 << idx_blocks_.size();
     VLOG(1) << "Creating level-" << level << " in index b-tree";
-    idx_blocks_.push_back(CreateBlockBuilder(false));
+    idx_blocks_.emplace_back(CreateBlockBuilder(false));
   }
 
-  IndexBlockBuilder &idx_block = idx_blocks_[level];
-  idx_block.Add(key, block_ptr);
+  IndexBlockBuilder* idx_block = idx_blocks_[level].get();
+  idx_block->Add(key, block_ptr);
 
-  size_t est_size = idx_block.EstimateEncodedSize();
+  size_t est_size = idx_block->EstimateEncodedSize();
   if (est_size > options_->index_block_size) {
-    DCHECK(idx_block.Count() > 1)
+    DCHECK(idx_block->Count() > 1)
       << "Index block full with only one entry - this would create "
       << "an infinite loop";
     // This index block is full, flush it.
@@ -101,7 +101,7 @@ Status IndexTreeBuilder::Finish(BTreeInfoPB *info) {
 }
 
 Status IndexTreeBuilder::FinishBlockAndPropagate(size_t level) {
-  IndexBlockBuilder &idx_block = idx_blocks_[level];
+  IndexBlockBuilder* idx_block = idx_blocks_[level].get();
 
   // If the block doesn't have any data in it, we don't need to
   // write it out.
@@ -109,7 +109,7 @@ Status IndexTreeBuilder::FinishBlockAndPropagate(size_t level) {
   // and then the file completes.
   //
   // TODO: add a test case which exercises this explicitly.
-  if (idx_block.Count() == 0) {
+  if (idx_block->Count() == 0) {
     return Status::OK();
   }
 
@@ -119,7 +119,7 @@ Status IndexTreeBuilder::FinishBlockAndPropagate(size_t level) {
 
   // Get the first key of the finished block.
   Slice first_in_idx_block;
-  Status s = idx_block.GetFirstKey(&first_in_idx_block);
+  Status s = idx_block->GetFirstKey(&first_in_idx_block);
 
   if (!s.ok()) {
     LOG(ERROR) << "Unable to get first key of level-" << level
@@ -135,7 +135,7 @@ Status IndexTreeBuilder::FinishBlockAndPropagate(size_t level) {
   // Finally, reset the block we just wrote. It's important to wait until
   // here to do this, since the first_in_idx_block data may point to internal
   // storage of the index block.
-  idx_block.Reset();
+  idx_block->Reset();
 
   return Status::OK();
 }
@@ -144,8 +144,8 @@ Status IndexTreeBuilder::FinishBlockAndPropagate(size_t level) {
 // to the file. Return the location of the written block
 // in 'written'.
 Status IndexTreeBuilder::FinishAndWriteBlock(size_t level, BlockPointer *written) {
-  IndexBlockBuilder &idx_block = idx_blocks_[level];
-  Slice data = idx_block.Finish();
+  IndexBlockBuilder* idx_block = idx_blocks_[level].get();
+  Slice data = idx_block->Finish();
 
   vector<Slice> v;
   v.push_back(data);
@@ -178,7 +178,7 @@ Status IndexTreeIterator::SeekToFirst() {
 
 bool IndexTreeIterator::HasNext() {
   for (int i = seeked_indexes_.size() - 1; i >= 0; i--) {
-    if (seeked_indexes_[i].iter.HasNext())
+    if (seeked_indexes_[i]->iter.HasNext())
       return true;
   }
   return false;
@@ -221,27 +221,27 @@ Status IndexTreeIterator::Next() {
 }
 
 const Slice IndexTreeIterator::GetCurrentKey() const {
-  return seeked_indexes_.back().iter.GetCurrentKey();
+  return seeked_indexes_.back()->iter.GetCurrentKey();
 }
 
 const BlockPointer &IndexTreeIterator::GetCurrentBlockPointer() const {
-  return seeked_indexes_.back().iter.GetCurrentBlockPointer();
+  return seeked_indexes_.back()->iter.GetCurrentBlockPointer();
 }
 
 IndexBlockIterator *IndexTreeIterator::BottomIter() {
-  return &seeked_indexes_.back().iter;
+  return &seeked_indexes_.back()->iter;
 }
 
 IndexBlockReader *IndexTreeIterator::BottomReader() {
-  return &seeked_indexes_.back().reader;
+  return &seeked_indexes_.back()->reader;
 }
 
 IndexBlockIterator *IndexTreeIterator::seeked_iter(int depth) {
-  return &seeked_indexes_[depth].iter;
+  return &seeked_indexes_[depth]->iter;
 }
 
 IndexBlockReader *IndexTreeIterator::seeked_reader(int depth) {
-  return &seeked_indexes_[depth].reader;
+  return &seeked_indexes_[depth]->reader;
 }
 
 Status IndexTreeIterator::LoadBlock(const BlockPointer &block, int depth) {
@@ -249,7 +249,7 @@ Status IndexTreeIterator::LoadBlock(const BlockPointer &block, int
depth) {
   SeekedIndex *seeked;
   if (depth < seeked_indexes_.size()) {
     // We have a cached instance from previous seek.
-    seeked = &seeked_indexes_[depth];
+    seeked = seeked_indexes_[depth].get();
 
     if (seeked->block_ptr.offset() == block.offset()) {
       // We're already seeked to this block - no need to re-parse it.
@@ -264,8 +264,8 @@ Status IndexTreeIterator::LoadBlock(const BlockPointer &block, int
depth) {
     seeked->iter.Reset();
   } else {
     // No cached instance, make a new one.
-    seeked_indexes_.push_back(new SeekedIndex());
-    seeked = &seeked_indexes_.back();
+    seeked_indexes_.emplace_back(new SeekedIndex());
+    seeked = seeked_indexes_.back().get();
   }
 
   RETURN_NOT_OK(reader_->ReadBlock(block, CFileReader::CACHE_BLOCK, &seeked->data));

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/6737d78e/src/kudu/cfile/index_btree.h
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/index_btree.h b/src/kudu/cfile/index_btree.h
index fbe48fb..ecd4c9b 100644
--- a/src/kudu/cfile/index_btree.h
+++ b/src/kudu/cfile/index_btree.h
@@ -18,8 +18,8 @@
 #ifndef KUDU_CFILE_INDEX_BTREE_H
 #define KUDU_CFILE_INDEX_BTREE_H
 
-#include <boost/ptr_container/ptr_vector.hpp>
 #include <memory>
+#include <vector>
 
 #include "kudu/cfile/block_handle.h"
 #include "kudu/cfile/cfile.pb.h"
@@ -29,8 +29,6 @@
 namespace kudu {
 namespace cfile {
 
-using boost::ptr_vector;
-
 class CFileReader;
 class CFileWriter;
 
@@ -63,7 +61,7 @@ class IndexTreeBuilder {
   const WriterOptions *options_;
   CFileWriter *writer_;
 
-  ptr_vector<IndexBlockBuilder> idx_blocks_;
+  std::vector<std::unique_ptr<IndexBlockBuilder>> idx_blocks_;
 
   DISALLOW_COPY_AND_ASSIGN(IndexTreeBuilder);
 };
@@ -116,7 +114,7 @@ class IndexTreeIterator {
 
   BlockPointer root_block_;
 
-  ptr_vector<SeekedIndex> seeked_indexes_;
+  std::vector<std::unique_ptr<SeekedIndex>> seeked_indexes_;
 
   DISALLOW_COPY_AND_ASSIGN(IndexTreeIterator);
 };


Mime
View raw message