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 2017/04/06 05:19:29 UTC
kudu git commit: tablet: check for row presence in rowset-wise order
Repository: kudu
Updated Branches:
refs/heads/master eca517108 -> 4568f2a4c
tablet: check for row presence in rowset-wise order
This changes the overall flow of applying batches of writes from:
for each key in batch:
find which rowsets may contain this key
for each rowset:
check if key is present in rowset
if not present in any rowset, apply the write
to:
sort all ops by key
bulk-query the interval tree
for each rowset:
for each key which might be in that rowset, in sorted order:
check if the key is present
if so, mark it as such
for each op:
if insert:
if it's not present in any rowset (based on above marking)
apply it
if mutate:
apply to the rowset determined above
The one wrinkle not expressed in the above pseudo-code is the handling
of batches with duplicate keys (eg insert/update/delete/insert
sequences of the same PK in one batch). In those cases, the later
operations may find their keys in different RowSets based on the results
of the earlier operations, and thus we need to continue to do the
presence checks one-by-one.
The aim with this patch is that because we end up accessing each rowset
many times sequentially in ascending key order, we open up the
opportunity for two potential optimizations:
1) a thread-local cache can keep seeked iterators within that rowset, as
well as hot blocks such as the index blocks, and reuse it cross-op
within the same batch
2) we can detect when several of the ops in a batch all fall into a
"gap" in a particular rowset, and "skip ahead", short circuiting a
bunch of checks
This patch isn't meant to give big wins on its own, but the further
patches in the series reap big benefits (see later commit messages for details)
As a simple benchmark to make sure performance didn't regress, I used
tpch_real_world with 12 writer threads on a single machine for scale
factor 100 (600M rows).
Before:
Wall time: 1007s
Server CPU time: 9333s
After:
Wall time: 1014s (+0.7%, probably noise)
Server CPU time: 8861s (-5.3%, could be significant)
Change-Id: I9a678bb0da130ce94aae3634c82ace2d6898ffa2
Reviewed-on: http://gerrit.cloudera.org:8080/6483
Tested-by: Kudu Jenkins
Reviewed-by: David Ribeiro Alves <dr...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/4568f2a4
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/4568f2a4
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/4568f2a4
Branch: refs/heads/master
Commit: 4568f2a4cbd999d5a2ab64d285205b8d30997339
Parents: eca5171
Author: Todd Lipcon <to...@apache.org>
Authored: Fri Mar 24 17:43:45 2017 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Thu Apr 6 05:00:16 2017 +0000
----------------------------------------------------------------------
src/kudu/integration-tests/fuzz-itest.cc | 34 +++
src/kudu/tablet/row_op.h | 21 +-
src/kudu/tablet/tablet.cc | 296 ++++++++++++++-----
src/kudu/tablet/tablet.h | 13 +-
.../tablet/transactions/write_transaction.cc | 11 +
.../tablet/transactions/write_transaction.h | 12 +
6 files changed, 304 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/4568f2a4/src/kudu/integration-tests/fuzz-itest.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/fuzz-itest.cc b/src/kudu/integration-tests/fuzz-itest.cc
index e98afb5..f28a29b 100644
--- a/src/kudu/integration-tests/fuzz-itest.cc
+++ b/src/kudu/integration-tests/fuzz-itest.cc
@@ -414,6 +414,13 @@ class FuzzTest : public KuduTest {
}
protected:
+ // Validate that the given sequence is valid and would not cause any
+ // errors assuming that there are no bugs. For example, checks to make sure there
+ // aren't duplicate inserts with no intervening deletions.
+ //
+ // Useful when using the 'delta' test case reduction tool to allow
+ // it to skip invalid test cases.
+ void ValidateFuzzCase(const vector<TestOp>& test_ops);
void RunFuzzCase(const vector<TestOp>& test_ops,
int update_multiplier);
@@ -569,8 +576,35 @@ string DumpTestCase(const vector<TestOp>& ops) {
return JoinStrings(strs, ",\n");
}
+void FuzzTest::ValidateFuzzCase(const vector<TestOp>& test_ops) {
+ vector<bool> exists(FLAGS_keyspace_size);
+ for (const auto& test_op : test_ops) {
+ switch (test_op.type) {
+ case TEST_INSERT:
+ case TEST_INSERT_PK_ONLY:
+ CHECK(!exists[test_op.val]) << "invalid case: inserting already-existing row";
+ exists[test_op.val] = true;
+ break;
+ case TEST_UPSERT:
+ case TEST_UPSERT_PK_ONLY:
+ exists[test_op.val] = true;
+ break;
+ case TEST_UPDATE:
+ CHECK(exists[test_op.val]) << "invalid case: updating non-existing row";
+ break;
+ case TEST_DELETE:
+ CHECK(exists[test_op.val]) << "invalid case: deleting non-existing row";
+ exists[test_op.val] = false;
+ break;
+ default:
+ break;
+ }
+ }
+}
+
void FuzzTest::RunFuzzCase(const vector<TestOp>& test_ops,
int update_multiplier = 1) {
+ ValidateFuzzCase(test_ops);
// Dump the test case, since we usually run a random one.
// This dump format is easy for a developer to copy-paste back
// into a test method in order to reproduce a failure.
http://git-wip-us.apache.org/repos/asf/kudu/blob/4568f2a4/src/kudu/tablet/row_op.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/row_op.h b/src/kudu/tablet/row_op.h
index 71bb089..904ba70 100644
--- a/src/kudu/tablet/row_op.h
+++ b/src/kudu/tablet/row_op.h
@@ -66,6 +66,10 @@ struct RowOp {
// The original operation as decoded from the client request.
DecodedRowOperation decoded_op;
+ // If this operation is being replayed from the log, set to the original
+ // result. Otherwise nullptr.
+ const OperationResultPB* orig_result_from_log_;
+
// The key probe structure contains the row key in both key-encoded and
// ContiguousRow formats, bloom probe structure, etc. This is set during
// the "prepare" phase.
@@ -75,12 +79,23 @@ struct RowOp {
// phase.
ScopedRowLock row_lock;
+ // Flag whether this op has already been validated by Tablet::ValidateOp.
+ bool validated = false;
+
+ // Flag whether this op has already had 'present_in_rowset' filled in.
+ // If false, 'present_in_rowset' must be nullptr. If true, and
+ // 'present_in_rowset' is nullptr, then this indicates that the key
+ // for this op does not exist in any RowSet.
+ bool checked_present = false;
+
+ // The RowSet in which this op's key has been found present and alive.
+ // This will be null if 'checked_present' is false, or if it has been
+ // checked and found not to be alive in any RowSet.
+ RowSet* present_in_rowset = nullptr;
+
// The result of the operation, after Apply.
gscoped_ptr<OperationResultPB> result;
- // If this operation is being replayed from the log, set to the original
- // result. Otherwise nullptr.
- const OperationResultPB* orig_result_from_log_;
};
http://git-wip-us.apache.org/repos/asf/kudu/blob/4568f2a4/src/kudu/tablet/tablet.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet.cc b/src/kudu/tablet/tablet.cc
index 66d2b27..ee173fd 100644
--- a/src/kudu/tablet/tablet.cc
+++ b/src/kudu/tablet/tablet.cc
@@ -412,6 +412,35 @@ void Tablet::StartTransaction(WriteTransactionState* tx_state) {
tx_state->SetMvccTx(std::move(mvcc_tx));
}
+bool Tablet::ValidateOpOrMarkFailed(RowOp* op) const {
+ if (op->validated) return true;
+
+ Status s = ValidateOp(*op);
+ if (PREDICT_FALSE(!s.ok())) {
+ // TODO(todd): add a metric tracking the number of invalid ops.
+ op->SetFailed(s);
+ return false;
+ }
+ op->validated = true;
+ return true;
+}
+
+Status Tablet::ValidateOp(const RowOp& op) const {
+ switch (op.decoded_op.type) {
+ case RowOperationsPB::INSERT:
+ case RowOperationsPB::UPSERT:
+ return ValidateInsertOrUpsertUnlocked(op);
+
+ case RowOperationsPB::UPDATE:
+ case RowOperationsPB::DELETE:
+ return ValidateMutateUnlocked(op);
+
+ default:
+ LOG_WITH_PREFIX(FATAL) << RowOperationsPB::Type_Name(op.decoded_op.type);
+ }
+ abort(); // unreachable
+}
+
Status Tablet::ValidateInsertOrUpsertUnlocked(const RowOp& op) const {
// Check that no individual cell is larger than the specified max.
ConstContiguousRow row(schema(), op.decoded_op.row_data);
@@ -476,33 +505,22 @@ Status Tablet::ValidateMutateUnlocked(const RowOp& op) const {
Status Tablet::InsertOrUpsertUnlocked(WriteTransactionState *tx_state,
RowOp* op,
ProbeStats* stats) {
-
- Status s = ValidateInsertOrUpsertUnlocked(*op);
- if (PREDICT_FALSE(!s.ok())) {
- // TODO(todd): add a metric tracking the number of invalid ops.
- op->SetFailed(s);
- return s;
- }
+ DCHECK(op->checked_present);
+ DCHECK(op->validated);
const bool is_upsert = op->decoded_op.type == RowOperationsPB::UPSERT;
const TabletComponents* comps = DCHECK_NOTNULL(tx_state->tablet_components());
- // First, ensure that it is a unique key by checking all the open RowSets.
- vector<RowSet *> to_check = FindRowSetsToCheck(op, comps);
- for (RowSet *rowset : to_check) {
- bool present = false;
- RETURN_NOT_OK(rowset->CheckRowPresent(*op->key_probe, &present, stats));
- if (present) {
- if (is_upsert) {
- return ApplyUpsertAsUpdate(tx_state, op, rowset, stats);
- }
- Status s = Status::AlreadyPresent("key already present");
- if (metrics_) {
- metrics_->insertions_failed_dup_key->Increment();
- }
- op->SetFailed(s);
- return s;
+ if (op->present_in_rowset) {
+ if (is_upsert) {
+ return ApplyUpsertAsUpdate(tx_state, op, op->present_in_rowset, stats);
}
+ Status s = Status::AlreadyPresent("key already present");
+ if (metrics_) {
+ metrics_->insertions_failed_dup_key->Increment();
+ }
+ op->SetFailed(s);
+ return s;
}
Timestamp ts = tx_state->timestamp();
@@ -513,7 +531,7 @@ Status Tablet::InsertOrUpsertUnlocked(WriteTransactionState *tx_state,
// Now try to op into memrowset. The memrowset itself will return
// AlreadyPresent if it has already been oped there.
- s = comps->memrowset->Insert(ts, row, tx_state->op_id());
+ Status s = comps->memrowset->Insert(ts, row, tx_state->op_id());
if (s.ok()) {
op->SetInsertSucceeded(comps->memrowset->mrs_id());
} else {
@@ -577,7 +595,7 @@ Status Tablet::ApplyUpsertAsUpdate(WriteTransactionState* tx_state,
return s;
}
-vector<RowSet*> Tablet::FindRowSetsToCheck(RowOp* op,
+vector<RowSet*> Tablet::FindRowSetsToCheck(const RowOp* op,
const TabletComponents* comps) {
vector<RowSet*> to_check;
if (PREDICT_TRUE(!op->orig_result_from_log_)) {
@@ -620,55 +638,32 @@ vector<RowSet*> Tablet::FindRowSetsToCheck(RowOp* op,
Status Tablet::MutateRowUnlocked(WriteTransactionState *tx_state,
RowOp* mutate,
ProbeStats* stats) {
- // Validate the mutation.
- Status s = ValidateMutateUnlocked(*mutate);
- if (!s.ok()) {
- mutate->SetFailed(s);
- return s;
- }
+ DCHECK(mutate->checked_present);
+ DCHECK(mutate->validated);
gscoped_ptr<OperationResultPB> result(new OperationResultPB());
const TabletComponents* comps = DCHECK_NOTNULL(tx_state->tablet_components());
Timestamp ts = tx_state->timestamp();
- // First try to update in memrowset.
- s = comps->memrowset->MutateRow(ts,
- *mutate->key_probe,
- mutate->decoded_op.changelist,
- tx_state->op_id(),
- stats,
- result.get());
- if (s.ok()) {
+ // If we found the row in any existing RowSet, mutate it there. Otherwise
+ // attempt to mutate in the MRS.
+ RowSet* rs_to_attempt = mutate->present_in_rowset ?
+ mutate->present_in_rowset : comps->memrowset.get();
+ Status s = rs_to_attempt->MutateRow(ts,
+ *mutate->key_probe,
+ mutate->decoded_op.changelist,
+ tx_state->op_id(),
+ stats,
+ result.get());
+ if (PREDICT_TRUE(s.ok())) {
mutate->SetMutateSucceeded(std::move(result));
- return s;
- }
- if (!s.IsNotFound()) {
- mutate->SetFailed(s);
- return s;
- }
-
- // Next, check the disk rowsets.
-
- vector<RowSet *> to_check = FindRowSetsToCheck(mutate, comps);
- for (RowSet *rs : to_check) {
- s = rs->MutateRow(ts,
- *mutate->key_probe,
- mutate->decoded_op.changelist,
- tx_state->op_id(),
- stats,
- result.get());
- if (s.ok()) {
- mutate->SetMutateSucceeded(std::move(result));
- return s;
- }
- if (!s.IsNotFound()) {
- mutate->SetFailed(s);
- return s;
+ } else {
+ if (s.IsNotFound()) {
+ // Replace internal error messages with one more suitable for users.
+ s = Status::NotFound("key not found");
}
+ mutate->SetFailed(s);
}
-
- s = Status::NotFound("key not found");
- mutate->SetFailed(s);
return s;
}
@@ -678,26 +673,148 @@ void Tablet::StartApplying(WriteTransactionState* tx_state) {
tx_state->set_tablet_components(components_);
}
+void Tablet::BulkCheckPresence(WriteTransactionState* tx_state) {
+ int num_ops = tx_state->row_ops().size();
+
+ // TODO(todd) determine why we sometimes get empty writes!
+ if (PREDICT_FALSE(num_ops == 0)) return;
+
+ // The compiler seems to be bad at hoisting this load out of the loops,
+ // so load it up top.
+ RowOp* const * row_ops_base = tx_state->row_ops().data();
+
+ // Run all of the ops through the RowSetTree.
+ vector<pair<Slice, int>> keys_and_indexes;
+ keys_and_indexes.reserve(num_ops);
+ for (int i = 0; i < num_ops; i++) {
+ RowOp* op = row_ops_base[i];
+ // If the op already failed in validation, or if we've got the original result
+ // filled in already during replay, then we don't need to consult the RowSetTree.
+ if (op->has_result() || op->orig_result_from_log_) continue;
+ keys_and_indexes.emplace_back(op->key_probe->encoded_key_slice(), i);
+ }
+
+ // Sort the query points by their probe keys, retaining the equivalent indexes.
+ //
+ // It's important to do a stable-sort here so that the 'unique' call
+ // below retains only the _first_ op the user specified, instead of
+ // an arbitrary one.
+ //
+ // TODO(todd): benchmark stable_sort vs using sort() and falling back to
+ // comparing 'a.second' when a.first == b.first. Some microbenchmarks
+ // seem to indicate stable_sort is actually faster.
+ // TODO(todd): could also consider weaving in a check in the loop above to
+ // see if the incoming batch is already totally-ordered and in that case
+ // skip this sort and std::unique call.
+ std::stable_sort(keys_and_indexes.begin(), keys_and_indexes.end(),
+ [](const pair<Slice, int>& a,
+ const pair<Slice, int>& b) {
+ return a.first.compare(b.first) < 0;
+ });
+ // If the batch has more than one operation for the same row, then we can't
+ // use the up-front presence optimization on those operations, since the
+ // first operation may change the result of the later presence-checks.
+ keys_and_indexes.erase(std::unique(
+ keys_and_indexes.begin(), keys_and_indexes.end(),
+ [](const pair<Slice, int>& a,
+ const pair<Slice, int>& b) {
+ return a.first == b.first;
+ }), keys_and_indexes.end());
+
+ // Unzip the keys into a separate array (since the RowSetTree API just wants a vector of
+ // Slices)
+ vector<Slice> keys(keys_and_indexes.size());
+ for (int i = 0; i < keys.size(); i++) {
+ keys[i] = keys_and_indexes[i].first;
+ }
+
+ // Actually perform the presence checks. We use the "bulk query" functionality
+ // provided by RowSetTree::ForEachRowSetContainingKeys(), which yields results
+ // via a callback, with grouping guarantees that callbacks for the same RowSet
+ // will be grouped together with increasing query keys.
+ //
+ // We want to process each such "group" (set of subsequent calls for the same
+ // RowSet) one at a time. So, the callback itself aggregates results into
+ // 'pending_group' and then calls 'ProcessPendingGroup' when the next group
+ // begins.
+ vector<pair<RowSet*, int>> pending_group;
+ const auto& ProcessPendingGroup = [&]() {
+ if (pending_group.empty()) return;
+ // Check invariant of the batch RowSetTree query: within each output group
+ // we should have fully-sorted keys.
+ DCHECK(std::is_sorted(pending_group.begin(), pending_group.end(),
+ [&](const pair<RowSet*, int>& a,
+ const pair<RowSet*, int>& b) {
+ auto s_a = keys[a.second];
+ auto s_b = keys[b.second];
+ return s_a.compare(s_b) < 0;
+ }));
+ RowSet* rs = pending_group[0].first;
+ for (auto it = pending_group.begin();
+ it != pending_group.end();
+ ++it) {
+ DCHECK_EQ(it->first, rs) << "All results within a group should be for the same RowSet";
+ int op_idx = keys_and_indexes[it->second].second;
+ RowOp* op = row_ops_base[op_idx];
+ if (op->present_in_rowset) {
+ // Already found this op present somewhere.
+ continue;
+ }
+
+ // TODO(todd) is CHECK_OK correct? it used to be that errors here
+ // would just be silently ignored, so this seems at least an improvement.
+ bool present = false;
+ CHECK_OK(rs->CheckRowPresent(*op->key_probe, &present, tx_state->mutable_op_stats(op_idx)));
+ if (present) {
+ op->present_in_rowset = rs;
+ }
+ }
+ pending_group.clear();
+ };
+
+ const TabletComponents* comps = DCHECK_NOTNULL(tx_state->tablet_components());
+ comps->rowsets->ForEachRowSetContainingKeys(
+ keys,
+ [&](RowSet* rs, int i) {
+ if (!pending_group.empty() && rs != pending_group.back().first) {
+ ProcessPendingGroup();
+ }
+ pending_group.emplace_back(rs, i);
+ });
+ // Process the last group.
+ ProcessPendingGroup();
+
+ // Mark all of the ops as having been checked.
+ // TODO(todd): this could potentially be weaved into the std::unique() call up
+ // above to avoid some cache misses.
+ for (auto& p : keys_and_indexes) {
+ row_ops_base[p.second]->checked_present = true;
+ }
+}
+
void Tablet::ApplyRowOperations(WriteTransactionState* tx_state) {
- // Allocate the ProbeStats objects from the transaction's arena, so
- // they're all contiguous and we don't need to do any central allocation.
int num_ops = tx_state->row_ops().size();
- ProbeStats* stats_array = static_cast<ProbeStats*>(
- tx_state->arena()->AllocateBytesAligned(sizeof(ProbeStats) * num_ops,
- alignof(ProbeStats)));
StartApplying(tx_state);
- int i = 0;
- for (RowOp* row_op : tx_state->row_ops()) {
- ProbeStats* stats = &stats_array[i++];
- // Manually run the constructor to clear the stats to 0 before collecting
- // them.
- new (stats) ProbeStats();
- ApplyRowOperation(tx_state, row_op, stats);
+
+ // Validate all of the ops.
+ for (RowOp* op : tx_state->row_ops()) {
+ ValidateOpOrMarkFailed(op);
}
- if (metrics_) {
- metrics_->AddProbeStats(stats_array, num_ops, tx_state->arena());
+ BulkCheckPresence(tx_state);
+
+ // Actually apply the ops.
+ for (int op_idx = 0; op_idx < num_ops; op_idx++) {
+ RowOp* row_op = tx_state->row_ops()[op_idx];
+ if (row_op->has_result()) continue;
+
+ ApplyRowOperation(tx_state, row_op, tx_state->mutable_op_stats(op_idx));
+ DCHECK(row_op->has_result());
+ }
+
+ if (metrics_ && num_ops > 0) {
+ metrics_->AddProbeStats(tx_state->mutable_op_stats(0), num_ops, tx_state->arena());
}
}
@@ -710,6 +827,27 @@ void Tablet::ApplyRowOperation(WriteTransactionState* tx_state,
DCHECK(tx_state->op_id().IsInitialized()) << "TransactionState OpId needed for anchoring";
DCHECK_EQ(tx_state->schema_at_decode_time(), schema());
+ if (!ValidateOpOrMarkFailed(row_op)) {
+ return;
+ }
+
+ // If we were unable to check rowset presence in batch (e.g. because we are processing
+ // a batch which contains some duplicate keys) we need to do so now.
+ if (PREDICT_FALSE(!row_op->checked_present)) {
+ vector<RowSet *> to_check = FindRowSetsToCheck(row_op, tx_state->tablet_components());
+ for (RowSet *rowset : to_check) {
+ bool present = false;
+ // TODO(todd) is CHECK_OK correct? it used to be that errors here
+ // would just be silently ignored, so this seems at least an improvement.
+ CHECK_OK(rowset->CheckRowPresent(*row_op->key_probe, &present, stats));
+ if (present) {
+ row_op->present_in_rowset = rowset;
+ break;
+ }
+ }
+ row_op->checked_present = true;
+ }
+
switch (row_op->decoded_op.type) {
case RowOperationsPB::INSERT:
case RowOperationsPB::UPSERT:
http://git-wip-us.apache.org/repos/asf/kudu/blob/4568f2a4/src/kudu/tablet/tablet.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/tablet.h b/src/kudu/tablet/tablet.h
index 71e73e3..a7c1d84 100644
--- a/src/kudu/tablet/tablet.h
+++ b/src/kudu/tablet/tablet.h
@@ -400,6 +400,13 @@ class Tablet {
Status FlushUnlocked();
+ // Validate the contents of 'op' and return a bad Status if it is invalid.
+ Status ValidateOp(const RowOp& op) const;
+
+ // Validate 'op' as in 'ValidateOp()' above. If it is invalid, marks the op as failed
+ // and returns false. If valid, marks the op as validated and returns true.
+ bool ValidateOpOrMarkFailed(RowOp* op) const;
+
// Validate the given insert/upsert operation. In particular, checks that the size
// of any cells is not too large given the configured maximum on the server, and
// that the encoded key is not too large.
@@ -432,9 +439,13 @@ class Tablet {
// Return the list of RowSets that need to be consulted when processing the
// given insertion or mutation.
- static std::vector<RowSet*> FindRowSetsToCheck(RowOp* op,
+ static std::vector<RowSet*> FindRowSetsToCheck(const RowOp* op,
const TabletComponents* comps);
+ // For each of the operations in 'tx_state', check for the presence of their
+ // row keys in the RowSets in the current RowSetTree (as determined by the transaction's
+ // captured TabletComponents).
+ void BulkCheckPresence(WriteTransactionState* tx_state);
// Capture a set of iterators which, together, reflect all of the data in the tablet.
//
http://git-wip-us.apache.org/repos/asf/kudu/blob/4568f2a4/src/kudu/tablet/transactions/write_transaction.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/write_transaction.cc b/src/kudu/tablet/transactions/write_transaction.cc
index 7efd276..592635e 100644
--- a/src/kudu/tablet/transactions/write_transaction.cc
+++ b/src/kudu/tablet/transactions/write_transaction.cc
@@ -262,6 +262,17 @@ void WriteTransactionState::SetRowOps(vector<DecodedRowOperation> decoded_ops) {
for (DecodedRowOperation& op : decoded_ops) {
row_ops_.push_back(arena->NewObject<RowOp>(std::move(op)));
}
+
+ // Allocate the ProbeStats objects from the transaction's arena, so
+ // they're all contiguous and we don't need to do any central allocation.
+ stats_array_ = static_cast<ProbeStats*>(
+ arena->AllocateBytesAligned(sizeof(ProbeStats) * row_ops_.size(),
+ alignof(ProbeStats)));
+
+ // Manually run the constructor to clear the stats to 0 before collecting them.
+ for (int i = 0; i < row_ops_.size(); i++) {
+ new (&stats_array_[i]) ProbeStats();
+ }
}
void WriteTransactionState::StartApplying() {
http://git-wip-us.apache.org/repos/asf/kudu/blob/4568f2a4/src/kudu/tablet/transactions/write_transaction.h
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/transactions/write_transaction.h b/src/kudu/tablet/transactions/write_transaction.h
index aa25a8e..da03433 100644
--- a/src/kudu/tablet/transactions/write_transaction.h
+++ b/src/kudu/tablet/transactions/write_transaction.h
@@ -26,6 +26,7 @@
#include "kudu/gutil/macros.h"
#include "kudu/tablet/lock_manager.h"
#include "kudu/tablet/mvcc.h"
+#include "kudu/tablet/rowset.h"
#include "kudu/tablet/tablet.pb.h"
#include "kudu/tablet/transactions/transaction.h"
#include "kudu/util/locks.h"
@@ -158,6 +159,13 @@ class WriteTransactionState : public TransactionState {
return row_ops_;
}
+ // Return the ProbeStats object collecting statistics for op index 'i'.
+ ProbeStats* mutable_op_stats(int i) {
+ DCHECK_LT(i, row_ops_.size());
+ DCHECK(stats_array_);
+ return &stats_array_[i];
+ }
+
// Set the 'row_ops' member based on the given decoded operations.
void SetRowOps(std::vector<DecodedRowOperation> decoded_ops);
@@ -192,6 +200,10 @@ class WriteTransactionState : public TransactionState {
// Protected by superclass's txn_state_lock_.
std::vector<RowOp*> row_ops_;
+ // Array of ProbeStats for each of the operations in 'row_ops_'.
+ // Allocated from this transaction's arena during SetRowOps().
+ ProbeStats* stats_array_ = nullptr;
+
// The MVCC transaction, set up during PREPARE phase
gscoped_ptr<ScopedTransaction> mvcc_tx_;