Skip to content

Commit

Permalink
[c++-client] reduce in-flight-op partition key lifetime
Browse files Browse the repository at this point in the history
This commit changes the C++ MetaCache to take the lookup partition key
by value, and updates Batcher to pass the partition key by move when
calling the MetaCache. Additionally, the partition key is no longer
stored as a field in the InFlightOp. The effect is that the InFlightOp
is smaller by the size of a std::string, and the lifetime of the
partition key is reduced from when the InFlightOp is complete to when
the meta cache lookup is complete.

Change-Id: Ia949b65a9447979c9c5eff324448af307a1db1b7
Reviewed-on: http://gerrit.cloudera.org:8080/4114
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <[email protected]>
Reviewed-by: Adar Dembo <[email protected]>
  • Loading branch information
danburkert authored and adembo committed Aug 24, 2016
1 parent 2976b2a commit effcd2c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 3 additions & 5 deletions src/kudu/client/batcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ struct InFlightOp {
// The actual operation.
gscoped_ptr<KuduWriteOperation> write_op;

string partition_key;

// The tablet the operation is destined for.
// This is only filled in after passing through the kLookingUpTablet state.
scoped_refptr<RemoteTablet> tablet;
Expand Down Expand Up @@ -531,8 +529,8 @@ Status Batcher::Add(KuduWriteOperation* write_op) {
// As soon as we get the op, start looking up where it belongs,
// so that when the user calls Flush, we are ready to go.
gscoped_ptr<InFlightOp> op(new InFlightOp());
RETURN_NOT_OK(write_op->table_->partition_schema()
.EncodeKey(write_op->row(), &op->partition_key));
string partition_key;
RETURN_NOT_OK(write_op->table_->partition_schema().EncodeKey(write_op->row(), &partition_key));
op->write_op.reset(write_op);
op->state = InFlightOp::kLookingUpTablet;

Expand All @@ -547,7 +545,7 @@ Status Batcher::Add(KuduWriteOperation* write_op) {
base::RefCountInc(&outstanding_lookups_);
client_->data_->meta_cache_->LookupTabletByKey(
op->write_op->table(),
op->partition_key,
std::move(partition_key),
deadline,
&op->tablet,
Bind(&Batcher::TabletLookupFinished, this, op.get()));
Expand Down
8 changes: 4 additions & 4 deletions src/kudu/client/meta_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -947,14 +947,14 @@ void MetaCache::ClearCache() {
}

void MetaCache::LookupTabletByKey(const KuduTable* table,
const string& partition_key,
string partition_key,
const MonoTime& deadline,
scoped_refptr<RemoteTablet>* remote_tablet,
const StatusCallback& callback) {
LookupRpc* rpc = new LookupRpc(this,
callback,
table,
partition_key,
std::move(partition_key),
remote_tablet,
deadline,
client_->data_->messenger_,
Expand All @@ -963,14 +963,14 @@ void MetaCache::LookupTabletByKey(const KuduTable* table,
}

void MetaCache::LookupTabletByKeyOrNext(const KuduTable* table,
const string& partition_key,
string partition_key,
const MonoTime& deadline,
scoped_refptr<RemoteTablet>* remote_tablet,
const StatusCallback& callback) {
LookupRpc* rpc = new LookupRpc(this,
callback,
table,
partition_key,
std::move(partition_key),
remote_tablet,
deadline,
client_->data_->messenger_,
Expand Down
4 changes: 2 additions & 2 deletions src/kudu/client/meta_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,15 @@ class MetaCache : public RefCountedThreadSafe<MetaCache> {
// NOTE: the memory referenced by 'table' must remain valid until 'callback'
// is invoked.
void LookupTabletByKey(const KuduTable* table,
const std::string& partition_key,
std::string partition_key,
const MonoTime& deadline,
scoped_refptr<RemoteTablet>* remote_tablet,
const StatusCallback& callback);

// Look up which tablet hosts the given partition key, or the next tablet if
// the key falls in a non-covered range partition.
void LookupTabletByKeyOrNext(const KuduTable* table,
const std::string& partition_key,
std::string partition_key,
const MonoTime& deadline,
scoped_refptr<RemoteTablet>* remote_tablet,
const StatusCallback& callback);
Expand Down

0 comments on commit effcd2c

Please sign in to comment.