You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2016/02/23 00:53:06 UTC
[1/3] incubator-kudu git commit: arena: switch from shared_ptr
components to unique_ptr
Repository: incubator-kudu
Updated Branches:
refs/heads/master 2878c5862 -> 7b157c5c1
arena: switch from shared_ptr components to unique_ptr
We used to use shared_ptr here for laziness rather than for any
real sharing. unique_ptr works just as well, now that we are
in C++11.
Change-Id: If5218339809e6cb05461f978fe75860b97b01b61
Reviewed-on: http://gerrit.cloudera.org:8080/2242
Tested-by: Kudu Jenkins
Reviewed-by: Dan Burkert <da...@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/6a6a9c27
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/6a6a9c27
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/6a6a9c27
Branch: refs/heads/master
Commit: 6a6a9c27603f28cb77726f974d3b61e886cd7f77
Parents: 2878c58
Author: Todd Lipcon <to...@cloudera.com>
Authored: Sat Dec 19 15:24:59 2015 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Mon Feb 22 23:52:00 2016 +0000
----------------------------------------------------------------------
src/kudu/util/memory/arena.cc | 11 +++++------
src/kudu/util/memory/arena.h | 2 +-
2 files changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/6a6a9c27/src/kudu/util/memory/arena.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/arena.cc b/src/kudu/util/memory/arena.cc
index 822a4f6..8922f44 100644
--- a/src/kudu/util/memory/arena.cc
+++ b/src/kudu/util/memory/arena.cc
@@ -17,7 +17,6 @@
// specific language governing permissions and limitations
// under the License.
//
-
#include "kudu/util/memory/arena.h"
#include <algorithm>
@@ -30,9 +29,9 @@ using std::copy;
using std::max;
using std::min;
using std::reverse;
-using std::shared_ptr;
using std::sort;
using std::swap;
+using std::unique_ptr;
DEFINE_int64(arena_warn_threshold_bytes, 256*1024*1024,
"Number of bytes beyond which to emit a warning for a large arena");
@@ -124,7 +123,7 @@ typename ArenaBase<THREADSAFE>::Component* ArenaBase<THREADSAFE>::NewComponent(
template <bool THREADSAFE>
void ArenaBase<THREADSAFE>::AddComponent(ArenaBase::Component *component) {
ReleaseStoreCurrent(component);
- arena_.push_back(shared_ptr<Component>(component));
+ arena_.push_back(unique_ptr<Component>(component));
arena_footprint_ += component->size();
if (PREDICT_FALSE(arena_footprint_ > FLAGS_arena_warn_threshold_bytes) && !warned_) {
LOG(WARNING) << "Arena " << reinterpret_cast<const void *>(this)
@@ -140,10 +139,10 @@ void ArenaBase<THREADSAFE>::Reset() {
lock_guard<mutex_type> lock(&component_lock_);
if (PREDICT_FALSE(arena_.size() > 1)) {
- shared_ptr<Component> last = arena_.back();
+ unique_ptr<Component> last = std::move(arena_.back());
arena_.clear();
- arena_.push_back(last);
- ReleaseStoreCurrent(last.get());
+ arena_.emplace_back(std::move(last));
+ ReleaseStoreCurrent(arena_[0].get());
}
arena_.back()->Reset();
arena_footprint_ = arena_.back()->size();
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/6a6a9c27/src/kudu/util/memory/arena.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/memory/arena.h b/src/kudu/util/memory/arena.h
index 69c3636..21af74d 100644
--- a/src/kudu/util/memory/arena.h
+++ b/src/kudu/util/memory/arena.h
@@ -185,7 +185,7 @@ class ArenaBase {
}
BufferAllocator* const buffer_allocator_;
- vector<std::shared_ptr<Component> > arena_;
+ vector<std::unique_ptr<Component> > arena_;
// The current component to allocate from.
// Use AcquireLoadCurrent and ReleaseStoreCurrent to load/store.
[2/3] incubator-kudu git commit: Remove use of boost::ptr_vector in
non-test code
Posted by to...@apache.org.
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 <da...@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 <to...@apache.org>
Authored: Thu Feb 18 21:11:04 2016 -0800
Committer: Todd Lipcon <to...@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);
};
[3/3] incubator-kudu git commit: lock_manager: change from
emulated-move to C++11 move
Posted by to...@apache.org.
lock_manager: change from emulated-move to C++11 move
Change-Id: I35b06fdfd52006731b5a20b1e15704ab9967385e
Reviewed-on: http://gerrit.cloudera.org:8080/2244
Tested-by: Kudu Jenkins
Reviewed-by: Dan Burkert <da...@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/7b157c5c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/7b157c5c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/7b157c5c
Branch: refs/heads/master
Commit: 7b157c5c1b494de41cfbabd35f44eff2bf4bf8c8
Parents: 6737d78
Author: Todd Lipcon <to...@apache.org>
Authored: Thu Feb 18 21:19:44 2016 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Mon Feb 22 23:52:16 2016 +0000
----------------------------------------------------------------------
src/kudu/tablet/lock_manager-test.cc | 2 +-
src/kudu/tablet/lock_manager.cc | 8 ++++----
src/kudu/tablet/lock_manager.h | 21 ++++++++++-----------
src/kudu/tablet/tablet.cc | 9 ++++-----
4 files changed, 19 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/7b157c5c/src/kudu/tablet/lock_manager-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/lock_manager-test.cc b/src/kudu/tablet/lock_manager-test.cc
index 28a7a35..4fa098c 100644
--- a/src/kudu/tablet/lock_manager-test.cc
+++ b/src/kudu/tablet/lock_manager-test.cc
@@ -99,7 +99,7 @@ TEST_F(LockManagerTest, TestMoveLock) {
ASSERT_TRUE(row_lock.acquired());
// Move it to a new instance.
- ScopedRowLock moved_lock(row_lock.Pass());
+ ScopedRowLock moved_lock(std::move(row_lock));
ASSERT_TRUE(moved_lock.acquired());
ASSERT_FALSE(row_lock.acquired());
}
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/7b157c5c/src/kudu/tablet/lock_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/lock_manager.cc b/src/kudu/tablet/lock_manager.cc
index 0f17dfc..d83005f 100644
--- a/src/kudu/tablet/lock_manager.cc
+++ b/src/kudu/tablet/lock_manager.cc
@@ -278,12 +278,12 @@ ScopedRowLock::ScopedRowLock(LockManager *manager,
}
}
-ScopedRowLock::ScopedRowLock(RValue other) {
- TakeState(other.object);
+ScopedRowLock::ScopedRowLock(ScopedRowLock&& other) {
+ TakeState(&other);
}
-ScopedRowLock& ScopedRowLock::operator=(RValue other) {
- TakeState(other.object);
+ScopedRowLock& ScopedRowLock::operator=(ScopedRowLock&& other) {
+ TakeState(&other);
return *this;
}
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/7b157c5c/src/kudu/tablet/lock_manager.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/lock_manager.h b/src/kudu/tablet/lock_manager.h
index 6bfaa67..731a897 100644
--- a/src/kudu/tablet/lock_manager.h
+++ b/src/kudu/tablet/lock_manager.h
@@ -73,26 +73,25 @@ class LockManager {
// }
// // lock is released when the object exits its scope.
//
-// This class emulates C++11 move constructors and thus can be
-// copied by using the special '.Pass()' function. For example:
+// This class implements C++11 move constructors and thus can be
+// transferred around using std::move(). For example:
//
// void DoSomething(ScopedRowLock l) {
// // l owns the lock and will release at the end of this function
// }
// ScopedRowLock my_lock(&manager, ...);
-// DoSomething(l.Pass());
-// CHECK(!l.acquired()); // doesn't own lock anymore, since it Pass()ed
+// DoSomething(std::move(l);
+// CHECK(!l.acquired()); // doesn't own lock anymore, since it moved
class ScopedRowLock {
- MOVE_ONLY_TYPE_FOR_CPP_03(ScopedRowLock, RValue);
public:
// Construct an initially-unlocked lock holder.
// You can later assign this to actually hold a lock using
- // the emulated move-constructor:
+ // the move-constructor:
// ScopedRowLock l;
- // l = ScopedRowLock(...); // use the ctor below
+ // l = ScopedRowLock(...);
// or
- // l = other_row_lock.Pass();
+ // l = std::move(other_row_lock);
ScopedRowLock()
: manager_(NULL),
acquired_(false),
@@ -104,9 +103,9 @@ class ScopedRowLock {
ScopedRowLock(LockManager *manager, const TransactionState* ctx,
const Slice &key, LockManager::LockMode mode);
- // Emulated Move constructor
- ScopedRowLock(RValue other); // NOLINT(runtime/explicit)
- ScopedRowLock& operator=(RValue other);
+ // Move constructor and assignment.
+ ScopedRowLock(ScopedRowLock&& other);
+ ScopedRowLock& operator=(ScopedRowLock&& other);
void Release();
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/7b157c5c/src/kudu/tablet/tablet.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet.cc b/src/kudu/tablet/tablet.cc
index 88f8417..c2cb4a2 100644
--- a/src/kudu/tablet/tablet.cc
+++ b/src/kudu/tablet/tablet.cc
@@ -327,11 +327,10 @@ Status Tablet::AcquireLockForOp(WriteTransactionState* tx_state, RowOp* op) {
op->key_probe.reset(new tablet::RowSetKeyProbe(row_key));
RETURN_NOT_OK(CheckRowInTablet(row_key));
- ScopedRowLock row_lock(&lock_manager_,
- tx_state,
- op->key_probe->encoded_key_slice(),
- LockManager::LOCK_EXCLUSIVE);
- op->row_lock = row_lock.Pass();
+ op->row_lock = ScopedRowLock(&lock_manager_,
+ tx_state,
+ op->key_probe->encoded_key_slice(),
+ LockManager::LOCK_EXCLUSIVE);
return Status::OK();
}