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 2018/03/30 18:33:04 UTC
[1/5] kudu git commit: util: use uint64_t values for resource limits
and adjust usages
Repository: kudu
Updated Branches:
refs/heads/master 61d3fff2f -> 3634672e8
util: use uint64_t values for resource limits and adjust usages
Turns out rlim_t is an unsigned 64-bit type, and although a root shell on my
laptop won't let me set RLIMIT_NOFILE particularly high, I can set
RLIMIT_NPROC to any value, and even to RLIM_INFINITY (-1).
So to handle every value correctly, we should really be treating these as
uint64_t rather than int64_t. That also gives us correct RLIM_INFINITY
handling for free, because -1 becomes kuint64max. This also effectively
reverts commit 17aceda.
However, not all callers expect uint64_t values, so some conversion is still
necessary. I also took the opportunity to beef up how the resource limits
were used by incorporating the values of /proc/sys/kernel/pid_max,
/proc/sys/kernel/threads-max, and /proc/sys/fs/file-max as upper bounds.
Change-Id: I7e9bb71af886f732f36a8c93876f47e7591aeadb
Reviewed-on: http://gerrit.cloudera.org:8080/9806
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/bae6170c
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/bae6170c
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/bae6170c
Branch: refs/heads/master
Commit: bae6170c77e12b45c83cea3ef15d8047029f47db
Parents: 61d3fff
Author: Adar Dembo <ad...@cloudera.com>
Authored: Mon Mar 26 13:45:53 2018 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 30 01:29:39 2018 +0000
----------------------------------------------------------------------
src/kudu/fs/block_manager.cc | 27 ++++++++++++++++++-------
src/kudu/kserver/kserver.cc | 42 ++++++++++++++++++++++++++++-----------
src/kudu/util/env.h | 7 +++----
src/kudu/util/env_posix.cc | 11 +++++-----
4 files changed, 58 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/bae6170c/src/kudu/fs/block_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/fs/block_manager.cc b/src/kudu/fs/block_manager.cc
index 71a3075..94b4590 100644
--- a/src/kudu/fs/block_manager.cc
+++ b/src/kudu/fs/block_manager.cc
@@ -17,15 +17,19 @@
#include "kudu/fs/block_manager.h"
+#include <algorithm>
#include <mutex>
#include <ostream>
#include <gflags/gflags.h>
#include <glog/logging.h>
+#include "kudu/gutil/integral_types.h"
#include "kudu/gutil/macros.h"
+#include "kudu/gutil/strings/numbers.h"
#include "kudu/gutil/strings/substitute.h"
#include "kudu/util/env.h"
+#include "kudu/util/faststring.h"
#include "kudu/util/flag_tags.h"
// The default value is optimized for throughput in the case that
@@ -51,15 +55,14 @@ TAG_FLAG(block_manager_preflush_control, experimental);
DEFINE_int64(block_manager_max_open_files, -1,
"Maximum number of open file descriptors to be used for data "
- "blocks. If -1, Kudu will use 40% of its resource limit as per "
- "getrlimit(). This is a soft limit. It is an error to use a "
- "value of 0.");
+ "blocks. If -1, Kudu will automatically calculate this value. "
+ "This is a soft limit. It is an error to use a value of 0.");
TAG_FLAG(block_manager_max_open_files, advanced);
TAG_FLAG(block_manager_max_open_files, evolving);
static bool ValidateMaxOpenFiles(const char* /*flagname*/, int64_t value) {
- if (value == 0) {
- LOG(ERROR) << "Invalid max open files: cannot be 0";
+ if (value == 0 || value < -1) {
+ LOG(ERROR) << "Invalid max open files: cannot be " << value;
return false;
}
return true;
@@ -81,11 +84,21 @@ int64_t GetFileCacheCapacityForBlockManager(Env* env) {
env->IncreaseResourceLimit(Env::ResourceLimitType::OPEN_FILES_PER_PROCESS);
});
- int64_t rlimit =
+ uint64_t rlimit =
env->GetResourceLimit(Env::ResourceLimitType::OPEN_FILES_PER_PROCESS);
// See block_manager_max_open_files.
if (FLAGS_block_manager_max_open_files == -1) {
- return (2 * rlimit) / 5;
+ // Use file-max as a possible upper bound.
+ faststring buf;
+ uint64_t buf_val;
+ if (ReadFileToString(env, "/proc/sys/fs/file-max", &buf).ok() &&
+ safe_strtou64(buf.ToString(), &buf_val)) {
+ rlimit = std::min(rlimit, buf_val);
+ }
+
+ // Callers of this function expect a signed 64-bit integer, so we need to
+ // cap rlimit just in case it's too large.
+ return std::min((2 * rlimit) / 5, static_cast<uint64_t>(kint64max));
}
LOG_IF(FATAL, FLAGS_block_manager_max_open_files > rlimit) <<
Substitute(
http://git-wip-us.apache.org/repos/asf/kudu/blob/bae6170c/src/kudu/kserver/kserver.cc
----------------------------------------------------------------------
diff --git a/src/kudu/kserver/kserver.cc b/src/kudu/kserver/kserver.cc
index b695979..512a7fb 100644
--- a/src/kudu/kserver/kserver.cc
+++ b/src/kudu/kserver/kserver.cc
@@ -17,36 +17,38 @@
#include "kudu/kserver/kserver.h"
+#include <algorithm>
#include <cstdint>
#include <memory>
#include <mutex>
#include <ostream>
#include <string>
-#include <utility>
#include <gflags/gflags.h>
#include <glog/logging.h>
#include "kudu/fs/fs_manager.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/strings/numbers.h"
#include "kudu/gutil/strings/substitute.h"
#include "kudu/rpc/messenger.h"
#include "kudu/util/env.h"
+#include "kudu/util/faststring.h"
#include "kudu/util/flag_tags.h"
#include "kudu/util/metrics.h"
#include "kudu/util/status.h"
#include "kudu/util/threadpool.h"
-DEFINE_int64(server_thread_pool_max_thread_count, -1,
+DEFINE_int32(server_thread_pool_max_thread_count, -1,
"Maximum number of threads to allow in each server-wide thread "
- "pool. If -1, Kudu will use 10% of its running thread per "
- "effective uid resource limit as per getrlimit(). It is an error "
- "to use a value of 0.");
+ "pool. If -1, Kudu will automatically calculate this value. It "
+ "is an error to use a value of 0.");
TAG_FLAG(server_thread_pool_max_thread_count, advanced);
TAG_FLAG(server_thread_pool_max_thread_count, evolving);
-static bool ValidateThreadPoolThreadLimit(const char* /*flagname*/, int64_t value) {
- if (value == 0) {
- LOG(ERROR) << "Invalid thread pool thread limit: cannot be 0";
+static bool ValidateThreadPoolThreadLimit(const char* /*flagname*/, int32_t value) {
+ if (value == 0 || value < -1) {
+ LOG(ERROR) << "Invalid thread pool thread limit: cannot be " << value;
return false;
}
return true;
@@ -85,17 +87,33 @@ METRIC_DEFINE_histogram(server, op_apply_run_time, "Operation Apply Run Time",
namespace {
-int64_t GetThreadPoolThreadLimit(Env* env) {
+int GetThreadPoolThreadLimit(Env* env) {
// Maximize this process' running thread limit first, if possible.
static std::once_flag once;
std::call_once(once, [&]() {
env->IncreaseResourceLimit(Env::ResourceLimitType::RUNNING_THREADS_PER_EUID);
});
- int64_t rlimit = env->GetResourceLimit(Env::ResourceLimitType::RUNNING_THREADS_PER_EUID);
+ uint64_t rlimit = env->GetResourceLimit(Env::ResourceLimitType::RUNNING_THREADS_PER_EUID);
// See server_thread_pool_max_thread_count.
if (FLAGS_server_thread_pool_max_thread_count == -1) {
- return rlimit / 10;
+ // Use both pid_max and threads-max as possible upper bounds.
+ faststring buf;
+ uint64_t buf_val;
+ for (const auto& proc_file : { "/proc/sys/kernel/pid_max",
+ "/proc/sys/kernel/threads-max" }) {
+ if (ReadFileToString(env, proc_file, &buf).ok() &&
+ safe_strtou64(buf.ToString(), &buf_val)) {
+ rlimit = std::min(rlimit, buf_val);
+ }
+ }
+
+ // Callers of this function expect a signed 32-bit integer, so we need to
+ // further cap the limit just in case it's too large.
+ rlimit = std::min(rlimit, static_cast<uint64_t>(kint32max));
+
+ // Take only 10% of the calculated limit; we don't want to hog the system.
+ return static_cast<int32_t>(rlimit) / 10;
}
LOG_IF(FATAL, FLAGS_server_thread_pool_max_thread_count > rlimit) <<
Substitute(
@@ -128,7 +146,7 @@ Status KuduServer::Init() {
// These pools are shared by all replicas hosted by this server, and thus
// are capped at a portion of the overall per-euid thread resource limit.
- int64_t server_wide_pool_limit = GetThreadPoolThreadLimit(fs_manager_->env());
+ int server_wide_pool_limit = GetThreadPoolThreadLimit(fs_manager_->env());
RETURN_NOT_OK(ThreadPoolBuilder("prepare")
.set_max_threads(server_wide_pool_limit)
.Build(&tablet_prepare_pool_));
http://git-wip-us.apache.org/repos/asf/kudu/blob/bae6170c/src/kudu/util/env.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/env.h b/src/kudu/util/env.h
index 279dc18..5cf357e 100644
--- a/src/kudu/util/env.h
+++ b/src/kudu/util/env.h
@@ -319,12 +319,11 @@ class Env {
RUNNING_THREADS_PER_EUID,
};
- // Gets the process' current limit for the given resource type.
- //
- // Returns kint32max if the limit exceeds kint32max or if there is no limit.
+ // Gets the process' current limit for the given resource type. If there is
+ // no limit, returns kuint64max.
//
// On UNIX platforms, this is equivalent to the resource's soft limit.
- virtual int64_t GetResourceLimit(ResourceLimitType t) = 0;
+ virtual uint64_t GetResourceLimit(ResourceLimitType t) = 0;
// Increases the resource limit by as much as possible.
//
http://git-wip-us.apache.org/repos/asf/kudu/blob/bae6170c/src/kudu/util/env_posix.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/env_posix.cc b/src/kudu/util/env_posix.cc
index a8c0c0e..9ba583b 100644
--- a/src/kudu/util/env_posix.cc
+++ b/src/kudu/util/env_posix.cc
@@ -1585,15 +1585,14 @@ class PosixEnv : public Env {
return Status::OK();
}
- virtual int64_t GetResourceLimit(ResourceLimitType t) OVERRIDE {
+ virtual uint64_t GetResourceLimit(ResourceLimitType t) OVERRIDE {
+ static_assert(RLIM_INFINITY == kuint64max,
+ "RLIM_INFINITY is assumed to be 2^64 - 1");
+
// There's no reason for this to ever fail.
struct rlimit l;
PCHECK(getrlimit(ResourceLimitTypeToUnixRlimit(t), &l) == 0);
-
- // RLIM_INFINITY is defined to -1, which will be 2^64-1 when converted to
- // rlim_cur's type (uint64_t). Thus it'll also be captured by the
- // comparison and converted into kint32max.
- return l.rlim_cur > kint32max ? kint32max : l.rlim_cur;
+ return l.rlim_cur;
}
virtual void IncreaseResourceLimit(ResourceLimitType t) OVERRIDE {
[2/5] kudu git commit: rpc-test: fix multi-threaded test from running
too long
Posted by to...@apache.org.
rpc-test: fix multi-threaded test from running too long
In TSAN builds this test was taking several minutes. This makes the test
run based on a timer rather than an explicit count.
Change-Id: I827a07d5b1d2463cb845ef6b04ec36036b2ddfbb
Reviewed-on: http://gerrit.cloudera.org:8080/9856
Reviewed-by: Sailesh Mukil <sa...@cloudera.com>
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Tested-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/5508ae7c
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/5508ae7c
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/5508ae7c
Branch: refs/heads/master
Commit: 5508ae7c7e81a026abd2786bd958de4774d56458
Parents: bae6170
Author: Todd Lipcon <to...@apache.org>
Authored: Thu Mar 29 13:57:08 2018 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 30 01:58:04 2018 +0000
----------------------------------------------------------------------
src/kudu/rpc/rpc-test.cc | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/5508ae7c/src/kudu/rpc/rpc-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/rpc-test.cc b/src/kudu/rpc/rpc-test.cc
index 85f82eb..61a619f 100644
--- a/src/kudu/rpc/rpc-test.cc
+++ b/src/kudu/rpc/rpc-test.cc
@@ -1264,7 +1264,11 @@ static void SendAndCancelRpcs(Proxy* p, const Slice& slice) {
// Used to generate sleep time between invoking RPC and requesting cancellation.
Random rand(SeedRandom());
- for (int i = 0; i < 40; ++i) {
+ auto end_time = MonoTime::Now() + MonoDelta::FromSeconds(
+ AllowSlowTests() ? 15 : 3);
+
+ int i = 0;
+ while (MonoTime::Now() < end_time) {
controller.Reset();
PushTwoStringsRequestPB request;
PushTwoStringsResponsePB resp;
@@ -1279,7 +1283,7 @@ static void SendAndCancelRpcs(Proxy* p, const Slice& slice) {
request, &resp, &controller,
boost::bind(&CountDownLatch::CountDown, boost::ref(latch)));
- if ((i % 8) != 0) {
+ if ((i++ % 8) != 0) {
// Sleep for a while before cancelling the RPC.
SleepFor(MonoDelta::FromMicroseconds(rand.Uniform64(100)));
controller.Cancel();
[4/5] kudu git commit: KUDU-2388. Fix TSAN race in
MaintenanceManager::UnregisterOp
Posted by to...@apache.org.
KUDU-2388. Fix TSAN race in MaintenanceManager::UnregisterOp
This fixes the following TSAN race:
WARNING: ThreadSanitizer: data race (pid=17822) Read of size 1 at 0x7b4c000054e8 by thread T59 (mutexes: write M1750):
...
#3 strings::internal::SubstituteArg::SubstituteArg(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) /data/somelongdirectorytoavoidrpathissues/src/kudu/src/kudu/gutil/strings/substitute.h:76 (libtserver.so+0x9edb0)
#4 kudu::MaintenanceManager::LogPrefix() const /data/somelongdirectorytoavoidrpathissues/src/kudu/src/kudu/util/maintenance_manager.cc:545:31 (libkudu_util.so+0x167791)
#5 kudu::MaintenanceManager::UnregisterOp(kudu::MaintenanceOp*) /data/somelongdirectorytoavoidrpathissues/src/kudu/src/kudu/util/maintenance_manager.cc:235:3 (libkudu_util.so+0x165963)
#6 kudu::MaintenanceOp::Unregister() /data/somelongdirectorytoavoidrpathissues/src/kudu/src/kudu/util/maintenance_manager.cc:123:13 (libkudu_util.so+0x1654fe)
#7 kudu::tablet::Tablet::UnregisterMaintenanceOps() /data/somelongdirectorytoavoidrpathissues/src/kudu/src/kudu/tablet/tablet.cc:1405:9 (libtablet.so+0xfb5af)
#8 kudu::tablet::TabletReplica::Stop() /data/somelongdirectorytoavoidrpathissues/src/kudu/src/kudu/tablet/tablet_replica.cc:271:25 (libtablet.so+0x146e66)
#9 kudu::tserver::TSTabletManager::DeleteTablet(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > c
Previous write of size 8 at 0x7b4c000054e8 by main thread:
#0 memcpy /data/somelongdirectorytoavoidrpathissues/src/kudu/thirdparty/src/llvm-4.0.0.src/projects/compiler-rt/lib/tsan/../sanitizer_common/sanitizer_common_interceptors.inc:655 (kudu-tserver+0x449e4c)
#1 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__move_assign(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::integral_constant<bool, true>) /data/somelongdirectorytoavoidrpathissues/src/kudu/thirdparty/installed/tsan/include/c++/v1/string:2044:18 (libkudu_util.so+0x16664d)
#2 std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) /data/somelongdirectorytoavoidrpathissues/src/kudu/thirdparty/installed/tsan/include/c++/v1/string:2055 (libkudu_util.so+0x16664d)
#3 kudu::MaintenanceManager::Init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) /data/somelongdirectorytoavoidrpathissues/src/kudu/src/kudu/util/maintenance_manager.cc:169 (libkudu_util.so+0x16664d)
...
The race is on the 'server_uuid_' field in the MaintenanceManager. This is set
during startup, but was being set _after_ calls such as UnregisterOp could be
made as seen above. That means the UnregisterOp call could either see an empty
UUID or even crash due to the above race.
This simply rejiggers the MaintenanceManager startup to take the UUID in as a
constructor parameter instead, and to instantiate the object slightly later
during startup.
Change-Id: Id06731f56eb98146f7b88541b936c0026b781b16
Reviewed-on: http://gerrit.cloudera.org:8080/9866
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/51e2ca40
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/51e2ca40
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/51e2ca40
Branch: refs/heads/master
Commit: 51e2ca40d17d34e953d188432afa1d4025d45b99
Parents: b2b8fb7
Author: Todd Lipcon <to...@apache.org>
Authored: Thu Mar 29 20:17:08 2018 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 30 16:06:16 2018 +0000
----------------------------------------------------------------------
src/kudu/master/master.cc | 8 +++++---
src/kudu/tserver/tablet_server.cc | 8 +++++---
src/kudu/util/maintenance_manager-test.cc | 4 ++--
src/kudu/util/maintenance_manager.cc | 12 +++++++-----
src/kudu/util/maintenance_manager.h | 8 +++++---
5 files changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/51e2ca40/src/kudu/master/master.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/master.cc b/src/kudu/master/master.cc
index ad09f47..ce16a46 100644
--- a/src/kudu/master/master.cc
+++ b/src/kudu/master/master.cc
@@ -100,8 +100,7 @@ Master::Master(const MasterOptions& opts)
catalog_manager_(new CatalogManager(this)),
path_handlers_(new MasterPathHandlers(this)),
opts_(opts),
- registration_initialized_(false),
- maintenance_manager_(new MaintenanceManager(MaintenanceManager::kDefaultOptions)) {
+ registration_initialized_(false) {
}
Master::~Master() {
@@ -128,6 +127,9 @@ Status Master::Init() {
RETURN_NOT_OK(path_handlers_->Register(web_server_.get()));
}
+ maintenance_manager_.reset(new MaintenanceManager(
+ MaintenanceManager::kDefaultOptions, fs_manager_->uuid()));
+
// The certificate authority object is initialized upon loading
// CA private key and certificate from the system table when the server
// becomes a leader.
@@ -152,7 +154,7 @@ Status Master::Start() {
Status Master::StartAsync() {
CHECK_EQ(kInitialized, state_);
- RETURN_NOT_OK(maintenance_manager_->Init(fs_manager_->uuid()));
+ RETURN_NOT_OK(maintenance_manager_->Start());
gscoped_ptr<ServiceIf> impl(new MasterServiceImpl(this));
gscoped_ptr<ServiceIf> consensus_service(new ConsensusServiceImpl(
http://git-wip-us.apache.org/repos/asf/kudu/blob/51e2ca40/src/kudu/tserver/tablet_server.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_server.cc b/src/kudu/tserver/tablet_server.cc
index 8fdb85d..efbbe03 100644
--- a/src/kudu/tserver/tablet_server.cc
+++ b/src/kudu/tserver/tablet_server.cc
@@ -56,8 +56,7 @@ TabletServer::TabletServer(const TabletServerOptions& opts)
opts_(opts),
tablet_manager_(new TSTabletManager(this)),
scanner_manager_(new ScannerManager(metric_entity())),
- path_handlers_(new TabletServerPathHandlers(this)),
- maintenance_manager_(new MaintenanceManager(MaintenanceManager::kDefaultOptions)) {
+ path_handlers_(new TabletServerPathHandlers(this)) {
}
TabletServer::~TabletServer() {
@@ -95,6 +94,9 @@ Status TabletServer::Init() {
RETURN_NOT_OK(path_handlers_->Register(web_server_.get()));
}
+ maintenance_manager_.reset(new MaintenanceManager(
+ MaintenanceManager::kDefaultOptions, fs_manager_->uuid()));
+
heartbeater_.reset(new Heartbeater(opts_, this));
RETURN_NOT_OK_PREPEND(tablet_manager_->Init(),
@@ -130,7 +132,7 @@ Status TabletServer::Start() {
RETURN_NOT_OK(KuduServer::Start());
RETURN_NOT_OK(heartbeater_->Start());
- RETURN_NOT_OK(maintenance_manager_->Init(fs_manager_->uuid()));
+ RETURN_NOT_OK(maintenance_manager_->Start());
google::FlushLogFiles(google::INFO); // Flush the startup messages.
http://git-wip-us.apache.org/repos/asf/kudu/blob/51e2ca40/src/kudu/util/maintenance_manager-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/maintenance_manager-test.cc b/src/kudu/util/maintenance_manager-test.cc
index 1889139..6777e06 100644
--- a/src/kudu/util/maintenance_manager-test.cc
+++ b/src/kudu/util/maintenance_manager-test.cc
@@ -70,12 +70,12 @@ class MaintenanceManagerTest : public KuduTest {
options.num_threads = 2;
options.polling_interval_ms = 1;
options.history_size = kHistorySize;
- manager_.reset(new MaintenanceManager(options));
+ manager_.reset(new MaintenanceManager(options, kFakeUuid));
manager_->set_memory_pressure_func_for_tests(
[&](double* consumption) {
return indicate_memory_pressure_.load();
});
- ASSERT_OK(manager_->Init(kFakeUuid));
+ ASSERT_OK(manager_->Start());
}
void TearDown() override {
http://git-wip-us.apache.org/repos/asf/kudu/blob/51e2ca40/src/kudu/util/maintenance_manager.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/maintenance_manager.cc b/src/kudu/util/maintenance_manager.cc
index 2694d6c..9a42464 100644
--- a/src/kudu/util/maintenance_manager.cc
+++ b/src/kudu/util/maintenance_manager.cc
@@ -141,9 +141,11 @@ const MaintenanceManager::Options MaintenanceManager::kDefaultOptions = {
.history_size = 0,
};
-MaintenanceManager::MaintenanceManager(const Options& options)
- : num_threads_(options.num_threads <= 0 ?
- FLAGS_maintenance_manager_num_threads : options.num_threads),
+MaintenanceManager::MaintenanceManager(const Options& options,
+ std::string server_uuid)
+ : server_uuid_(std::move(server_uuid)),
+ num_threads_(options.num_threads <= 0 ?
+ FLAGS_maintenance_manager_num_threads : options.num_threads),
cond_(&lock_),
shutdown_(false),
polling_interval_ms_(options.polling_interval_ms <= 0 ?
@@ -165,8 +167,8 @@ MaintenanceManager::~MaintenanceManager() {
Shutdown();
}
-Status MaintenanceManager::Init(std::string server_uuid) {
- server_uuid_ = std::move(server_uuid);
+Status MaintenanceManager::Start() {
+ CHECK(!monitor_thread_);
RETURN_NOT_OK(Thread::Create("maintenance", "maintenance_scheduler",
boost::bind(&MaintenanceManager::RunSchedulerThread, this),
&monitor_thread_));
http://git-wip-us.apache.org/repos/asf/kudu/blob/51e2ca40/src/kudu/util/maintenance_manager.h
----------------------------------------------------------------------
diff --git a/src/kudu/util/maintenance_manager.h b/src/kudu/util/maintenance_manager.h
index dc36f67..7d20c8a 100644
--- a/src/kudu/util/maintenance_manager.h
+++ b/src/kudu/util/maintenance_manager.h
@@ -274,10 +274,12 @@ class MaintenanceManager : public std::enable_shared_from_this<MaintenanceManage
uint32_t history_size;
};
- explicit MaintenanceManager(const Options& options);
+ MaintenanceManager(const Options& options, std::string server_uuid);
~MaintenanceManager();
- Status Init(std::string server_uuid);
+ // Start running the maintenance manager.
+ // Must be called at most once.
+ Status Start();
void Shutdown();
// Register an op with the manager.
@@ -318,6 +320,7 @@ class MaintenanceManager : public std::enable_shared_from_this<MaintenanceManage
std::string LogPrefix() const;
+ const std::string server_uuid_;
const int32_t num_threads_;
OpMapTy ops_; // registered operations
Mutex lock_;
@@ -331,7 +334,6 @@ class MaintenanceManager : public std::enable_shared_from_this<MaintenanceManage
// the completed_ops_count_ % the vector's size and then the count needs to be incremented.
std::vector<OpInstance> completed_ops_;
int64_t completed_ops_count_;
- std::string server_uuid_;
Random rand_;
// Function which should return true if the server is under global memory pressure.
[5/5] kudu git commit: KUDU-2393. Fix flaky DebugUtilTest.TestSnapshot
Posted by to...@apache.org.
KUDU-2393. Fix flaky DebugUtilTest.TestSnapshot
This test was flaky with two different failure modes which I believe
have the same root cause: when the test starts, it's possible that there
is still some thread from a prior test case in the process of shutting
down. Even though we join() on our threads religiously, there is a very
short period of time after join() returns where the dying thread is
still listed in /proc/self/task/. This meant that we would sometimes
fail the assertion that checks that the number of returned stacks
matches the number of running threads (because the thread finished
exiting just before we called SnapshotAllStacks). In other cases we
would still see that exiting thread, but it would exit before responding
to our stack trace signal, so we'd see a "timed out" response.
The fix is a little hacky - we calculate the expected number of running
threads and ASSERT_EVENTUALLY to wait until reality matches
expectations.
Change-Id: I2f0fc29877b4d67a3720e47f4183684891f09bc0
Reviewed-on: http://gerrit.cloudera.org:8080/9864
Reviewed-by: Todd Lipcon <to...@apache.org>
Tested-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/3634672e
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/3634672e
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/3634672e
Branch: refs/heads/master
Commit: 3634672e8381037d84bf516adbff6f6d62a226d1
Parents: 51e2ca4
Author: Todd Lipcon <to...@apache.org>
Authored: Thu Mar 29 19:38:34 2018 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 30 16:07:40 2018 +0000
----------------------------------------------------------------------
src/kudu/util/debug-util-test.cc | 36 +++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/3634672e/src/kudu/util/debug-util-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/debug-util-test.cc b/src/kudu/util/debug-util-test.cc
index b44c207..25e4ae0 100644
--- a/src/kudu/util/debug-util-test.cc
+++ b/src/kudu/util/debug-util-test.cc
@@ -30,7 +30,9 @@
#include <string>
#include <vector>
+#include <gflags/gflags_declare.h>
#include <glog/logging.h>
+#include <glog/stl_logging.h>
#include <gtest/gtest.h>
#include "kudu/gutil/ref_counted.h"
@@ -38,6 +40,7 @@
#include "kudu/util/array_view.h"
#include "kudu/util/countdown_latch.h"
#include "kudu/util/debug-util.h"
+#include "kudu/util/kernel_stack_watchdog.h"
#include "kudu/util/monotime.h"
#include "kudu/util/scoped_cleanup.h"
#include "kudu/util/status.h"
@@ -48,6 +51,9 @@
using std::string;
using std::vector;
+DECLARE_int32(test_timeout_after);
+DECLARE_int32(stress_cpu_threads);
+
namespace kudu {
class DebugUtilTest : public KuduTest {
@@ -154,15 +160,33 @@ TEST_F(DebugUtilTest, TestSignalStackTrace) {
// We don't validate the results in any way -- but this verifies that we can
// dump library threads such as the libc timer_thread and properly time out.
TEST_F(DebugUtilTest, TestSnapshot) {
+ // HACK: prior tests in this suite start threads. Even though they Join on the
+ // threads before the test case finishes, there is actually a very short
+ // period of time after Join() returns but before the actual thread has exited
+ // and removed itself from /proc/self/task/. That means that 'ListThreads' below
+ // can sometimes show these threads from prior test cases, and then the assertions
+ // in this test case would fail.
+ //
+ // So, we have to wait here for the number of running threads to level off to the
+ // expected value.
+ // Ensure Kernel Stack Watchdog is running.
+ KernelStackWatchdog::GetInstance();
+ int initial_thread_count =
+ 1 // main thread
+ + 1 // KernelStackWatchdog
+ + (FLAGS_test_timeout_after > 0 ? 1 : 0) // test timeout thread if running
+ + FLAGS_stress_cpu_threads;
+#ifdef THREAD_SANITIZER
+ initial_thread_count++; // tsan signal thread
+#endif
// The test and runtime environment runs various utility threads (for example,
// the kernel stack watchdog, the TSAN runtime thread, the test timeout thread, etc).
// Count them before we start any additional threads for this test.
- int initial_thread_count;
- {
- vector<pid_t> threads;
- ASSERT_OK(ListThreads(&threads));
- initial_thread_count = threads.size();
- }
+ ASSERT_EVENTUALLY([&]{
+ vector<pid_t> threads;
+ ASSERT_OK(ListThreads(&threads));
+ ASSERT_EQ(initial_thread_count, threads.size()) << threads;
+ });
// Start a bunch of sleeping threads.
const int kNumThreads = 30;
[3/5] kudu git commit: KUDU-1977. Avoid extra reference counting for
fast-path MetaCache lookups
Posted by to...@apache.org.
KUDU-1977. Avoid extra reference counting for fast-path MetaCache lookups
This does a bit of refactoring of MetaCache so that fast-path lookups
can occur without allocating a LookupRpc object. This avoids an
allocation/deallocation pair as well as reference counting overhead on
various objects. The reference counting was seen as a bottleneck in a
workload like:
$ kudu perf loadgen -num-threads 16 \
-num-rows-per-thread $[10*1000*1000] -table-num-replicas 3 \
-table-num-buckets=100 <master>
I ran before/after on the above command writing into a large (100+-node
cluster) that I had handy. A few key stats:
Before:
time total : 90676.3 ms
1458961.567442 task-clock (msec) # 15.954 CPUs utilized
Top lines of profile:
27.21% kudu kudu [.] kudu::client::internal::MetaCache::LookupTabletByKeyFastPath
14.95% kudu kudu [.] kudu::subtle::RefCountedThreadSafeBase::AddRef
12.52% kudu kudu [.] kudu::subtle::RefCountedThreadSafeBase::Release
4.75% kudu kudu [.] kudu::client::internal::MetaCache::LookupTabletByKey
3.04% kudu kudu [.] operator new[]
1.78% rpc reactor-387 kudu [.] std::unordered_set<InFlightOp*>::erase
After:
time total : 60796.6 ms
693975.355549 task-clock (msec) # 11.154 CPUs utilized
Top lines of profile:
14.05% kudu kudu [.] kudu::client::internal::MetaCache::LookupTabletByKeyFastPath
7.89% kudu kudu [.] operator new[]
4.96% rpc reactor-397 kudu [.] std::unordered_set<InFlightOp*>::erase
4.47% kudu libc-2.17.so [.] __memcpy_ssse3_back
3.42% rpc reactor-397 kudu [.] kudu::client::KuduInsert::~KuduInsert
In other words, this reduced CPU by more than 2x and throughput by about 50%.
Results on the above were relatively stable across multiple runs, with
wall-clock showing more variance than CPU-time.
The new bottleneck seems to be the rw_spinlock in MetaCache.
Change-Id: I5f17ffa88289c766b5b168b22da9781bf78f5592
Reviewed-on: http://gerrit.cloudera.org:8080/9753
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Tested-by: Kudu Jenkins
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/b2b8fb74
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/b2b8fb74
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/b2b8fb74
Branch: refs/heads/master
Commit: b2b8fb74dc564b5e55af6406982e80f2efa19f3c
Parents: 5508ae7
Author: Todd Lipcon <to...@apache.org>
Authored: Wed Mar 21 20:34:34 2018 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 30 03:16:08 2018 +0000
----------------------------------------------------------------------
src/kudu/client/batcher.cc | 1 +
src/kudu/client/client-test.cc | 15 +--
src/kudu/client/meta_cache.cc | 144 +++++++++++++++------------
src/kudu/client/meta_cache.h | 45 ++++++---
src/kudu/client/partitioner-internal.cc | 5 +-
src/kudu/client/scan_token-internal.cc | 14 +--
src/kudu/client/scanner-internal.cc | 12 ++-
src/kudu/client/schema.h | 2 +
8 files changed, 140 insertions(+), 98 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/b2b8fb74/src/kudu/client/batcher.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/batcher.cc b/src/kudu/client/batcher.cc
index 1b7e2b8..6e30970 100644
--- a/src/kudu/client/batcher.cc
+++ b/src/kudu/client/batcher.cc
@@ -601,6 +601,7 @@ Status Batcher::Add(KuduWriteOperation* write_op) {
op->write_op->table(),
std::move(partition_key),
deadline,
+ MetaCache::LookupType::kPoint,
&op->tablet,
Bind(&Batcher::TabletLookupFinished, this, op.get()));
IgnoreResult(op.release());
http://git-wip-us.apache.org/repos/asf/kudu/blob/b2b8fb74/src/kudu/client/client-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index 5b37ca1..a227b15 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -204,8 +204,11 @@ class ClientTest : public KuduTest {
const string& partition_key) {
scoped_refptr<internal::RemoteTablet> rt;
Synchronizer sync;
- client_->data_->meta_cache_->LookupTabletByKey(table, partition_key, MonoTime::Max(), &rt,
- sync.AsStatusCallback());
+ client_->data_->meta_cache_->LookupTabletByKey(
+ table, partition_key, MonoTime::Max(),
+ internal::MetaCache::LookupType::kPoint,
+ &rt,
+ sync.AsStatusCallback());
CHECK_OK(sync.Wait());
return rt;
}
@@ -1790,21 +1793,21 @@ TEST_F(ClientTest, TestMetaCacheExpiry) {
// Clear the cache.
meta_cache->ClearCache();
internal::MetaCacheEntry entry;
- ASSERT_FALSE(meta_cache->LookupTabletByKeyFastPath(client_table_.get(), "", &entry));
+ ASSERT_FALSE(meta_cache->LookupEntryByKeyFastPath(client_table_.get(), "", &entry));
// Prime the cache.
CHECK_NOTNULL(MetaCacheLookup(client_table_.get(), "").get());
- ASSERT_TRUE(meta_cache->LookupTabletByKeyFastPath(client_table_.get(), "", &entry));
+ ASSERT_TRUE(meta_cache->LookupEntryByKeyFastPath(client_table_.get(), "", &entry));
ASSERT_FALSE(entry.stale());
// Sleep in order to expire the cache.
SleepFor(MonoDelta::FromMilliseconds(FLAGS_table_locations_ttl_ms));
ASSERT_TRUE(entry.stale());
- ASSERT_FALSE(meta_cache->LookupTabletByKeyFastPath(client_table_.get(), "", &entry));
+ ASSERT_FALSE(meta_cache->LookupEntryByKeyFastPath(client_table_.get(), "", &entry));
// Force a lookup and ensure the entry is refreshed.
CHECK_NOTNULL(MetaCacheLookup(client_table_.get(), "").get());
- ASSERT_TRUE(meta_cache->LookupTabletByKeyFastPath(client_table_.get(), "", &entry));
+ ASSERT_TRUE(meta_cache->LookupEntryByKeyFastPath(client_table_.get(), "", &entry));
ASSERT_FALSE(entry.stale());
}
http://git-wip-us.apache.org/repos/asf/kudu/blob/b2b8fb74/src/kudu/client/meta_cache.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/meta_cache.cc b/src/kudu/client/meta_cache.cc
index a204773..aa77741 100644
--- a/src/kudu/client/meta_cache.cc
+++ b/src/kudu/client/meta_cache.cc
@@ -18,7 +18,6 @@
#include "kudu/client/meta_cache.h"
#include <algorithm>
-#include <cstddef>
#include <mutex>
#include <ostream>
#include <set>
@@ -329,8 +328,7 @@ string MetaCacheEntry::DebugString(const KuduTable* table) const {
const string& lower_bound = lower_bound_partition_key();
const string& upper_bound = upper_bound_partition_key();
- string lower_bound_string = lower_bound.empty() ? "<start>" :
- table->partition_schema().PartitionKeyDebugString(lower_bound, *table->schema().schema_);
+ string lower_bound_string = MetaCache::DebugLowerBoundPartitionKey(table, lower_bound);
string upper_bound_string = upper_bound.empty() ? "<end>" :
table->partition_schema().PartitionKeyDebugString(upper_bound, *table->schema().schema_);
@@ -443,7 +441,8 @@ void MetaCacheServerPicker::PickLeader(const ServerPickedCallback& callback,
table_,
tablet_->partition().partition_key_start(),
deadline,
- NULL,
+ MetaCache::LookupType::kPoint,
+ nullptr,
Bind(&MetaCacheServerPicker::LookUpTabletCb, Unretained(this), callback, deadline));
return;
}
@@ -540,11 +539,12 @@ class LookupRpc : public Rpc {
scoped_refptr<RemoteTablet>* remote_tablet,
const MonoTime& deadline,
shared_ptr<Messenger> messenger,
- int max_returned_locations,
- bool is_exact_lookup,
+ MetaCache::LookupType lookup_type,
ReplicaController::Visibility replica_visibility);
virtual ~LookupRpc();
virtual void SendRpc() OVERRIDE;
+ // Send the next RPC without consulting the metacache.
+ void SendRpcSlowPath();
virtual string ToString() const OVERRIDE;
const GetTableLocationsRequestPB& req() const { return req_; }
@@ -552,7 +552,18 @@ class LookupRpc : public Rpc {
const string& table_name() const { return table_->name(); }
const string& table_id() const { return table_->id(); }
const string& partition_key() const { return partition_key_; }
- bool is_exact_lookup() const { return is_exact_lookup_; }
+ bool is_exact_lookup() const {
+ return lookup_type_ == MetaCache::LookupType::kPoint;
+ }
+ int locations_to_fetch() const {
+ switch (lookup_type_) {
+ case MetaCache::LookupType::kLowerBound:
+ return kFetchTabletsPerRangeLookup;
+ case MetaCache::LookupType::kPoint:
+ return kFetchTabletsPerPointLookup;
+ }
+ __builtin_unreachable();
+ }
const KuduTable* table() const { return table_; }
private:
@@ -597,13 +608,8 @@ class LookupRpc : public Rpc {
// Whether this lookup has acquired a master lookup permit.
bool has_permit_;
- // The max number of tablets to fetch per round trip from the master
- const int max_returned_locations_;
-
- // If true, this lookup is for an exact tablet match with the requested
- // partition key. If false, the next tablet after the partition key should be
- // returned if the partition key falls in a non-covered partition range.
- const bool is_exact_lookup_;
+ // Whether this lookup is for a range or a point.
+ const MetaCache::LookupType lookup_type_;
// Controlling which replicas to look up. If set to Visibility::ALL,
// non-voter tablet replicas, if any, appear in the lookup result in addition
@@ -617,8 +623,7 @@ LookupRpc::LookupRpc(scoped_refptr<MetaCache> meta_cache,
scoped_refptr<RemoteTablet>* remote_tablet,
const MonoTime& deadline,
shared_ptr<Messenger> messenger,
- int max_returned_locations,
- bool is_exact_lookup,
+ MetaCache::LookupType lookup_type,
ReplicaController::Visibility replica_visibility)
: Rpc(deadline, std::move(messenger)),
meta_cache_(std::move(meta_cache)),
@@ -627,8 +632,7 @@ LookupRpc::LookupRpc(scoped_refptr<MetaCache> meta_cache,
partition_key_(std::move(partition_key)),
remote_tablet_(remote_tablet),
has_permit_(false),
- max_returned_locations_(max_returned_locations),
- is_exact_lookup_(is_exact_lookup),
+ lookup_type_(lookup_type),
replica_visibility_(replica_visibility) {
DCHECK(deadline.Initialized());
}
@@ -640,28 +644,17 @@ LookupRpc::~LookupRpc() {
}
void LookupRpc::SendRpc() {
- // Fast path: lookup in the cache.
- MetaCacheEntry entry;
- while (PREDICT_TRUE(meta_cache_->LookupTabletByKeyFastPath(table_, partition_key_, &entry))
- && (entry.is_non_covered_range() || entry.tablet()->HasLeader())) {
- VLOG(4) << "Fast lookup: found " << entry.DebugString(table_) << " for " << ToString();
- if (!entry.is_non_covered_range()) {
- if (remote_tablet_) {
- *remote_tablet_ = entry.tablet();
- }
- user_cb_.Run(Status::OK());
- delete this;
- return;
- }
- if (is_exact_lookup_ || entry.upper_bound_partition_key().empty()) {
- user_cb_.Run(Status::NotFound("No tablet covering the requested range partition",
- entry.DebugString(table_)));
- delete this;
- return;
- }
- partition_key_ = entry.upper_bound_partition_key();
+ Status fastpath_status = meta_cache_->DoFastPathLookup(
+ table_, &partition_key_, lookup_type_, remote_tablet_);
+ if (!fastpath_status.IsIncomplete()) {
+ user_cb_.Run(fastpath_status);
+ delete this;
+ return;
}
+ SendRpcSlowPath();
+}
+void LookupRpc::SendRpcSlowPath() {
// Slow path: must lookup the tablet in the master.
VLOG(4) << "Fast lookup: no cache entry for " << ToString()
<< ": refreshing our metadata from the Master";
@@ -679,7 +672,7 @@ void LookupRpc::SendRpc() {
// Fill out the request.
req_.mutable_table()->set_table_id(table_->id());
req_.set_partition_key_start(partition_key_);
- req_.set_max_returned_locations(max_returned_locations_);
+ req_.set_max_returned_locations(locations_to_fetch());
if (replica_visibility_ == ReplicaController::Visibility::ALL) {
req_.set_replica_type_filter(master::ANY_REPLICA);
}
@@ -705,9 +698,7 @@ void LookupRpc::SendRpc() {
string LookupRpc::ToString() const {
return Substitute("GetTableLocations { table: '$0', partition-key: ($1), attempt: $2 }",
table_->name(),
- (partition_key_.empty() ? "<start>" :
- table_->partition_schema()
- .PartitionKeyDebugString(partition_key_, *table_->schema().schema_)),
+ MetaCache::DebugLowerBoundPartitionKey(table_, partition_key_),
num_attempts());
}
@@ -806,7 +797,7 @@ void LookupRpc::SendRpcCb(const Status& status) {
if (new_status.ok()) {
MetaCacheEntry entry;
- new_status = meta_cache_->ProcessLookupResponse(*this, &entry, max_returned_locations_);
+ new_status = meta_cache_->ProcessLookupResponse(*this, &entry, locations_to_fetch());
if (entry.is_non_covered_range()) {
new_status = Status::NotFound("No tablet covering the requested range partition",
entry.DebugString(table_));
@@ -967,9 +958,9 @@ Status MetaCache::ProcessLookupResponse(const LookupRpc& rpc,
return Status::OK();
}
-bool MetaCache::LookupTabletByKeyFastPath(const KuduTable* table,
- const string& partition_key,
- MetaCacheEntry* entry) {
+bool MetaCache::LookupEntryByKeyFastPath(const KuduTable* table,
+ const string& partition_key,
+ MetaCacheEntry* entry) {
shared_lock<rw_spinlock> l(lock_);
const TabletMap* tablets = FindOrNull(tablets_by_table_and_key_, table->id());
if (PREDICT_FALSE(!tablets)) {
@@ -996,6 +987,30 @@ bool MetaCache::LookupTabletByKeyFastPath(const KuduTable* table,
return false;
}
+Status MetaCache::DoFastPathLookup(const KuduTable* table,
+ string* partition_key,
+ MetaCache::LookupType lookup_type,
+ scoped_refptr<RemoteTablet>* remote_tablet) {
+ MetaCacheEntry entry;
+ while (PREDICT_TRUE(LookupEntryByKeyFastPath(table, *partition_key, &entry))
+ && (entry.is_non_covered_range() || entry.tablet()->HasLeader())) {
+ VLOG(4) << "Fast lookup: found " << entry.DebugString(table) << " for "
+ << DebugLowerBoundPartitionKey(table, *partition_key);
+ if (!entry.is_non_covered_range()) {
+ if (remote_tablet) {
+ *remote_tablet = entry.tablet();
+ }
+ return Status::OK();
+ }
+ if (lookup_type == LookupType::kPoint || entry.upper_bound_partition_key().empty()) {
+ return Status::NotFound("No tablet covering the requested range partition",
+ entry.DebugString(table));
+ }
+ *partition_key = entry.upper_bound_partition_key();
+ }
+ return Status::Incomplete("");
+}
+
void MetaCache::ClearNonCoveredRangeEntries(const std::string& table_id) {
VLOG(3) << "Clearing non-covered range entries of table " << table_id;
std::lock_guard<rw_spinlock> l(lock_);
@@ -1026,26 +1041,18 @@ void MetaCache::ClearCache() {
void MetaCache::LookupTabletByKey(const KuduTable* table,
string partition_key,
const MonoTime& deadline,
+ MetaCache::LookupType lookup_type,
scoped_refptr<RemoteTablet>* remote_tablet,
const StatusCallback& callback) {
- LookupRpc* rpc = new LookupRpc(this,
- callback,
- table,
- std::move(partition_key),
- remote_tablet,
- deadline,
- client_->data_->messenger_,
- kFetchTabletsPerPointLookup,
- true, replica_visibility_);
- rpc->SendRpc();
-}
+ // Try a fast path without allocating a LookupRpc.
+ // This avoids the allocation and also reference count increment/decrements.
+ Status fastpath_status = DoFastPathLookup(
+ table, &partition_key, lookup_type, remote_tablet);
+ if (!fastpath_status.IsIncomplete()) {
+ callback.Run(fastpath_status);
+ return;
+ }
-void MetaCache::LookupTabletByKeyOrNext(const KuduTable* table,
- string partition_key,
- const MonoTime& deadline,
- scoped_refptr<RemoteTablet>* remote_tablet,
- const StatusCallback& callback,
- int max_returned_locations) {
LookupRpc* rpc = new LookupRpc(this,
callback,
table,
@@ -1053,9 +1060,9 @@ void MetaCache::LookupTabletByKeyOrNext(const KuduTable* table,
remote_tablet,
deadline,
client_->data_->messenger_,
- max_returned_locations,
- false, replica_visibility_);
- rpc->SendRpc();
+ lookup_type,
+ replica_visibility_);
+ rpc->SendRpcSlowPath();
}
void MetaCache::MarkTSFailed(RemoteTabletServer* ts,
@@ -1081,6 +1088,11 @@ void MetaCache::ReleaseMasterLookupPermit() {
master_lookup_sem_.Release();
}
+string MetaCache::DebugLowerBoundPartitionKey(const KuduTable* table, const string& partition_key) {
+ return partition_key.empty() ? "<start>" :
+ table->partition_schema().PartitionKeyDebugString(partition_key, *table->schema().schema_);
+}
+
} // namespace internal
} // namespace client
} // namespace kudu
http://git-wip-us.apache.org/repos/asf/kudu/blob/b2b8fb74/src/kudu/client/meta_cache.h
----------------------------------------------------------------------
diff --git a/src/kudu/client/meta_cache.h b/src/kudu/client/meta_cache.h
index ec003b7..34232bc 100644
--- a/src/kudu/client/meta_cache.h
+++ b/src/kudu/client/meta_cache.h
@@ -373,6 +373,17 @@ class MetaCache : public RefCountedThreadSafe<MetaCache> {
MetaCache(KuduClient* client, ReplicaController::Visibility replica_visibility);
~MetaCache();
+ // Determines what type of operation a MetaCache lookup is being done for.
+ enum class LookupType {
+ // The lookup should only return a tablet which actually covers the
+ // requested partition key.
+ kPoint,
+ // The lookup should return the next tablet after the requested
+ // partition key if the requested key does not fall within a covered
+ // range.
+ kLowerBound
+ };
+
// Look up which tablet hosts the given partition key for a table. When it is
// available, the tablet is stored in 'remote_tablet' (if not NULL) and the
// callback is fired. Only tablets with non-failed LEADERs are considered.
@@ -385,18 +396,10 @@ class MetaCache : public RefCountedThreadSafe<MetaCache> {
void LookupTabletByKey(const KuduTable* table,
std::string partition_key,
const MonoTime& deadline,
+ LookupType lookup_type,
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,
- std::string partition_key,
- const MonoTime& deadline,
- scoped_refptr<RemoteTablet>* remote_tablet,
- const StatusCallback& callback,
- int max_returned_locations = kFetchTabletsPerPointLookup);
-
// Clears the non-covered range entries from a table's meta cache.
void ClearNonCoveredRangeEntries(const std::string& table_id);
@@ -414,6 +417,10 @@ class MetaCache : public RefCountedThreadSafe<MetaCache> {
bool AcquireMasterLookupPermit();
void ReleaseMasterLookupPermit();
+ // Return stringified representation of the given partition key, using "<start>" if empty.
+ static std::string DebugLowerBoundPartitionKey(const KuduTable* table,
+ const std::string& partition_key);
+
private:
friend class LookupRpc;
@@ -427,10 +434,22 @@ class MetaCache : public RefCountedThreadSafe<MetaCache> {
int max_returned_locations);
// Lookup the given tablet by key, only consulting local information.
- // Returns true and sets *remote_tablet if successful.
- bool LookupTabletByKeyFastPath(const KuduTable* table,
- const std::string& partition_key,
- MetaCacheEntry* entry);
+ // Returns true and sets *entry if successful.
+ bool LookupEntryByKeyFastPath(const KuduTable* table,
+ const std::string& partition_key,
+ MetaCacheEntry* entry);
+
+ // Perform the complete fast-path lookup. Returns:
+ // - NotFound if the lookup hits a non-covering range.
+ // - Incomplete if the fast path was not possible
+ // - OK if the lookup was successful.
+ //
+ // If 'lookup_type' is kLowerBound, then 'partition_key' will be updated to indicate the
+ // start of the range for the matched tablet.
+ Status DoFastPathLookup(const KuduTable* table,
+ std::string* partition_key, // in-out parameter
+ LookupType lookup_type,
+ scoped_refptr<RemoteTablet>* remote_tablet);
// Update our information about the given tablet server.
//
http://git-wip-us.apache.org/repos/asf/kudu/blob/b2b8fb74/src/kudu/client/partitioner-internal.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/partitioner-internal.cc b/src/kudu/client/partitioner-internal.cc
index 0f4458f..826d402 100644
--- a/src/kudu/client/partitioner-internal.cc
+++ b/src/kudu/client/partitioner-internal.cc
@@ -53,8 +53,9 @@ Status KuduPartitionerBuilder::Data::Build(KuduPartitioner** partitioner) {
while (true) {
scoped_refptr<internal::RemoteTablet> tablet;
Synchronizer sync;
- mc->LookupTabletByKeyOrNext(table_.get(), next_part_key, deadline,
- &tablet, sync.AsStatusCallback());
+ mc->LookupTabletByKey(table_.get(), next_part_key, deadline,
+ internal::MetaCache::LookupType::kLowerBound,
+ &tablet, sync.AsStatusCallback());
Status s = sync.Wait();
if (s.IsNotFound()) {
// No more tablets
http://git-wip-us.apache.org/repos/asf/kudu/blob/b2b8fb74/src/kudu/client/scan_token-internal.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/scan_token-internal.cc b/src/kudu/client/scan_token-internal.cc
index beb43ad..21fc786 100644
--- a/src/kudu/client/scan_token-internal.cc
+++ b/src/kudu/client/scan_token-internal.cc
@@ -62,6 +62,8 @@ using strings::Substitute;
namespace kudu {
namespace client {
+using internal::MetaCache;
+
KuduScanToken::Data::Data(KuduTable* table,
ScanTokenPB message,
unique_ptr<KuduTablet> tablet)
@@ -283,12 +285,12 @@ Status KuduScanTokenBuilder::Data::Build(vector<KuduScanToken*>* tokens) {
scoped_refptr<internal::RemoteTablet> tablet;
Synchronizer sync;
const string& partition_key = pruner.NextPartitionKey();
- client->data_->meta_cache_->LookupTabletByKeyOrNext(table,
- partition_key,
- deadline,
- &tablet,
- sync.AsStatusCallback(),
- internal::kFetchTabletsPerRangeLookup);
+ client->data_->meta_cache_->LookupTabletByKey(table,
+ partition_key,
+ deadline,
+ MetaCache::LookupType::kLowerBound,
+ &tablet,
+ sync.AsStatusCallback());
Status s = sync.Wait();
if (s.IsNotFound()) {
// No more tablets in the table.
http://git-wip-us.apache.org/repos/asf/kudu/blob/b2b8fb74/src/kudu/client/scanner-internal.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/scanner-internal.cc b/src/kudu/client/scanner-internal.cc
index ea67ec2..f2bb4e8 100644
--- a/src/kudu/client/scanner-internal.cc
+++ b/src/kudu/client/scanner-internal.cc
@@ -390,11 +390,13 @@ Status KuduScanner::Data::OpenTablet(const string& partition_key,
for (int attempt = 1;; attempt++) {
Synchronizer sync;
- table_->client()->data_->meta_cache_->LookupTabletByKeyOrNext(table_.get(),
- partition_key,
- deadline,
- &remote_,
- sync.AsStatusCallback());
+ table_->client()->data_->meta_cache_->LookupTabletByKey(
+ table_.get(),
+ partition_key,
+ deadline,
+ internal::MetaCache::LookupType::kLowerBound,
+ &remote_,
+ sync.AsStatusCallback());
Status s = sync.Wait();
if (s.IsNotFound()) {
// No more tablets in the table.
http://git-wip-us.apache.org/repos/asf/kudu/blob/b2b8fb74/src/kudu/client/schema.h
----------------------------------------------------------------------
diff --git a/src/kudu/client/schema.h b/src/kudu/client/schema.h
index 279a79d..79abbfc 100644
--- a/src/kudu/client/schema.h
+++ b/src/kudu/client/schema.h
@@ -53,6 +53,7 @@ namespace client {
namespace internal {
class GetTableSchemaRpc;
class LookupRpc;
+class MetaCache;
class MetaCacheEntry;
class WriteRpc;
} // namespace internal
@@ -581,6 +582,7 @@ class KUDU_EXPORT KuduSchema {
friend class ScanConfiguration;
friend class internal::GetTableSchemaRpc;
friend class internal::LookupRpc;
+ friend class internal::MetaCache;
friend class internal::MetaCacheEntry;
friend class internal::WriteRpc;
friend class tools::RemoteKsckMaster;