You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by he...@apache.org on 2017/03/29 02:53:42 UTC

[01/14] incubator-impala git commit: IMPALA-5031: Remove undefined behavior: left shift of negative values

Repository: incubator-impala
Updated Branches:
  refs/heads/master 874d20d0f -> 23100102c


IMPALA-5031: Remove undefined behavior: left shift of negative values

Left shift of negative values is undefined According to C++14 section
5.8 [expr.shift], paragraph 2.

Change-Id: I9d965c3950a878c0a41b374d51bbe2e5705b3360
Reviewed-on: http://gerrit.cloudera.org:8080/6491
Reviewed-by: Dan Hecht <dh...@cloudera.com>
Reviewed-by: Tim Armstrong <ta...@cloudera.com>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/4aa8e2d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/4aa8e2d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/4aa8e2d5

Branch: refs/heads/master
Commit: 4aa8e2d5cf590d6366a600f15bed3e998ccc4031
Parents: 874d20d
Author: Jim Apple <jb...@apache.org>
Authored: Sat Mar 25 13:35:19 2017 -0700
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Tue Mar 28 22:16:25 2017 +0000

----------------------------------------------------------------------
 be/src/exec/read-write-util.cc        | 4 ++--
 be/src/exec/zigzag-test.cc            | 2 +-
 be/src/exprs/bit-byte-functions-ir.cc | 4 +++-
 3 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/4aa8e2d5/be/src/exec/read-write-util.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/read-write-util.cc b/be/src/exec/read-write-util.cc
index 1ae98c3..ef9f412 100644
--- a/be/src/exec/read-write-util.cc
+++ b/be/src/exec/read-write-util.cc
@@ -93,7 +93,7 @@ ReadWriteUtil::ReadZInteger<ReadWriteUtil::MAX_ZINT_LEN, ReadWriteUtil::ZIntResu
 
 int ReadWriteUtil::PutZInt(int32_t integer, uint8_t* buf) {
   // Move the sign bit to the first bit.
-  uint32_t uinteger = (integer << 1) ^ (integer >> 31);
+  uint32_t uinteger = (static_cast<uint32_t>(integer) << 1) ^ (integer >> 31);
   const int mask = 0x7f;
   const int cont = 0x80;
   buf[0] = uinteger & mask;
@@ -110,7 +110,7 @@ int ReadWriteUtil::PutZInt(int32_t integer, uint8_t* buf) {
 
 int ReadWriteUtil::PutZLong(int64_t longint, uint8_t* buf) {
   // Move the sign bit to the first bit.
-  uint64_t ulongint = (longint << 1) ^ (longint >> 63);
+  uint64_t ulongint = (static_cast<uint64_t>(longint) << 1) ^ (longint >> 63);
   const int mask = 0x7f;
   const int cont = 0x80;
   buf[0] = ulongint & mask;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/4aa8e2d5/be/src/exec/zigzag-test.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/zigzag-test.cc b/be/src/exec/zigzag-test.cc
index 87b686c..ea9363f 100644
--- a/be/src/exec/zigzag-test.cc
+++ b/be/src/exec/zigzag-test.cc
@@ -98,7 +98,7 @@ TEST(ZigzagTest, Basic) {
     value = HashUtil::Hash(&value, sizeof (value), i);
     TestZInt(value);
     TestZLong(value);
-    TestZLong((static_cast<int64_t>(value) << 32) | value);
+    TestZLong((static_cast<uint64_t>(value) << 32) | value);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/4aa8e2d5/be/src/exprs/bit-byte-functions-ir.cc
----------------------------------------------------------------------
diff --git a/be/src/exprs/bit-byte-functions-ir.cc b/be/src/exprs/bit-byte-functions-ir.cc
index c2208ad..3464174 100644
--- a/be/src/exprs/bit-byte-functions-ir.cc
+++ b/be/src/exprs/bit-byte-functions-ir.cc
@@ -158,7 +158,9 @@ static T RotateRightImpl(T v, int32_t shift) {
 
   // Handle wrapping around multiple times
   shift = shift % (sizeof(T) * 8);
-  return BitUtil::ShiftRightLogical(v, shift) | (v << (sizeof(T) * 8 - shift));
+  using UnsignedT = std::make_unsigned_t<T>;
+  return BitUtil::ShiftRightLogical(v, shift)
+      | (static_cast<UnsignedT>(v) << (sizeof(T) * 8 - shift));
 }
 
 template<typename T>


[02/14] incubator-impala git commit: IMPALA-4041: Limit catalog and admission control updates to coordinators

Posted by he...@apache.org.
IMPALA-4041: Limit catalog and admission control updates to coordinators

With this commit we add the ability to limit catalog updates to a
limited set of coordinator nodes. A new startup option, termed
'is_coordinator' is added to indicate if a node is a coordinator.
Coordinators accept connections through HS2 and Beeswax interfaces
and can also participate in query execution. Non-coordinator nodes
do not receive catalog updates from the statestore, do not initialize
a query scheduler and cannot accept Beeswax and HS2 client connections.

Testing:
- Added a custom cluster test that launches a cluster in which the
number of coordinators is less than the cluster size and runs a number
of smoke queries.
- Successfully run exhaustive tests.

Change-Id: I5f2c74abdbcd60ac050efa323616bd41182ceff3
Reviewed-on: http://gerrit.cloudera.org:8080/6344
Reviewed-by: Dimitris Tsirogiannis <dt...@cloudera.com>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/296df3c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/296df3c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/296df3c8

Branch: refs/heads/master
Commit: 296df3c8269b7be16120397d60e97b6f24fc390b
Parents: 4aa8e2d
Author: Dimitris Tsirogiannis <dt...@cloudera.com>
Authored: Thu Mar 9 15:24:51 2017 -0800
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Tue Mar 28 22:27:25 2017 +0000

----------------------------------------------------------------------
 be/src/runtime/exec-env.cc                |  53 +++++---
 be/src/runtime/exec-env.h                 |   7 +-
 be/src/scheduling/admission-controller.cc |  26 ++--
 be/src/scheduling/admission-controller.h  |  11 +-
 be/src/scheduling/scheduler-test-util.cc  |  16 +--
 be/src/scheduling/scheduler-test.cc       |   9 +-
 be/src/scheduling/scheduler.cc            |  89 +++----------
 be/src/scheduling/scheduler.h             |   8 +-
 be/src/service/impala-server.cc           | 173 +++++++++++++++++--------
 be/src/service/impala-server.h            |  18 ++-
 be/src/service/impalad-main.cc            |  24 ++--
 be/src/service/query-exec-state.cc        |  19 ++-
 be/src/testutil/in-process-servers.h      |   9 +-
 be/src/util/webserver.cc                  |  33 +++--
 bin/start-impala-cluster.py               |  24 +++-
 tests/common/custom_cluster_test_suite.py |   7 +-
 tests/common/impala_service.py            |  14 ++
 tests/custom_cluster/test_coordinators.py |  86 ++++++++++++
 www/root.tmpl                             |   4 +
 19 files changed, 415 insertions(+), 215 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/runtime/exec-env.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/exec-env.cc b/be/src/runtime/exec-env.cc
index 611520c..dd27a91 100644
--- a/be/src/runtime/exec-env.cc
+++ b/be/src/runtime/exec-env.cc
@@ -40,6 +40,7 @@
 #include "runtime/query-exec-mgr.h"
 #include "runtime/thread-resource-mgr.h"
 #include "runtime/tmp-file-mgr.h"
+#include "scheduling/admission-controller.h"
 #include "scheduling/request-pool-service.h"
 #include "scheduling/scheduler.h"
 #include "service/frontend.h"
@@ -79,12 +80,14 @@ DEFINE_int32(state_store_subscriber_port, 23000,
     "port where StatestoreSubscriberService should be exported");
 DEFINE_int32(num_hdfs_worker_threads, 16,
     "(Advanced) The number of threads in the global HDFS operation pool");
+DEFINE_bool(disable_admission_control, false, "Disables admission control.");
 
 DECLARE_int32(state_store_port);
 DECLARE_int32(num_threads_per_core);
 DECLARE_int32(num_cores);
 DECLARE_int32(be_port);
 DECLARE_string(mem_limit);
+DECLARE_bool(is_coordinator);
 
 // TODO: Remove the following RM-related flags in Impala 3.0.
 DEFINE_bool(enable_rm, false, "Deprecated");
@@ -123,7 +126,7 @@ const static string DEFAULT_FS = "fs.defaultFS";
 
 namespace impala {
 
-ExecEnv* ExecEnv::exec_env_ = NULL;
+ExecEnv* ExecEnv::exec_env_ = nullptr;
 
 ExecEnv::ExecEnv()
   : metrics_(new MetricGroup("impala-metrics")),
@@ -139,7 +142,7 @@ ExecEnv::ExecEnv()
     htable_factory_(new HBaseTableFactory()),
     disk_io_mgr_(new DiskIoMgr()),
     webserver_(new Webserver()),
-    mem_tracker_(NULL),
+    mem_tracker_(nullptr),
     pool_mem_trackers_(new PoolMemTrackerRegistry),
     thread_mgr_(new ThreadResourceMgr),
     hdfs_op_thread_pool_(
@@ -168,10 +171,19 @@ ExecEnv::ExecEnv()
         Substitute("impalad@$0", TNetworkAddressToString(backend_address_)),
         subscriber_address, statestore_address, metrics_.get()));
 
-    scheduler_.reset(new Scheduler(statestore_subscriber_.get(),
-        statestore_subscriber_->id(), backend_address_, metrics_.get(), webserver_.get(),
-        request_pool_service_.get()));
-  } else {
+    if (FLAGS_is_coordinator) {
+      scheduler_.reset(new Scheduler(statestore_subscriber_.get(),
+          statestore_subscriber_->id(), backend_address_, metrics_.get(),
+          webserver_.get(), request_pool_service_.get()));
+    }
+
+    if (!FLAGS_disable_admission_control) {
+      admission_controller_.reset(new AdmissionController(statestore_subscriber_.get(),
+          request_pool_service_.get(), metrics_.get(), backend_address_));
+    } else {
+      LOG(INFO) << "Admission control is disabled.";
+    }
+  } else if (FLAGS_is_coordinator) {
     vector<TNetworkAddress> addresses;
     addresses.push_back(MakeNetworkAddress(FLAGS_hostname, FLAGS_be_port));
     scheduler_.reset(new Scheduler(
@@ -196,7 +208,7 @@ ExecEnv::ExecEnv(const string& hostname, int backend_port, int subscriber_port,
     htable_factory_(new HBaseTableFactory()),
     disk_io_mgr_(new DiskIoMgr()),
     webserver_(new Webserver(webserver_port)),
-    mem_tracker_(NULL),
+    mem_tracker_(nullptr),
     pool_mem_trackers_(new PoolMemTrackerRegistry),
     thread_mgr_(new ThreadResourceMgr),
     hdfs_op_thread_pool_(
@@ -208,7 +220,7 @@ ExecEnv::ExecEnv(const string& hostname, int backend_port, int subscriber_port,
     async_rpc_pool_(new CallableThreadPool("rpc-pool", "async-rpc-sender", 8, 10000)),
     query_exec_mgr_(new QueryExecMgr()),
     buffer_reservation_(nullptr),
-    buffer_pool_(NULL),
+    buffer_pool_(nullptr),
     enable_webserver_(FLAGS_enable_webserver && webserver_port > 0),
     is_fe_tests_(false),
     backend_address_(MakeNetworkAddress(FLAGS_hostname, FLAGS_be_port)) {
@@ -224,10 +236,18 @@ ExecEnv::ExecEnv(const string& hostname, int backend_port, int subscriber_port,
         Substitute("impalad@$0", TNetworkAddressToString(backend_address_)),
         subscriber_address, statestore_address, metrics_.get()));
 
-    scheduler_.reset(new Scheduler(statestore_subscriber_.get(),
-        statestore_subscriber_->id(), backend_address_, metrics_.get(), webserver_.get(),
-        request_pool_service_.get()));
-  } else {
+    if (FLAGS_is_coordinator) {
+      scheduler_.reset(new Scheduler(statestore_subscriber_.get(),
+          statestore_subscriber_->id(), backend_address_, metrics_.get(),
+          webserver_.get(), request_pool_service_.get()));
+    }
+
+    if (FLAGS_disable_admission_control) LOG(INFO) << "Admission control is disabled.";
+    if (!FLAGS_disable_admission_control) {
+      admission_controller_.reset(new AdmissionController(statestore_subscriber_.get(),
+          request_pool_service_.get(), metrics_.get(), backend_address_));
+    }
+  } else if (FLAGS_is_coordinator) {
     vector<TNetworkAddress> addresses;
     addresses.push_back(MakeNetworkAddress(hostname, backend_port));
     scheduler_.reset(new Scheduler(
@@ -284,7 +304,7 @@ Status ExecEnv::StartServices() {
     return Status("Failed to parse mem limit from '" + FLAGS_mem_limit + "'.");
   }
 
-  metrics_->Init(enable_webserver_ ? webserver_.get() : NULL);
+  metrics_->Init(enable_webserver_ ? webserver_.get() : nullptr);
   impalad_client_cache_->InitMetrics(metrics_.get(), "impala-server.backends");
   catalogd_client_cache_->InitMetrics(metrics_.get(), "catalog.server");
   RETURN_IF_ERROR(RegisterMemoryMetrics(metrics_.get(), true));
@@ -326,7 +346,8 @@ Status ExecEnv::StartServices() {
     LOG(INFO) << "Not starting webserver";
   }
 
-  if (scheduler_ != NULL) RETURN_IF_ERROR(scheduler_->Init());
+  if (scheduler_ != nullptr) RETURN_IF_ERROR(scheduler_->Init());
+  if (admission_controller_ != nullptr) RETURN_IF_ERROR(admission_controller_->Init());
 
   // Get the fs.defaultFS value set in core-site.xml and assign it to
   // configured_defaultFs
@@ -340,7 +361,7 @@ Status ExecEnv::StartServices() {
     default_fs_ = "hdfs://";
   }
   // Must happen after all topic registrations / callbacks are done
-  if (statestore_subscriber_.get() != NULL) {
+  if (statestore_subscriber_.get() != nullptr) {
     Status status = statestore_subscriber_->Start();
     if (!status.ok()) {
       status.AddDetail("Statestore subscriber did not start up.");
@@ -355,6 +376,6 @@ void ExecEnv::InitBufferPool(int64_t min_page_size, int64_t capacity) {
   DCHECK(buffer_pool_ == nullptr);
   buffer_pool_.reset(new BufferPool(min_page_size, capacity));
   buffer_reservation_.reset(new ReservationTracker());
-  buffer_reservation_->InitRootTracker(NULL, capacity);
+  buffer_reservation_->InitRootTracker(nullptr, capacity);
 }
 }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/runtime/exec-env.h
----------------------------------------------------------------------
diff --git a/be/src/runtime/exec-env.h b/be/src/runtime/exec-env.h
index a5777ef..87824ba 100644
--- a/be/src/runtime/exec-env.h
+++ b/be/src/runtime/exec-env.h
@@ -28,6 +28,7 @@
 
 namespace impala {
 
+class AdmissionController;
 class BufferPool;
 class CallableThreadPool;
 class DataStreamMgr;
@@ -72,10 +73,6 @@ class ExecEnv {
 
   void SetImpalaServer(ImpalaServer* server) { impala_server_ = server; }
 
-  StatestoreSubscriber* statestore_subscriber() {
-    return statestore_subscriber_.get();
-  }
-
   DataStreamMgr* stream_mgr() { return stream_mgr_.get(); }
   ImpalaBackendClientCache* impalad_client_cache() {
     return impalad_client_cache_.get();
@@ -106,6 +103,7 @@ class ExecEnv {
   void set_enable_webserver(bool enable) { enable_webserver_ = enable; }
 
   Scheduler* scheduler() { return scheduler_.get(); }
+  AdmissionController* admission_controller() { return admission_controller_.get(); }
   StatestoreSubscriber* subscriber() { return statestore_subscriber_.get(); }
 
   const TNetworkAddress& backend_address() const { return backend_address_; }
@@ -129,6 +127,7 @@ class ExecEnv {
   boost::scoped_ptr<MetricGroup> metrics_;
   boost::scoped_ptr<DataStreamMgr> stream_mgr_;
   boost::scoped_ptr<Scheduler> scheduler_;
+  boost::scoped_ptr<AdmissionController> admission_controller_;
   boost::scoped_ptr<StatestoreSubscriber> statestore_subscriber_;
   boost::scoped_ptr<ImpalaBackendClientCache> impalad_client_cache_;
   boost::scoped_ptr<CatalogServiceClientCache> catalogd_client_cache_;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/scheduling/admission-controller.cc
----------------------------------------------------------------------
diff --git a/be/src/scheduling/admission-controller.cc b/be/src/scheduling/admission-controller.cc
index 3c9947a..efec78a 100644
--- a/be/src/scheduling/admission-controller.cc
+++ b/be/src/scheduling/admission-controller.cc
@@ -199,9 +199,11 @@ string AdmissionController::PoolStats::DebugString() const {
 
 // TODO: do we need host_id_ to come from host_addr or can it just take the same id
 // the Scheduler has (coming from the StatestoreSubscriber)?
-AdmissionController::AdmissionController(RequestPoolService* request_pool_service,
-    MetricGroup* metrics, const TNetworkAddress& host_addr)
-    : request_pool_service_(request_pool_service),
+AdmissionController::AdmissionController(StatestoreSubscriber* subscriber,
+    RequestPoolService* request_pool_service, MetricGroup* metrics,
+    const TNetworkAddress& host_addr)
+    : subscriber_(subscriber),
+      request_pool_service_(request_pool_service),
       metrics_group_(metrics),
       host_id_(TNetworkAddressToString(host_addr)),
       thrift_serializer_(false),
@@ -224,10 +226,10 @@ AdmissionController::~AdmissionController() {
   dequeue_thread_->Join();
 }
 
-Status AdmissionController::Init(StatestoreSubscriber* subscriber) {
+Status AdmissionController::Init() {
   StatestoreSubscriber::UpdateCallback cb =
     bind<void>(mem_fn(&AdmissionController::UpdatePoolStats), this, _1, _2);
-  Status status = subscriber->AddTopic(IMPALA_REQUEST_QUEUE_TOPIC, true, cb);
+  Status status = subscriber_->AddTopic(IMPALA_REQUEST_QUEUE_TOPIC, true, cb);
   if (!status.ok()) {
     status.AddDetail("AdmissionController failed to register request queue topic");
   }
@@ -578,12 +580,12 @@ void AdmissionController::PoolStats::UpdateRemoteStats(const string& host_id,
   if (VLOG_ROW_IS_ON) {
     stringstream ss;
     ss << "Stats update for pool=" << name_ << " backend=" << host_id;
-    if (host_stats == NULL) ss << " topic deletion";
+    if (host_stats == nullptr) ss << " topic deletion";
     if (it != remote_stats_.end()) ss << " previous: " << DebugPoolStats(it->second);
-    if (host_stats != NULL) ss << " new: " << DebugPoolStats(*host_stats);
+    if (host_stats != nullptr) ss << " new: " << DebugPoolStats(*host_stats);
     VLOG_ROW << ss.str();
   }
-  if (host_stats == NULL) {
+  if (host_stats == nullptr) {
     if (it != remote_stats_.end()) {
       remote_stats_.erase(it);
     } else {
@@ -620,7 +622,7 @@ void AdmissionController::HandleTopicDeletions(const vector<string>& topic_delet
     string topic_backend_id;
     if (!ParsePoolTopicKey(topic_key, &pool_name, &topic_backend_id)) continue;
     if (topic_backend_id == host_id_) continue;
-    GetPoolStats(pool_name)->UpdateRemoteStats(topic_backend_id, NULL);
+    GetPoolStats(pool_name)->UpdateRemoteStats(topic_backend_id, nullptr);
   }
 }
 
@@ -705,7 +707,7 @@ void AdmissionController::PoolStats::UpdateMemTrackerStats() {
       ExecEnv::GetInstance()->pool_mem_trackers()->GetRequestPoolMemTracker(name_, false);
 
   const int64_t current_reserved =
-      tracker == NULL ? static_cast<int64_t>(0) : tracker->GetPoolMemReserved();
+      tracker == nullptr ? static_cast<int64_t>(0) : tracker->GetPoolMemReserved();
   if (current_reserved != local_stats_.backend_mem_reserved) {
     parent_->pools_for_updates_.insert(name_);
     local_stats_.backend_mem_reserved = current_reserved;
@@ -713,7 +715,7 @@ void AdmissionController::PoolStats::UpdateMemTrackerStats() {
   }
 
   const int64_t current_usage =
-      tracker == NULL ? static_cast<int64_t>(0) : tracker->consumption();
+      tracker == nullptr ? static_cast<int64_t>(0) : tracker->consumption();
   metrics_.local_backend_mem_usage->set_value(current_usage);
 }
 
@@ -797,7 +799,7 @@ void AdmissionController::DequeueLoop() {
 
       while (max_to_dequeue > 0 && !queue.empty()) {
         QueueNode* queue_node = queue.head();
-        DCHECK(queue_node != NULL);
+        DCHECK(queue_node != nullptr);
         DCHECK(!queue_node->is_admitted.IsSet());
         const QuerySchedule& schedule = queue_node->schedule;
         string not_admitted_reason;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/scheduling/admission-controller.h
----------------------------------------------------------------------
diff --git a/be/src/scheduling/admission-controller.h b/be/src/scheduling/admission-controller.h
index f0a37d8..d3ec49d 100644
--- a/be/src/scheduling/admission-controller.h
+++ b/be/src/scheduling/admission-controller.h
@@ -178,7 +178,8 @@ class ExecEnv;
 ///       better idea of what is perhaps unnecessary.
 class AdmissionController {
  public:
-  AdmissionController(RequestPoolService* request_pool_service, MetricGroup* metrics,
+  AdmissionController(StatestoreSubscriber* subscriber,
+      RequestPoolService* request_pool_service, MetricGroup* metrics,
       const TNetworkAddress& host_addr);
   ~AdmissionController();
 
@@ -196,8 +197,8 @@ class AdmissionController {
   /// This does not block.
   Status ReleaseQuery(QuerySchedule* schedule);
 
-  /// Registers with the subscription manager.
-  Status Init(StatestoreSubscriber* subscriber);
+  /// Registers the request queue topic with the statestore.
+  Status Init();
 
  private:
   class PoolStats;
@@ -206,6 +207,10 @@ class AdmissionController {
   /// Statestore topic name.
   static const std::string IMPALA_REQUEST_QUEUE_TOPIC;
 
+  /// Subscription manager used to handle admission control updates. This is not
+  /// owned by this class.
+  StatestoreSubscriber* subscriber_;
+
   /// Used for user-to-pool resolution and looking up pool configurations. Not owned by
   /// the AdmissionController.
   RequestPoolService* request_pool_service_;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/scheduling/scheduler-test-util.cc
----------------------------------------------------------------------
diff --git a/be/src/scheduling/scheduler-test-util.cc b/be/src/scheduling/scheduler-test-util.cc
index 2474f33..782379c 100644
--- a/be/src/scheduling/scheduler-test-util.cc
+++ b/be/src/scheduling/scheduler-test-util.cc
@@ -450,13 +450,13 @@ SchedulerWrapper::SchedulerWrapper(const Plan& plan)
 }
 
 Status SchedulerWrapper::Compute(bool exec_at_coord, Result* result) {
-  DCHECK(scheduler_ != NULL);
+  DCHECK(scheduler_ != nullptr);
 
   // Compute Assignment.
   FragmentScanRangeAssignment* assignment = result->AddAssignment();
-  return scheduler_->ComputeScanRangeAssignment(*scheduler_->GetBackendConfig(), 0, NULL,
-      false, plan_.scan_range_locations(), plan_.referenced_datanodes(), exec_at_coord,
-      plan_.query_options(), NULL, assignment);
+  return scheduler_->ComputeScanRangeAssignment(*scheduler_->GetBackendConfig(), 0,
+      nullptr, false, plan_.scan_range_locations(), plan_.referenced_datanodes(),
+      exec_at_coord, plan_.query_options(), nullptr, assignment);
 }
 
 void SchedulerWrapper::AddBackend(const Host& host) {
@@ -495,7 +495,7 @@ void SchedulerWrapper::SendEmptyUpdate() {
 }
 
 void SchedulerWrapper::InitializeScheduler() {
-  DCHECK(scheduler_ == NULL);
+  DCHECK(scheduler_ == nullptr);
   DCHECK_GT(plan_.cluster().NumHosts(), 0) << "Cannot initialize scheduler with 0 "
                                            << "hosts.";
   const Host& scheduler_host = plan_.cluster().hosts()[0];
@@ -504,8 +504,8 @@ void SchedulerWrapper::InitializeScheduler() {
   scheduler_backend_address.hostname = scheduler_host.ip;
   scheduler_backend_address.port = scheduler_host.be_port;
 
-  scheduler_.reset(new Scheduler(
-      NULL, scheduler_backend_id, scheduler_backend_address, &metrics_, NULL, NULL));
+  scheduler_.reset(new Scheduler(nullptr, scheduler_backend_id, scheduler_backend_address,
+      &metrics_, nullptr, nullptr));
   scheduler_->Init();
   // Initialize the scheduler backend maps.
   SendFullMembershipMap();
@@ -532,7 +532,7 @@ void SchedulerWrapper::AddHostToTopicDelta(const Host& host, TTopicDelta* delta)
 }
 
 void SchedulerWrapper::SendTopicDelta(const TTopicDelta& delta) {
-  DCHECK(scheduler_ != NULL);
+  DCHECK(scheduler_ != nullptr);
   // Wrap in topic delta map.
   StatestoreSubscriber::TopicDeltaMap delta_map;
   delta_map.emplace(Scheduler::IMPALA_MEMBERSHIP_TOPIC, delta);

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/scheduling/scheduler-test.cc
----------------------------------------------------------------------
diff --git a/be/src/scheduling/scheduler-test.cc b/be/src/scheduling/scheduler-test.cc
index 272a288..3e05c5b 100644
--- a/be/src/scheduling/scheduler-test.cc
+++ b/be/src/scheduling/scheduler-test.cc
@@ -362,8 +362,11 @@ TEST_F(SchedulerTest, TestSendUpdates) {
 }
 
 /// IMPALA-4329: Test scheduling with no backends.
-/// With the fix for IMPALA-4494, the scheduler will always register its local backend
-/// with itself, so scheduling with no backends will still succeed.
+/// With the fix for IMPALA-5058, the scheduler is no longer responsible for
+/// registering the local backend with itself. This functionality is moved to
+/// ImpalaServer::MembershipCallback() and the scheduler will receive the local
+/// backend info through the statestore update, so until that happens, scheduling
+/// should fail.
 TEST_F(SchedulerTest, TestEmptyBackendConfig) {
   Cluster cluster;
   cluster.AddHost(false, true);
@@ -377,7 +380,7 @@ TEST_F(SchedulerTest, TestEmptyBackendConfig) {
   Result result(plan);
   SchedulerWrapper scheduler(plan);
   Status status = scheduler.Compute(&result);
-  EXPECT_TRUE(status.ok());
+  EXPECT_TRUE(!status.ok());
 }
 
 /// IMPALA-4494: Test scheduling with no backends but exec_at_coord.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/scheduling/scheduler.cc
----------------------------------------------------------------------
diff --git a/be/src/scheduling/scheduler.cc b/be/src/scheduling/scheduler.cc
index 70dbcdc..a73e13a 100644
--- a/be/src/scheduling/scheduler.cc
+++ b/be/src/scheduling/scheduler.cc
@@ -30,6 +30,7 @@
 #include "gen-cpp/ImpalaInternalService_constants.h"
 #include "gen-cpp/Types_types.h"
 #include "rapidjson/rapidjson.h"
+#include "runtime/exec-env.h"
 #include "statestore/statestore-subscriber.h"
 #include "util/container-util.h"
 #include "util/metrics.h"
@@ -46,8 +47,6 @@ using namespace strings;
 DECLARE_int32(be_port);
 DECLARE_string(hostname);
 
-DEFINE_bool(disable_admission_control, false, "Disables admission control.");
-
 namespace impala {
 
 static const string LOCAL_ASSIGNMENTS_KEY("simple-scheduler.local-assignments.total");
@@ -69,17 +68,11 @@ Scheduler::Scheduler(StatestoreSubscriber* subscriber, const string& backend_id,
     statestore_subscriber_(subscriber),
     local_backend_id_(backend_id),
     thrift_serializer_(false),
-    total_assignments_(NULL),
-    total_local_assignments_(NULL),
-    initialized_(NULL),
+    total_assignments_(nullptr),
+    total_local_assignments_(nullptr),
+    initialized_(nullptr),
     request_pool_service_(request_pool_service) {
   local_backend_descriptor_.address = backend_address;
-
-  if (FLAGS_disable_admission_control) LOG(INFO) << "Admission control is disabled.";
-  if (!FLAGS_disable_admission_control) {
-    admission_controller_.reset(
-        new AdmissionController(request_pool_service_, metrics, backend_address));
-  }
 }
 
 Scheduler::Scheduler(const vector<TNetworkAddress>& backends, MetricGroup* metrics,
@@ -87,20 +80,14 @@ Scheduler::Scheduler(const vector<TNetworkAddress>& backends, MetricGroup* metri
   : backend_config_(std::make_shared<const BackendConfig>(backends)),
     metrics_(metrics),
     webserver_(webserver),
-    statestore_subscriber_(NULL),
+    statestore_subscriber_(nullptr),
     thrift_serializer_(false),
-    total_assignments_(NULL),
-    total_local_assignments_(NULL),
-    initialized_(NULL),
+    total_assignments_(nullptr),
+    total_local_assignments_(nullptr),
+    initialized_(nullptr),
     request_pool_service_(request_pool_service) {
   DCHECK(backends.size() > 0);
   local_backend_descriptor_.address = MakeNetworkAddress(FLAGS_hostname, FLAGS_be_port);
-  if (FLAGS_disable_admission_control) LOG(INFO) << "Admission control is disabled.";
-  // request_pool_service_ may be null in unit tests
-  if (request_pool_service_ != NULL && !FLAGS_disable_admission_control) {
-    admission_controller_.reset(
-        new AdmissionController(request_pool_service_, metrics, TNetworkAddress()));
-  }
 }
 
 Status Scheduler::Init() {
@@ -122,14 +109,14 @@ Status Scheduler::Init() {
 
   coord_only_backend_config_.AddBackend(local_backend_descriptor_);
 
-  if (webserver_ != NULL) {
+  if (webserver_ != nullptr) {
     Webserver::UrlCallback backends_callback =
         bind<void>(mem_fn(&Scheduler::BackendsUrlCallback), this, _1, _2);
     webserver_->RegisterUrlCallback(
         BACKENDS_WEB_PAGE, BACKENDS_TEMPLATE, backends_callback);
   }
 
-  if (statestore_subscriber_ != NULL) {
+  if (statestore_subscriber_ != nullptr) {
     StatestoreSubscriber::UpdateCallback cb =
         bind<void>(mem_fn(&Scheduler::UpdateMembership), this, _1, _2);
     Status status = statestore_subscriber_->AddTopic(IMPALA_MEMBERSHIP_TOPIC, true, cb);
@@ -137,12 +124,9 @@ Status Scheduler::Init() {
       status.AddDetail("Scheduler failed to register membership topic");
       return status;
     }
-    if (!FLAGS_disable_admission_control) {
-      RETURN_IF_ERROR(admission_controller_->Init(statestore_subscriber_));
-    }
   }
 
-  if (metrics_ != NULL) {
+  if (metrics_ != nullptr) {
     // This is after registering with the statestored, so we already have to synchronize
     // access to the backend_config_ shared_ptr.
     int num_backends = GetBackendConfig()->NumBackends();
@@ -153,8 +137,8 @@ Status Scheduler::Init() {
         metrics_->AddGauge<int64_t>(NUM_BACKENDS_KEY, num_backends);
   }
 
-  if (statestore_subscriber_ != NULL) {
-    if (webserver_ != NULL) {
+  if (statestore_subscriber_ != nullptr) {
+    if (webserver_ != nullptr) {
       const TNetworkAddress& webserver_address = webserver_->http_address();
       if (IsWildcardAddress(webserver_address.hostname)) {
         local_backend_descriptor_.__set_debug_http_address(
@@ -253,31 +237,9 @@ void Scheduler::UpdateMembership(
     }
   }
 
-  // If the local backend is not in our view of the membership list, we should add it
-  // and tell the statestore. We also ensure that it is part of our backend config.
-  if (current_membership_.find(local_backend_id_) == current_membership_.end()) {
-    new_backend_config->AddBackend(local_backend_descriptor_);
-    VLOG(1) << "Registering local backend with statestore";
-    subscriber_topic_updates->push_back(TTopicDelta());
-    TTopicDelta& update = subscriber_topic_updates->back();
-    update.topic_name = IMPALA_MEMBERSHIP_TOPIC;
-    update.topic_entries.push_back(TTopicItem());
-
-    TTopicItem& item = update.topic_entries.back();
-    item.key = local_backend_id_;
-    Status status = thrift_serializer_.Serialize(&local_backend_descriptor_, &item.value);
-    if (!status.ok()) {
-      LOG(WARNING) << "Failed to serialize Impala backend address for statestore topic:"
-                   << " " << status.GetDetail();
-      subscriber_topic_updates->pop_back();
-    }
-  }
-
-  DCHECK(new_backend_config->LookUpBackendIp(
-      local_backend_descriptor_.address.hostname, nullptr));
   SetBackendConfig(new_backend_config);
 
-  if (metrics_ != NULL) {
+  if (metrics_ != nullptr) {
     /// TODO-MT: fix this (do we even need to report it?)
     num_fragment_instances_metric_->set_value(current_membership_.size());
   }
@@ -285,7 +247,7 @@ void Scheduler::UpdateMembership(
 
 Scheduler::BackendConfigPtr Scheduler::GetBackendConfig() const {
   lock_guard<mutex> l(backend_config_lock_);
-  DCHECK(backend_config_.get() != NULL);
+  DCHECK(backend_config_.get() != nullptr);
   BackendConfigPtr backend_config = backend_config_;
   return backend_config;
 }
@@ -660,7 +622,7 @@ Status Scheduler::ComputeScanRangeAssignment(const BackendConfig& backend_config
       //   cache to worry about.
       // Remote reads will always break ties by backend rank.
       bool decide_local_assignment_by_rank = random_replica || cached_replica;
-      const IpAddr* backend_ip = NULL;
+      const IpAddr* backend_ip = nullptr;
       backend_ip = assignment_ctx.SelectLocalBackendHost(
           backend_candidates, decide_local_assignment_by_rank);
       TBackendDescriptor backend;
@@ -771,17 +733,6 @@ Status Scheduler::Schedule(QuerySchedule* schedule) {
     }
   }
   schedule->SetUniqueHosts(unique_hosts);
-
-  if (!FLAGS_disable_admission_control) {
-    RETURN_IF_ERROR(admission_controller_->AdmitQuery(schedule));
-  }
-  return Status::OK();
-}
-
-Status Scheduler::Release(QuerySchedule* schedule) {
-  if (!FLAGS_disable_admission_control) {
-    RETURN_IF_ERROR(admission_controller_->ReleaseQuery(schedule));
-  }
   return Status::OK();
 }
 
@@ -844,7 +795,7 @@ const IpAddr* Scheduler::AssignmentCtx::SelectRemoteBackendHost() {
     DCHECK_EQ(backend_config_.NumBackends(), assignment_heap_.size());
     candidate_ip = &(assignment_heap_.top().ip);
   }
-  DCHECK(candidate_ip != NULL);
+  DCHECK(candidate_ip != nullptr);
   return candidate_ip;
 }
 
@@ -866,7 +817,7 @@ int Scheduler::AssignmentCtx::GetBackendRank(const IpAddr& ip) const {
 
 void Scheduler::AssignmentCtx::SelectBackendOnHost(
     const IpAddr& backend_ip, TBackendDescriptor* backend) {
-  DCHECK(backend_config_.LookUpBackendIp(backend_ip, NULL));
+  DCHECK(backend_config_.LookUpBackendIp(backend_ip, nullptr));
   const BackendConfig::BackendList& backends_on_host =
       backend_config_.GetBackendListForHost(backend_ip);
   DCHECK(backends_on_host.size() > 0);
@@ -934,8 +885,8 @@ void Scheduler::AssignmentCtx::RecordScanRangeAssignment(
     if (is_cached) assignment_byte_counters_.cached_bytes += scan_range_length;
   }
 
-  if (total_assignments_ != NULL) {
-    DCHECK(total_local_assignments_ != NULL);
+  if (total_assignments_ != nullptr) {
+    DCHECK(total_local_assignments_ != nullptr);
     total_assignments_->Increment(1);
     if (!remote_read) total_local_assignments_->Increment(1);
   }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/scheduling/scheduler.h
----------------------------------------------------------------------
diff --git a/be/src/scheduling/scheduler.h b/be/src/scheduling/scheduler.h
index bd2aff4..ca520c8 100644
--- a/be/src/scheduling/scheduler.h
+++ b/be/src/scheduling/scheduler.h
@@ -33,9 +33,9 @@
 #include "gen-cpp/Types_types.h" // for TNetworkAddress
 #include "rapidjson/document.h"
 #include "rpc/thrift-util.h"
-#include "scheduling/admission-controller.h"
 #include "scheduling/backend-config.h"
 #include "scheduling/query-schedule.h"
+#include "scheduling/request-pool-service.h"
 #include "statestore/statestore-subscriber.h"
 #include "util/metrics.h"
 #include "util/network-util.h"
@@ -101,9 +101,6 @@ class Scheduler {
   /// returning.
   Status Schedule(QuerySchedule* schedule);
 
-  /// Releases the reserved resources (if any) from the given schedule.
-  Status Release(QuerySchedule* schedule);
-
  private:
   /// Map from a host's IP address to the next backend to be round-robin scheduled for
   /// that host (needed for setups with multiple backends on a single host)
@@ -324,9 +321,6 @@ class Scheduler {
   /// us.
   RequestPoolService* request_pool_service_;
 
-  /// Used to make admission decisions in 'Schedule()'
-  boost::scoped_ptr<AdmissionController> admission_controller_;
-
   /// Helper methods to access backend_config_ (the shared_ptr, not its contents),
   /// protecting the access with backend_config_lock_.
   BackendConfigPtr GetBackendConfig() const;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/service/impala-server.cc
----------------------------------------------------------------------
diff --git a/be/src/service/impala-server.cc b/be/src/service/impala-server.cc
index 8417cf1..313708e 100644
--- a/be/src/service/impala-server.cc
+++ b/be/src/service/impala-server.cc
@@ -177,6 +177,10 @@ DEFINE_int32(idle_query_timeout, 0, "The time, in seconds, that a query may be i
     "QUERY_TIMEOUT_S overrides this setting, but, if set, --idle_query_timeout represents"
     " the maximum allowable timeout.");
 
+DEFINE_bool(is_coordinator, true, "If true, this Impala daemon can accept and coordinate "
+    "queries from clients. If false, this daemon will only execute query fragments, and "
+    "will refuse client connections.");
+
 // TODO: Remove for Impala 3.0.
 DEFINE_string(local_nodemanager_url, "", "Deprecated");
 
@@ -244,7 +248,8 @@ class CancellationWork {
 };
 
 ImpalaServer::ImpalaServer(ExecEnv* exec_env)
-    : exec_env_(exec_env) {
+    : exec_env_(exec_env),
+      thrift_serializer_(false) {
   // Initialize default config
   InitializeConfigVariables();
 
@@ -328,15 +333,21 @@ ImpalaServer::ImpalaServer(ExecEnv* exec_env)
   ABORT_IF_ERROR(ExternalDataSourceExecutor::InitJNI(exec_env->metrics()));
 
   // Register the membership callback if required
-  if (exec_env->subscriber() != NULL) {
-    StatestoreSubscriber::UpdateCallback cb =
-        bind<void>(mem_fn(&ImpalaServer::MembershipCallback), this, _1, _2);
+  if (exec_env->subscriber() != nullptr) {
+    auto cb = [this] (const StatestoreSubscriber::TopicDeltaMap& state,
+         vector<TTopicDelta>* topic_updates) {
+      this->MembershipCallback(state, topic_updates);
+    };
     exec_env->subscriber()->AddTopic(Scheduler::IMPALA_MEMBERSHIP_TOPIC, true, cb);
 
-    StatestoreSubscriber::UpdateCallback catalog_cb =
-        bind<void>(mem_fn(&ImpalaServer::CatalogUpdateCallback), this, _1, _2);
-    exec_env->subscriber()->AddTopic(
-        CatalogServer::IMPALA_CATALOG_TOPIC, true, catalog_cb);
+    if (FLAGS_is_coordinator) {
+      auto catalog_cb = [this] (const StatestoreSubscriber::TopicDeltaMap& state,
+          vector<TTopicDelta>* topic_updates) {
+        this->CatalogUpdateCallback(state, topic_updates);
+      };
+      exec_env->subscriber()->AddTopic(CatalogServer::IMPALA_CATALOG_TOPIC, true,
+          catalog_cb);
+    }
   }
 
   ABORT_IF_ERROR(UpdateCatalogMetrics());
@@ -358,6 +369,7 @@ ImpalaServer::ImpalaServer(ExecEnv* exec_env)
   query_expiration_thread_.reset(new Thread("impala-server", "query-expirer",
       bind<void>(&ImpalaServer::ExpireQueries, this)));
 
+  is_coordinator_ = FLAGS_is_coordinator;
   exec_env_->SetImpalaServer(this);
 }
 
@@ -392,6 +404,8 @@ Status ImpalaServer::LogLineageRecord(const QueryExecState& query_exec_state) {
   return status;
 }
 
+bool ImpalaServer::IsCoordinator() { return is_coordinator_; }
+
 bool ImpalaServer::IsLineageLoggingEnabled() {
   return !FLAGS_lineage_event_log_dir.empty();
 }
@@ -562,7 +576,7 @@ Status ImpalaServer::InitProfileLogging() {
 
 Status ImpalaServer::GetRuntimeProfileStr(const TUniqueId& query_id,
     bool base64_encoded, stringstream* output) {
-  DCHECK(output != NULL);
+  DCHECK(output != nullptr);
   // Search for the query id in the active query map
   {
     shared_ptr<QueryExecState> exec_state = GetQueryExecState(query_id, false);
@@ -599,9 +613,9 @@ Status ImpalaServer::GetExecSummary(const TUniqueId& query_id, TExecSummary* res
   // Search for the query id in the active query map.
   {
     shared_ptr<QueryExecState> exec_state = GetQueryExecState(query_id, true);
-    if (exec_state != NULL) {
+    if (exec_state != nullptr) {
       lock_guard<mutex> l(*exec_state->lock(), adopt_lock_t());
-      if (exec_state->coord() != NULL) {
+      if (exec_state->coord() != nullptr) {
         TExecProgress progress;
         {
           lock_guard<SpinLock> lock(exec_state->coord()->GetExecSummaryLock());
@@ -687,7 +701,7 @@ void ImpalaServer::ArchiveQuery(const QueryExecState& query) {
 
   if (FLAGS_query_log_size == 0) return;
   QueryStateRecord record(query, true, encoded_profile_str);
-  if (query.coord() != NULL) {
+  if (query.coord() != nullptr) {
     lock_guard<SpinLock> lock(query.coord()->GetExecSummaryLock());
     record.exec_summary = query.coord()->exec_summary();
   }
@@ -771,7 +785,7 @@ Status ImpalaServer::ExecuteInternal(
     shared_ptr<SessionState> session_state,
     bool* registered_exec_state,
     shared_ptr<QueryExecState>* exec_state) {
-  DCHECK(session_state != NULL);
+  DCHECK(session_state != nullptr);
   *registered_exec_state = false;
 
   exec_state->reset(new QueryExecState(query_ctx, exec_env_, exec_env_->frontend(),
@@ -820,7 +834,7 @@ Status ImpalaServer::ExecuteInternal(
     }
   }
 
-  if ((*exec_state)->coord() != NULL) {
+  if ((*exec_state)->coord() != nullptr) {
     const unordered_set<TNetworkAddress>& unique_hosts =
         (*exec_state)->schedule()->unique_hosts();
     if (!unique_hosts.empty()) {
@@ -944,7 +958,7 @@ Status ImpalaServer::UnregisterQuery(const TUniqueId& query_id, bool check_infli
     exec_state->session()->inflight_queries.erase(query_id);
   }
 
-  if (exec_state->coord() != NULL) {
+  if (exec_state->coord() != nullptr) {
     string exec_summary;
     {
       lock_guard<SpinLock> lock(exec_state->coord()->GetExecSummaryLock());
@@ -975,12 +989,12 @@ Status ImpalaServer::UnregisterQuery(const TUniqueId& query_id, bool check_infli
 
 Status ImpalaServer::UpdateCatalogMetrics() {
   TGetDbsResult dbs;
-  RETURN_IF_ERROR(exec_env_->frontend()->GetDbs(NULL, NULL, &dbs));
+  RETURN_IF_ERROR(exec_env_->frontend()->GetDbs(nullptr, nullptr, &dbs));
   ImpaladMetrics::CATALOG_NUM_DBS->set_value(dbs.dbs.size());
   ImpaladMetrics::CATALOG_NUM_TABLES->set_value(0L);
   for (const TDatabase& db: dbs.dbs) {
     TGetTablesResult table_names;
-    RETURN_IF_ERROR(exec_env_->frontend()->GetTableNames(db.db_name, NULL, NULL,
+    RETURN_IF_ERROR(exec_env_->frontend()->GetTableNames(db.db_name, nullptr, nullptr,
         &table_names));
     ImpaladMetrics::CATALOG_NUM_TABLES->Increment(table_names.tables.size());
   }
@@ -992,7 +1006,7 @@ Status ImpalaServer::CancelInternal(const TUniqueId& query_id, bool check_inflig
     const Status* cause) {
   VLOG_QUERY << "Cancel(): query_id=" << PrintId(query_id);
   shared_ptr<QueryExecState> exec_state = GetQueryExecState(query_id, false);
-  if (exec_state == NULL) return Status("Invalid or unknown query handle");
+  if (exec_state == nullptr) return Status("Invalid or unknown query handle");
   exec_state->Cancel(check_inflight, cause);
   return Status::OK();
 }
@@ -1014,7 +1028,7 @@ Status ImpalaServer::CloseSessionInternal(const TUniqueId& session_id,
     session_state = entry->second;
     session_state_map_.erase(session_id);
   }
-  DCHECK(session_state != NULL);
+  DCHECK(session_state != nullptr);
   if (session_state->session_type == TSessionType::BEESWAX) {
     ImpaladMetrics::IMPALA_SERVER_NUM_OPEN_BEESWAX_SESSIONS->Increment(-1L);
   } else {
@@ -1081,7 +1095,7 @@ void ImpalaServer::ReportExecStatus(
   // every report (assign each query a local int32_t id and use that to index into a
   // vector of QueryExecStates, w/o lookup or locking?)
   shared_ptr<QueryExecState> exec_state = GetQueryExecState(params.query_id, false);
-  if (exec_state.get() == NULL) {
+  if (exec_state.get() == nullptr) {
     // This is expected occasionally (since a report RPC might be in flight while
     // cancellation is happening). Return an error to the caller to get it to stop.
     const string& err = Substitute("ReportExecStatus(): Received report for unknown "
@@ -1475,6 +1489,10 @@ void ImpalaServer::MembershipCallback(
       // This is a new item - add it to the map of known backends.
       known_backends_.insert(make_pair(item.key, backend_descriptor));
     }
+
+    // Register the local backend in the statestore and update the list of known backends.
+    AddLocalBackendToStatestore(subscriber_topic_updates);
+
     // Process membership deletions.
     for (const string& backend_id: delta.topic_deletions) {
       known_backends_.erase(backend_id);
@@ -1559,13 +1577,48 @@ void ImpalaServer::MembershipCallback(
   }
 }
 
+void ImpalaServer::AddLocalBackendToStatestore(
+    vector<TTopicDelta>* subscriber_topic_updates) {
+  const string& local_backend_id = exec_env_->subscriber()->id();
+  if (known_backends_.find(local_backend_id) != known_backends_.end()) return;
+
+  TBackendDescriptor local_backend_descriptor;
+  local_backend_descriptor.__set_address(
+      MakeNetworkAddress(FLAGS_hostname, FLAGS_be_port));
+  IpAddr ip;
+  const Hostname& hostname = local_backend_descriptor.address.hostname;
+  Status status = HostnameToIpAddr(hostname, &ip);
+  if (!status.ok()) {
+    // TODO: Should we do something about this failure?
+    LOG(WARNING) << "Failed to convert hostname " << hostname << " to IP address: "
+                 << status.GetDetail();
+    return;
+  }
+  local_backend_descriptor.ip_address = ip;
+  subscriber_topic_updates->emplace_back(TTopicDelta());
+  TTopicDelta& update = subscriber_topic_updates->back();
+  update.topic_name = Scheduler::IMPALA_MEMBERSHIP_TOPIC;
+  update.topic_entries.emplace_back(TTopicItem());
+
+  TTopicItem& item = update.topic_entries.back();
+  item.key = local_backend_id;
+  status = thrift_serializer_.Serialize(&local_backend_descriptor, &item.value);
+  if (!status.ok()) {
+    LOG(WARNING) << "Failed to serialize Impala backend descriptor for statestore topic:"
+                 << " " << status.GetDetail();
+    subscriber_topic_updates->pop_back();
+  } else {
+    known_backends_.insert(make_pair(item.key, local_backend_descriptor));
+  }
+}
+
 ImpalaServer::QueryStateRecord::QueryStateRecord(const QueryExecState& exec_state,
     bool copy_profile, const string& encoded_profile) {
   id = exec_state.query_id();
   const TExecRequest& request = exec_state.exec_request();
 
   const string* plan_str = exec_state.summary_profile().GetInfoString("Plan");
-  if (plan_str != NULL) plan = *plan_str;
+  if (plan_str != nullptr) plan = *plan_str;
   stmt = exec_state.sql_stmt();
   stmt_type = request.stmt_type;
   effective_user = exec_state.effective_user();
@@ -1575,7 +1628,7 @@ ImpalaServer::QueryStateRecord::QueryStateRecord(const QueryExecState& exec_stat
   has_coord = false;
 
   Coordinator* coord = exec_state.coord();
-  if (coord != NULL) {
+  if (coord != nullptr) {
     num_complete_fragments = coord->progress().num_complete();
     total_fragments = coord->progress().total();
     has_coord = true;
@@ -1770,7 +1823,7 @@ void ImpalaServer::RegisterSessionTimeout(int32_t session_timeout) {
         if (expiration_event->first > now) break;
         shared_ptr<QueryExecState> query_state =
             GetQueryExecState(expiration_event->second, false);
-        if (query_state.get() == NULL) {
+        if (query_state.get() == nullptr) {
           // Query was deleted some other way.
           queries_by_timestamp_.erase(expiration_event++);
           continue;
@@ -1830,17 +1883,43 @@ void ImpalaServer::RegisterSessionTimeout(int32_t session_timeout) {
 
 Status CreateImpalaServer(ExecEnv* exec_env, int beeswax_port, int hs2_port, int be_port,
     ThriftServer** beeswax_server, ThriftServer** hs2_server, ThriftServer** be_server,
-    ImpalaServer** impala_server) {
-  DCHECK((beeswax_port == 0) == (beeswax_server == NULL));
-  DCHECK((hs2_port == 0) == (hs2_server == NULL));
-  DCHECK((be_port == 0) == (be_server == NULL));
+    boost::shared_ptr<ImpalaServer>* impala_server) {
+  DCHECK((beeswax_port == 0) == (beeswax_server == nullptr));
+  DCHECK((hs2_port == 0) == (hs2_server == nullptr));
+  DCHECK((be_port == 0) == (be_server == nullptr));
 
-  boost::shared_ptr<ImpalaServer> handler(new ImpalaServer(exec_env));
+  impala_server->reset(new ImpalaServer(exec_env));
 
-  if (beeswax_port != 0 && beeswax_server != NULL) {
+  if (be_port != 0 && be_server != nullptr) {
+    boost::shared_ptr<ImpalaInternalService> thrift_if(new ImpalaInternalService());
+    boost::shared_ptr<TProcessor> be_processor(
+        new ImpalaInternalServiceProcessor(thrift_if));
+    boost::shared_ptr<TProcessorEventHandler> event_handler(
+        new RpcEventHandler("backend", exec_env->metrics()));
+    be_processor->setEventHandler(event_handler);
+
+    *be_server = new ThriftServer("backend", be_processor, be_port, nullptr,
+        exec_env->metrics(), FLAGS_be_service_threads);
+    if (EnableInternalSslConnections()) {
+      LOG(INFO) << "Enabling SSL for backend";
+      RETURN_IF_ERROR((*be_server)->EnableSsl(FLAGS_ssl_server_certificate,
+          FLAGS_ssl_private_key, FLAGS_ssl_private_key_password_cmd));
+    }
+
+    LOG(INFO) << "ImpalaInternalService listening on " << be_port;
+  }
+  if (!FLAGS_is_coordinator) {
+    LOG(INFO) << "Started worker Impala server on "
+              << ExecEnv::GetInstance()->backend_address();
+    return Status::OK();
+  }
+
+  // Initialize the HS2 and Beeswax services.
+  if (beeswax_port != 0 && beeswax_server != nullptr) {
     // Beeswax FE must be a TThreadPoolServer because ODBC and Hue only support
     // TThreadPoolServer.
-    boost::shared_ptr<TProcessor> beeswax_processor(new ImpalaServiceProcessor(handler));
+    boost::shared_ptr<TProcessor> beeswax_processor(
+        new ImpalaServiceProcessor(*impala_server));
     boost::shared_ptr<TProcessorEventHandler> event_handler(
         new RpcEventHandler("beeswax", exec_env->metrics()));
     beeswax_processor->setEventHandler(event_handler);
@@ -1848,7 +1927,7 @@ Status CreateImpalaServer(ExecEnv* exec_env, int beeswax_port, int hs2_port, int
         beeswax_port, AuthManager::GetInstance()->GetExternalAuthProvider(),
         exec_env->metrics(), FLAGS_fe_service_threads, ThriftServer::ThreadPool);
 
-    (*beeswax_server)->SetConnectionHandler(handler.get());
+    (*beeswax_server)->SetConnectionHandler(impala_server->get());
     if (!FLAGS_ssl_server_certificate.empty()) {
       LOG(INFO) << "Enabling SSL for Beeswax";
       RETURN_IF_ERROR((*beeswax_server)->EnableSsl(FLAGS_ssl_server_certificate,
@@ -1858,10 +1937,10 @@ Status CreateImpalaServer(ExecEnv* exec_env, int beeswax_port, int hs2_port, int
     LOG(INFO) << "Impala Beeswax Service listening on " << beeswax_port;
   }
 
-  if (hs2_port != 0 && hs2_server != NULL) {
+  if (hs2_port != 0 && hs2_server != nullptr) {
     // HiveServer2 JDBC driver does not support non-blocking server.
     boost::shared_ptr<TProcessor> hs2_fe_processor(
-        new ImpalaHiveServer2ServiceProcessor(handler));
+        new ImpalaHiveServer2ServiceProcessor(*impala_server));
     boost::shared_ptr<TProcessorEventHandler> event_handler(
         new RpcEventHandler("hs2", exec_env->metrics()));
     hs2_fe_processor->setEventHandler(event_handler);
@@ -1870,7 +1949,7 @@ Status CreateImpalaServer(ExecEnv* exec_env, int beeswax_port, int hs2_port, int
         AuthManager::GetInstance()->GetExternalAuthProvider(), exec_env->metrics(),
         FLAGS_fe_service_threads, ThriftServer::ThreadPool);
 
-    (*hs2_server)->SetConnectionHandler(handler.get());
+    (*hs2_server)->SetConnectionHandler(impala_server->get());
     if (!FLAGS_ssl_server_certificate.empty()) {
       LOG(INFO) << "Enabling SSL for HiveServer2";
       RETURN_IF_ERROR((*hs2_server)->EnableSsl(FLAGS_ssl_server_certificate,
@@ -1880,32 +1959,14 @@ Status CreateImpalaServer(ExecEnv* exec_env, int beeswax_port, int hs2_port, int
     LOG(INFO) << "Impala HiveServer2 Service listening on " << hs2_port;
   }
 
-  if (be_port != 0 && be_server != NULL) {
-    boost::shared_ptr<ImpalaInternalService> thrift_if(new ImpalaInternalService());
-    boost::shared_ptr<TProcessor> be_processor(
-        new ImpalaInternalServiceProcessor(thrift_if));
-    boost::shared_ptr<TProcessorEventHandler> event_handler(
-        new RpcEventHandler("backend", exec_env->metrics()));
-    be_processor->setEventHandler(event_handler);
-
-    *be_server = new ThriftServer("backend", be_processor, be_port, NULL,
-        exec_env->metrics(), FLAGS_be_service_threads);
-    if (EnableInternalSslConnections()) {
-      LOG(INFO) << "Enabling SSL for backend";
-      RETURN_IF_ERROR((*be_server)->EnableSsl(FLAGS_ssl_server_certificate,
-          FLAGS_ssl_private_key, FLAGS_ssl_private_key_password_cmd));
-    }
-
-    LOG(INFO) << "ImpalaInternalService listening on " << be_port;
-  }
-  if (impala_server != NULL) *impala_server = handler.get();
-
+  LOG(INFO) << "Started coordinator Impala server on "
+            << ExecEnv::GetInstance()->backend_address();
   return Status::OK();
 }
 
 bool ImpalaServer::GetSessionIdForQuery(const TUniqueId& query_id,
     TUniqueId* session_id) {
-  DCHECK(session_id != NULL);
+  DCHECK(session_id != nullptr);
   lock_guard<mutex> l(query_exec_state_map_lock_);
   QueryExecStateMap::iterator i = query_exec_state_map_.find(query_id);
   if (i == query_exec_state_map_.end()) {
@@ -1931,7 +1992,7 @@ shared_ptr<ImpalaServer::QueryExecState> ImpalaServer::GetQueryExecState(
 void ImpalaServer::UpdateFilter(TUpdateFilterResult& result,
     const TUpdateFilterParams& params) {
   shared_ptr<QueryExecState> query_exec_state = GetQueryExecState(params.query_id, false);
-  if (query_exec_state.get() == NULL) {
+  if (query_exec_state.get() == nullptr) {
     LOG(INFO) << "Could not find query exec state: " << params.query_id;
     return;
   }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/service/impala-server.h
----------------------------------------------------------------------
diff --git a/be/src/service/impala-server.h b/be/src/service/impala-server.h
index 588a5c3..45e8080 100644
--- a/be/src/service/impala-server.h
+++ b/be/src/service/impala-server.h
@@ -270,6 +270,9 @@ class ImpalaServer : public ImpalaServiceIf, public ImpalaHiveServer2ServiceIf,
   /// Returns true if lineage logging is enabled, false otherwise.
   bool IsLineageLoggingEnabled();
 
+  /// Retuns true if this is a coordinator, false otherwise.
+  bool IsCoordinator();
+
   /// The prefix of audit event log filename.
   static const string AUDIT_EVENT_LOG_FILE_PREFIX;
 
@@ -432,6 +435,10 @@ class ImpalaServer : public ImpalaServiceIf, public ImpalaHiveServer2ServiceIf,
   /// on why the failure occurred.
   Status AuthorizeProxyUser(const std::string& user, const std::string& do_as_user);
 
+  // Check if the local backend descriptor is in the list of known backends. If not, add
+  // it to the list of known backends and add it to the 'topic_updates'.
+  void AddLocalBackendToStatestore(std::vector<TTopicDelta>* topic_updates);
+
   /// Snapshot of a query's state, archived in the query log.
   struct QueryStateRecord {
     /// Pretty-printed runtime profile. TODO: Copy actual profile object
@@ -942,6 +949,13 @@ class ImpalaServer : public ImpalaServiceIf, public ImpalaHiveServer2ServiceIf,
 
   /// Container for a thread that runs ExpireQueries() if FLAGS_idle_query_timeout is set.
   boost::scoped_ptr<Thread> query_expiration_thread_;
+
+  /// Serializes TBackendDescriptors when creating topic updates
+  ThriftSerializer thrift_serializer_;
+
+  /// True if this ImpalaServer can accept client connections and coordinate
+  /// queries.
+  bool is_coordinator_;
 };
 
 /// Create an ImpalaServer and Thrift servers.
@@ -949,6 +963,8 @@ class ImpalaServer : public ImpalaServiceIf, public ImpalaHiveServer2ServiceIf,
 /// ImpalaService (Beeswax) on beeswax_port (returned via beeswax_server).
 /// If hs2_port != 0 (and hs2_server != NULL), creates a ThriftServer exporting
 /// ImpalaHiveServer2Service on hs2_port (returned via hs2_server).
+/// ImpalaService and ImpalaHiveServer2Service are initialized only if this
+/// Impala server is a coordinator (indicated by the is_coordinator flag).
 /// If be_port != 0 (and be_server != NULL), create a ThriftServer exporting
 /// ImpalaInternalService on be_port (returned via be_server).
 /// Returns created ImpalaServer. The caller owns fe_server and be_server.
@@ -958,7 +974,7 @@ class ImpalaServer : public ImpalaServiceIf, public ImpalaHiveServer2ServiceIf,
 /// which case none of the output parameters can be assumed to be valid.
 Status CreateImpalaServer(ExecEnv* exec_env, int beeswax_port, int hs2_port,
     int be_port, ThriftServer** beeswax_server, ThriftServer** hs2_server,
-    ThriftServer** be_server, ImpalaServer** impala_server);
+    ThriftServer** be_server, boost::shared_ptr<ImpalaServer>* impala_server);
 
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/service/impalad-main.cc
----------------------------------------------------------------------
diff --git a/be/src/service/impalad-main.cc b/be/src/service/impalad-main.cc
index 4848b45..01e5b55 100644
--- a/be/src/service/impalad-main.cc
+++ b/be/src/service/impalad-main.cc
@@ -56,6 +56,7 @@ DECLARE_int32(hs2_port);
 DECLARE_int32(be_port);
 DECLARE_string(principal);
 DECLARE_bool(enable_rm);
+DECLARE_bool(is_coordinator);
 
 int ImpaladMain(int argc, char** argv) {
   InitCommonRuntime(argc, argv, true);
@@ -84,14 +85,17 @@ int ImpaladMain(int argc, char** argv) {
   ThriftServer* beeswax_server = NULL;
   ThriftServer* hs2_server = NULL;
   ThriftServer* be_server = NULL;
-  ImpalaServer* server = NULL;
+  boost::shared_ptr<ImpalaServer> server;
   ABORT_IF_ERROR(CreateImpalaServer(&exec_env, FLAGS_beeswax_port, FLAGS_hs2_port,
       FLAGS_be_port, &beeswax_server, &hs2_server, &be_server, &server));
 
   ABORT_IF_ERROR(be_server->Start());
 
-  ABORT_IF_ERROR(beeswax_server->Start());
-  ABORT_IF_ERROR(hs2_server->Start());
+  if (FLAGS_is_coordinator) {
+    ABORT_IF_ERROR(beeswax_server->Start());
+    ABORT_IF_ERROR(hs2_server->Start());
+  }
+
   Status status = exec_env.StartServices();
   if (!status.ok()) {
     LOG(ERROR) << "Impalad services did not start correctly, exiting.  Error: "
@@ -101,13 +105,17 @@ int ImpaladMain(int argc, char** argv) {
   }
   ImpaladMetrics::IMPALA_SERVER_READY->set_value(true);
   LOG(INFO) << "Impala has started.";
-  // this blocks until the beeswax and hs2 servers terminate
-  beeswax_server->Join();
-  hs2_server->Join();
 
+  be_server->Join();
   delete be_server;
-  delete beeswax_server;
-  delete hs2_server;
+
+  if (FLAGS_is_coordinator) {
+    // this blocks until the beeswax and hs2 servers terminate
+    beeswax_server->Join();
+    hs2_server->Join();
+    delete beeswax_server;
+    delete hs2_server;
+  }
 
   return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/service/query-exec-state.cc
----------------------------------------------------------------------
diff --git a/be/src/service/query-exec-state.cc b/be/src/service/query-exec-state.cc
index 2cf2e5d..f704676 100644
--- a/be/src/service/query-exec-state.cc
+++ b/be/src/service/query-exec-state.cc
@@ -25,6 +25,7 @@
 #include "runtime/row-batch.h"
 #include "runtime/runtime-state.h"
 #include "runtime/exec-env.h"
+#include "scheduling/admission-controller.h"
 #include "scheduling/scheduler.h"
 #include "service/frontend.h"
 #include "service/impala-server.h"
@@ -456,6 +457,14 @@ Status ImpalaServer::QueryExecState::ExecQueryOrDmlRequest(
     RETURN_IF_ERROR(UpdateQueryStatus(status));
   }
 
+  if (exec_env_->admission_controller() != nullptr) {
+    status = exec_env_->admission_controller()->AdmitQuery(schedule_.get());
+    {
+      lock_guard<mutex> l(lock_);
+      RETURN_IF_ERROR(UpdateQueryStatus(status));
+    }
+  }
+
   coord_.reset(new Coordinator(*schedule_, exec_env_, query_events_));
   status = coord_->Exec();
   {
@@ -570,10 +579,12 @@ void ImpalaServer::QueryExecState::Done() {
 
   if (coord_.get() != NULL) {
     // Release any reserved resources.
-    Status status = exec_env_->scheduler()->Release(schedule_.get());
-    if (!status.ok()) {
-      LOG(WARNING) << "Failed to release resources of query " << schedule_->query_id()
-                   << " because of error: " << status.GetDetail();
+    if (exec_env_->admission_controller() != nullptr) {
+      Status status = exec_env_->admission_controller()->ReleaseQuery(schedule_.get());
+      if (!status.ok()) {
+        LOG(WARNING) << "Failed to release resources of query " << schedule_->query_id()
+                     << " because of error: " << status.GetDetail();
+      }
     }
     coord_->TearDown();
   }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/testutil/in-process-servers.h
----------------------------------------------------------------------
diff --git a/be/src/testutil/in-process-servers.h b/be/src/testutil/in-process-servers.h
index 54c7484..870f02d 100644
--- a/be/src/testutil/in-process-servers.h
+++ b/be/src/testutil/in-process-servers.h
@@ -69,7 +69,7 @@ class InProcessImpalaServer {
   /// there was an error joining.
   Status Join();
 
-  ImpalaServer* impala_server() { return impala_server_; }
+  ImpalaServer* impala_server() { return impala_server_.get(); }
 
   MetricGroup* metrics() { return exec_env_->metrics(); }
 
@@ -92,10 +92,9 @@ class InProcessImpalaServer {
 
   uint32_t hs2_port_;
 
-  /// The ImpalaServer that handles client and backend requests. Not owned by this class;
-  /// instead it's owned via shared_ptrs in the ThriftServers. See CreateImpalaServer for
-  /// details.
-  ImpalaServer* impala_server_;
+  /// The ImpalaServer that handles client and backend requests. Ownership is shared via
+  /// shared_ptrs with the ThriftServers. See CreateImpalaServer for details.
+  boost::shared_ptr<ImpalaServer> impala_server_;
 
   /// ExecEnv holds much of the per-service state
   boost::scoped_ptr<ExecEnv> exec_env_;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/be/src/util/webserver.cc
----------------------------------------------------------------------
diff --git a/be/src/util/webserver.cc b/be/src/util/webserver.cc
index 61ef3ea..3b7c4f9 100644
--- a/be/src/util/webserver.cc
+++ b/be/src/util/webserver.cc
@@ -34,6 +34,8 @@
 
 #include "common/logging.h"
 #include "rpc/thrift-util.h"
+#include "runtime/exec-env.h"
+#include "service/impala-server.h"
 #include "thirdparty/mustache/mustache.h"
 #include "util/asan.h"
 #include "util/coding-util.h"
@@ -97,6 +99,8 @@ DEFINE_string(webserver_password_file, "",
 DEFINE_string(webserver_x_frame_options, "DENY",
     "webserver will add X-Frame-Options HTTP header with this value");
 
+DECLARE_bool(is_coordinator);
+
 static const char* DOC_FOLDER = "/www/";
 static const int DOC_FOLDER_LEN = strlen(DOC_FOLDER);
 
@@ -116,7 +120,7 @@ static const char* ERROR_KEY = "__error_msg__";
 const char* GetDefaultDocumentRoot() {
   stringstream ss;
   char* impala_home = getenv("IMPALA_HOME");
-  if (impala_home == NULL) {
+  if (impala_home == nullptr) {
     return ""; // Empty document root means don't serve static files
   } else {
     ss << impala_home;
@@ -152,7 +156,7 @@ string BuildHeaderString(ResponseCode response, ContentType content_type) {
 }
 
 Webserver::Webserver()
-    : context_(NULL),
+    : context_(nullptr),
       error_handler_(UrlHandler(bind<void>(&Webserver::ErrorHandler, this, _1, _2),
           "error.tmpl", false)) {
   http_address_ = MakeNetworkAddress(
@@ -161,7 +165,7 @@ Webserver::Webserver()
 }
 
 Webserver::Webserver(const int port)
-    : context_(NULL),
+    : context_(nullptr),
       error_handler_(UrlHandler(bind<void>(&Webserver::ErrorHandler, this, _1, _2),
           "error.tmpl", false)) {
   http_address_ = MakeNetworkAddress("0.0.0.0", port);
@@ -186,6 +190,13 @@ void Webserver::RootHandler(const ArgumentMap& args, Document* document) {
     document->GetAllocator());
   document->AddMember("process_state_info", process_state_info,
     document->GetAllocator());
+
+  ExecEnv* env = ExecEnv::GetInstance();
+  if (env == nullptr || env->impala_server() == nullptr) return;
+  string mode = (env->impala_server()->IsCoordinator()) ?
+      "Coordinator + Executor" : "Executor";
+  Value impala_server_mode(mode.c_str(), document->GetAllocator());
+  document->AddMember("impala_server_mode", impala_server_mode, document->GetAllocator());
 }
 
 void Webserver::ErrorHandler(const ArgumentMap& args, Document* document) {
@@ -300,7 +311,7 @@ Status Webserver::Start() {
   options.push_back("no");
 
   // Options must be a NULL-terminated list
-  options.push_back(NULL);
+  options.push_back(nullptr);
 
   // squeasel ignores SIGCHLD and we need it to run kinit. This means that since
   // squeasel does not reap its own children CGI programs must be avoided.
@@ -321,7 +332,7 @@ Status Webserver::Start() {
   // Restore the child signal handler so wait() works properly.
   signal(SIGCHLD, sig_chld);
 
-  if (context_ == NULL) {
+  if (context_ == nullptr) {
     stringstream error_msg;
     error_msg << "Webserver: Could not start on address " << http_address_;
     return Status(error_msg.str());
@@ -337,14 +348,14 @@ Status Webserver::Start() {
 }
 
 void Webserver::Stop() {
-  if (context_ != NULL) {
+  if (context_ != nullptr) {
     sq_stop(context_);
-    context_ = NULL;
+    context_ = nullptr;
   }
 }
 
 void Webserver::GetCommonJson(Document* document) {
-  DCHECK(document != NULL);
+  DCHECK(document != nullptr);
   Value obj(kObjectType);
   obj.AddMember("process-name", google::ProgramInvocationShortName(),
       document->GetAllocator());
@@ -365,7 +376,7 @@ void Webserver::GetCommonJson(Document* document) {
 
 int Webserver::LogMessageCallbackStatic(const struct sq_connection* connection,
     const char* message) {
-  if (message != NULL) {
+  if (message != nullptr) {
     LOG(INFO) << "Webserver: " << message;
   }
   return PROCESSING_COMPLETE;
@@ -389,7 +400,7 @@ int Webserver::BeginRequestCallback(struct sq_connection* connection,
   }
 
   map<string, string> arguments;
-  if (request_info->query_string != NULL) {
+  if (request_info->query_string != nullptr) {
     BuildArgumentMap(request_info->query_string, &arguments);
   }
 
@@ -397,7 +408,7 @@ int Webserver::BeginRequestCallback(struct sq_connection* connection,
   UrlHandlerMap::const_iterator it = url_handlers_.find(request_info->uri);
   ResponseCode response = OK;
   ContentType content_type = HTML;
-  const UrlHandler* url_handler = NULL;
+  const UrlHandler* url_handler = nullptr;
   if (it == url_handlers_.end()) {
     response = NOT_FOUND;
     arguments[ERROR_KEY] = Substitute("No URI handler for '$0'", request_info->uri);

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/bin/start-impala-cluster.py
----------------------------------------------------------------------
diff --git a/bin/start-impala-cluster.py b/bin/start-impala-cluster.py
index b276b08..37671e3 100755
--- a/bin/start-impala-cluster.py
+++ b/bin/start-impala-cluster.py
@@ -36,6 +36,8 @@ DEFAULT_IMPALA_MAX_LOG_FILES = os.environ.get('IMPALA_MAX_LOG_FILES', 10)
 parser = OptionParser()
 parser.add_option("-s", "--cluster_size", type="int", dest="cluster_size", default=3,
                   help="Size of the cluster (number of impalad instances to start).")
+parser.add_option("-c", "--num_coordinators", type="int", dest="num_coordinators",
+                  default=3, help="Number of coordinators.")
 parser.add_option("--build_type", dest="build_type", default= 'latest',
                   help="Build type to use - debug / release / latest")
 parser.add_option("--impalad_args", dest="impalad_args", action="append", type="string",
@@ -204,7 +206,7 @@ def build_jvm_args(instance_num):
   BASE_JVM_DEBUG_PORT = 30000
   return JVM_ARGS % (BASE_JVM_DEBUG_PORT + instance_num, options.jvm_args)
 
-def start_impalad_instances(cluster_size):
+def start_impalad_instances(cluster_size, num_coordinators):
   if cluster_size == 0:
     # No impalad instances should be started.
     return
@@ -239,6 +241,10 @@ def start_impalad_instances(cluster_size):
     if options.kudu_master_hosts:
       # Must be prepended, otherwise the java options interfere.
       args = "-kudu_master_hosts %s %s" % (options.kudu_master_hosts, args)
+
+    if i >= num_coordinators:
+      args = "-is_coordinator=false %s" % (args)
+
     stderr_log_file_path = os.path.join(options.log_dir, '%s-error.log' % service_name)
     exec_impala_process(IMPALAD_PATH, args, stderr_log_file_path)
 
@@ -279,9 +285,10 @@ def wait_for_cluster_web(timeout_in_seconds=CLUSTER_WAIT_TIMEOUT_IN_SECONDS):
   # impalad processes may take a while to come up.
   wait_for_impala_process_count(impala_cluster)
   for impalad in impala_cluster.impalads:
-    impalad.service.wait_for_num_known_live_backends(options.cluster_size,
-        timeout=CLUSTER_WAIT_TIMEOUT_IN_SECONDS, interval=2)
-    wait_for_catalog(impalad, timeout_in_seconds=CLUSTER_WAIT_TIMEOUT_IN_SECONDS)
+    if impalad._get_arg_value('is_coordinator', default='true') == 'true':
+      impalad.service.wait_for_num_known_live_backends(options.cluster_size,
+          timeout=CLUSTER_WAIT_TIMEOUT_IN_SECONDS, interval=2)
+      wait_for_catalog(impalad, timeout_in_seconds=CLUSTER_WAIT_TIMEOUT_IN_SECONDS)
 
 def wait_for_catalog(impalad, timeout_in_seconds):
   """Waits for the impalad catalog to become ready"""
@@ -326,6 +333,10 @@ if __name__ == "__main__":
     print 'Please specify a cluster size >= 0'
     sys.exit(1)
 
+  if options.num_coordinators <= 0:
+    print 'Please specify a valid number of coordinators > 0'
+    sys.exit(1)
+
   if not os.path.isdir(options.log_dir):
     print 'Log dir does not exist or is not a directory: %s' % options.log_dir
     sys.exit(1)
@@ -372,7 +383,7 @@ if __name__ == "__main__":
       if not options.restart_impalad_only:
         start_statestore()
         start_catalogd()
-      start_impalad_instances(options.cluster_size)
+      start_impalad_instances(options.cluster_size, options.num_coordinators)
       # Sleep briefly to reduce log spam: the cluster takes some time to start up.
       sleep(3)
       wait_for_cluster()
@@ -380,4 +391,5 @@ if __name__ == "__main__":
       print 'Error starting cluster: %s' % e
       sys.exit(1)
 
-  print 'Impala Cluster Running with %d nodes.' % options.cluster_size
+  print 'Impala Cluster Running with %d nodes and %d coordinators.' % (
+      options.cluster_size, options.num_coordinators)

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/tests/common/custom_cluster_test_suite.py
----------------------------------------------------------------------
diff --git a/tests/common/custom_cluster_test_suite.py b/tests/common/custom_cluster_test_suite.py
index 28f598c..b19b5d2 100644
--- a/tests/common/custom_cluster_test_suite.py
+++ b/tests/common/custom_cluster_test_suite.py
@@ -30,6 +30,7 @@ from time import sleep
 
 IMPALA_HOME = os.environ['IMPALA_HOME']
 CLUSTER_SIZE = 3
+NUM_COORDINATORS = CLUSTER_SIZE
 # The number of statestore subscribers is CLUSTER_SIZE (# of impalad) + 1 (for catalogd).
 NUM_SUBSCRIBERS = CLUSTER_SIZE + 1
 
@@ -107,10 +108,11 @@ class CustomClusterTestSuite(ImpalaTestSuite):
 
   @classmethod
   def _start_impala_cluster(cls, options, log_dir=os.getenv('LOG_DIR', "/tmp/"),
-      cluster_size=CLUSTER_SIZE, log_level=1):
+      cluster_size=CLUSTER_SIZE, num_coordinators=NUM_COORDINATORS, log_level=1):
     cls.impala_log_dir = log_dir
     cmd = [os.path.join(IMPALA_HOME, 'bin/start-impala-cluster.py'),
            '--cluster_size=%d' % cluster_size,
+           '--num_coordinators=%d' % num_coordinators,
            '--log_dir=%s' % log_dir,
            '--log_level=%s' % log_level]
     try:
@@ -123,7 +125,8 @@ class CustomClusterTestSuite(ImpalaTestSuite):
       raise Exception("statestored was not found")
     statestored.service.wait_for_live_subscribers(NUM_SUBSCRIBERS, timeout=60)
     for impalad in cls.cluster.impalads:
-      impalad.service.wait_for_num_known_live_backends(CLUSTER_SIZE, timeout=60)
+      if impalad._get_arg_value('is_coordinator', default='true') == 'true':
+        impalad.service.wait_for_num_known_live_backends(CLUSTER_SIZE, timeout=60)
 
   def assert_impalad_log_contains(self, level, line_regex, expected_count=1):
     """

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/tests/common/impala_service.py
----------------------------------------------------------------------
diff --git a/tests/common/impala_service.py b/tests/common/impala_service.py
index 4e9c815..265b1b6 100644
--- a/tests/common/impala_service.py
+++ b/tests/common/impala_service.py
@@ -26,6 +26,10 @@ import urllib
 from time import sleep, time
 
 from tests.common.impala_connection import create_connection, create_ldap_connection
+from TCLIService import TCLIService
+from thrift.transport.TSocket import TSocket
+from thrift.transport.TTransport import TBufferedTransport
+from thrift.protocol import TBinaryProtocol
 
 logging.basicConfig(level=logging.ERROR, format='%(threadName)s: %(message)s')
 LOG = logging.getLogger('impala_service')
@@ -201,6 +205,16 @@ class ImpaladService(BaseImpalaService):
     client.connect()
     return client
 
+  def create_hs2_client(self):
+    """Creates a new HS2 client connection to the impalad"""
+    host, port = (self.hostname, self.hs2_port)
+    socket = TSocket(host, port)
+    transport = TBufferedTransport(socket)
+    transport.open()
+    protocol = TBinaryProtocol.TBinaryProtocol(transport)
+    hs2_client = TCLIService.Client(protocol)
+    return hs2_client
+
   def get_catalog_object_dump(self, object_type, object_name):
     return self.read_debug_webpage('catalog_objects?object_type=%s&object_name=%s' %\
         (object_type, object_name))

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/tests/custom_cluster/test_coordinators.py
----------------------------------------------------------------------
diff --git a/tests/custom_cluster/test_coordinators.py b/tests/custom_cluster/test_coordinators.py
new file mode 100644
index 0000000..6010404
--- /dev/null
+++ b/tests/custom_cluster/test_coordinators.py
@@ -0,0 +1,86 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# The base class that should be used for almost all Impala tests
+
+import pytest
+
+from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
+
+class TestCoordinators(CustomClusterTestSuite):
+  @pytest.mark.execute_serially
+  def test_multiple_coordinators(self):
+    """Test a cluster configuration in which not all impalad nodes are coordinators.
+      Verify that only coordinators can accept client connections and that select and DDL
+      queries run successfully."""
+
+    db_name = "TEST_MUL_COORD_DB"
+    self._start_impala_cluster([], num_coordinators=2, cluster_size=3)
+    assert len(self.cluster.impalads) == 3
+
+    coordinator1 = self.cluster.impalads[0]
+    coordinator2 = self.cluster.impalads[1]
+    worker = self.cluster.impalads[2]
+
+    # Verify that Beeswax and HS2 client connections can't be established at a worker node
+    beeswax_client = None
+    try:
+      beeswax_client = worker.service.create_beeswax_client()
+    except: pass
+    finally:
+      assert beeswax_client is None
+
+    hs2_client = None
+    try:
+      hs2_client = worker.service.create_hs2_client()
+    except: pass
+    finally:
+      assert hs2_client is None
+
+    # Verify that queries can successfully run on coordinator nodes
+    try:
+      client1 = coordinator1.service.create_beeswax_client()
+      client2 = coordinator2.service.create_beeswax_client()
+
+      # select queries
+      self.execute_query_expect_success(client1, "select 1")
+      self.execute_query_expect_success(client2, "select * from functional.alltypes");
+      # DDL queries w/o SYNC_DDL
+      self.execute_query_expect_success(client1, "refresh functional.alltypes")
+      query_options = {"sync_ddl" : 1}
+      self.execute_query_expect_success(client2, "refresh functional.alltypesagg",
+          query_options)
+      self.execute_query_expect_success(client1,
+          "create database if not exists %s" % db_name, query_options)
+      # Create a table using one coordinator
+      self.execute_query_expect_success(client1,
+          "create table %s.foo1 (col int)" % db_name, query_options)
+      # Drop the table using the other coordinator
+      self.execute_query_expect_success(client2, "drop table %s.foo1" % db_name,
+          query_options)
+      # Swap roles and repeat
+      self.execute_query_expect_success(client2,
+          "create table %s.foo2 (col int)" % db_name, query_options)
+      self.execute_query_expect_success(client1, "drop table %s.foo2" % db_name,
+          query_options)
+      self.execute_query_expect_success(client1, "drop database %s cascade" % db_name)
+    finally:
+      # Ensure the worker hasn't received any table metadata
+      num_tbls = worker.service.get_metric_value('catalog.num-tables')
+      assert num_tbls == 0
+      client1.close()
+      client2.close()

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/296df3c8/www/root.tmpl
----------------------------------------------------------------------
diff --git a/www/root.tmpl b/www/root.tmpl
index 916b48b..40d448a 100644
--- a/www/root.tmpl
+++ b/www/root.tmpl
@@ -18,6 +18,10 @@ under the License.
 -->
 {{! Template for / }}
 {{>www/common-header.tmpl}}
+  {{?impala_server_mode}}
+  <h2>Impala Server Mode: {{impala_server_mode}}</h2>
+  {{/impala_server_mode}}
+
   <h2>Vers<span id="v">i</span>on</h2>
   <pre id="version_pre">{{version}}</pre>
 


[08/14] incubator-impala git commit: IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

Posted by he...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/cpu.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/cpu.cc b/be/src/gutil/cpu.cc
new file mode 100644
index 0000000..f4c3885
--- /dev/null
+++ b/be/src/gutil/cpu.cc
@@ -0,0 +1,289 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "kudu/gutil/cpu.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <algorithm>
+
+#include "kudu/gutil/basictypes.h"
+#include "kudu/gutil/strings/stringpiece.h"
+
+#if defined(__x86_64__)
+#if defined(_MSC_VER)
+#include <intrin.h>
+#include <immintrin.h>  // For _xgetbv()
+#endif
+#endif
+
+namespace base {
+
+CPU::CPU()
+  : signature_(0),
+    type_(0),
+    family_(0),
+    model_(0),
+    stepping_(0),
+    ext_model_(0),
+    ext_family_(0),
+    has_mmx_(false),
+    has_sse_(false),
+    has_sse2_(false),
+    has_sse3_(false),
+    has_ssse3_(false),
+    has_sse41_(false),
+    has_sse42_(false),
+    has_avx_(false),
+    has_avx2_(false),
+    has_aesni_(false),
+    has_non_stop_time_stamp_counter_(false),
+    has_broken_neon_(false),
+    cpu_vendor_("unknown") {
+  Initialize();
+}
+
+namespace {
+
+#if defined(__x86_64__)
+#ifndef _MSC_VER
+
+#if defined(__pic__) && defined(__i386__)
+
+void __cpuid(int cpu_info[4], int info_type) {
+  __asm__ volatile (
+    "mov %%ebx, %%edi\n"
+    "cpuid\n"
+    "xchg %%edi, %%ebx\n"
+    : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
+    : "a"(info_type)
+  );
+}
+
+#else
+
+void __cpuid(int cpu_info[4], int info_type) {
+  __asm__ volatile (
+    "cpuid\n"
+    : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
+    : "a"(info_type), "c"(0)
+  );
+}
+
+#endif
+
+// _xgetbv returns the value of an Intel Extended Control Register (XCR).
+// Currently only XCR0 is defined by Intel so |xcr| should always be zero.
+uint64 _xgetbv(uint32 xcr) {
+  uint32 eax, edx;
+
+  __asm__ volatile (
+    "xgetbv" : "=a"(eax), "=d"(edx) : "c"(xcr));
+  return (static_cast<uint64>(edx) << 32) | eax;
+}
+
+#endif  // !_MSC_VER
+#endif  // __x86_64__
+
+#if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
+class LazyCpuInfoValue {
+ public:
+  LazyCpuInfoValue() : has_broken_neon_(false) {
+    // This function finds the value from /proc/cpuinfo under the key "model
+    // name" or "Processor". "model name" is used in Linux 3.8 and later (3.7
+    // and later for arm64) and is shown once per CPU. "Processor" is used in
+    // earler versions and is shown only once at the top of /proc/cpuinfo
+    // regardless of the number CPUs.
+    const char kModelNamePrefix[] = "model name\t: ";
+    const char kProcessorPrefix[] = "Processor\t: ";
+
+    // This function also calculates whether we believe that this CPU has a
+    // broken NEON unit based on these fields from cpuinfo:
+    unsigned implementer = 0, architecture = 0, variant = 0, part = 0,
+             revision = 0;
+    const struct {
+      const char key[17];
+      unsigned int* result;
+    } kUnsignedValues[] = {
+      {"CPU implementer", &implementer},
+      {"CPU architecture", &architecture},
+      {"CPU variant", &variant},
+      {"CPU part", &part},
+      {"CPU revision", &revision},
+    };
+
+    std::string contents;
+    ReadFileToString(FilePath("/proc/cpuinfo"), &contents);
+    DCHECK(!contents.empty());
+    if (contents.empty()) {
+      return;
+    }
+
+    std::istringstream iss(contents);
+    std::string line;
+    while (std::getline(iss, line)) {
+      if (brand_.empty() &&
+          (line.compare(0, strlen(kModelNamePrefix), kModelNamePrefix) == 0 ||
+           line.compare(0, strlen(kProcessorPrefix), kProcessorPrefix) == 0)) {
+        brand_.assign(line.substr(strlen(kModelNamePrefix)));
+      }
+
+      for (size_t i = 0; i < arraysize(kUnsignedValues); i++) {
+        const char *key = kUnsignedValues[i].key;
+        const size_t len = strlen(key);
+
+        if (line.compare(0, len, key) == 0 &&
+            line.size() >= len + 1 &&
+            (line[len] == '\t' || line[len] == ' ' || line[len] == ':')) {
+          size_t colon_pos = line.find(':', len);
+          if (colon_pos == std::string::npos) {
+            continue;
+          }
+
+          const StringPiece line_sp(line);
+          StringPiece value_sp = line_sp.substr(colon_pos + 1);
+          while (!value_sp.empty() &&
+                 (value_sp[0] == ' ' || value_sp[0] == '\t')) {
+            value_sp = value_sp.substr(1);
+          }
+
+          // The string may have leading "0x" or not, so we use strtoul to
+          // handle that.
+          char* endptr;
+          std::string value(value_sp.as_string());
+          unsigned long int result = strtoul(value.c_str(), &endptr, 0);
+          if (*endptr == 0 && result <= UINT_MAX) {
+            *kUnsignedValues[i].result = result;
+          }
+        }
+      }
+    }
+
+    has_broken_neon_ =
+      implementer == 0x51 &&
+      architecture == 7 &&
+      variant == 1 &&
+      part == 0x4d &&
+      revision == 0;
+  }
+
+  const std::string& brand() const { return brand_; }
+  bool has_broken_neon() const { return has_broken_neon_; }
+
+ private:
+  std::string brand_;
+  bool has_broken_neon_;
+  DISALLOW_COPY_AND_ASSIGN(LazyCpuInfoValue);
+};
+
+base::LazyInstance<LazyCpuInfoValue>::Leaky g_lazy_cpuinfo =
+    LAZY_INSTANCE_INITIALIZER;
+
+#endif  // defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) ||
+        // defined(OS_LINUX))
+
+}  // anonymous namespace
+
+void CPU::Initialize() {
+#if defined(__x86_64__)
+  int cpu_info[4] = {-1};
+  char cpu_string[48];
+
+  // __cpuid with an InfoType argument of 0 returns the number of
+  // valid Ids in CPUInfo[0] and the CPU identification string in
+  // the other three array elements. The CPU identification string is
+  // not in linear order. The code below arranges the information
+  // in a human readable form. The human readable order is CPUInfo[1] |
+  // CPUInfo[3] | CPUInfo[2]. CPUInfo[2] and CPUInfo[3] are swapped
+  // before using memcpy to copy these three array elements to cpu_string.
+  __cpuid(cpu_info, 0);
+  int num_ids = cpu_info[0];
+  std::swap(cpu_info[2], cpu_info[3]);
+  memcpy(cpu_string, &cpu_info[1], 3 * sizeof(cpu_info[1]));
+  cpu_vendor_.assign(cpu_string, 3 * sizeof(cpu_info[1]));
+
+  // Interpret CPU feature information.
+  if (num_ids > 0) {
+    int cpu_info7[4] = {0};
+    __cpuid(cpu_info, 1);
+    if (num_ids >= 7) {
+      __cpuid(cpu_info7, 7);
+    }
+    signature_ = cpu_info[0];
+    stepping_ = cpu_info[0] & 0xf;
+    model_ = ((cpu_info[0] >> 4) & 0xf) + ((cpu_info[0] >> 12) & 0xf0);
+    family_ = (cpu_info[0] >> 8) & 0xf;
+    type_ = (cpu_info[0] >> 12) & 0x3;
+    ext_model_ = (cpu_info[0] >> 16) & 0xf;
+    ext_family_ = (cpu_info[0] >> 20) & 0xff;
+    has_mmx_ =   (cpu_info[3] & 0x00800000) != 0;
+    has_sse_ =   (cpu_info[3] & 0x02000000) != 0;
+    has_sse2_ =  (cpu_info[3] & 0x04000000) != 0;
+    has_sse3_ =  (cpu_info[2] & 0x00000001) != 0;
+    has_ssse3_ = (cpu_info[2] & 0x00000200) != 0;
+    has_sse41_ = (cpu_info[2] & 0x00080000) != 0;
+    has_sse42_ = (cpu_info[2] & 0x00100000) != 0;
+    // AVX instructions will generate an illegal instruction exception unless
+    //   a) they are supported by the CPU,
+    //   b) XSAVE is supported by the CPU and
+    //   c) XSAVE is enabled by the kernel.
+    // See http://software.intel.com/en-us/blogs/2011/04/14/is-avx-enabled
+    //
+    // In addition, we have observed some crashes with the xgetbv instruction
+    // even after following Intel's example code. (See crbug.com/375968.)
+    // Because of that, we also test the XSAVE bit because its description in
+    // the CPUID documentation suggests that it signals xgetbv support.
+    has_avx_ =
+        (cpu_info[2] & 0x10000000) != 0 &&
+        (cpu_info[2] & 0x04000000) != 0 /* XSAVE */ &&
+        (cpu_info[2] & 0x08000000) != 0 /* OSXSAVE */ &&
+        (_xgetbv(0) & 6) == 6 /* XSAVE enabled by kernel */;
+    has_aesni_ = (cpu_info[2] & 0x02000000) != 0;
+    has_avx2_ = has_avx_ && (cpu_info7[1] & 0x00000020) != 0;
+  }
+
+  // Get the brand string of the cpu.
+  __cpuid(cpu_info, 0x80000000);
+  const int parameter_end = 0x80000004;
+  int max_parameter = cpu_info[0];
+
+  if (cpu_info[0] >= parameter_end) {
+    char* cpu_string_ptr = cpu_string;
+
+    for (int parameter = 0x80000002; parameter <= parameter_end &&
+         cpu_string_ptr < &cpu_string[sizeof(cpu_string)]; parameter++) {
+      __cpuid(cpu_info, parameter);
+      memcpy(cpu_string_ptr, cpu_info, sizeof(cpu_info));
+      cpu_string_ptr += sizeof(cpu_info);
+    }
+    cpu_brand_.assign(cpu_string, cpu_string_ptr - cpu_string);
+  }
+
+  const int parameter_containing_non_stop_time_stamp_counter = 0x80000007;
+  if (max_parameter >= parameter_containing_non_stop_time_stamp_counter) {
+    __cpuid(cpu_info, parameter_containing_non_stop_time_stamp_counter);
+    has_non_stop_time_stamp_counter_ = (cpu_info[3] & (1 << 8)) != 0;
+  }
+#elif defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
+  cpu_brand_.assign(g_lazy_cpuinfo.Get().brand());
+  has_broken_neon_ = g_lazy_cpuinfo.Get().has_broken_neon();
+#else
+  #error unknown architecture
+#endif
+}
+
+CPU::IntelMicroArchitecture CPU::GetIntelMicroArchitecture() const {
+  if (has_avx2()) return AVX2;
+  if (has_avx()) return AVX;
+  if (has_sse42()) return SSE42;
+  if (has_sse41()) return SSE41;
+  if (has_ssse3()) return SSSE3;
+  if (has_sse3()) return SSE3;
+  if (has_sse2()) return SSE2;
+  if (has_sse()) return SSE;
+  return PENTIUM;
+}
+
+}  // namespace base

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/cpu.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/cpu.h b/be/src/gutil/cpu.h
new file mode 100644
index 0000000..6549814
--- /dev/null
+++ b/be/src/gutil/cpu.h
@@ -0,0 +1,90 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_CPU_H_
+#define BASE_CPU_H_
+
+#include <string>
+
+namespace base {
+
+// Query information about the processor.
+class CPU {
+ public:
+  // Constructor
+  CPU();
+
+  enum IntelMicroArchitecture {
+    PENTIUM,
+    SSE,
+    SSE2,
+    SSE3,
+    SSSE3,
+    SSE41,
+    SSE42,
+    AVX,
+    AVX2,
+    MAX_INTEL_MICRO_ARCHITECTURE
+  };
+
+  // Accessors for CPU information.
+  const std::string& vendor_name() const { return cpu_vendor_; }
+  int signature() const { return signature_; }
+  int stepping() const { return stepping_; }
+  int model() const { return model_; }
+  int family() const { return family_; }
+  int type() const { return type_; }
+  int extended_model() const { return ext_model_; }
+  int extended_family() const { return ext_family_; }
+  bool has_mmx() const { return has_mmx_; }
+  bool has_sse() const { return has_sse_; }
+  bool has_sse2() const { return has_sse2_; }
+  bool has_sse3() const { return has_sse3_; }
+  bool has_ssse3() const { return has_ssse3_; }
+  bool has_sse41() const { return has_sse41_; }
+  bool has_sse42() const { return has_sse42_; }
+  bool has_avx() const { return has_avx_; }
+  bool has_avx2() const { return has_avx2_; }
+  bool has_aesni() const { return has_aesni_; }
+  bool has_non_stop_time_stamp_counter() const {
+    return has_non_stop_time_stamp_counter_;
+  }
+  // has_broken_neon is only valid on ARM chips. If true, it indicates that we
+  // believe that the NEON unit on the current CPU is flawed and cannot execute
+  // some code. See https://code.google.com/p/chromium/issues/detail?id=341598
+  bool has_broken_neon() const { return has_broken_neon_; }
+
+  IntelMicroArchitecture GetIntelMicroArchitecture() const;
+  const std::string& cpu_brand() const { return cpu_brand_; }
+
+ private:
+  // Query the processor for CPUID information.
+  void Initialize();
+
+  int signature_;  // raw form of type, family, model, and stepping
+  int type_;  // process type
+  int family_;  // family of the processor
+  int model_;  // model of processor
+  int stepping_;  // processor revision number
+  int ext_model_;
+  int ext_family_;
+  bool has_mmx_;
+  bool has_sse_;
+  bool has_sse2_;
+  bool has_sse3_;
+  bool has_ssse3_;
+  bool has_sse41_;
+  bool has_sse42_;
+  bool has_avx_;
+  bool has_avx2_;
+  bool has_aesni_;
+  bool has_non_stop_time_stamp_counter_;
+  bool has_broken_neon_;
+  std::string cpu_vendor_;
+  std::string cpu_brand_;
+};
+
+}  // namespace base
+
+#endif  // BASE_CPU_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/cycleclock-inl.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/cycleclock-inl.h b/be/src/gutil/cycleclock-inl.h
index f5a1333..7738592 100644
--- a/be/src/gutil/cycleclock-inl.h
+++ b/be/src/gutil/cycleclock-inl.h
@@ -1,16 +1,21 @@
 // Copyright (C) 1999-2007 Google, Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // All rights reserved.
 // Extracted from base/timer.h by jrvb
@@ -26,13 +31,13 @@
 // with modifications by m3b.  See also
 //    https://setisvn.ssl.berkeley.edu/svn/lib/fftw-3.0.1/kernel/cycle.h
 
-#ifndef SUPERSONIC_OPENSOURCE_AUXILIARY_CYCLECLOCK_INL_H_
-#define SUPERSONIC_OPENSOURCE_AUXILIARY_CYCLECLOCK_INL_H_
+#ifndef GUTIL_CYCLECLOCK_INL_H_
+#define GUTIL_CYCLECLOCK_INL_H_
 
 #include <sys/time.h>
 
-#include "gutil/port.h"
-#include "gutil/arm_instruction_set_select.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/arm_instruction_set_select.h"
 
 // Please do not nest #if directives.  Keep one section, and one #if per
 // platform.
@@ -143,7 +148,7 @@ inline int64 CycleClock::Now() {
 
 // ----------------------------------------------------------------
 #elif defined(ARMV6)  // V6 is the earliest arm that has a standard cyclecount
-#include "base/sysinfo.h"
+#include "kudu/gutil/sysinfo.h"
 inline int64 CycleClock::Now() {
   uint32 pmccntr;
   uint32 pmuseren;
@@ -166,7 +171,7 @@ inline int64 CycleClock::Now() {
 
 // ----------------------------------------------------------------
 #elif defined(ARMV3)
-#include "base/sysinfo.h"   // for CyclesPerSecond()
+#include "kudu/gutil/sysinfo.h"   // for CyclesPerSecond()
 inline int64 CycleClock::Now() {
   struct timeval tv;
   gettimeofday(&tv, NULL);
@@ -176,7 +181,7 @@ inline int64 CycleClock::Now() {
 
 // ----------------------------------------------------------------
 #elif defined(__mips__)
-#include "base/sysinfo.h"
+#include "kudu/gutil/sysinfo.h"
 inline int64 CycleClock::Now() {
   // mips apparently only allows rdtsc for superusers, so we fall
   // back to gettimeofday.  It's possible clock_gettime would be better.
@@ -195,4 +200,4 @@ inline int64 CycleClock::Now() {
 #error You need to define CycleTimer for your O/S and CPU
 #endif
 
-#endif  // SUPERSONIC_OPENSOURCE_AUXILIARY_CYCLECLOCK_INL_H_
+#endif  // GUTIL_CYCLECLOCK_INL_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/dynamic_annotations.c
----------------------------------------------------------------------
diff --git a/be/src/gutil/dynamic_annotations.c b/be/src/gutil/dynamic_annotations.c
new file mode 100644
index 0000000..32c032b
--- /dev/null
+++ b/be/src/gutil/dynamic_annotations.c
@@ -0,0 +1,173 @@
+/* Copyright (c) 2008-2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ---
+ * Author: Kostya Serebryany
+ */
+
+#ifdef __cplusplus
+# error "This file should be built as pure C to avoid name mangling"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "gutil/dynamic_annotations.h"
+
+#ifdef __GNUC__
+/* valgrind.h uses gcc extensions so it won't build with other compilers */
+#include "gutil/valgrind.h"
+#endif
+
+/* Compiler-based ThreadSanitizer defines
+   DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL = 1
+   and provides its own definitions of the functions. */
+
+#ifndef DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL
+# define DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL 0
+#endif
+
+/* Each function is empty and called (via a macro) only in debug mode.
+   The arguments are captured by dynamic tools at runtime. */
+
+#if DYNAMIC_ANNOTATIONS_ENABLED == 1 \
+    && DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0
+
+void AnnotateRWLockCreate(const char *file, int line,
+                          const volatile void *lock){}
+void AnnotateRWLockDestroy(const char *file, int line,
+                           const volatile void *lock){}
+void AnnotateRWLockAcquired(const char *file, int line,
+                            const volatile void *lock, long is_w){}
+void AnnotateRWLockReleased(const char *file, int line,
+                            const volatile void *lock, long is_w){}
+void AnnotateBarrierInit(const char *file, int line,
+                         const volatile void *barrier, long count,
+                         long reinitialization_allowed) {}
+void AnnotateBarrierWaitBefore(const char *file, int line,
+                               const volatile void *barrier) {}
+void AnnotateBarrierWaitAfter(const char *file, int line,
+                              const volatile void *barrier) {}
+void AnnotateBarrierDestroy(const char *file, int line,
+                            const volatile void *barrier) {}
+
+void AnnotateCondVarWait(const char *file, int line,
+                         const volatile void *cv,
+                         const volatile void *lock){}
+void AnnotateCondVarSignal(const char *file, int line,
+                           const volatile void *cv){}
+void AnnotateCondVarSignalAll(const char *file, int line,
+                              const volatile void *cv){}
+void AnnotatePublishMemoryRange(const char *file, int line,
+                                const volatile void *address,
+                                long size){}
+void AnnotateUnpublishMemoryRange(const char *file, int line,
+                                  const volatile void *address,
+                                  long size){}
+void AnnotatePCQCreate(const char *file, int line,
+                       const volatile void *pcq){}
+void AnnotatePCQDestroy(const char *file, int line,
+                        const volatile void *pcq){}
+void AnnotatePCQPut(const char *file, int line,
+                    const volatile void *pcq){}
+void AnnotatePCQGet(const char *file, int line,
+                    const volatile void *pcq){}
+void AnnotateNewMemory(const char *file, int line,
+                       const volatile void *mem,
+                       long size){}
+void AnnotateExpectRace(const char *file, int line,
+                        const volatile void *mem,
+                        const char *description){}
+void AnnotateBenignRace(const char *file, int line,
+                        const volatile void *mem,
+                        const char *description){}
+void AnnotateBenignRaceSized(const char *file, int line,
+                             const volatile void *mem,
+                             long size,
+                             const char *description) {}
+void AnnotateMutexIsUsedAsCondVar(const char *file, int line,
+                                  const volatile void *mu){}
+void AnnotateTraceMemory(const char *file, int line,
+                         const volatile void *arg){}
+void AnnotateThreadName(const char *file, int line,
+                        const char *name){}
+void AnnotateIgnoreReadsBegin(const char *file, int line){}
+void AnnotateIgnoreReadsEnd(const char *file, int line){}
+void AnnotateIgnoreWritesBegin(const char *file, int line){}
+void AnnotateIgnoreWritesEnd(const char *file, int line){}
+void AnnotateEnableRaceDetection(const char *file, int line, int enable){}
+void AnnotateNoOp(const char *file, int line,
+                  const volatile void *arg){}
+void AnnotateFlushState(const char *file, int line){}
+
+#endif  /* DYNAMIC_ANNOTATIONS_ENABLED == 1
+    && DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */
+
+#if DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0
+
+static int GetRunningOnValgrind(void) {
+#ifdef RUNNING_ON_VALGRIND
+  if (RUNNING_ON_VALGRIND) return 1;
+#endif
+  char *running_on_valgrind_str = getenv("RUNNING_ON_VALGRIND");
+  if (running_on_valgrind_str) {
+    return strcmp(running_on_valgrind_str, "0") != 0;
+  }
+  return 0;
+}
+
+/* See the comments in dynamic_annotations.h */
+int RunningOnValgrind(void) {
+  static volatile int running_on_valgrind = -1;
+  int local_running_on_valgrind = running_on_valgrind;
+  /* C doesn't have thread-safe initialization of statics, and we
+     don't want to depend on pthread_once here, so hack it. */
+  ANNOTATE_BENIGN_RACE(&running_on_valgrind, "safe hack");
+  if (local_running_on_valgrind == -1)
+    running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind();
+  return local_running_on_valgrind;
+}
+
+/* See the comments in dynamic_annotations.h */
+double ValgrindSlowdown(void) {
+  /* Same initialization hack as in RunningOnValgrind(). */
+  static volatile double slowdown = 0.0;
+  double local_slowdown = slowdown;
+  ANNOTATE_BENIGN_RACE(&slowdown, "safe hack");
+  if (RunningOnValgrind() == 0) {
+    return 1.0;
+  }
+  if (local_slowdown == 0.0) {
+    char *env = getenv("VALGRIND_SLOWDOWN");
+    slowdown = local_slowdown = env ? atof(env) : 50.0;
+  }
+  return local_slowdown;
+}
+
+#endif  /* DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/dynamic_annotations.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/dynamic_annotations.cc b/be/src/gutil/dynamic_annotations.cc
deleted file mode 100644
index 5743674..0000000
--- a/be/src/gutil/dynamic_annotations.cc
+++ /dev/null
@@ -1,173 +0,0 @@
-/* Copyright (c) 2008-2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * ---
- * Author: Kostya Serebryany
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "dynamic_annotations.h"
-
-#ifdef __GNUC__
-/* valgrind.h uses gcc extensions so it won't build with other compilers */
-#include "gutil/valgrind.h"
-#endif
-
-// Impala modification: made this file C++ and use extern "C" (IMPALA-3183).
-extern "C" {
-
-/* Compiler-based ThreadSanitizer defines
-   DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL = 1
-   and provides its own definitions of the functions. */
-
-#ifndef DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL
-# define DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL 0
-#endif
-
-/* Each function is empty and called (via a macro) only in debug mode.
-   The arguments are captured by dynamic tools at runtime. */
-
-#if DYNAMIC_ANNOTATIONS_ENABLED == 1 \
-    && DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0
-
-void AnnotateRWLockCreate(const char *file, int line,
-                          const volatile void *lock){}
-void AnnotateRWLockDestroy(const char *file, int line,
-                           const volatile void *lock){}
-void AnnotateRWLockAcquired(const char *file, int line,
-                            const volatile void *lock, long is_w){}
-void AnnotateRWLockReleased(const char *file, int line,
-                            const volatile void *lock, long is_w){}
-void AnnotateBarrierInit(const char *file, int line,
-                         const volatile void *barrier, long count,
-                         long reinitialization_allowed) {}
-void AnnotateBarrierWaitBefore(const char *file, int line,
-                               const volatile void *barrier) {}
-void AnnotateBarrierWaitAfter(const char *file, int line,
-                              const volatile void *barrier) {}
-void AnnotateBarrierDestroy(const char *file, int line,
-                            const volatile void *barrier) {}
-
-void AnnotateCondVarWait(const char *file, int line,
-                         const volatile void *cv,
-                         const volatile void *lock){}
-void AnnotateCondVarSignal(const char *file, int line,
-                           const volatile void *cv){}
-void AnnotateCondVarSignalAll(const char *file, int line,
-                              const volatile void *cv){}
-void AnnotatePublishMemoryRange(const char *file, int line,
-                                const volatile void *address,
-                                long size){}
-void AnnotateUnpublishMemoryRange(const char *file, int line,
-                                  const volatile void *address,
-                                  long size){}
-void AnnotatePCQCreate(const char *file, int line,
-                       const volatile void *pcq){}
-void AnnotatePCQDestroy(const char *file, int line,
-                        const volatile void *pcq){}
-void AnnotatePCQPut(const char *file, int line,
-                    const volatile void *pcq){}
-void AnnotatePCQGet(const char *file, int line,
-                    const volatile void *pcq){}
-void AnnotateNewMemory(const char *file, int line,
-                       const volatile void *mem,
-                       long size){}
-void AnnotateExpectRace(const char *file, int line,
-                        const volatile void *mem,
-                        const char *description){}
-void AnnotateBenignRace(const char *file, int line,
-                        const volatile void *mem,
-                        const char *description){}
-void AnnotateBenignRaceSized(const char *file, int line,
-                             const volatile void *mem,
-                             long size,
-                             const char *description) {}
-void AnnotateMutexIsUsedAsCondVar(const char *file, int line,
-                                  const volatile void *mu){}
-void AnnotateTraceMemory(const char *file, int line,
-                         const volatile void *arg){}
-void AnnotateThreadName(const char *file, int line,
-                        const char *name){}
-void AnnotateIgnoreReadsBegin(const char *file, int line){}
-void AnnotateIgnoreReadsEnd(const char *file, int line){}
-void AnnotateIgnoreWritesBegin(const char *file, int line){}
-void AnnotateIgnoreWritesEnd(const char *file, int line){}
-void AnnotateEnableRaceDetection(const char *file, int line, int enable){}
-void AnnotateNoOp(const char *file, int line,
-                  const volatile void *arg){}
-void AnnotateFlushState(const char *file, int line){}
-
-#endif  /* DYNAMIC_ANNOTATIONS_ENABLED == 1
-    && DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */
-
-#if DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0
-
-static int GetRunningOnValgrind(void) {
-#ifdef RUNNING_ON_VALGRIND
-  if (RUNNING_ON_VALGRIND) return 1;
-#endif
-  char *running_on_valgrind_str = getenv("RUNNING_ON_VALGRIND");
-  if (running_on_valgrind_str) {
-    return strcmp(running_on_valgrind_str, "0") != 0;
-  }
-  return 0;
-}
-
-/* See the comments in dynamic_annotations.h */
-int RunningOnValgrind(void) {
-  static volatile int running_on_valgrind = -1;
-  int local_running_on_valgrind = running_on_valgrind;
-  /* C doesn't have thread-safe initialization of statics, and we
-     don't want to depend on pthread_once here, so hack it. */
-  ANNOTATE_BENIGN_RACE(&running_on_valgrind, "safe hack");
-  if (local_running_on_valgrind == -1)
-    running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind();
-  return local_running_on_valgrind;
-}
-
-/* See the comments in dynamic_annotations.h */
-double ValgrindSlowdown(void) {
-  /* Same initialization hack as in RunningOnValgrind(). */
-  static volatile double slowdown = 0.0;
-  double local_slowdown = slowdown;
-  ANNOTATE_BENIGN_RACE(&slowdown, "safe hack");
-  if (RunningOnValgrind() == 0) {
-    return 1.0;
-  }
-  if (local_slowdown == 0.0) {
-    char *env = getenv("VALGRIND_SLOWDOWN");
-    slowdown = local_slowdown = env ? atof(env) : 50.0;
-  }
-  return local_slowdown;
-}
-
-#endif  /* DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */
-}

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/dynamic_annotations.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/dynamic_annotations.h b/be/src/gutil/dynamic_annotations.h
index 53e6c31..ce68d89 100644
--- a/be/src/gutil/dynamic_annotations.h
+++ b/be/src/gutil/dynamic_annotations.h
@@ -246,6 +246,15 @@
       ANNOTATE_IGNORE_READS_END();\
     }while(0)\
 
+  /* Start ignoring all synchronization until ANNOTATE_IGNORE_SYNC_END
+     is called. */
+  #define ANNOTATE_IGNORE_SYNC_BEGIN() \
+    AnnotateIgnoreSyncBegin(__FILE__, __LINE__)
+
+  /* Stop ignoring all synchronization. */
+  #define ANNOTATE_IGNORE_SYNC_END() \
+    AnnotateIgnoreSyncEnd(__FILE__, __LINE__)
+
   /* Enable (enable!=0) or disable (enable==0) race detection for all threads.
      This annotation could be useful if you want to skip expensive race analysis
      during some period of program execution, e.g. during initialization. */
@@ -374,6 +383,8 @@
   #define ANNOTATE_IGNORE_WRITES_END() /* empty */
   #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() /* empty */
   #define ANNOTATE_IGNORE_READS_AND_WRITES_END() /* empty */
+  #define ANNOTATE_IGNORE_SYNC_BEGIN() /* empty */
+  #define ANNOTATE_IGNORE_SYNC_END() /* empty */
   #define ANNOTATE_ENABLE_RACE_DETECTION(enable) /* empty */
   #define ANNOTATE_NO_OP(arg) /* empty */
   #define ANNOTATE_FLUSH_STATE() /* empty */
@@ -396,7 +407,7 @@
 
 #if defined(__GNUC__) && (!defined(SWIG)) && (!defined(__clang__))
 
-#if DYNAMIC_ANNOTATIONS_ENABLED == 0 && LLVM_ENABLE_THREADS == 0
+#if DYNAMIC_ANNOTATIONS_ENABLED == 0
 #define ANNOTALYSIS_ONLY 1
 #undef ANNOTALYSIS_STATIC_INLINE
 #define ANNOTALYSIS_STATIC_INLINE static inline
@@ -524,6 +535,8 @@ void AnnotateIgnoreWritesBegin(const char *file, int line)
 ANNOTALYSIS_STATIC_INLINE
 void AnnotateIgnoreWritesEnd(const char *file, int line)
     ANNOTALYSIS_IGNORE_WRITES_END ANNOTALYSIS_SEMICOLON_OR_EMPTY_BODY
+void AnnotateIgnoreSyncBegin(const char *file, int line);
+void AnnotateIgnoreSyncEnd(const char *file, int line);
 void AnnotateEnableRaceDetection(const char *file, int line, int enable);
 void AnnotateNoOp(const char *file, int line,
                   const volatile void *arg);
@@ -559,6 +572,53 @@ int RunningOnValgrind(void);
  */
 double ValgrindSlowdown(void);
 
+
+/* AddressSanitizer annotations from LLVM asan_interface.h */
+
+
+#if defined(__SANITIZE_ADDRESS__) || defined(ADDRESS_SANITIZER)
+// Marks memory region [addr, addr+size) as unaddressable.
+// This memory must be previously allocated by the user program. Accessing
+// addresses in this region from instrumented code is forbidden until
+// this region is unpoisoned. This function is not guaranteed to poison
+// the whole region - it may poison only subregion of [addr, addr+size) due
+// to ASan alignment restrictions.
+// Method is NOT thread-safe in the sense that no two threads can
+// (un)poison memory in the same memory region simultaneously.
+void __asan_poison_memory_region(void const volatile *addr, size_t size);
+// Marks memory region [addr, addr+size) as addressable.
+// This memory must be previously allocated by the user program. Accessing
+// addresses in this region is allowed until this region is poisoned again.
+// This function may unpoison a superregion of [addr, addr+size) due to
+// ASan alignment restrictions.
+// Method is NOT thread-safe in the sense that no two threads can
+// (un)poison memory in the same memory region simultaneously.
+void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
+
+// User code should use macros instead of functions.
+#define ASAN_POISON_MEMORY_REGION(addr, size)   \
+  __asan_poison_memory_region((addr), (size))
+#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
+  __asan_unpoison_memory_region((addr), (size))
+#else
+#define ASAN_POISON_MEMORY_REGION(addr, size)   \
+  ((void)(addr), (void)(size))
+#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
+  ((void)(addr), (void)(size))
+#endif
+
+// Sets the callback to be called right before death on error.
+// Passing 0 will unset the callback.
+void __asan_set_death_callback(void (*callback)(void));
+
+#if defined(__SANITIZE_ADDRESS__) || defined(ADDRESS_SANITIZER)
+#define ASAN_SET_DEATH_CALLBACK(cb)   \
+  __asan_set_death_callback((cb))
+#else
+#define ASAN_SET_DEATH_CALLBACK(cb)   \
+  ((void)(cb))
+#endif
+
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/endian.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/endian.h b/be/src/gutil/endian.h
index fe8cf85..5ed8f38 100644
--- a/be/src/gutil/endian.h
+++ b/be/src/gutil/endian.h
@@ -1,16 +1,21 @@
 // Copyright 2005 Google Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // ---
 //
@@ -27,9 +32,9 @@
 
 #include <assert.h>
 
-#include "gutil/int128.h"
-#include "gutil/integral_types.h"
-#include "gutil/port.h"
+#include "kudu/gutil/int128.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/port.h"
 
 inline uint64 gbswap_64(uint64 host_int) {
 #if defined(__GNUC__) && defined(__x86_64__) && !defined(__APPLE__)
@@ -74,15 +79,17 @@ inline uint64 ghtonll(uint64 x) { return x; }
 #error "Unsupported bytesex: Either IS_BIG_ENDIAN or IS_LITTLE_ENDIAN must be defined"  // NOLINT
 #endif  // bytesex
 
-// This one is safe to take as it's an extension
-#define htonll(x) ghtonll(x)
 
 // ntoh* and hton* are the same thing for any size and bytesex,
 // since the function is an involution, i.e., its own inverse.
 #define gntohl(x) ghtonl(x)
 #define gntohs(x) ghtons(x)
 #define gntohll(x) ghtonll(x)
+#if !defined(__APPLE__)
+// This one is safe to take as it's an extension
+#define htonll(x) ghtonll(x)
 #define ntohll(x) htonll(x)
+#endif
 
 // Utilities to convert numbers between the current hosts's native byte
 // order and little-endian byte order

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/fixedarray.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/fixedarray.h b/be/src/gutil/fixedarray.h
index d201df9..3e9e072 100644
--- a/be/src/gutil/fixedarray.h
+++ b/be/src/gutil/fixedarray.h
@@ -1,16 +1,21 @@
 // Copyright 2005 Google Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // ---
 //
@@ -19,10 +24,12 @@
 #define UTIL_GTL_FIXEDARRAY_H__
 
 #include <stddef.h>
+
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/macros.h"
-#include "gutil/manual_constructor.h"
+
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/manual_constructor.h"
 
 // A FixedArray<T> represents a non-resizable array of T where the
 // length of the array does not need to be a compile time constant.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/gscoped_ptr.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/gscoped_ptr.h b/be/src/gutil/gscoped_ptr.h
index 4232b97..eee1ec7 100644
--- a/be/src/gutil/gscoped_ptr.h
+++ b/be/src/gutil/gscoped_ptr.h
@@ -50,15 +50,15 @@
 //     return gscoped_ptr<Foo>(new Foo("new"));
 //   }
 //   gscoped_ptr<Foo> PassThru(gscoped_ptr<Foo> arg) {
-//     return arg.Pass();
+//     return std::move(arg);
 //   }
 //
 //   {
 //     gscoped_ptr<Foo> ptr(new Foo("yay"));  // ptr manages Foo("yay").
-//     TakesOwnership(ptr.Pass());           // ptr no longer owns Foo("yay").
+//     TakesOwnership(std::move(ptr));           // ptr no longer owns Foo("yay").
 //     gscoped_ptr<Foo> ptr2 = CreateFoo();   // ptr2 owns the return Foo.
 //     gscoped_ptr<Foo> ptr3 =                // ptr3 now owns what was in ptr2.
-//         PassThru(ptr2.Pass());            // ptr2 is correspondingly NULL.
+//         PassThru(std::move(ptr2));            // ptr2 is correspondingly NULL.
 //   }
 //
 // Notice that if you do not call Pass() when returning from PassThru(), or
@@ -72,7 +72,7 @@
 // gscoped_ptr<Child> to gscoped_ptr<Parent>:
 //
 //   gscoped_ptr<Foo> foo(new Foo());
-//   gscoped_ptr<FooParent> parent = foo.Pass();
+//   gscoped_ptr<FooParent> parent = std::move(foo);
 //
 // PassAs<>() should be used to upcast return value in return statement:
 //
@@ -91,8 +91,8 @@
 // some of the older compilers we have to support.
 // -------------------------------------------------------------------------
 
-#ifndef BASE_MEMORY_SCOPED_PTR_H_
-#define BASE_MEMORY_SCOPED_PTR_H_
+#ifndef KUDU_GUTIL_GSCOPED_PTR_H_
+#define KUDU_GUTIL_GSCOPED_PTR_H_
 
 // This is an implementation designed to match the anticipated future TR2
 // implementation of the scoped_ptr class, and its closely-related brethren,
@@ -104,12 +104,12 @@
 
 #include <algorithm>  // For std::swap().
 
-#include "gutil/basictypes.h"
-#include "gutil/template_util.h"
-#include "gutil/type_traits.h"
-#include "gutil/move.h"
+#include "kudu/gutil/basictypes.h"
+#include "kudu/gutil/template_util.h"
+#include "kudu/gutil/type_traits.h"
+#include "kudu/gutil/move.h"
 
-namespace base {
+namespace kudu {
 
 namespace subtle {
 class RefCountedBase;
@@ -174,7 +174,7 @@ struct DefaultDeleter<T[n]> {
 // Function object which invokes 'free' on its parameter, which must be
 // a pointer. Can be used to store malloc-allocated pointers in gscoped_ptr:
 //
-// gscoped_ptr<int, base::FreeDeleter> foo_ptr(
+// gscoped_ptr<int, kudu::FreeDeleter> foo_ptr(
 //     static_cast<int*>(malloc(sizeof(int))));
 struct FreeDeleter {
   inline void operator()(void* ptr) const {
@@ -186,8 +186,8 @@ namespace internal {
 
 template <typename T> struct IsNotRefCounted {
   enum {
-    value = !base::is_convertible<T*, base::subtle::RefCountedBase*>::value &&
-        !base::is_convertible<T*, base::subtle::RefCountedThreadSafeBase*>::
+    value = !base::is_convertible<T*, kudu::subtle::RefCountedBase*>::value &&
+        !base::is_convertible<T*, kudu::subtle::RefCountedThreadSafeBase*>::
             value
   };
 };
@@ -285,7 +285,7 @@ class gscoped_ptr_impl {
   // discussion of this technique.
   struct Data : public D {
     explicit Data(T* ptr_in) : ptr(ptr_in) {}
-    Data(T* ptr_in, const D& other) : D(other), ptr(ptr_in) {}
+    Data(T* ptr_in, D other) : D(std::move(other)), ptr(ptr_in) {}
     T* ptr;
   };
 
@@ -296,7 +296,7 @@ class gscoped_ptr_impl {
 
 }  // namespace internal
 
-}  // namespace base
+}  // namespace kudu
 
 // A gscoped_ptr<T> is like a T*, except that the destructor of gscoped_ptr<T>
 // automatically deletes the pointer it holds (if any).
@@ -314,11 +314,11 @@ class gscoped_ptr_impl {
 // unique_ptr<> features. Known deficiencies include not supporting move-only
 // deleteres, function pointers as deleters, and deleters with reference
 // types.
-template <class T, class D = base::DefaultDeleter<T> >
+template <class T, class D = kudu::DefaultDeleter<T> >
 class gscoped_ptr {
   MOVE_ONLY_TYPE_FOR_CPP_03(gscoped_ptr, RValue)
 
-  COMPILE_ASSERT(base::internal::IsNotRefCounted<T>::value,
+  COMPILE_ASSERT(kudu::internal::IsNotRefCounted<T>::value,
                  T_is_refcounted_type_and_needs_scoped_refptr);
 
  public:
@@ -393,7 +393,7 @@ class gscoped_ptr {
   // Allow gscoped_ptr<element_type> to be used in boolean expressions, but not
   // implicitly convertible to a real bool (which is dangerous).
  private:
-  typedef base::internal::gscoped_ptr_impl<element_type, deleter_type>
+  typedef kudu::internal::gscoped_ptr_impl<element_type, deleter_type>
       gscoped_ptr::*Testable;
 
  public:
@@ -433,7 +433,7 @@ class gscoped_ptr {
  private:
   // Needed to reach into |impl_| in the constructor.
   template <typename U, typename V> friend class gscoped_ptr;
-  base::internal::gscoped_ptr_impl<element_type, deleter_type> impl_;
+  kudu::internal::gscoped_ptr_impl<element_type, deleter_type> impl_;
 
   // Forbid comparison of gscoped_ptr types.  If U != T, it totally
   // doesn't make sense, and if U == T, it still doesn't make sense
@@ -500,7 +500,7 @@ class gscoped_ptr<T[], D> {
   // Allow gscoped_ptr<element_type> to be used in boolean expressions, but not
   // implicitly convertible to a real bool (which is dangerous).
  private:
-  typedef base::internal::gscoped_ptr_impl<element_type, deleter_type>
+  typedef kudu::internal::gscoped_ptr_impl<element_type, deleter_type>
       gscoped_ptr::*Testable;
 
  public:
@@ -531,7 +531,7 @@ class gscoped_ptr<T[], D> {
   enum { type_must_be_complete = sizeof(element_type) };
 
   // Actually hold the data.
-  base::internal::gscoped_ptr_impl<element_type, deleter_type> impl_;
+  kudu::internal::gscoped_ptr_impl<element_type, deleter_type> impl_;
 
   // Disable initialization from any type other than element_type*, by
   // providing a constructor that matches such an initialization, but is
@@ -691,12 +691,12 @@ bool operator!=(C* p1, const gscoped_array<C>& p2) {
   return p1 != p2.get();
 }
 
-// DEPRECATED: Use gscoped_ptr<C, base::FreeDeleter> instead.
+// DEPRECATED: Use gscoped_ptr<C, kudu::FreeDeleter> instead.
 //
 // gscoped_ptr_malloc<> is similar to gscoped_ptr<>, but it accepts a
 // second template argument, the functor used to free the object.
 
-template<class C, class FreeProc = base::FreeDeleter>
+template<class C, class FreeProc = kudu::FreeDeleter>
 class gscoped_ptr_malloc {
   MOVE_ONLY_TYPE_FOR_CPP_03(gscoped_ptr_malloc, RValue)
 
@@ -827,4 +827,4 @@ gscoped_ptr<T> make_gscoped_ptr(T* ptr) {
   return gscoped_ptr<T>(ptr);
 }
 
-#endif  // BASE_MEMORY_SCOPED_PTR_H_
+#endif  // KUDU_GUTIL_GSCOPED_PTR_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/builtin_type_hash.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/builtin_type_hash.h b/be/src/gutil/hash/builtin_type_hash.h
index 173839b..c979eb2 100644
--- a/be/src/gutil/hash/builtin_type_hash.h
+++ b/be/src/gutil/hash/builtin_type_hash.h
@@ -10,10 +10,10 @@
 #include <stddef.h>
 #include <stdint.h>
 
-#include "gutil/casts.h"
-#include "gutil/integral_types.h"
-#include "gutil/macros.h"
-#include "gutil/hash/jenkins_lookup2.h"
+#include "kudu/gutil/casts.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/hash/jenkins_lookup2.h"
 
 inline uint32 Hash32NumWithSeed(uint32 num, uint32 c) {
   uint32 b = 0x9e3779b9UL;            // the golden ratio; an arbitrary value

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/city.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/city.cc b/be/src/gutil/hash/city.cc
index c35e70e..cc00ff7 100644
--- a/be/src/gutil/hash/city.cc
+++ b/be/src/gutil/hash/city.cc
@@ -14,7 +14,7 @@
 // optimize the code here by writing a program that systematically explores
 // more of the space of possible hash functions, or by using SIMD instructions.
 
-#include "gutil/hash/city.h"
+#include "kudu/gutil/hash/city.h"
 
 #include <sys/types.h>
 #include <algorithm>
@@ -28,12 +28,12 @@ using std::swap;
 using std::make_pair;
 using std::pair;
 
-#include "gutil/int128.h"
-#include "gutil/integral_types.h"
+#include "kudu/gutil/int128.h"
+#include "kudu/gutil/integral_types.h"
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/hash/hash128to64.h"
-#include "gutil/endian.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/hash/hash128to64.h"
+#include "kudu/gutil/endian.h"
 
 namespace util_hash {
 
@@ -305,7 +305,7 @@ uint128 CityHash128(const char *s, size_t len) {
                                uint128(LittleEndian::Load64(s) ^ k3,
                                        LittleEndian::Load64(s + 8)));
   } else if (len >= 8) {
-    return CityHash128WithSeed(NULL,
+    return CityHash128WithSeed(nullptr,
                                0,
                                uint128(LittleEndian::Load64(s) ^ (len * k0),
                                        LittleEndian::Load64(s + len - 8) ^ k1));

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/city.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/city.h b/be/src/gutil/hash/city.h
index d5925e5..e99202e 100644
--- a/be/src/gutil/hash/city.h
+++ b/be/src/gutil/hash/city.h
@@ -23,8 +23,8 @@
 
 #include <stddef.h>  // for size_t.
 
-#include "gutil/int128.h"
-#include "gutil/integral_types.h"
+#include "kudu/gutil/int128.h"
+#include "kudu/gutil/integral_types.h"
 
 namespace util_hash {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/hash.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/hash.cc b/be/src/gutil/hash/hash.cc
index 85c4663..92a8ca2 100644
--- a/be/src/gutil/hash/hash.cc
+++ b/be/src/gutil/hash/hash.cc
@@ -7,13 +7,13 @@
 // To find the implementation of the core Bob Jenkins lookup2 hash, look in
 // jenkins.cc.
 
-#include "gutil/hash/hash.h"
+#include "kudu/gutil/hash/hash.h"
 
-#include "gutil/integral_types.h"
+#include "kudu/gutil/integral_types.h"
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/hash/jenkins.h"
-#include "gutil/hash/jenkins_lookup2.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/hash/jenkins.h"
+#include "kudu/gutil/hash/jenkins_lookup2.h"
 
 // For components that ship code externally (notably the Google Search
 // Appliance) we want to change the fingerprint function so that
@@ -36,10 +36,6 @@ static inline uint32 char2unsigned(char c) {
   return static_cast<uint32>(static_cast<unsigned char>(c));
 }
 
-static inline uint64 char2unsigned64(char c) {
-  return static_cast<uint64>(static_cast<unsigned char>(c));
-}
-
 uint64 FingerprintReferenceImplementation(const char *s, uint32 len) {
   uint32 hi = Hash32StringWithSeed(s, len, kFingerprintSeed0);
   uint32 lo = Hash32StringWithSeed(s, len, kFingerprintSeed1);
@@ -193,8 +189,8 @@ uint64 FingerprintInterleavedImplementation(const char *s, uint32 len) {
 #include <ext/hash_set>
 namespace __gnu_cxx {
 
-template class hash_set<string>;
-template class hash_map<string, string>;
+template class hash_set<std::string>;
+template class hash_map<std::string, std::string>;
 
 }  // namespace __gnu_cxx
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/hash.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/hash.h b/be/src/gutil/hash/hash.h
index 05116a7..3c14f80 100644
--- a/be/src/gutil/hash/hash.h
+++ b/be/src/gutil/hash/hash.h
@@ -77,12 +77,6 @@
 #include <stdint.h>     // for uintptr_t
 #include <string.h>
 #include <algorithm>
-using std::copy;
-using std::max;
-using std::min;
-using std::reverse;
-using std::sort;
-using std::swap;
 #include <ext/hash_map>
 using __gnu_cxx::hash;
 using __gnu_cxx::hash_map;     // hacky way to make sure we import standard hash<> fns
@@ -90,22 +84,19 @@ using __gnu_cxx::hash_map;     // hacky way to make sure we import standard hash
 using __gnu_cxx::hash;
 using __gnu_cxx::hash_set;
 #include <string>
-using std::string;
 #include <utility>
-using std::make_pair;
-using std::pair;
-
-#include "gutil/casts.h"
-#include "gutil/int128.h"
-#include "gutil/integral_types.h"
-#include "gutil/macros.h"
-#include "gutil/port.h"
-#include "gutil/hash/city.h"
-#include "gutil/hash/hash128to64.h"
-#include "gutil/hash/jenkins.h"
-#include "gutil/hash/jenkins_lookup2.h"
-#include "gutil/hash/legacy_hash.h"
-#include "gutil/hash/string_hash.h"
+
+#include "kudu/gutil/casts.h"
+#include "kudu/gutil/int128.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/hash/city.h"
+#include "kudu/gutil/hash/hash128to64.h"
+#include "kudu/gutil/hash/jenkins.h"
+#include "kudu/gutil/hash/jenkins_lookup2.h"
+#include "kudu/gutil/hash/legacy_hash.h"
+#include "kudu/gutil/hash/string_hash.h"
 
 #include <ext/hash_set>
 namespace __gnu_cxx {
@@ -123,14 +114,6 @@ struct hash {
 };
 #endif  // defined(_MSC_VER)
 
-template<> struct hash<int64> {
-  size_t operator()(int64 x) const { return static_cast<size_t>(x); }
-};
-
-template<> struct hash<uint64> {
-  size_t operator()(uint64 x) const { return static_cast<size_t>(x); }
-};
-
 #endif  // !defined(_STLP_LONG_LONG) && !(defined(_MSC_VER) && _MSC_VER >= 1600)
 
 template<> struct hash<bool> {
@@ -186,10 +169,10 @@ inline uint64 CombineFingerprintHalves(uint32 hi, uint32 lo) {
   return result;
 }
 
-inline uint64 Fingerprint(const string& s) {
+inline uint64 Fingerprint(const std::string& s) {
   return Fingerprint(s.data(), static_cast<uint32>(s.size()));
 }
-inline uint64 Hash64StringWithSeed(const string& s, uint64 c) {
+inline uint64 Hash64StringWithSeed(const std::string& s, uint64 c) {
   return Hash64StringWithSeed(s.data(), static_cast<uint32>(s.size()), c);
 }
 inline uint64 Fingerprint(schar c) {
@@ -283,8 +266,8 @@ struct hash<std::basic_string<_CharT, _Traits, _Alloc> > {
 };
 
 // they don't define a hash for const string at all
-template<> struct hash<const string> {
-  size_t operator()(const string& k) const {
+template<> struct hash<const std::string> {
+  size_t operator()(const std::string& k) const {
     return HashTo32(k.data(), static_cast<uint32>(k.length()));
   }
 };
@@ -306,12 +289,12 @@ template<> struct hash<char const*> {
 
 // MSVC 10.0 and above have already defined this.
 #if !defined(_MSC_VER) || _MSC_VER < 1600
-template<> struct hash<string> {
-  size_t operator()(const string& k) const {
+template<> struct hash<std::string> {
+  size_t operator()(const std::string& k) const {
     return HashTo32(k.data(), k.length());
   }
   // Less than operator:
-  bool operator()(const string& a, const string& b) const {
+  bool operator()(const std::string& a, const std::string& b) const {
     return a < b;
   }
   static const size_t bucket_size = 4;  // These are required by MSVC
@@ -426,8 +409,8 @@ struct GoodFastHash<const std::basic_string<_CharT, _Traits, _Alloc> > {
 #include <ext/hash_set>
 namespace __gnu_cxx {
 
-extern template class hash_set<string>;
-extern template class hash_map<string, string>;
+extern template class hash_set<std::string>;
+extern template class hash_map<std::string, std::string>;
 
 }  // namespace __gnu_cxx
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/hash128to64.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/hash128to64.h b/be/src/gutil/hash/hash128to64.h
index af95662..481a010 100644
--- a/be/src/gutil/hash/hash128to64.h
+++ b/be/src/gutil/hash/hash128to64.h
@@ -4,8 +4,8 @@
 #ifndef UTIL_HASH_HASH128TO64_H_
 #define UTIL_HASH_HASH128TO64_H_
 
-#include "gutil/int128.h"
-#include "gutil/integral_types.h"
+#include "kudu/gutil/int128.h"
+#include "kudu/gutil/integral_types.h"
 
 // Hash 128 input bits down to 64 bits of output.
 // This is intended to be a reasonably good hash function.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/jenkins.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/jenkins.cc b/be/src/gutil/hash/jenkins.cc
index 7fd34bd..70a7e30 100644
--- a/be/src/gutil/hash/jenkins.cc
+++ b/be/src/gutil/hash/jenkins.cc
@@ -16,12 +16,12 @@
 // to load words from memory a byte at a time.  See gwshash.cc for an
 // implementation that is compatible with Bob Jenkins' lookup2.c.
 
-#include "gutil/hash/jenkins.h"
+#include "kudu/gutil/hash/jenkins.h"
 
-#include "gutil/integral_types.h"
+#include "kudu/gutil/integral_types.h"
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/hash/jenkins_lookup2.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/hash/jenkins_lookup2.h"
 
 static inline uint32 char2unsigned(char c) {
   return static_cast<uint32>(static_cast<unsigned char>(c));

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/jenkins.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/jenkins.h b/be/src/gutil/hash/jenkins.h
index 6837a66..90a47ed 100644
--- a/be/src/gutil/hash/jenkins.h
+++ b/be/src/gutil/hash/jenkins.h
@@ -10,7 +10,7 @@
 #ifndef UTIL_HASH_JENKINS_H_
 #define UTIL_HASH_JENKINS_H_
 
-#include "gutil/integral_types.h"
+#include "kudu/gutil/integral_types.h"
 
 // ----------------------------------------------------------------------
 // Hash32StringWithSeed()

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/jenkins_lookup2.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/jenkins_lookup2.h b/be/src/gutil/hash/jenkins_lookup2.h
index 6793809..e6ffa84 100644
--- a/be/src/gutil/hash/jenkins_lookup2.h
+++ b/be/src/gutil/hash/jenkins_lookup2.h
@@ -15,8 +15,8 @@
 #ifndef UTIL_HASH_JENKINS_LOOKUP2_H_
 #define UTIL_HASH_JENKINS_LOOKUP2_H_
 
-#include "gutil/integral_types.h"
-#include "gutil/port.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/port.h"
 
 // ----------------------------------------------------------------------
 // mix()

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/legacy_hash.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/legacy_hash.h b/be/src/gutil/hash/legacy_hash.h
index 31029eb..3a69336 100644
--- a/be/src/gutil/hash/legacy_hash.h
+++ b/be/src/gutil/hash/legacy_hash.h
@@ -10,9 +10,9 @@
 #ifndef UTIL_HASH_LEGACY_HASH_H_
 #define UTIL_HASH_LEGACY_HASH_H_
 
-#include "gutil/integral_types.h"
-#include "gutil/hash/builtin_type_hash.h"
-#include "gutil/hash/string_hash.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/hash/builtin_type_hash.h"
+#include "kudu/gutil/hash/string_hash.h"
 
 // Hash8, Hash16 and Hash32 are for legacy use only.
 typedef uint32 Hash32;
@@ -73,9 +73,6 @@ HASH_TO((uint32 c), Hash32NumWithSeed(static_cast<uint32>(c), MIX32))
 HASH_TO((int32 c),  Hash32NumWithSeed(static_cast<uint32>(c), MIX32))
 HASH_TO((uint64 c), static_cast<uint32>(Hash64NumWithSeed(c, MIX64) >> 32))
 HASH_TO((int64 c),  static_cast<uint32>(Hash64NumWithSeed(c, MIX64) >> 32))
-#ifdef _LP64
-HASH_TO((intptr_t c),  static_cast<uint32>(Hash64NumWithSeed(c, MIX64) >> 32))
-#endif
 
 #undef HASH_TO        // clean up the macro space
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/hash/string_hash.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/string_hash.h b/be/src/gutil/hash/string_hash.h
index 4e39997..d8c20f3 100644
--- a/be/src/gutil/hash/string_hash.h
+++ b/be/src/gutil/hash/string_hash.h
@@ -13,11 +13,11 @@
 
 #include <stddef.h>
 
-#include "gutil/port.h"
-#include "gutil/integral_types.h"
-#include "gutil/hash/city.h"
-#include "gutil/hash/jenkins.h"
-#include "gutil/hash/jenkins_lookup2.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/hash/city.h"
+#include "kudu/gutil/hash/jenkins.h"
+#include "kudu/gutil/hash/jenkins_lookup2.h"
 
 namespace hash_internal {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/int128.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/int128.cc b/be/src/gutil/int128.cc
index 9e2ab18..eeaee2f 100644
--- a/be/src/gutil/int128.cc
+++ b/be/src/gutil/int128.cc
@@ -6,8 +6,8 @@
 #include <iostream>
 using std::cout;
 using std::endl;
-#include "gutil/int128.h"
-#include "gutil/integral_types.h"
+#include "kudu/gutil/int128.h"
+#include "kudu/gutil/integral_types.h"
 
 const uint128_pod kuint128max = {
     static_cast<uint64>(GG_LONGLONG(0xFFFFFFFFFFFFFFFF)),

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/int128.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/int128.h b/be/src/gutil/int128.h
index 72b87cd..2a19cca 100644
--- a/be/src/gutil/int128.h
+++ b/be/src/gutil/int128.h
@@ -7,7 +7,7 @@
 
 #include <iosfwd>
 using std::ostream;
-#include "gutil/integral_types.h"
+#include "kudu/gutil/integral_types.h"
 
 struct uint128_pod;
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/integral_types.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/integral_types.h b/be/src/gutil/integral_types.h
index a57ef1e..cbcf917 100644
--- a/be/src/gutil/integral_types.h
+++ b/be/src/gutil/integral_types.h
@@ -10,6 +10,8 @@
 #ifndef BASE_INTEGRAL_TYPES_H_
 #define BASE_INTEGRAL_TYPES_H_
 
+#include <inttypes.h>
+
 // These typedefs are also defined in base/google.swig. In the
 // SWIG environment, we use those definitions and avoid duplicate
 // definitions here with an ifdef. The definitions should be the
@@ -18,14 +20,14 @@
 // Standard typedefs
 // All Google2 code is compiled with -funsigned-char to make "char"
 // unsigned.  Google2 code therefore doesn't need a "uchar" type.
-typedef signed char         schar;
-typedef signed char         int8;
-typedef short               int16;
-typedef int                 int32;
+typedef int8_t              schar;
+typedef int8_t              int8;
+typedef int16_t             int16;
+typedef int32_t             int32;
 #ifdef _MSC_VER
 typedef __int64             int64;
 #else
-typedef long long           int64;
+typedef int64_t             int64;
 #endif /* _MSC_VER */
 
 // NOTE: unsigned types are DANGEROUS in loops and other arithmetical
@@ -34,13 +36,13 @@ typedef long long           int64;
 // use 'unsigned' to express "this value should always be positive";
 // use assertions for this.
 
-typedef unsigned char      uint8;
-typedef unsigned short     uint16;
-typedef unsigned int       uint32;
+typedef uint8_t        uint8;
+typedef uint16_t       uint16;
+typedef uint32_t       uint32;
 #ifdef _MSC_VER
 typedef unsigned __int64   uint64;
 #else
-typedef unsigned long long uint64;
+typedef uint64_t uint64;
 #endif /* _MSC_VER */
 
 // A type to represent a Unicode code-point value. As of Unicode 4.0,
@@ -72,16 +74,10 @@ typedef unsigned long      uword_t;
 #define GG_LONGLONG(x) x##I64
 #define GG_ULONGLONG(x) x##UI64
 
-// Length modifier in printf format string for int64's (e.g. within %d)
-#define GG_LL_FORMAT "I64"  // As in printf("%I64d", ...)
-#define GG_LL_FORMAT_W L"I64"
-
 #else   /* not Visual C++ */
 
 #define GG_LONGLONG(x) x##LL
 #define GG_ULONGLONG(x) x##ULL
-#define GG_LL_FORMAT "ll"  // As in "%lld". Note that "q" is poor form also.
-#define GG_LL_FORMAT_W L"ll"
 
 #endif  // _MSC_VER
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/linux_syscall_support.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/linux_syscall_support.h b/be/src/gutil/linux_syscall_support.h
index 59d1dcc..5476d0b 100644
--- a/be/src/gutil/linux_syscall_support.h
+++ b/be/src/gutil/linux_syscall_support.h
@@ -235,7 +235,7 @@ struct siginfo;
 struct kernel_old_sigaction {
   union {
     void             (*sa_handler_)(int);
-    void             (*sa_sigaction_)(int, int *, void *);
+    void             (*sa_sigaction_)(int, struct siginfo *, void *);
   };
   unsigned long      sa_mask;
   unsigned long      sa_flags;
@@ -272,13 +272,13 @@ struct kernel_sigaction {
   unsigned long      sa_flags;
   union {
     void             (*sa_handler_)(int);
-    void             (*sa_sigaction_)(int, int *, void *);
+    void             (*sa_sigaction_)(int, struct siginfo *, void *);
   };
   struct kernel_sigset_t sa_mask;
 #else
   union {
     void             (*sa_handler_)(int);
-    void             (*sa_sigaction_)(int, int *, void *);
+    void             (*sa_sigaction_)(int, struct siginfo *, void *);
   };
   unsigned long      sa_flags;
   void               (*sa_restorer)(void);
@@ -2603,15 +2603,15 @@ struct kernel_io_event {
             /* check for fn == NULL
              * and child_stack == NULL
              */
-            "cmp"LSS_SIZE_S"i cr0, %6, 0\n\t"
-            "cmp"LSS_SIZE_S"i cr1, %7, 0\n\t"
+            "cmp" LSS_SIZE_S "i cr0, %6, 0\n\t"
+            "cmp" LSS_SIZE_S "i cr1, %7, 0\n\t"
             "cror cr0*4+eq, cr1*4+eq, cr0*4+eq\n\t"
             "beq- cr0, 1f\n\t"
 
             /* set up stack frame for child                                  */
-            "clrr"LSS_SIZE_S"i %7, %7, 4\n\t"
+            "clrr" LSS_SIZE_S "i %7, %7, 4\n\t"
             "li 0, 0\n\t"
-            "st"LSS_SIZE_S"u 0, %13(%7)\n\t"
+            "st" LSS_SIZE_S "u 0, %13(%7)\n\t"
 
             /* fn, arg, child_stack are saved across the syscall: r27-29     */
             "mr 28, %6\n\t"
@@ -2629,7 +2629,7 @@ struct kernel_io_event {
             "sc\n\t"
 
             /* Test if syscall was successful                                */
-            "cmp"LSS_SIZE_S"i cr1, 3, 0\n\t"
+            "cmp" LSS_SIZE_S "i cr1, 3, 0\n\t"
             "crandc cr1*4+eq, cr1*4+eq, cr0*4+so\n\t"
             "bne- cr1, 1f\n\t"
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/logging-inl.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/logging-inl.h b/be/src/gutil/logging-inl.h
index 795c21a..409a99c 100644
--- a/be/src/gutil/logging-inl.h
+++ b/be/src/gutil/logging-inl.h
@@ -1,16 +1,21 @@
 // Copyright 2012 Google Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // All rights reserved.
 //

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/macros.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/macros.h b/be/src/gutil/macros.h
index ca0daea..f271bd4 100644
--- a/be/src/gutil/macros.h
+++ b/be/src/gutil/macros.h
@@ -11,7 +11,7 @@
 #define BASE_MACROS_H_
 
 #include <stddef.h>         // For size_t
-#include "gutil/port.h"
+#include "kudu/gutil/port.h"
 
 // The swigged version of an abstract class must be concrete if any methods
 // return objects of the abstract type. We keep it abstract in C++ and
@@ -39,10 +39,8 @@ template <bool>
 struct CompileAssert {
 };
 
-#ifndef COMPILE_ASSERT
 #define COMPILE_ASSERT(expr, msg) \
-  typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
-#endif
+  typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] ATTRIBUTE_UNUSED
 
 // Implementation details of COMPILE_ASSERT:
 //
@@ -95,21 +93,10 @@ struct CompileAssert {
 // Note, that most uses of DISALLOW_ASSIGN and DISALLOW_COPY are broken
 // semantically, one should either use disallow both or neither. Try to
 // avoid these in new code.
-//
-// The LANG_CXX11 branch is a workaround for
-// http://gcc.gnu.org/PR51213 in gcc-4.7 / Crosstool v16.
-// TODO(user): Remove "&& !defined(__clang_)" when =delete is
-// gcc-4.7 before =delete is allowed, go back to the C++98 definition.
 #ifndef DISALLOW_COPY_AND_ASSIGN
-#if LANG_CXX11 && !defined(__clang__)
 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
   TypeName(const TypeName&) = delete;      \
   void operator=(const TypeName&) = delete
-#else
-#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
-  TypeName(const TypeName&);               \
-  void operator=(const TypeName&)
-#endif
 #endif
 
 // An older, politically incorrect name for the above.
@@ -123,7 +110,7 @@ struct CompileAssert {
 // that wants to prevent anyone from instantiating it. This is
 // especially useful for classes containing only static methods.
 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
-  TypeName();                                    \
+  TypeName() = delete;                           \
   DISALLOW_COPY_AND_ASSIGN(TypeName)
 
 // The arraysize(arr) macro returns the # of elements in an array arr.
@@ -205,6 +192,14 @@ char (&ArraySizeHelper(const T (&array)[N]))[N];
 #define AS_STRING(x)   AS_STRING_INTERNAL(x)
 #define AS_STRING_INTERNAL(x)   #x
 
+// Macro that allows definition of a variable appended with the current line
+// number in the source file. Typically for use by other macros to allow the
+// user to declare multiple variables with the same "base" name inside the same
+// lexical block.
+#define VARNAME_LINENUM(varname) VARNAME_LINENUM_INTERNAL(varname ## _L, __LINE__)
+#define VARNAME_LINENUM_INTERNAL(v, line) VARNAME_LINENUM_INTERNAL2(v, line)
+#define VARNAME_LINENUM_INTERNAL2(v, line) v ## line
+
 // The following enum should be used only as a constructor argument to indicate
 // that the variable has static storage class, and that the constructor should
 // do nothing to its state.  It indicates to the reader that it is legal to

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/manual_constructor.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/manual_constructor.h b/be/src/gutil/manual_constructor.h
index 1434f72..adcda07 100644
--- a/be/src/gutil/manual_constructor.h
+++ b/be/src/gutil/manual_constructor.h
@@ -45,7 +45,7 @@
 
 #include <stddef.h>
 
-#include "gutil/port.h"
+#include "kudu/gutil/port.h"
 
 namespace base {
 


[10/14] incubator-impala git commit: IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

Posted by he...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/bind_internal.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/bind_internal.h b/be/src/gutil/bind_internal.h
new file mode 100644
index 0000000..6764d7e
--- /dev/null
+++ b/be/src/gutil/bind_internal.h
@@ -0,0 +1,2695 @@
+// This file was GENERATED by command:
+//     pump.py bind_internal.h.pump
+// DO NOT EDIT BY HAND!!!
+
+
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef KUDU_GUTIL_BIND_INTERNAL_H_
+#define KUDU_GUTIL_BIND_INTERNAL_H_
+
+#include "kudu/gutil/bind_helpers.h"
+#include "kudu/gutil/callback_internal.h"
+#include "kudu/gutil/raw_scoped_refptr_mismatch_checker.h"
+#include "kudu/gutil/template_util.h"
+
+#if defined(OS_WIN)
+#include "kudu/gutil/bind_internal_win.h"
+#endif
+
+// During Chromium import, WeakPtr-related code was removed.
+
+namespace kudu {
+namespace internal {
+
+// See kudu/gutil/callback.h for user documentation.
+//
+//
+// CONCEPTS:
+//  Runnable -- A type (really a type class) that has a single Run() method
+//              and a RunType typedef that corresponds to the type of Run().
+//              A Runnable can declare that it should treated like a method
+//              call by including a typedef named IsMethod.  The value of
+//              this typedef is NOT inspected, only the existence.  When a
+//              Runnable declares itself a method, Bind() will enforce special
+//              refcounting + WeakPtr handling semantics for the first
+//              parameter which is expected to be an object.
+//  Functor -- A copyable type representing something that should be called.
+//             All function pointers, Callback<>, and Runnables are functors
+//             even if the invocation syntax differs.
+//  RunType -- A function type (as opposed to function _pointer_ type) for
+//             a Run() function.  Usually just a convenience typedef.
+//  (Bound)ArgsType -- A function type that is being (ab)used to store the
+//                     types of set of arguments.  The "return" type is always
+//                     void here.  We use this hack so that we do not need
+//                     a new type name for each arity of type. (eg.,
+//                     BindState1, BindState2).  This makes forward
+//                     declarations and friending much much easier.
+//
+// Types:
+//  RunnableAdapter<> -- Wraps the various "function" pointer types into an
+//                       object that adheres to the Runnable interface.
+//                       There are |3*ARITY| RunnableAdapter types.
+//  FunctionTraits<> -- Type traits that unwrap a function signature into a
+//                      a set of easier to use typedefs.  Used mainly for
+//                      compile time asserts.
+//                      There are |ARITY| FunctionTraits types.
+//  ForceVoidReturn<> -- Helper class for translating function signatures to
+//                       equivalent forms with a "void" return type.
+//                    There are |ARITY| ForceVoidReturn types.
+//  FunctorTraits<> -- Type traits used determine the correct RunType and
+//                     RunnableType for a Functor.  This is where function
+//                     signature adapters are applied.
+//                    There are |ARITY| ForceVoidReturn types.
+//  MakeRunnable<> -- Takes a Functor and returns an object in the Runnable
+//                    type class that represents the underlying Functor.
+//                    There are |O(1)| MakeRunnable types.
+//  InvokeHelper<> -- Take a Runnable + arguments and actully invokes it.
+// Handle the differing syntaxes needed for WeakPtr<> support,
+//                    and for ignoring return values.  This is separate from
+//                    Invoker to avoid creating multiple version of Invoker<>
+//                    which grows at O(n^2) with the arity.
+//                    There are |k*ARITY| InvokeHelper types.
+//  Invoker<> -- Unwraps the curried parameters and executes the Runnable.
+//               There are |(ARITY^2 + ARITY)/2| Invoketypes.
+//  BindState<> -- Stores the curried parameters, and is the main entry point
+//                 into the Bind() system, doing most of the type resolution.
+//                 There are ARITY BindState types.
+
+// RunnableAdapter<>
+//
+// The RunnableAdapter<> templates provide a uniform interface for invoking
+// a function pointer, method pointer, or const method pointer. The adapter
+// exposes a Run() method with an appropriate signature. Using this wrapper
+// allows for writing code that supports all three pointer types without
+// undue repetition.  Without it, a lot of code would need to be repeated 3
+// times.
+//
+// For method pointers and const method pointers the first argument to Run()
+// is considered to be the received of the method.  This is similar to STL's
+// mem_fun().
+//
+// This class also exposes a RunType typedef that is the function type of the
+// Run() function.
+//
+// If and only if the wrapper contains a method or const method pointer, an
+// IsMethod typedef is exposed.  The existence of this typedef (NOT the value)
+// marks that the wrapper should be considered a method wrapper.
+
+template <typename Functor>
+class RunnableAdapter;
+
+// Function: Arity 0.
+template <typename R>
+class RunnableAdapter<R(*)()> {
+ public:
+  typedef R (RunType)();
+
+  explicit RunnableAdapter(R(*function)())
+      : function_(function) {
+  }
+
+  R Run() {
+    return function_();
+  }
+
+ private:
+  R (*function_)();
+};
+
+// Method: Arity 0.
+template <typename R, typename T>
+class RunnableAdapter<R(T::*)()> {
+ public:
+  typedef R (RunType)(T*);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)())
+      : method_(method) {
+  }
+
+  R Run(T* object) {
+    return (object->*method_)();
+  }
+
+ private:
+  R (T::*method_)();
+};
+
+// Const Method: Arity 0.
+template <typename R, typename T>
+class RunnableAdapter<R(T::*)() const> {
+ public:
+  typedef R (RunType)(const T*);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)() const)
+      : method_(method) {
+  }
+
+  R Run(const T* object) {
+    return (object->*method_)();
+  }
+
+ private:
+  R (T::*method_)() const;
+};
+
+// Function: Arity 1.
+template <typename R, typename A1>
+class RunnableAdapter<R(*)(A1)> {
+ public:
+  typedef R (RunType)(A1);
+
+  explicit RunnableAdapter(R(*function)(A1))
+      : function_(function) {
+  }
+
+  R Run(typename CallbackParamTraits<A1>::ForwardType a1) {
+    return function_(CallbackForward(a1));
+  }
+
+ private:
+  R (*function_)(A1);
+};
+
+// Method: Arity 1.
+template <typename R, typename T, typename A1>
+class RunnableAdapter<R(T::*)(A1)> {
+ public:
+  typedef R (RunType)(T*, A1);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1))
+      : method_(method) {
+  }
+
+  R Run(T* object, typename CallbackParamTraits<A1>::ForwardType a1) {
+    return (object->*method_)(CallbackForward(a1));
+  }
+
+ private:
+  R (T::*method_)(A1);
+};
+
+// Const Method: Arity 1.
+template <typename R, typename T, typename A1>
+class RunnableAdapter<R(T::*)(A1) const> {
+ public:
+  typedef R (RunType)(const T*, A1);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1) const)
+      : method_(method) {
+  }
+
+  R Run(const T* object, typename CallbackParamTraits<A1>::ForwardType a1) {
+    return (object->*method_)(CallbackForward(a1));
+  }
+
+ private:
+  R (T::*method_)(A1) const;
+};
+
+// Function: Arity 2.
+template <typename R, typename A1, typename A2>
+class RunnableAdapter<R(*)(A1, A2)> {
+ public:
+  typedef R (RunType)(A1, A2);
+
+  explicit RunnableAdapter(R(*function)(A1, A2))
+      : function_(function) {
+  }
+
+  R Run(typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2) {
+    return function_(CallbackForward(a1), CallbackForward(a2));
+  }
+
+ private:
+  R (*function_)(A1, A2);
+};
+
+// Method: Arity 2.
+template <typename R, typename T, typename A1, typename A2>
+class RunnableAdapter<R(T::*)(A1, A2)> {
+ public:
+  typedef R (RunType)(T*, A1, A2);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2))
+      : method_(method) {
+  }
+
+  R Run(T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2));
+  }
+
+ private:
+  R (T::*method_)(A1, A2);
+};
+
+// Const Method: Arity 2.
+template <typename R, typename T, typename A1, typename A2>
+class RunnableAdapter<R(T::*)(A1, A2) const> {
+ public:
+  typedef R (RunType)(const T*, A1, A2);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2) const)
+      : method_(method) {
+  }
+
+  R Run(const T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2));
+  }
+
+ private:
+  R (T::*method_)(A1, A2) const;
+};
+
+// Function: Arity 3.
+template <typename R, typename A1, typename A2, typename A3>
+class RunnableAdapter<R(*)(A1, A2, A3)> {
+ public:
+  typedef R (RunType)(A1, A2, A3);
+
+  explicit RunnableAdapter(R(*function)(A1, A2, A3))
+      : function_(function) {
+  }
+
+  R Run(typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3) {
+    return function_(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3));
+  }
+
+ private:
+  R (*function_)(A1, A2, A3);
+};
+
+// Method: Arity 3.
+template <typename R, typename T, typename A1, typename A2, typename A3>
+class RunnableAdapter<R(T::*)(A1, A2, A3)> {
+ public:
+  typedef R (RunType)(T*, A1, A2, A3);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3))
+      : method_(method) {
+  }
+
+  R Run(T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3);
+};
+
+// Const Method: Arity 3.
+template <typename R, typename T, typename A1, typename A2, typename A3>
+class RunnableAdapter<R(T::*)(A1, A2, A3) const> {
+ public:
+  typedef R (RunType)(const T*, A1, A2, A3);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3) const)
+      : method_(method) {
+  }
+
+  R Run(const T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3) const;
+};
+
+// Function: Arity 4.
+template <typename R, typename A1, typename A2, typename A3, typename A4>
+class RunnableAdapter<R(*)(A1, A2, A3, A4)> {
+ public:
+  typedef R (RunType)(A1, A2, A3, A4);
+
+  explicit RunnableAdapter(R(*function)(A1, A2, A3, A4))
+      : function_(function) {
+  }
+
+  R Run(typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4) {
+    return function_(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4));
+  }
+
+ private:
+  R (*function_)(A1, A2, A3, A4);
+};
+
+// Method: Arity 4.
+template <typename R, typename T, typename A1, typename A2, typename A3,
+    typename A4>
+class RunnableAdapter<R(T::*)(A1, A2, A3, A4)> {
+ public:
+  typedef R (RunType)(T*, A1, A2, A3, A4);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3, A4))
+      : method_(method) {
+  }
+
+  R Run(T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3, A4);
+};
+
+// Const Method: Arity 4.
+template <typename R, typename T, typename A1, typename A2, typename A3,
+    typename A4>
+class RunnableAdapter<R(T::*)(A1, A2, A3, A4) const> {
+ public:
+  typedef R (RunType)(const T*, A1, A2, A3, A4);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3, A4) const)
+      : method_(method) {
+  }
+
+  R Run(const T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3, A4) const;
+};
+
+// Function: Arity 5.
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5>
+class RunnableAdapter<R(*)(A1, A2, A3, A4, A5)> {
+ public:
+  typedef R (RunType)(A1, A2, A3, A4, A5);
+
+  explicit RunnableAdapter(R(*function)(A1, A2, A3, A4, A5))
+      : function_(function) {
+  }
+
+  R Run(typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4,
+      typename CallbackParamTraits<A5>::ForwardType a5) {
+    return function_(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5));
+  }
+
+ private:
+  R (*function_)(A1, A2, A3, A4, A5);
+};
+
+// Method: Arity 5.
+template <typename R, typename T, typename A1, typename A2, typename A3,
+    typename A4, typename A5>
+class RunnableAdapter<R(T::*)(A1, A2, A3, A4, A5)> {
+ public:
+  typedef R (RunType)(T*, A1, A2, A3, A4, A5);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3, A4, A5))
+      : method_(method) {
+  }
+
+  R Run(T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4,
+      typename CallbackParamTraits<A5>::ForwardType a5) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3, A4, A5);
+};
+
+// Const Method: Arity 5.
+template <typename R, typename T, typename A1, typename A2, typename A3,
+    typename A4, typename A5>
+class RunnableAdapter<R(T::*)(A1, A2, A3, A4, A5) const> {
+ public:
+  typedef R (RunType)(const T*, A1, A2, A3, A4, A5);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3, A4, A5) const)
+      : method_(method) {
+  }
+
+  R Run(const T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4,
+      typename CallbackParamTraits<A5>::ForwardType a5) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3, A4, A5) const;
+};
+
+// Function: Arity 6.
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6>
+class RunnableAdapter<R(*)(A1, A2, A3, A4, A5, A6)> {
+ public:
+  typedef R (RunType)(A1, A2, A3, A4, A5, A6);
+
+  explicit RunnableAdapter(R(*function)(A1, A2, A3, A4, A5, A6))
+      : function_(function) {
+  }
+
+  R Run(typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4,
+      typename CallbackParamTraits<A5>::ForwardType a5,
+      typename CallbackParamTraits<A6>::ForwardType a6) {
+    return function_(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5),
+        CallbackForward(a6));
+  }
+
+ private:
+  R (*function_)(A1, A2, A3, A4, A5, A6);
+};
+
+// Method: Arity 6.
+template <typename R, typename T, typename A1, typename A2, typename A3,
+    typename A4, typename A5, typename A6>
+class RunnableAdapter<R(T::*)(A1, A2, A3, A4, A5, A6)> {
+ public:
+  typedef R (RunType)(T*, A1, A2, A3, A4, A5, A6);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3, A4, A5, A6))
+      : method_(method) {
+  }
+
+  R Run(T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4,
+      typename CallbackParamTraits<A5>::ForwardType a5,
+      typename CallbackParamTraits<A6>::ForwardType a6) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5),
+        CallbackForward(a6));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3, A4, A5, A6);
+};
+
+// Const Method: Arity 6.
+template <typename R, typename T, typename A1, typename A2, typename A3,
+    typename A4, typename A5, typename A6>
+class RunnableAdapter<R(T::*)(A1, A2, A3, A4, A5, A6) const> {
+ public:
+  typedef R (RunType)(const T*, A1, A2, A3, A4, A5, A6);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3, A4, A5, A6) const)
+      : method_(method) {
+  }
+
+  R Run(const T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4,
+      typename CallbackParamTraits<A5>::ForwardType a5,
+      typename CallbackParamTraits<A6>::ForwardType a6) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5),
+        CallbackForward(a6));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3, A4, A5, A6) const;
+};
+
+// Function: Arity 7.
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6, typename A7>
+class RunnableAdapter<R(*)(A1, A2, A3, A4, A5, A6, A7)> {
+ public:
+  typedef R (RunType)(A1, A2, A3, A4, A5, A6, A7);
+
+  explicit RunnableAdapter(R(*function)(A1, A2, A3, A4, A5, A6, A7))
+      : function_(function) {
+  }
+
+  R Run(typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4,
+      typename CallbackParamTraits<A5>::ForwardType a5,
+      typename CallbackParamTraits<A6>::ForwardType a6,
+      typename CallbackParamTraits<A7>::ForwardType a7) {
+    return function_(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5),
+        CallbackForward(a6), CallbackForward(a7));
+  }
+
+ private:
+  R (*function_)(A1, A2, A3, A4, A5, A6, A7);
+};
+
+// Method: Arity 7.
+template <typename R, typename T, typename A1, typename A2, typename A3,
+    typename A4, typename A5, typename A6, typename A7>
+class RunnableAdapter<R(T::*)(A1, A2, A3, A4, A5, A6, A7)> {
+ public:
+  typedef R (RunType)(T*, A1, A2, A3, A4, A5, A6, A7);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3, A4, A5, A6, A7))
+      : method_(method) {
+  }
+
+  R Run(T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4,
+      typename CallbackParamTraits<A5>::ForwardType a5,
+      typename CallbackParamTraits<A6>::ForwardType a6,
+      typename CallbackParamTraits<A7>::ForwardType a7) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5),
+        CallbackForward(a6), CallbackForward(a7));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3, A4, A5, A6, A7);
+};
+
+// Const Method: Arity 7.
+template <typename R, typename T, typename A1, typename A2, typename A3,
+    typename A4, typename A5, typename A6, typename A7>
+class RunnableAdapter<R(T::*)(A1, A2, A3, A4, A5, A6, A7) const> {
+ public:
+  typedef R (RunType)(const T*, A1, A2, A3, A4, A5, A6, A7);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)(A1, A2, A3, A4, A5, A6, A7) const)
+      : method_(method) {
+  }
+
+  R Run(const T* object, typename CallbackParamTraits<A1>::ForwardType a1,
+      typename CallbackParamTraits<A2>::ForwardType a2,
+      typename CallbackParamTraits<A3>::ForwardType a3,
+      typename CallbackParamTraits<A4>::ForwardType a4,
+      typename CallbackParamTraits<A5>::ForwardType a5,
+      typename CallbackParamTraits<A6>::ForwardType a6,
+      typename CallbackParamTraits<A7>::ForwardType a7) {
+    return (object->*method_)(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5),
+        CallbackForward(a6), CallbackForward(a7));
+  }
+
+ private:
+  R (T::*method_)(A1, A2, A3, A4, A5, A6, A7) const;
+};
+
+
+// FunctionTraits<>
+//
+// Breaks a function signature apart into typedefs for easier introspection.
+template <typename Sig>
+struct FunctionTraits;
+
+template <typename R>
+struct FunctionTraits<R()> {
+  typedef R ReturnType;
+};
+
+template <typename R, typename A1>
+struct FunctionTraits<R(A1)> {
+  typedef R ReturnType;
+  typedef A1 A1Type;
+};
+
+template <typename R, typename A1, typename A2>
+struct FunctionTraits<R(A1, A2)> {
+  typedef R ReturnType;
+  typedef A1 A1Type;
+  typedef A2 A2Type;
+};
+
+template <typename R, typename A1, typename A2, typename A3>
+struct FunctionTraits<R(A1, A2, A3)> {
+  typedef R ReturnType;
+  typedef A1 A1Type;
+  typedef A2 A2Type;
+  typedef A3 A3Type;
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4>
+struct FunctionTraits<R(A1, A2, A3, A4)> {
+  typedef R ReturnType;
+  typedef A1 A1Type;
+  typedef A2 A2Type;
+  typedef A3 A3Type;
+  typedef A4 A4Type;
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5>
+struct FunctionTraits<R(A1, A2, A3, A4, A5)> {
+  typedef R ReturnType;
+  typedef A1 A1Type;
+  typedef A2 A2Type;
+  typedef A3 A3Type;
+  typedef A4 A4Type;
+  typedef A5 A5Type;
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6>
+struct FunctionTraits<R(A1, A2, A3, A4, A5, A6)> {
+  typedef R ReturnType;
+  typedef A1 A1Type;
+  typedef A2 A2Type;
+  typedef A3 A3Type;
+  typedef A4 A4Type;
+  typedef A5 A5Type;
+  typedef A6 A6Type;
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6, typename A7>
+struct FunctionTraits<R(A1, A2, A3, A4, A5, A6, A7)> {
+  typedef R ReturnType;
+  typedef A1 A1Type;
+  typedef A2 A2Type;
+  typedef A3 A3Type;
+  typedef A4 A4Type;
+  typedef A5 A5Type;
+  typedef A6 A6Type;
+  typedef A7 A7Type;
+};
+
+
+// ForceVoidReturn<>
+//
+// Set of templates that support forcing the function return type to void.
+template <typename Sig>
+struct ForceVoidReturn;
+
+template <typename R>
+struct ForceVoidReturn<R()> {
+  typedef void(RunType)();
+};
+
+template <typename R, typename A1>
+struct ForceVoidReturn<R(A1)> {
+  typedef void(RunType)(A1);
+};
+
+template <typename R, typename A1, typename A2>
+struct ForceVoidReturn<R(A1, A2)> {
+  typedef void(RunType)(A1, A2);
+};
+
+template <typename R, typename A1, typename A2, typename A3>
+struct ForceVoidReturn<R(A1, A2, A3)> {
+  typedef void(RunType)(A1, A2, A3);
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4>
+struct ForceVoidReturn<R(A1, A2, A3, A4)> {
+  typedef void(RunType)(A1, A2, A3, A4);
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5>
+struct ForceVoidReturn<R(A1, A2, A3, A4, A5)> {
+  typedef void(RunType)(A1, A2, A3, A4, A5);
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6>
+struct ForceVoidReturn<R(A1, A2, A3, A4, A5, A6)> {
+  typedef void(RunType)(A1, A2, A3, A4, A5, A6);
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6, typename A7>
+struct ForceVoidReturn<R(A1, A2, A3, A4, A5, A6, A7)> {
+  typedef void(RunType)(A1, A2, A3, A4, A5, A6, A7);
+};
+
+
+// FunctorTraits<>
+//
+// See description at top of file.
+template <typename T>
+struct FunctorTraits {
+  typedef RunnableAdapter<T> RunnableType;
+  typedef typename RunnableType::RunType RunType;
+};
+
+template <typename T>
+struct FunctorTraits<IgnoreResultHelper<T> > {
+  typedef typename FunctorTraits<T>::RunnableType RunnableType;
+  typedef typename ForceVoidReturn<
+      typename RunnableType::RunType>::RunType RunType;
+};
+
+template <typename T>
+struct FunctorTraits<Callback<T> > {
+  typedef Callback<T> RunnableType;
+  typedef typename Callback<T>::RunType RunType;
+};
+
+
+// MakeRunnable<>
+//
+// Converts a passed in functor to a RunnableType using type inference.
+
+template <typename T>
+typename FunctorTraits<T>::RunnableType MakeRunnable(const T& t) {
+  return RunnableAdapter<T>(t);
+}
+
+template <typename T>
+typename FunctorTraits<T>::RunnableType
+MakeRunnable(const IgnoreResultHelper<T>& t) {
+  return MakeRunnable(t.functor_);
+}
+
+template <typename T>
+const typename FunctorTraits<Callback<T> >::RunnableType&
+MakeRunnable(const Callback<T>& t) {
+  DCHECK(!t.is_null());
+  return t;
+}
+
+
+// InvokeHelper<>
+//
+// There are 3 logical InvokeHelper<> specializations: normal, void-return,
+// WeakCalls.
+//
+// The normal type just calls the underlying runnable.
+//
+// We need a InvokeHelper to handle void return types in order to support
+// IgnoreResult().  Normally, if the Runnable's RunType had a void return,
+// the template system would just accept "return functor.Run()" ignoring
+// the fact that a void function is being used with return. This piece of
+// sugar breaks though when the Runnable's RunType is not void.  Thus, we
+// need a partial specialization to change the syntax to drop the "return"
+// from the invocation call.
+//
+// WeakCalls similarly need special syntax that is applied to the first
+// argument to check if they should no-op themselves.
+template <bool IsWeakCall, typename ReturnType, typename Runnable,
+          typename ArgsType>
+struct InvokeHelper;
+
+template <typename ReturnType, typename Runnable>
+struct InvokeHelper<false, ReturnType, Runnable,
+    void()>  {
+  static ReturnType MakeItSo(Runnable runnable) {
+    return runnable.Run();
+  }
+};
+
+template <typename Runnable>
+struct InvokeHelper<false, void, Runnable,
+    void()>  {
+  static void MakeItSo(Runnable runnable) {
+    runnable.Run();
+  }
+};
+
+template <typename ReturnType, typename Runnable,typename A1>
+struct InvokeHelper<false, ReturnType, Runnable,
+    void(A1)>  {
+  static ReturnType MakeItSo(Runnable runnable, A1 a1) {
+    return runnable.Run(CallbackForward(a1));
+  }
+};
+
+template <typename Runnable,typename A1>
+struct InvokeHelper<false, void, Runnable,
+    void(A1)>  {
+  static void MakeItSo(Runnable runnable, A1 a1) {
+    runnable.Run(CallbackForward(a1));
+  }
+};
+
+template <typename ReturnType, typename Runnable,typename A1, typename A2>
+struct InvokeHelper<false, ReturnType, Runnable,
+    void(A1, A2)>  {
+  static ReturnType MakeItSo(Runnable runnable, A1 a1, A2 a2) {
+    return runnable.Run(CallbackForward(a1), CallbackForward(a2));
+  }
+};
+
+template <typename Runnable,typename A1, typename A2>
+struct InvokeHelper<false, void, Runnable,
+    void(A1, A2)>  {
+  static void MakeItSo(Runnable runnable, A1 a1, A2 a2) {
+    runnable.Run(CallbackForward(a1), CallbackForward(a2));
+  }
+};
+
+template <typename ReturnType, typename Runnable,typename A1, typename A2,
+    typename A3>
+struct InvokeHelper<false, ReturnType, Runnable,
+    void(A1, A2, A3)>  {
+  static ReturnType MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3) {
+    return runnable.Run(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3));
+  }
+};
+
+template <typename Runnable,typename A1, typename A2, typename A3>
+struct InvokeHelper<false, void, Runnable,
+    void(A1, A2, A3)>  {
+  static void MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3) {
+    runnable.Run(CallbackForward(a1), CallbackForward(a2), CallbackForward(a3));
+  }
+};
+
+template <typename ReturnType, typename Runnable,typename A1, typename A2,
+    typename A3, typename A4>
+struct InvokeHelper<false, ReturnType, Runnable,
+    void(A1, A2, A3, A4)>  {
+  static ReturnType MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3, A4 a4) {
+    return runnable.Run(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4));
+  }
+};
+
+template <typename Runnable,typename A1, typename A2, typename A3, typename A4>
+struct InvokeHelper<false, void, Runnable,
+    void(A1, A2, A3, A4)>  {
+  static void MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3, A4 a4) {
+    runnable.Run(CallbackForward(a1), CallbackForward(a2), CallbackForward(a3),
+        CallbackForward(a4));
+  }
+};
+
+template <typename ReturnType, typename Runnable,typename A1, typename A2,
+    typename A3, typename A4, typename A5>
+struct InvokeHelper<false, ReturnType, Runnable,
+    void(A1, A2, A3, A4, A5)>  {
+  static ReturnType MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3, A4 a4,
+      A5 a5) {
+    return runnable.Run(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5));
+  }
+};
+
+template <typename Runnable,typename A1, typename A2, typename A3, typename A4,
+    typename A5>
+struct InvokeHelper<false, void, Runnable,
+    void(A1, A2, A3, A4, A5)>  {
+  static void MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
+    runnable.Run(CallbackForward(a1), CallbackForward(a2), CallbackForward(a3),
+        CallbackForward(a4), CallbackForward(a5));
+  }
+};
+
+template <typename ReturnType, typename Runnable,typename A1, typename A2,
+    typename A3, typename A4, typename A5, typename A6>
+struct InvokeHelper<false, ReturnType, Runnable,
+    void(A1, A2, A3, A4, A5, A6)>  {
+  static ReturnType MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3, A4 a4,
+      A5 a5, A6 a6) {
+    return runnable.Run(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5),
+        CallbackForward(a6));
+  }
+};
+
+template <typename Runnable,typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6>
+struct InvokeHelper<false, void, Runnable,
+    void(A1, A2, A3, A4, A5, A6)>  {
+  static void MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5,
+      A6 a6) {
+    runnable.Run(CallbackForward(a1), CallbackForward(a2), CallbackForward(a3),
+        CallbackForward(a4), CallbackForward(a5), CallbackForward(a6));
+  }
+};
+
+template <typename ReturnType, typename Runnable,typename A1, typename A2,
+    typename A3, typename A4, typename A5, typename A6, typename A7>
+struct InvokeHelper<false, ReturnType, Runnable,
+    void(A1, A2, A3, A4, A5, A6, A7)>  {
+  static ReturnType MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3, A4 a4,
+      A5 a5, A6 a6, A7 a7) {
+    return runnable.Run(CallbackForward(a1), CallbackForward(a2),
+        CallbackForward(a3), CallbackForward(a4), CallbackForward(a5),
+        CallbackForward(a6), CallbackForward(a7));
+  }
+};
+
+template <typename Runnable,typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6, typename A7>
+struct InvokeHelper<false, void, Runnable,
+    void(A1, A2, A3, A4, A5, A6, A7)>  {
+  static void MakeItSo(Runnable runnable, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5,
+      A6 a6, A7 a7) {
+    runnable.Run(CallbackForward(a1), CallbackForward(a2), CallbackForward(a3),
+        CallbackForward(a4), CallbackForward(a5), CallbackForward(a6),
+        CallbackForward(a7));
+  }
+};
+
+// Invoker<>
+//
+// See description at the top of the file.
+template <int NumBound, typename Storage, typename RunType>
+struct Invoker;
+
+// Arity 0 -> 0.
+template <typename StorageType, typename R>
+struct Invoker<0, StorageType, R()> {
+  typedef R(RunType)(BindStateBase*);
+
+  typedef R(UnboundRunType)();
+
+  static R Run(BindStateBase* base) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void()>
+               ::MakeItSo(storage->runnable_);
+  }
+};
+
+// Arity 1 -> 1.
+template <typename StorageType, typename R,typename X1>
+struct Invoker<0, StorageType, R(X1)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X1>::ForwardType);
+
+  typedef R(UnboundRunType)(X1);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X1>::ForwardType x1) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename CallbackParamTraits<X1>::ForwardType x1)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1));
+  }
+};
+
+// Arity 1 -> 0.
+template <typename StorageType, typename R,typename X1>
+struct Invoker<1, StorageType, R(X1)> {
+  typedef R(RunType)(BindStateBase*);
+
+  typedef R(UnboundRunType)();
+
+  static R Run(BindStateBase* base) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1));
+  }
+};
+
+// Arity 2 -> 2.
+template <typename StorageType, typename R,typename X1, typename X2>
+struct Invoker<0, StorageType, R(X1, X2)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X1>::ForwardType,
+      typename CallbackParamTraits<X2>::ForwardType);
+
+  typedef R(UnboundRunType)(X1, X2);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X1>::ForwardType x1,
+      typename CallbackParamTraits<X2>::ForwardType x2) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename CallbackParamTraits<X1>::ForwardType x1,
+               typename CallbackParamTraits<X2>::ForwardType x2)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2));
+  }
+};
+
+// Arity 2 -> 1.
+template <typename StorageType, typename R,typename X1, typename X2>
+struct Invoker<1, StorageType, R(X1, X2)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X2>::ForwardType);
+
+  typedef R(UnboundRunType)(X2);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X2>::ForwardType x2) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X2>::ForwardType x2)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2));
+  }
+};
+
+// Arity 2 -> 0.
+template <typename StorageType, typename R,typename X1, typename X2>
+struct Invoker<2, StorageType, R(X1, X2)> {
+  typedef R(RunType)(BindStateBase*);
+
+  typedef R(UnboundRunType)();
+
+  static R Run(BindStateBase* base) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2));
+  }
+};
+
+// Arity 3 -> 3.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3>
+struct Invoker<0, StorageType, R(X1, X2, X3)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X1>::ForwardType,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType);
+
+  typedef R(UnboundRunType)(X1, X2, X3);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X1>::ForwardType x1,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename CallbackParamTraits<X1>::ForwardType x1,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3));
+  }
+};
+
+// Arity 3 -> 2.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3>
+struct Invoker<1, StorageType, R(X1, X2, X3)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType);
+
+  typedef R(UnboundRunType)(X2, X3);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3));
+  }
+};
+
+// Arity 3 -> 1.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3>
+struct Invoker<2, StorageType, R(X1, X2, X3)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X3>::ForwardType);
+
+  typedef R(UnboundRunType)(X3);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X3>::ForwardType x3) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X3>::ForwardType x3)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3));
+  }
+};
+
+// Arity 3 -> 0.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3>
+struct Invoker<3, StorageType, R(X1, X2, X3)> {
+  typedef R(RunType)(BindStateBase*);
+
+  typedef R(UnboundRunType)();
+
+  static R Run(BindStateBase* base) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3));
+  }
+};
+
+// Arity 4 -> 4.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4>
+struct Invoker<0, StorageType, R(X1, X2, X3, X4)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X1>::ForwardType,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType);
+
+  typedef R(UnboundRunType)(X1, X2, X3, X4);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X1>::ForwardType x1,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename CallbackParamTraits<X1>::ForwardType x1,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4));
+  }
+};
+
+// Arity 4 -> 3.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4>
+struct Invoker<1, StorageType, R(X1, X2, X3, X4)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType);
+
+  typedef R(UnboundRunType)(X2, X3, X4);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4));
+  }
+};
+
+// Arity 4 -> 2.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4>
+struct Invoker<2, StorageType, R(X1, X2, X3, X4)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType);
+
+  typedef R(UnboundRunType)(X3, X4);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4));
+  }
+};
+
+// Arity 4 -> 1.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4>
+struct Invoker<3, StorageType, R(X1, X2, X3, X4)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X4>::ForwardType);
+
+  typedef R(UnboundRunType)(X4);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X4>::ForwardType x4) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X4>::ForwardType x4)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4));
+  }
+};
+
+// Arity 4 -> 0.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4>
+struct Invoker<4, StorageType, R(X1, X2, X3, X4)> {
+  typedef R(RunType)(BindStateBase*);
+
+  typedef R(UnboundRunType)();
+
+  static R Run(BindStateBase* base) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+    typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    typename Bound4UnwrapTraits::ForwardType x4 =
+        Bound4UnwrapTraits::Unwrap(storage->p4_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename Bound4UnwrapTraits::ForwardType)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4));
+  }
+};
+
+// Arity 5 -> 5.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5>
+struct Invoker<0, StorageType, R(X1, X2, X3, X4, X5)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X1>::ForwardType,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType);
+
+  typedef R(UnboundRunType)(X1, X2, X3, X4, X5);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X1>::ForwardType x1,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename CallbackParamTraits<X1>::ForwardType x1,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5));
+  }
+};
+
+// Arity 5 -> 4.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5>
+struct Invoker<1, StorageType, R(X1, X2, X3, X4, X5)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType);
+
+  typedef R(UnboundRunType)(X2, X3, X4, X5);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5));
+  }
+};
+
+// Arity 5 -> 3.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5>
+struct Invoker<2, StorageType, R(X1, X2, X3, X4, X5)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType);
+
+  typedef R(UnboundRunType)(X3, X4, X5);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5));
+  }
+};
+
+// Arity 5 -> 2.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5>
+struct Invoker<3, StorageType, R(X1, X2, X3, X4, X5)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType);
+
+  typedef R(UnboundRunType)(X4, X5);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5));
+  }
+};
+
+// Arity 5 -> 1.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5>
+struct Invoker<4, StorageType, R(X1, X2, X3, X4, X5)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X5>::ForwardType);
+
+  typedef R(UnboundRunType)(X5);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X5>::ForwardType x5) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+    typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    typename Bound4UnwrapTraits::ForwardType x4 =
+        Bound4UnwrapTraits::Unwrap(storage->p4_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename Bound4UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X5>::ForwardType x5)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5));
+  }
+};
+
+// Arity 5 -> 0.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5>
+struct Invoker<5, StorageType, R(X1, X2, X3, X4, X5)> {
+  typedef R(RunType)(BindStateBase*);
+
+  typedef R(UnboundRunType)();
+
+  static R Run(BindStateBase* base) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+    typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits;
+    typedef typename StorageType::Bound5UnwrapTraits Bound5UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    typename Bound4UnwrapTraits::ForwardType x4 =
+        Bound4UnwrapTraits::Unwrap(storage->p4_);
+    typename Bound5UnwrapTraits::ForwardType x5 =
+        Bound5UnwrapTraits::Unwrap(storage->p5_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename Bound4UnwrapTraits::ForwardType,
+               typename Bound5UnwrapTraits::ForwardType)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5));
+  }
+};
+
+// Arity 6 -> 6.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6>
+struct Invoker<0, StorageType, R(X1, X2, X3, X4, X5, X6)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X1>::ForwardType,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename CallbackParamTraits<X6>::ForwardType);
+
+  typedef R(UnboundRunType)(X1, X2, X3, X4, X5, X6);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X1>::ForwardType x1,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5,
+      typename CallbackParamTraits<X6>::ForwardType x6) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename CallbackParamTraits<X1>::ForwardType x1,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5,
+               typename CallbackParamTraits<X6>::ForwardType x6)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6));
+  }
+};
+
+// Arity 6 -> 5.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6>
+struct Invoker<1, StorageType, R(X1, X2, X3, X4, X5, X6)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename CallbackParamTraits<X6>::ForwardType);
+
+  typedef R(UnboundRunType)(X2, X3, X4, X5, X6);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5,
+      typename CallbackParamTraits<X6>::ForwardType x6) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5,
+               typename CallbackParamTraits<X6>::ForwardType x6)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6));
+  }
+};
+
+// Arity 6 -> 4.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6>
+struct Invoker<2, StorageType, R(X1, X2, X3, X4, X5, X6)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename CallbackParamTraits<X6>::ForwardType);
+
+  typedef R(UnboundRunType)(X3, X4, X5, X6);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5,
+      typename CallbackParamTraits<X6>::ForwardType x6) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5,
+               typename CallbackParamTraits<X6>::ForwardType x6)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6));
+  }
+};
+
+// Arity 6 -> 3.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6>
+struct Invoker<3, StorageType, R(X1, X2, X3, X4, X5, X6)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename CallbackParamTraits<X6>::ForwardType);
+
+  typedef R(UnboundRunType)(X4, X5, X6);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5,
+      typename CallbackParamTraits<X6>::ForwardType x6) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5,
+               typename CallbackParamTraits<X6>::ForwardType x6)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6));
+  }
+};
+
+// Arity 6 -> 2.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6>
+struct Invoker<4, StorageType, R(X1, X2, X3, X4, X5, X6)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename CallbackParamTraits<X6>::ForwardType);
+
+  typedef R(UnboundRunType)(X5, X6);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X5>::ForwardType x5,
+      typename CallbackParamTraits<X6>::ForwardType x6) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+    typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    typename Bound4UnwrapTraits::ForwardType x4 =
+        Bound4UnwrapTraits::Unwrap(storage->p4_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename Bound4UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X5>::ForwardType x5,
+               typename CallbackParamTraits<X6>::ForwardType x6)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6));
+  }
+};
+
+// Arity 6 -> 1.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6>
+struct Invoker<5, StorageType, R(X1, X2, X3, X4, X5, X6)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X6>::ForwardType);
+
+  typedef R(UnboundRunType)(X6);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X6>::ForwardType x6) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+    typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits;
+    typedef typename StorageType::Bound5UnwrapTraits Bound5UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    typename Bound4UnwrapTraits::ForwardType x4 =
+        Bound4UnwrapTraits::Unwrap(storage->p4_);
+    typename Bound5UnwrapTraits::ForwardType x5 =
+        Bound5UnwrapTraits::Unwrap(storage->p5_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename Bound4UnwrapTraits::ForwardType,
+               typename Bound5UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X6>::ForwardType x6)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6));
+  }
+};
+
+// Arity 6 -> 0.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6>
+struct Invoker<6, StorageType, R(X1, X2, X3, X4, X5, X6)> {
+  typedef R(RunType)(BindStateBase*);
+
+  typedef R(UnboundRunType)();
+
+  static R Run(BindStateBase* base) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+    typedef typename StorageType::Bound4UnwrapTraits Bound4UnwrapTraits;
+    typedef typename StorageType::Bound5UnwrapTraits Bound5UnwrapTraits;
+    typedef typename StorageType::Bound6UnwrapTraits Bound6UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    typename Bound4UnwrapTraits::ForwardType x4 =
+        Bound4UnwrapTraits::Unwrap(storage->p4_);
+    typename Bound5UnwrapTraits::ForwardType x5 =
+        Bound5UnwrapTraits::Unwrap(storage->p5_);
+    typename Bound6UnwrapTraits::ForwardType x6 =
+        Bound6UnwrapTraits::Unwrap(storage->p6_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename Bound4UnwrapTraits::ForwardType,
+               typename Bound5UnwrapTraits::ForwardType,
+               typename Bound6UnwrapTraits::ForwardType)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6));
+  }
+};
+
+// Arity 7 -> 7.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6, typename X7>
+struct Invoker<0, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X1>::ForwardType,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename CallbackParamTraits<X6>::ForwardType,
+      typename CallbackParamTraits<X7>::ForwardType);
+
+  typedef R(UnboundRunType)(X1, X2, X3, X4, X5, X6, X7);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X1>::ForwardType x1,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5,
+      typename CallbackParamTraits<X6>::ForwardType x6,
+      typename CallbackParamTraits<X7>::ForwardType x7) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename CallbackParamTraits<X1>::ForwardType x1,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5,
+               typename CallbackParamTraits<X6>::ForwardType x6,
+               typename CallbackParamTraits<X7>::ForwardType x7)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6), CallbackForward(x7));
+  }
+};
+
+// Arity 7 -> 6.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6, typename X7>
+struct Invoker<1, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X2>::ForwardType,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename CallbackParamTraits<X6>::ForwardType,
+      typename CallbackParamTraits<X7>::ForwardType);
+
+  typedef R(UnboundRunType)(X2, X3, X4, X5, X6, X7);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X2>::ForwardType x2,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5,
+      typename CallbackParamTraits<X6>::ForwardType x6,
+      typename CallbackParamTraits<X7>::ForwardType x7) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X2>::ForwardType x2,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5,
+               typename CallbackParamTraits<X6>::ForwardType x6,
+               typename CallbackParamTraits<X7>::ForwardType x7)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6), CallbackForward(x7));
+  }
+};
+
+// Arity 7 -> 5.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6, typename X7>
+struct Invoker<2, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X3>::ForwardType,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename CallbackParamTraits<X6>::ForwardType,
+      typename CallbackParamTraits<X7>::ForwardType);
+
+  typedef R(UnboundRunType)(X3, X4, X5, X6, X7);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X3>::ForwardType x3,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5,
+      typename CallbackParamTraits<X6>::ForwardType x6,
+      typename CallbackParamTraits<X7>::ForwardType x7) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X3>::ForwardType x3,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5,
+               typename CallbackParamTraits<X6>::ForwardType x6,
+               typename CallbackParamTraits<X7>::ForwardType x7)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6), CallbackForward(x7));
+  }
+};
+
+// Arity 7 -> 4.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6, typename X7>
+struct Invoker<3, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X4>::ForwardType,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename CallbackParamTraits<X6>::ForwardType,
+      typename CallbackParamTraits<X7>::ForwardType);
+
+  typedef R(UnboundRunType)(X4, X5, X6, X7);
+
+  static R Run(BindStateBase* base,
+      typename CallbackParamTraits<X4>::ForwardType x4,
+      typename CallbackParamTraits<X5>::ForwardType x5,
+      typename CallbackParamTraits<X6>::ForwardType x6,
+      typename CallbackParamTraits<X7>::ForwardType x7) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+    typedef typename StorageType::Bound1UnwrapTraits Bound1UnwrapTraits;
+    typedef typename StorageType::Bound2UnwrapTraits Bound2UnwrapTraits;
+    typedef typename StorageType::Bound3UnwrapTraits Bound3UnwrapTraits;
+
+    typename Bound1UnwrapTraits::ForwardType x1 =
+        Bound1UnwrapTraits::Unwrap(storage->p1_);
+    typename Bound2UnwrapTraits::ForwardType x2 =
+        Bound2UnwrapTraits::Unwrap(storage->p2_);
+    typename Bound3UnwrapTraits::ForwardType x3 =
+        Bound3UnwrapTraits::Unwrap(storage->p3_);
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(typename Bound1UnwrapTraits::ForwardType,
+               typename Bound2UnwrapTraits::ForwardType,
+               typename Bound3UnwrapTraits::ForwardType,
+               typename CallbackParamTraits<X4>::ForwardType x4,
+               typename CallbackParamTraits<X5>::ForwardType x5,
+               typename CallbackParamTraits<X6>::ForwardType x6,
+               typename CallbackParamTraits<X7>::ForwardType x7)>
+               ::MakeItSo(storage->runnable_, CallbackForward(x1),
+                   CallbackForward(x2), CallbackForward(x3),
+                   CallbackForward(x4), CallbackForward(x5),
+                   CallbackForward(x6), CallbackForward(x7));
+  }
+};
+
+// Arity 7 -> 3.
+template <typename StorageType, typename R,typename X1, typename X2,
+    typename X3, typename X4, typename X5, typename X6, typename X7>
+struct Invoker<4, StorageType, R(X1, X2, X3, X4, X5, X6, X7)> {
+  typedef R(RunType)(BindStateBase*,
+      typename CallbackParamTraits<X5>::ForwardType,
+      typename Ca

<TRUNCATED>


[11/14] incubator-impala git commit: IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

Posted by he...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/bind.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/bind.h b/be/src/gutil/bind.h
new file mode 100644
index 0000000..8875f70
--- /dev/null
+++ b/be/src/gutil/bind.h
@@ -0,0 +1,539 @@
+// This file was GENERATED by command:
+//     pump.py bind.h.pump
+// DO NOT EDIT BY HAND!!!
+
+
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef KUDU_GUTIL_BIND_H_
+#define KUDU_GUTIL_BIND_H_
+
+#include "kudu/gutil/bind_internal.h"
+#include "kudu/gutil/callback_internal.h"
+
+// -----------------------------------------------------------------------------
+// Usage documentation
+// -----------------------------------------------------------------------------
+//
+// See kudu/gutil/callback.h for documentation.
+//
+//
+// -----------------------------------------------------------------------------
+// Implementation notes
+// -----------------------------------------------------------------------------
+//
+// If you're reading the implementation, before proceeding further, you should
+// read the top comment of kudu/gutil/bind_internal.h for a definition of common
+// terms and concepts.
+//
+// RETURN TYPES
+//
+// Though Bind()'s result is meant to be stored in a Callback<> type, it
+// cannot actually return the exact type without requiring a large amount
+// of extra template specializations. The problem is that in order to
+// discern the correct specialization of Callback<>, Bind would need to
+// unwrap the function signature to determine the signature's arity, and
+// whether or not it is a method.
+//
+// Each unique combination of (arity, function_type, num_prebound) where
+// function_type is one of {function, method, const_method} would require
+// one specialization.  We eventually have to do a similar number of
+// specializations anyways in the implementation (see the Invoker<>,
+// classes).  However, it is avoidable in Bind if we return the result
+// via an indirection like we do below.
+//
+// TODO(ajwong): We might be able to avoid this now, but need to test.
+//
+// It is possible to move most of the COMPILE_ASSERT asserts into BindState<>,
+// but it feels a little nicer to have the asserts here so people do not
+// need to crack open bind_internal.h.  On the other hand, it makes Bind()
+// harder to read.
+
+namespace kudu {
+
+template <typename Functor>
+Callback<
+    typename internal::BindState<
+        typename internal::FunctorTraits<Functor>::RunnableType,
+        typename internal::FunctorTraits<Functor>::RunType,
+        void()>
+            ::UnboundRunType>
+Bind(Functor functor) {
+  // Typedefs for how to store and run the functor.
+  typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
+  typedef typename internal::FunctorTraits<Functor>::RunType RunType;
+
+  typedef internal::BindState<RunnableType, RunType, void()> BindState;
+
+
+  return Callback<typename BindState::UnboundRunType>(
+      new BindState(internal::MakeRunnable(functor)));
+}
+
+template <typename Functor, typename P1>
+Callback<
+    typename internal::BindState<
+        typename internal::FunctorTraits<Functor>::RunnableType,
+        typename internal::FunctorTraits<Functor>::RunType,
+        void(typename internal::CallbackParamTraits<P1>::StorageType)>
+            ::UnboundRunType>
+Bind(Functor functor, const P1& p1) {
+  // Typedefs for how to store and run the functor.
+  typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
+  typedef typename internal::FunctorTraits<Functor>::RunType RunType;
+
+  // Use RunnableType::RunType instead of RunType above because our
+  // checks should below for bound references need to know what the actual
+  // functor is going to interpret the argument as.
+  typedef internal::FunctionTraits<typename RunnableType::RunType>
+      BoundFunctorTraits;
+
+  // Do not allow binding a non-const reference parameter. Non-const reference
+  // parameters are disallowed by the Google style guide.  Also, binding a
+  // non-const reference parameter can make for subtle bugs because the
+  // invoked function will receive a reference to the stored copy of the
+  // argument and not the original.
+  COMPILE_ASSERT(
+      !(base::is_non_const_reference<typename
+          BoundFunctorTraits::A1Type>::value ),
+      do_not_bind_functions_with_nonconst_ref);
+
+  // For methods, we need to be careful for parameter 1.  We do not require
+  // a scoped_refptr because BindState<> itself takes care of AddRef() for
+  // methods. We also disallow binding of an array as the method's target
+  // object.
+  COMPILE_ASSERT(
+      internal::HasIsMethodTag<RunnableType>::value ||
+          !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
+      p1_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
+                     !base::is_array<P1>::value,
+                 first_bound_argument_to_method_cannot_be_array);
+  typedef internal::BindState<RunnableType, RunType,
+      void(typename internal::CallbackParamTraits<P1>::StorageType)> BindState;
+
+
+  return Callback<typename BindState::UnboundRunType>(
+      new BindState(internal::MakeRunnable(functor), p1));
+}
+
+template <typename Functor, typename P1, typename P2>
+Callback<
+    typename internal::BindState<
+        typename internal::FunctorTraits<Functor>::RunnableType,
+        typename internal::FunctorTraits<Functor>::RunType,
+        void(typename internal::CallbackParamTraits<P1>::StorageType,
+            typename internal::CallbackParamTraits<P2>::StorageType)>
+            ::UnboundRunType>
+Bind(Functor functor, const P1& p1, const P2& p2) {
+  // Typedefs for how to store and run the functor.
+  typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
+  typedef typename internal::FunctorTraits<Functor>::RunType RunType;
+
+  // Use RunnableType::RunType instead of RunType above because our
+  // checks should below for bound references need to know what the actual
+  // functor is going to interpret the argument as.
+  typedef internal::FunctionTraits<typename RunnableType::RunType>
+      BoundFunctorTraits;
+
+  // Do not allow binding a non-const reference parameter. Non-const reference
+  // parameters are disallowed by the Google style guide.  Also, binding a
+  // non-const reference parameter can make for subtle bugs because the
+  // invoked function will receive a reference to the stored copy of the
+  // argument and not the original.
+  COMPILE_ASSERT(
+      !(base::is_non_const_reference<typename
+          BoundFunctorTraits::A1Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A2Type>::value ),
+      do_not_bind_functions_with_nonconst_ref);
+
+  // For methods, we need to be careful for parameter 1.  We do not require
+  // a scoped_refptr because BindState<> itself takes care of AddRef() for
+  // methods. We also disallow binding of an array as the method's target
+  // object.
+  COMPILE_ASSERT(
+      internal::HasIsMethodTag<RunnableType>::value ||
+          !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
+      p1_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
+                     !base::is_array<P1>::value,
+                 first_bound_argument_to_method_cannot_be_array);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
+                 p2_is_refcounted_type_and_needs_scoped_refptr);
+  typedef internal::BindState<RunnableType, RunType,
+      void(typename internal::CallbackParamTraits<P1>::StorageType,
+      typename internal::CallbackParamTraits<P2>::StorageType)> BindState;
+
+
+  return Callback<typename BindState::UnboundRunType>(
+      new BindState(internal::MakeRunnable(functor), p1, p2));
+}
+
+template <typename Functor, typename P1, typename P2, typename P3>
+Callback<
+    typename internal::BindState<
+        typename internal::FunctorTraits<Functor>::RunnableType,
+        typename internal::FunctorTraits<Functor>::RunType,
+        void(typename internal::CallbackParamTraits<P1>::StorageType,
+            typename internal::CallbackParamTraits<P2>::StorageType,
+            typename internal::CallbackParamTraits<P3>::StorageType)>
+            ::UnboundRunType>
+Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3) {
+  // Typedefs for how to store and run the functor.
+  typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
+  typedef typename internal::FunctorTraits<Functor>::RunType RunType;
+
+  // Use RunnableType::RunType instead of RunType above because our
+  // checks should below for bound references need to know what the actual
+  // functor is going to interpret the argument as.
+  typedef internal::FunctionTraits<typename RunnableType::RunType>
+      BoundFunctorTraits;
+
+  // Do not allow binding a non-const reference parameter. Non-const reference
+  // parameters are disallowed by the Google style guide.  Also, binding a
+  // non-const reference parameter can make for subtle bugs because the
+  // invoked function will receive a reference to the stored copy of the
+  // argument and not the original.
+  COMPILE_ASSERT(
+      !(base::is_non_const_reference<typename
+          BoundFunctorTraits::A1Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A2Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A3Type>::value ),
+      do_not_bind_functions_with_nonconst_ref);
+
+  // For methods, we need to be careful for parameter 1.  We do not require
+  // a scoped_refptr because BindState<> itself takes care of AddRef() for
+  // methods. We also disallow binding of an array as the method's target
+  // object.
+  COMPILE_ASSERT(
+      internal::HasIsMethodTag<RunnableType>::value ||
+          !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
+      p1_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
+                     !base::is_array<P1>::value,
+                 first_bound_argument_to_method_cannot_be_array);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
+                 p2_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
+                 p3_is_refcounted_type_and_needs_scoped_refptr);
+  typedef internal::BindState<RunnableType, RunType,
+      void(typename internal::CallbackParamTraits<P1>::StorageType,
+      typename internal::CallbackParamTraits<P2>::StorageType,
+      typename internal::CallbackParamTraits<P3>::StorageType)> BindState;
+
+
+  return Callback<typename BindState::UnboundRunType>(
+      new BindState(internal::MakeRunnable(functor), p1, p2, p3));
+}
+
+template <typename Functor, typename P1, typename P2, typename P3, typename P4>
+Callback<
+    typename internal::BindState<
+        typename internal::FunctorTraits<Functor>::RunnableType,
+        typename internal::FunctorTraits<Functor>::RunType,
+        void(typename internal::CallbackParamTraits<P1>::StorageType,
+            typename internal::CallbackParamTraits<P2>::StorageType,
+            typename internal::CallbackParamTraits<P3>::StorageType,
+            typename internal::CallbackParamTraits<P4>::StorageType)>
+            ::UnboundRunType>
+Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4) {
+  // Typedefs for how to store and run the functor.
+  typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
+  typedef typename internal::FunctorTraits<Functor>::RunType RunType;
+
+  // Use RunnableType::RunType instead of RunType above because our
+  // checks should below for bound references need to know what the actual
+  // functor is going to interpret the argument as.
+  typedef internal::FunctionTraits<typename RunnableType::RunType>
+      BoundFunctorTraits;
+
+  // Do not allow binding a non-const reference parameter. Non-const reference
+  // parameters are disallowed by the Google style guide.  Also, binding a
+  // non-const reference parameter can make for subtle bugs because the
+  // invoked function will receive a reference to the stored copy of the
+  // argument and not the original.
+  COMPILE_ASSERT(
+      !(base::is_non_const_reference<typename
+          BoundFunctorTraits::A1Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A2Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A3Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A4Type>::value ),
+      do_not_bind_functions_with_nonconst_ref);
+
+  // For methods, we need to be careful for parameter 1.  We do not require
+  // a scoped_refptr because BindState<> itself takes care of AddRef() for
+  // methods. We also disallow binding of an array as the method's target
+  // object.
+  COMPILE_ASSERT(
+      internal::HasIsMethodTag<RunnableType>::value ||
+          !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
+      p1_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
+                     !base::is_array<P1>::value,
+                 first_bound_argument_to_method_cannot_be_array);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
+                 p2_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
+                 p3_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
+                 p4_is_refcounted_type_and_needs_scoped_refptr);
+  typedef internal::BindState<RunnableType, RunType,
+      void(typename internal::CallbackParamTraits<P1>::StorageType,
+      typename internal::CallbackParamTraits<P2>::StorageType,
+      typename internal::CallbackParamTraits<P3>::StorageType,
+      typename internal::CallbackParamTraits<P4>::StorageType)> BindState;
+
+
+  return Callback<typename BindState::UnboundRunType>(
+      new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4));
+}
+
+template <typename Functor, typename P1, typename P2, typename P3, typename P4,
+    typename P5>
+Callback<
+    typename internal::BindState<
+        typename internal::FunctorTraits<Functor>::RunnableType,
+        typename internal::FunctorTraits<Functor>::RunType,
+        void(typename internal::CallbackParamTraits<P1>::StorageType,
+            typename internal::CallbackParamTraits<P2>::StorageType,
+            typename internal::CallbackParamTraits<P3>::StorageType,
+            typename internal::CallbackParamTraits<P4>::StorageType,
+            typename internal::CallbackParamTraits<P5>::StorageType)>
+            ::UnboundRunType>
+Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
+    const P5& p5) {
+  // Typedefs for how to store and run the functor.
+  typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
+  typedef typename internal::FunctorTraits<Functor>::RunType RunType;
+
+  // Use RunnableType::RunType instead of RunType above because our
+  // checks should below for bound references need to know what the actual
+  // functor is going to interpret the argument as.
+  typedef internal::FunctionTraits<typename RunnableType::RunType>
+      BoundFunctorTraits;
+
+  // Do not allow binding a non-const reference parameter. Non-const reference
+  // parameters are disallowed by the Google style guide.  Also, binding a
+  // non-const reference parameter can make for subtle bugs because the
+  // invoked function will receive a reference to the stored copy of the
+  // argument and not the original.
+  COMPILE_ASSERT(
+      !(base::is_non_const_reference<typename
+          BoundFunctorTraits::A1Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A2Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A3Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A4Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A5Type>::value ),
+      do_not_bind_functions_with_nonconst_ref);
+
+  // For methods, we need to be careful for parameter 1.  We do not require
+  // a scoped_refptr because BindState<> itself takes care of AddRef() for
+  // methods. We also disallow binding of an array as the method's target
+  // object.
+  COMPILE_ASSERT(
+      internal::HasIsMethodTag<RunnableType>::value ||
+          !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
+      p1_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
+                     !base::is_array<P1>::value,
+                 first_bound_argument_to_method_cannot_be_array);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
+                 p2_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
+                 p3_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
+                 p4_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value,
+                 p5_is_refcounted_type_and_needs_scoped_refptr);
+  typedef internal::BindState<RunnableType, RunType,
+      void(typename internal::CallbackParamTraits<P1>::StorageType,
+      typename internal::CallbackParamTraits<P2>::StorageType,
+      typename internal::CallbackParamTraits<P3>::StorageType,
+      typename internal::CallbackParamTraits<P4>::StorageType,
+      typename internal::CallbackParamTraits<P5>::StorageType)> BindState;
+
+
+  return Callback<typename BindState::UnboundRunType>(
+      new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5));
+}
+
+template <typename Functor, typename P1, typename P2, typename P3, typename P4,
+    typename P5, typename P6>
+Callback<
+    typename internal::BindState<
+        typename internal::FunctorTraits<Functor>::RunnableType,
+        typename internal::FunctorTraits<Functor>::RunType,
+        void(typename internal::CallbackParamTraits<P1>::StorageType,
+            typename internal::CallbackParamTraits<P2>::StorageType,
+            typename internal::CallbackParamTraits<P3>::StorageType,
+            typename internal::CallbackParamTraits<P4>::StorageType,
+            typename internal::CallbackParamTraits<P5>::StorageType,
+            typename internal::CallbackParamTraits<P6>::StorageType)>
+            ::UnboundRunType>
+Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
+    const P5& p5, const P6& p6) {
+  // Typedefs for how to store and run the functor.
+  typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
+  typedef typename internal::FunctorTraits<Functor>::RunType RunType;
+
+  // Use RunnableType::RunType instead of RunType above because our
+  // checks should below for bound references need to know what the actual
+  // functor is going to interpret the argument as.
+  typedef internal::FunctionTraits<typename RunnableType::RunType>
+      BoundFunctorTraits;
+
+  // Do not allow binding a non-const reference parameter. Non-const reference
+  // parameters are disallowed by the Google style guide.  Also, binding a
+  // non-const reference parameter can make for subtle bugs because the
+  // invoked function will receive a reference to the stored copy of the
+  // argument and not the original.
+  COMPILE_ASSERT(
+      !(base::is_non_const_reference<typename
+          BoundFunctorTraits::A1Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A2Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A3Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A4Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A5Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A6Type>::value ),
+      do_not_bind_functions_with_nonconst_ref);
+
+  // For methods, we need to be careful for parameter 1.  We do not require
+  // a scoped_refptr because BindState<> itself takes care of AddRef() for
+  // methods. We also disallow binding of an array as the method's target
+  // object.
+  COMPILE_ASSERT(
+      internal::HasIsMethodTag<RunnableType>::value ||
+          !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
+      p1_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
+                     !base::is_array<P1>::value,
+                 first_bound_argument_to_method_cannot_be_array);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
+                 p2_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
+                 p3_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
+                 p4_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value,
+                 p5_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P6>::value,
+                 p6_is_refcounted_type_and_needs_scoped_refptr);
+  typedef internal::BindState<RunnableType, RunType,
+      void(typename internal::CallbackParamTraits<P1>::StorageType,
+      typename internal::CallbackParamTraits<P2>::StorageType,
+      typename internal::CallbackParamTraits<P3>::StorageType,
+      typename internal::CallbackParamTraits<P4>::StorageType,
+      typename internal::CallbackParamTraits<P5>::StorageType,
+      typename internal::CallbackParamTraits<P6>::StorageType)> BindState;
+
+
+  return Callback<typename BindState::UnboundRunType>(
+      new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6));
+}
+
+template <typename Functor, typename P1, typename P2, typename P3, typename P4,
+    typename P5, typename P6, typename P7>
+Callback<
+    typename internal::BindState<
+        typename internal::FunctorTraits<Functor>::RunnableType,
+        typename internal::FunctorTraits<Functor>::RunType,
+        void(typename internal::CallbackParamTraits<P1>::StorageType,
+            typename internal::CallbackParamTraits<P2>::StorageType,
+            typename internal::CallbackParamTraits<P3>::StorageType,
+            typename internal::CallbackParamTraits<P4>::StorageType,
+            typename internal::CallbackParamTraits<P5>::StorageType,
+            typename internal::CallbackParamTraits<P6>::StorageType,
+            typename internal::CallbackParamTraits<P7>::StorageType)>
+            ::UnboundRunType>
+Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
+    const P5& p5, const P6& p6, const P7& p7) {
+  // Typedefs for how to store and run the functor.
+  typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
+  typedef typename internal::FunctorTraits<Functor>::RunType RunType;
+
+  // Use RunnableType::RunType instead of RunType above because our
+  // checks should below for bound references need to know what the actual
+  // functor is going to interpret the argument as.
+  typedef internal::FunctionTraits<typename RunnableType::RunType>
+      BoundFunctorTraits;
+
+  // Do not allow binding a non-const reference parameter. Non-const reference
+  // parameters are disallowed by the Google style guide.  Also, binding a
+  // non-const reference parameter can make for subtle bugs because the
+  // invoked function will receive a reference to the stored copy of the
+  // argument and not the original.
+  COMPILE_ASSERT(
+      !(base::is_non_const_reference<typename
+          BoundFunctorTraits::A1Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A2Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A3Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A4Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A5Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A6Type>::value ||
+          base::is_non_const_reference<typename
+          BoundFunctorTraits::A7Type>::value ),
+      do_not_bind_functions_with_nonconst_ref);
+
+  // For methods, we need to be careful for parameter 1.  We do not require
+  // a scoped_refptr because BindState<> itself takes care of AddRef() for
+  // methods. We also disallow binding of an array as the method's target
+  // object.
+  COMPILE_ASSERT(
+      internal::HasIsMethodTag<RunnableType>::value ||
+          !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
+      p1_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
+                     !base::is_array<P1>::value,
+                 first_bound_argument_to_method_cannot_be_array);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
+                 p2_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
+                 p3_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
+                 p4_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value,
+                 p5_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P6>::value,
+                 p6_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P7>::value,
+                 p7_is_refcounted_type_and_needs_scoped_refptr);
+  typedef internal::BindState<RunnableType, RunType,
+      void(typename internal::CallbackParamTraits<P1>::StorageType,
+      typename internal::CallbackParamTraits<P2>::StorageType,
+      typename internal::CallbackParamTraits<P3>::StorageType,
+      typename internal::CallbackParamTraits<P4>::StorageType,
+      typename internal::CallbackParamTraits<P5>::StorageType,
+      typename internal::CallbackParamTraits<P6>::StorageType,
+      typename internal::CallbackParamTraits<P7>::StorageType)> BindState;
+
+
+  return Callback<typename BindState::UnboundRunType>(
+      new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6,
+          p7));
+}
+
+}  // namespace kudu
+
+#endif  // KUDU_GUTIL_BIND_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/bind.h.pump
----------------------------------------------------------------------
diff --git a/be/src/gutil/bind.h.pump b/be/src/gutil/bind.h.pump
new file mode 100644
index 0000000..538d6bd
--- /dev/null
+++ b/be/src/gutil/bind.h.pump
@@ -0,0 +1,153 @@
+$$ This is a pump file for generating file templates.  Pump is a python
+$$ script that is part of the Google Test suite of utilities.  Description
+$$ can be found here:
+$$
+$$ http://code.google.com/p/googletest/wiki/PumpManual
+$$
+
+$$
+$$ MAX_ARITY controls the number of arguments that Bind() supports.
+$$ The amount of code, and more importantly, the number of template types
+$$ generated by pump grows at O(MAX_ARITY^2).
+$$
+$$ We tried going to 11 and found it imposed an extra 10 penalty on windows
+$$ cycle times compared to our original baseline of 6.
+$$
+$$ Currently 7 is chosen as a compromise between supporting a convenient
+$$ number of arguments and keeping compile times low.  At 7, we have 115
+$$ templates being generated by pump.
+$$
+$$ Be careful when adjusting this number.  If people find a need to bind
+$$ a larger number of arguments, consider refactoring the function to use
+$$ a param struct instead of raising the MAX_ARITY.
+$$
+$$ See http://crbug.com/98542 for more context.
+$$
+$var MAX_ARITY = 7
+
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GUTIL_BIND_H_
+#define GUTIL_BIND_H_
+
+#include "gutil/bind_internal.h"
+#include "gutil/callback_internal.h"
+
+// -----------------------------------------------------------------------------
+// Usage documentation
+// -----------------------------------------------------------------------------
+//
+// See gutil/callback.h for documentation.
+//
+//
+// -----------------------------------------------------------------------------
+// Implementation notes
+// -----------------------------------------------------------------------------
+//
+// If you're reading the implementation, before proceeding further, you should
+// read the top comment of gutil/bind_internal.h for a definition of common
+// terms and concepts.
+//
+// RETURN TYPES
+//
+// Though Bind()'s result is meant to be stored in a Callback<> type, it
+// cannot actually return the exact type without requiring a large amount
+// of extra template specializations. The problem is that in order to
+// discern the correct specialization of Callback<>, Bind would need to
+// unwrap the function signature to determine the signature's arity, and
+// whether or not it is a method.
+//
+// Each unique combination of (arity, function_type, num_prebound) where
+// function_type is one of {function, method, const_method} would require
+// one specialization.  We eventually have to do a similar number of
+// specializations anyways in the implementation (see the Invoker<>,
+// classes).  However, it is avoidable in Bind if we return the result
+// via an indirection like we do below.
+//
+// TODO(ajwong): We might be able to avoid this now, but need to test.
+//
+// It is possible to move most of the COMPILE_ASSERT asserts into BindState<>,
+// but it feels a little nicer to have the asserts here so people do not
+// need to crack open bind_internal.h.  On the other hand, it makes Bind()
+// harder to read.
+
+namespace kudu {
+
+$range ARITY 0..MAX_ARITY
+$for ARITY [[
+$range ARG 1..ARITY
+
+template <typename Functor[[]]
+$if ARITY > 0 [[, ]] $for ARG , [[typename P$(ARG)]]>
+Callback<
+    typename internal::BindState<
+        typename internal::FunctorTraits<Functor>::RunnableType,
+        typename internal::FunctorTraits<Functor>::RunType,
+        void($for ARG , [[typename internal::CallbackParamTraits<P$(ARG)>::StorageType]])>
+            ::UnboundRunType>
+Bind(Functor functor
+$if ARITY > 0 [[, ]] $for ARG , [[const P$(ARG)& p$(ARG)]]) {
+  // Typedefs for how to store and run the functor.
+  typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
+  typedef typename internal::FunctorTraits<Functor>::RunType RunType;
+
+$if ARITY > 0 [[
+
+  // Use RunnableType::RunType instead of RunType above because our
+  // checks should below for bound references need to know what the actual
+  // functor is going to interpret the argument as.
+  typedef internal::FunctionTraits<typename RunnableType::RunType>
+      BoundFunctorTraits;
+
+  // Do not allow binding a non-const reference parameter. Non-const reference
+  // parameters are disallowed by the Google style guide.  Also, binding a
+  // non-const reference parameter can make for subtle bugs because the
+  // invoked function will receive a reference to the stored copy of the
+  // argument and not the original.
+  COMPILE_ASSERT(
+      !($for ARG || [[
+base::is_non_const_reference<typename BoundFunctorTraits::A$(ARG)Type>::value ]]),
+      do_not_bind_functions_with_nonconst_ref);
+
+]]
+
+
+$for ARG [[
+
+
+$if ARG == 1 [[
+  // For methods, we need to be careful for parameter 1.  We do not require
+  // a scoped_refptr because BindState<> itself takes care of AddRef() for
+  // methods. We also disallow binding of an array as the method's target
+  // object.
+  COMPILE_ASSERT(
+      internal::HasIsMethodTag<RunnableType>::value ||
+          !internal::NeedsScopedRefptrButGetsRawPtr<P$(ARG)>::value,
+      p$(ARG)_is_refcounted_type_and_needs_scoped_refptr);
+  COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
+                     !base::is_array<P$(ARG)>::value,
+                 first_bound_argument_to_method_cannot_be_array);
+]] $else [[
+  COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P$(ARG)>::value,
+                 p$(ARG)_is_refcounted_type_and_needs_scoped_refptr);
+]]  $$ $if ARG
+
+]]  $$ $for ARG
+
+  typedef internal::BindState<RunnableType, RunType, [[]]
+void($for ARG , [[typename internal::CallbackParamTraits<P$(ARG)>::StorageType]])> [[]]
+BindState;
+
+
+  return Callback<typename BindState::UnboundRunType>(
+      new BindState(internal::MakeRunnable(functor)[[]]
+$if ARITY > 0 [[, ]] $for ARG , [[p$(ARG)]]));
+}
+
+]]  $$ for ARITY
+
+}  // namespace kudu
+
+#endif  // GUTIL_BIND_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/bind_helpers.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/bind_helpers.h b/be/src/gutil/bind_helpers.h
new file mode 100644
index 0000000..8a106a6
--- /dev/null
+++ b/be/src/gutil/bind_helpers.h
@@ -0,0 +1,551 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This defines a set of argument wrappers and related factory methods that
+// can be used specify the refcounting and reference semantics of arguments
+// that are bound by the Bind() function in kudu/gutil/bind.h.
+//
+// It also defines a set of simple functions and utilities that people want
+// when using Callback<> and Bind().
+//
+//
+// ARGUMENT BINDING WRAPPERS
+//
+// The wrapper functions are kudu::Unretained(), kudu::Owned(), kudu::Passed(),
+// kudu::ConstRef(), and kudu::IgnoreResult().
+//
+// Unretained() allows Bind() to bind a non-refcounted class, and to disable
+// refcounting on arguments that are refcounted objects.
+//
+// Owned() transfers ownership of an object to the Callback resulting from
+// bind; the object will be deleted when the Callback is deleted.
+//
+// Passed() is for transferring movable-but-not-copyable types (eg. scoped_ptr)
+// through a Callback. Logically, this signifies a destructive transfer of
+// the state of the argument into the target function.  Invoking
+// Callback::Run() twice on a Callback that was created with a Passed()
+// argument will CHECK() because the first invocation would have already
+// transferred ownership to the target function.
+//
+// ConstRef() allows binding a constant reference to an argument rather
+// than a copy.
+//
+// IgnoreResult() is used to adapt a function or Callback with a return type to
+// one with a void return. This is most useful if you have a function with,
+// say, a pesky ignorable bool return that you want to use with PostTask or
+// something else that expect a Callback with a void return.
+//
+// EXAMPLE OF Unretained():
+//
+//   class Foo {
+//    public:
+//     void func() { cout << "Foo:f" << endl; }
+//   };
+//
+//   // In some function somewhere.
+//   Foo foo;
+//   Closure foo_callback =
+//       Bind(&Foo::func, Unretained(&foo));
+//   foo_callback.Run();  // Prints "Foo:f".
+//
+// Without the Unretained() wrapper on |&foo|, the above call would fail
+// to compile because Foo does not support the AddRef() and Release() methods.
+//
+//
+// EXAMPLE OF Owned():
+//
+//   void foo(int* arg) { cout << *arg << endl }
+//
+//   int* pn = new int(1);
+//   Closure foo_callback = Bind(&foo, Owned(pn));
+//
+//   foo_callback.Run();  // Prints "1"
+//   foo_callback.Run();  // Prints "1"
+//   *n = 2;
+//   foo_callback.Run();  // Prints "2"
+//
+//   foo_callback.Reset();  // |pn| is deleted.  Also will happen when
+//                          // |foo_callback| goes out of scope.
+//
+// Without Owned(), someone would have to know to delete |pn| when the last
+// reference to the Callback is deleted.
+//
+//
+// EXAMPLE OF ConstRef():
+//
+//   void foo(int arg) { cout << arg << endl }
+//
+//   int n = 1;
+//   Closure no_ref = Bind(&foo, n);
+//   Closure has_ref = Bind(&foo, ConstRef(n));
+//
+//   no_ref.Run();  // Prints "1"
+//   has_ref.Run();  // Prints "1"
+//
+//   n = 2;
+//   no_ref.Run();  // Prints "1"
+//   has_ref.Run();  // Prints "2"
+//
+// Note that because ConstRef() takes a reference on |n|, |n| must outlive all
+// its bound callbacks.
+//
+//
+// EXAMPLE OF IgnoreResult():
+//
+//   int DoSomething(int arg) { cout << arg << endl; }
+//
+//   // Assign to a Callback with a void return type.
+//   Callback<void(int)> cb = Bind(IgnoreResult(&DoSomething));
+//   cb->Run(1);  // Prints "1".
+//
+//   // Prints "1" on |ml|.
+//   ml->PostTask(FROM_HERE, Bind(IgnoreResult(&DoSomething), 1);
+//
+//
+// EXAMPLE OF Passed():
+//
+//   void TakesOwnership(scoped_ptr<Foo> arg) { }
+//   scoped_ptr<Foo> CreateFoo() { return scoped_ptr<Foo>(new Foo()); }
+//
+//   scoped_ptr<Foo> f(new Foo());
+//
+//   // |cb| is given ownership of Foo(). |f| is now NULL.
+//   // You can use f.Pass() in place of &f, but it's more verbose.
+//   Closure cb = Bind(&TakesOwnership, Passed(&f));
+//
+//   // Run was never called so |cb| still owns Foo() and deletes
+//   // it on Reset().
+//   cb.Reset();
+//
+//   // |cb| is given a new Foo created by CreateFoo().
+//   cb = Bind(&TakesOwnership, Passed(CreateFoo()));
+//
+//   // |arg| in TakesOwnership() is given ownership of Foo(). |cb|
+//   // no longer owns Foo() and, if reset, would not delete Foo().
+//   cb.Run();  // Foo() is now transferred to |arg| and deleted.
+//   cb.Run();  // This CHECK()s since Foo() already been used once.
+//
+// Passed() is particularly useful with PostTask() when you are transferring
+// ownership of an argument into a task, but don't necessarily know if the
+// task will always be executed. This can happen if the task is cancellable
+// or if it is posted to a MessageLoopProxy.
+//
+//
+// SIMPLE FUNCTIONS AND UTILITIES.
+//
+//   DoNothing() - Useful for creating a Closure that does nothing when called.
+//   DeletePointer<T>() - Useful for creating a Closure that will delete a
+//                        pointer when invoked. Only use this when necessary.
+//                        In most cases MessageLoop::DeleteSoon() is a better
+//                        fit.
+
+#ifndef KUDU_GUTIL_BIND_HELPERS_H_
+#define KUDU_GUTIL_BIND_HELPERS_H_
+
+#include <assert.h>
+
+#include "kudu/gutil/basictypes.h"
+#include "kudu/gutil/callback.h"
+#include "kudu/gutil/template_util.h"
+
+// Unneeded define from Chromium
+#define BASE_EXPORT
+
+
+namespace kudu {
+namespace internal {
+
+// Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T
+// for the existence of AddRef() and Release() functions of the correct
+// signature.
+//
+// http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error
+// http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence
+// http://stackoverflow.com/questions/4358584/sfinae-approach-comparison
+// http://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions
+//
+// The last link in particular show the method used below.
+//
+// For SFINAE to work with inherited methods, we need to pull some extra tricks
+// with multiple inheritance.  In the more standard formulation, the overloads
+// of Check would be:
+//
+//   template <typename C>
+//   Yes NotTheCheckWeWant(Helper<&C::TargetFunc>*);
+//
+//   template <typename C>
+//   No NotTheCheckWeWant(...);
+//
+//   static const bool value = sizeof(NotTheCheckWeWant<T>(0)) == sizeof(Yes);
+//
+// The problem here is that template resolution will not match
+// C::TargetFunc if TargetFunc does not exist directly in C.  That is, if
+// TargetFunc in inherited from an ancestor, &C::TargetFunc will not match,
+// |value| will be false.  This formulation only checks for whether or
+// not TargetFunc exist directly in the class being introspected.
+//
+// To get around this, we play a dirty trick with multiple inheritance.
+// First, We create a class BaseMixin that declares each function that we
+// want to probe for.  Then we create a class Base that inherits from both T
+// (the class we wish to probe) and BaseMixin.  Note that the function
+// signature in BaseMixin does not need to match the signature of the function
+// we are probing for; thus it's easiest to just use void(void).
+//
+// Now, if TargetFunc exists somewhere in T, then &Base::TargetFunc has an
+// ambiguous resolution between BaseMixin and T.  This lets us write the
+// following:
+//
+//   template <typename C>
+//   No GoodCheck(Helper<&C::TargetFunc>*);
+//
+//   template <typename C>
+//   Yes GoodCheck(...);
+//
+//   static const bool value = sizeof(GoodCheck<Base>(0)) == sizeof(Yes);
+//
+// Notice here that the variadic version of GoodCheck() returns Yes here
+// instead of No like the previous one. Also notice that we calculate |value|
+// by specializing GoodCheck() on Base instead of T.
+//
+// We've reversed the roles of the variadic, and Helper overloads.
+// GoodCheck(Helper<&C::TargetFunc>*), when C = Base, fails to be a valid
+// substitution if T::TargetFunc exists. Thus GoodCheck<Base>(0) will resolve
+// to the variadic version if T has TargetFunc.  If T::TargetFunc does not
+// exist, then &C::TargetFunc is not ambiguous, and the overload resolution
+// will prefer GoodCheck(Helper<&C::TargetFunc>*).
+//
+// This method of SFINAE will correctly probe for inherited names, but it cannot
+// typecheck those names.  It's still a good enough sanity check though.
+//
+// Works on gcc-4.2, gcc-4.4, and Visual Studio 2008.
+//
+// TODO(ajwong): Move to ref_counted.h or template_util.h when we've vetted
+// this works well.
+//
+// TODO(ajwong): Make this check for Release() as well.
+// See http://crbug.com/82038.
+template <typename T>
+class SupportsAddRefAndRelease {
+  typedef char Yes[1];
+  typedef char No[2];
+
+  struct BaseMixin {
+    void AddRef();
+  };
+
+// MSVC warns when you try to use Base if T has a private destructor, the
+// common pattern for refcounted types. It does this even though no attempt to
+// instantiate Base is made.  We disable the warning for this definition.
+#if defined(OS_WIN)
+#pragma warning(push)
+#pragma warning(disable:4624)
+#endif
+  struct Base : public T, public BaseMixin {
+  };
+#if defined(OS_WIN)
+#pragma warning(pop)
+#endif
+
+  template <void(BaseMixin::*)(void)> struct Helper {};
+
+  template <typename C>
+  static No& Check(Helper<&C::AddRef>*);
+
+  template <typename >
+  static Yes& Check(...);
+
+ public:
+  static const bool value = sizeof(Check<Base>(0)) == sizeof(Yes);
+};
+
+// Helpers to assert that arguments of a recounted type are bound with a
+// scoped_refptr.
+template <bool IsClasstype, typename T>
+struct UnsafeBindtoRefCountedArgHelper : base::false_type {
+};
+
+template <typename T>
+struct UnsafeBindtoRefCountedArgHelper<true, T>
+    : base::integral_constant<bool, SupportsAddRefAndRelease<T>::value> {
+};
+
+template <typename T>
+struct UnsafeBindtoRefCountedArg : base::false_type {
+};
+
+template <typename T>
+struct UnsafeBindtoRefCountedArg<T*>
+    : UnsafeBindtoRefCountedArgHelper<base::is_class<T>::value, T> {
+};
+
+template <typename T>
+class HasIsMethodTag {
+  typedef char Yes[1];
+  typedef char No[2];
+
+  template <typename U>
+  static Yes& Check(typename U::IsMethod*);
+
+  template <typename U>
+  static No& Check(...);
+
+ public:
+  static const bool value = sizeof(Check<T>(0)) == sizeof(Yes);
+};
+
+template <typename T>
+class UnretainedWrapper {
+ public:
+  explicit UnretainedWrapper(T* o) : ptr_(o) {}
+  T* get() const { return ptr_; }
+ private:
+  T* ptr_;
+};
+
+template <typename T>
+class ConstRefWrapper {
+ public:
+  explicit ConstRefWrapper(const T& o) : ptr_(&o) {}
+  const T& get() const { return *ptr_; }
+ private:
+  const T* ptr_;
+};
+
+template <typename T>
+struct IgnoreResultHelper {
+  explicit IgnoreResultHelper(T functor) : functor_(functor) {}
+
+  T functor_;
+};
+
+template <typename T>
+struct IgnoreResultHelper<Callback<T> > {
+  explicit IgnoreResultHelper(const Callback<T>& functor) : functor_(functor) {}
+
+  const Callback<T>& functor_;
+};
+
+// An alternate implementation is to avoid the destructive copy, and instead
+// specialize ParamTraits<> for OwnedWrapper<> to change the StorageType to
+// a class that is essentially a scoped_ptr<>.
+//
+// The current implementation has the benefit though of leaving ParamTraits<>
+// fully in callback_internal.h as well as avoiding type conversions during
+// storage.
+template <typename T>
+class OwnedWrapper {
+ public:
+  explicit OwnedWrapper(T* o) : ptr_(o) {}
+  ~OwnedWrapper() { delete ptr_; }
+  T* get() const { return ptr_; }
+  OwnedWrapper(const OwnedWrapper& other) {
+    ptr_ = other.ptr_;
+    other.ptr_ = NULL;
+  }
+
+ private:
+  mutable T* ptr_;
+};
+
+// PassedWrapper is a copyable adapter for a scoper that ignores const.
+//
+// It is needed to get around the fact that Bind() takes a const reference to
+// all its arguments.  Because Bind() takes a const reference to avoid
+// unnecessary copies, it is incompatible with movable-but-not-copyable
+// types; doing a destructive "move" of the type into Bind() would violate
+// the const correctness.
+//
+// This conundrum cannot be solved without either C++11 rvalue references or
+// a O(2^n) blowup of Bind() templates to handle each combination of regular
+// types and movable-but-not-copyable types.  Thus we introduce a wrapper type
+// that is copyable to transmit the correct type information down into
+// BindState<>. Ignoring const in this type makes sense because it is only
+// created when we are explicitly trying to do a destructive move.
+//
+// Two notes:
+//  1) PassedWrapper supports any type that has a "Pass()" function.
+//     This is intentional. The whitelisting of which specific types we
+//     support is maintained by CallbackParamTraits<>.
+//  2) is_valid_ is distinct from NULL because it is valid to bind a "NULL"
+//     scoper to a Callback and allow the Callback to execute once.
+template <typename T>
+class PassedWrapper {
+ public:
+  explicit PassedWrapper(T scoper) : is_valid_(true), scoper_(scoper.Pass()) {}
+  PassedWrapper(const PassedWrapper& other)
+      : is_valid_(other.is_valid_), scoper_(other.scoper_.Pass()) {
+  }
+  T Pass() const {
+    assert(is_valid_);
+    is_valid_ = false;
+    return scoper_.Pass();
+  }
+
+ private:
+  mutable bool is_valid_;
+  mutable T scoper_;
+};
+
+// Unwrap the stored parameters for the wrappers above.
+template <typename T>
+struct UnwrapTraits {
+  typedef const T& ForwardType;
+  static ForwardType Unwrap(const T& o) { return o; }
+};
+
+template <typename T>
+struct UnwrapTraits<UnretainedWrapper<T> > {
+  typedef T* ForwardType;
+  static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
+    return unretained.get();
+  }
+};
+
+template <typename T>
+struct UnwrapTraits<ConstRefWrapper<T> > {
+  typedef const T& ForwardType;
+  static ForwardType Unwrap(ConstRefWrapper<T> const_ref) {
+    return const_ref.get();
+  }
+};
+
+template <typename T>
+struct UnwrapTraits<scoped_refptr<T> > {
+  typedef T* ForwardType;
+  static ForwardType Unwrap(const scoped_refptr<T>& o) { return o.get(); }
+};
+
+// We didn't import WeakPtr from Chromium.
+//
+//template <typename T>
+//struct UnwrapTraits<WeakPtr<T> > {
+//  typedef const WeakPtr<T>& ForwardType;
+//  static ForwardType Unwrap(const WeakPtr<T>& o) { return o; }
+//};
+
+template <typename T>
+struct UnwrapTraits<OwnedWrapper<T> > {
+  typedef T* ForwardType;
+  static ForwardType Unwrap(const OwnedWrapper<T>& o) {
+    return o.get();
+  }
+};
+
+template <typename T>
+struct UnwrapTraits<PassedWrapper<T> > {
+  typedef T ForwardType;
+  static T Unwrap(PassedWrapper<T>& o) {
+    return o.Pass();
+  }
+};
+
+// Utility for handling different refcounting semantics in the Bind()
+// function.
+template <bool is_method, typename T>
+struct MaybeRefcount;
+
+template <typename T>
+struct MaybeRefcount<false, T> {
+  static void AddRef(const T&) {}
+  static void Release(const T&) {}
+};
+
+template <typename T, size_t n>
+struct MaybeRefcount<false, T[n]> {
+  static void AddRef(const T*) {}
+  static void Release(const T*) {}
+};
+
+template <typename T>
+struct MaybeRefcount<true, T> {
+  static void AddRef(const T&) {}
+  static void Release(const T&) {}
+};
+
+template <typename T>
+struct MaybeRefcount<true, T*> {
+  static void AddRef(T* o) { o->AddRef(); }
+  static void Release(T* o) { o->Release(); }
+};
+
+// No need to additionally AddRef() and Release() since we are storing a
+// scoped_refptr<> inside the storage object already.
+template <typename T>
+struct MaybeRefcount<true, scoped_refptr<T> > {
+  static void AddRef(const scoped_refptr<T>& o) {}
+  static void Release(const scoped_refptr<T>& o) {}
+};
+
+template <typename T>
+struct MaybeRefcount<true, const T*> {
+  static void AddRef(const T* o) { o->AddRef(); }
+  static void Release(const T* o) { o->Release(); }
+};
+
+// We didn't import WeakPtr from Chromium.
+//
+//// IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a
+//// method.  It is used internally by Bind() to select the correct
+//// InvokeHelper that will no-op itself in the event the WeakPtr<> for
+//// the target object is invalidated.
+////
+//// P1 should be the type of the object that will be received of the method.
+//template <bool IsMethod, typename P1>
+//struct IsWeakMethod : public false_type {};
+//
+//template <typename T>
+//struct IsWeakMethod<true, WeakPtr<T> > : public true_type {};
+//
+//template <typename T>
+//struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T> > > : public true_type {};
+
+}  // namespace internal
+
+template <typename T>
+static inline internal::UnretainedWrapper<T> Unretained(T* o) {
+  return internal::UnretainedWrapper<T>(o);
+}
+
+template <typename T>
+static inline internal::ConstRefWrapper<T> ConstRef(const T& o) {
+  return internal::ConstRefWrapper<T>(o);
+}
+
+template <typename T>
+static inline internal::OwnedWrapper<T> Owned(T* o) {
+  return internal::OwnedWrapper<T>(o);
+}
+
+// We offer 2 syntaxes for calling Passed().  The first takes a temporary and
+// is best suited for use with the return value of a function. The second
+// takes a pointer to the scoper and is just syntactic sugar to avoid having
+// to write Passed(scoper.Pass()).
+template <typename T>
+static inline internal::PassedWrapper<T> Passed(T scoper) {
+  return internal::PassedWrapper<T>(scoper.Pass());
+}
+template <typename T>
+static inline internal::PassedWrapper<T> Passed(T* scoper) {
+  return internal::PassedWrapper<T>(scoper->Pass());
+}
+
+template <typename T>
+static inline internal::IgnoreResultHelper<T> IgnoreResult(T data) {
+  return internal::IgnoreResultHelper<T>(data);
+}
+
+template <typename T>
+static inline internal::IgnoreResultHelper<Callback<T> >
+IgnoreResult(const Callback<T>& data) {
+  return internal::IgnoreResultHelper<Callback<T> >(data);
+}
+
+template<typename T>
+void DeletePointer(T* obj) {
+  delete obj;
+}
+
+}  // namespace kudu
+
+#endif  // BASE_BIND_HELPERS_H_


[14/14] incubator-impala git commit: IMPALA-4758: (2/2) Impala-side changes to build with latest gutil

Posted by he...@apache.org.
IMPALA-4758: (2/2) Impala-side changes to build with latest gutil

Meant to be taken as a whole with the previous commit. This patch makes
the necessary code changes to Impala and the gutil/ library to fix all
compilation errors. Future upgrades to gutil/ should redo the work in
this commit.

* Remove kudu/ include prefix with command:

git grep -l "include \"kudu/" | xargs sed -i 's/include \"kudu\//include
\"/g'

* Change KUDU_GUTIL_* guards to be GUTIL_*

git grep -l KUDU_GUTIL | xargs sed -i 's/KUDU_GUTIL/GUTIL/g'

* Replace glog/logging.h with common/logging.h

git grep -l "glog/logging" | xargs sed -i 's/glog\/logging/common\/logging/g'

* Provide our own implementation of since-removed MonotonicNanos()
* Reinstate COMPILE_FLAGS argument to ADD_EXPORTABLE_LIBRARY,
  used by gutil.
* Replay overwritten parts of following commits:

a7c3f30 - Remove AMD Opteron Rev E workaround from atomicops
54194af - IMPALA-4631: don't use floating point operations for time unit
conversions
152c586 - Improve AtomicInt abstraction and implementation

* Comment out non-compiling deprecated function definitions in numbers.h
* Overwrite changes from 92fafa "Use more efficient gutil implementation
  of Log2Ceiling" in favour of implementing them in Impala code only.
* Couple of misc fixes.

Change-Id: I4ac21d7d6401f21fcdfdd1132b8f322bfba4bb80
Reviewed-on: http://gerrit.cloudera.org:8080/5688
Reviewed-by: Dan Hecht <dh...@cloudera.com>
Tested-by: Impala Public Jenkins


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

Branch: refs/heads/master
Commit: 23100102c0a9a8f3a8a7ff069cbfaa7a56628238
Parents: 02f3e3f
Author: Henry Robinson <he...@cloudera.com>
Authored: Fri Mar 24 15:44:35 2017 -0700
Committer: Henry Robinson <he...@cloudera.com>
Committed: Wed Mar 29 02:52:34 2017 +0000

----------------------------------------------------------------------
 be/src/exec/hash-table.inline.h                 |  4 +-
 be/src/gutil/atomic_refcount.h                  | 10 ++--
 be/src/gutil/atomicops-internals-x86.cc         | 26 ++-------
 be/src/gutil/atomicops-internals-x86.h          | 48 ++++++----------
 be/src/gutil/atomicops.h                        | 16 +++---
 .../auxiliary/atomicops-internals-arm-generic.h |  4 +-
 .../auxiliary/atomicops-internals-arm-v6plus.h  |  2 +-
 .../auxiliary/atomicops-internals-windows.h     |  2 +-
 be/src/gutil/basictypes.h                       |  4 +-
 be/src/gutil/bind.h                             | 10 ++--
 be/src/gutil/bind_helpers.h                     | 10 ++--
 be/src/gutil/bind_internal.h                    | 16 +++---
 be/src/gutil/bits.cc                            |  2 +-
 be/src/gutil/bits.h                             | 14 ++---
 be/src/gutil/callback.h                         | 14 ++---
 be/src/gutil/callback_forward.h                 |  6 +-
 be/src/gutil/callback_internal.cc               |  2 +-
 be/src/gutil/callback_internal.h                | 10 ++--
 be/src/gutil/casts.h                            |  8 +--
 be/src/gutil/charmap.h                          |  6 +-
 be/src/gutil/cpu.cc                             |  6 +-
 be/src/gutil/cycleclock-inl.h                   | 10 ++--
 be/src/gutil/endian.h                           |  6 +-
 be/src/gutil/fixedarray.h                       |  8 +--
 be/src/gutil/gscoped_ptr.h                      | 14 ++---
 be/src/gutil/hash/builtin_type_hash.h           |  8 +--
 be/src/gutil/hash/city.cc                       | 14 ++---
 be/src/gutil/hash/city.h                        |  4 +-
 be/src/gutil/hash/hash.cc                       | 12 ++--
 be/src/gutil/hash/hash.h                        | 22 ++++----
 be/src/gutil/hash/hash128to64.h                 |  4 +-
 be/src/gutil/hash/jenkins.cc                    | 10 ++--
 be/src/gutil/hash/jenkins.h                     |  2 +-
 be/src/gutil/hash/jenkins_lookup2.h             |  4 +-
 be/src/gutil/hash/legacy_hash.h                 |  6 +-
 be/src/gutil/hash/string_hash.h                 | 10 ++--
 be/src/gutil/int128.cc                          |  4 +-
 be/src/gutil/int128.h                           |  2 +-
 be/src/gutil/macros.h                           |  5 +-
 be/src/gutil/manual_constructor.h               |  2 +-
 be/src/gutil/map-util.h                         |  4 +-
 be/src/gutil/mathlimits.cc                      |  4 +-
 be/src/gutil/once.cc                            | 10 ++--
 be/src/gutil/once.h                             | 12 ++--
 be/src/gutil/paranoid.h                         |  4 +-
 be/src/gutil/port.h                             |  6 +-
 .../gutil/raw_scoped_refptr_mismatch_checker.h  |  8 +--
 be/src/gutil/ref_counted.cc                     |  6 +-
 be/src/gutil/ref_counted.h                      |  6 +-
 be/src/gutil/ref_counted_memory.cc              |  4 +-
 be/src/gutil/ref_counted_memory.h               | 12 ++--
 be/src/gutil/singleton.h                        |  6 +-
 be/src/gutil/spinlock.cc                        | 10 ++--
 be/src/gutil/spinlock.h                         |  8 +--
 be/src/gutil/spinlock_internal.cc               |  8 +--
 be/src/gutil/spinlock_internal.h                |  4 +-
 be/src/gutil/spinlock_linux-inl.h               |  2 +-
 be/src/gutil/stl_util.h                         |  6 +-
 be/src/gutil/stringprintf.cc                    |  8 +--
 be/src/gutil/stringprintf.h                     |  2 +-
 be/src/gutil/strings/ascii_ctype.cc             |  2 +-
 be/src/gutil/strings/charset.cc                 |  2 +-
 be/src/gutil/strings/charset.h                  |  2 +-
 be/src/gutil/strings/escaping.cc                | 16 +++---
 be/src/gutil/strings/escaping.h                 | 10 ++--
 be/src/gutil/strings/fastmem.h                  |  4 +-
 be/src/gutil/strings/human_readable.cc          | 10 ++--
 be/src/gutil/strings/human_readable.h           |  6 +-
 be/src/gutil/strings/join.cc                    | 12 ++--
 be/src/gutil/strings/join.h                     | 14 ++---
 be/src/gutil/strings/memutil.cc                 |  4 +-
 be/src/gutil/strings/memutil.h                  |  2 +-
 be/src/gutil/strings/numbers.cc                 | 18 +++---
 be/src/gutil/strings/numbers.h                  | 58 ++++++++++----------
 be/src/gutil/strings/serialize.cc               | 16 +++---
 be/src/gutil/strings/serialize.h                | 18 +++---
 be/src/gutil/strings/split.cc                   | 18 +++---
 be/src/gutil/strings/split.h                    | 18 +++---
 be/src/gutil/strings/split_internal.h           |  4 +-
 be/src/gutil/strings/strcat.cc                  | 14 ++---
 be/src/gutil/strings/strcat.h                   |  6 +-
 be/src/gutil/strings/string_util-test.cc        |  2 +-
 be/src/gutil/strings/stringpiece.cc             | 12 ++--
 be/src/gutil/strings/stringpiece.h              | 10 ++--
 be/src/gutil/strings/strip.cc                   |  6 +-
 be/src/gutil/strings/strip.h                    |  4 +-
 be/src/gutil/strings/substitute.cc              | 14 ++---
 be/src/gutil/strings/substitute.h               |  6 +-
 be/src/gutil/strings/util.cc                    | 16 +++---
 be/src/gutil/strings/util.h                     |  6 +-
 be/src/gutil/strtoint.cc                        |  4 +-
 be/src/gutil/strtoint.h                         |  6 +-
 be/src/gutil/synchronization_profiling.h        |  2 +-
 be/src/gutil/sysinfo.cc                         | 10 ++--
 .../gutil/threading/thread_collision_warner.cc  |  6 +-
 .../gutil/threading/thread_collision_warner.h   |  6 +-
 be/src/gutil/type_traits.h                      |  2 +-
 be/src/gutil/walltime.cc                        |  3 +-
 be/src/gutil/walltime.h                         | 23 +++++---
 be/src/runtime/buffered-tuple-stream-test.cc    |  2 +-
 be/src/runtime/buffered-tuple-stream-v2-test.cc |  2 +-
 be/src/runtime/bufferpool/suballocator.cc       |  3 +-
 be/src/runtime/collection-value-builder.h       |  4 +-
 be/src/util/bit-util-test.cc                    | 18 +++---
 be/src/util/bit-util.h                          | 35 ++++++++++++
 be/src/util/error-util.h                        |  3 +-
 be/src/util/time.h                              |  4 +-
 cmake_modules/kudu_cmake_fns.txt                |  6 +-
 108 files changed, 493 insertions(+), 473 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/exec/hash-table.inline.h
----------------------------------------------------------------------
diff --git a/be/src/exec/hash-table.inline.h b/be/src/exec/hash-table.inline.h
index c266704..f055649 100644
--- a/be/src/exec/hash-table.inline.h
+++ b/be/src/exec/hash-table.inline.h
@@ -394,8 +394,8 @@ inline int64_t HashTable::CurrentMemSize() const {
 }
 
 inline int64_t HashTable::NumInsertsBeforeResize() const {
-  return max<int64_t>(0,
-      static_cast<int64_t>(num_buckets_ * MAX_FILL_FACTOR) - num_filled_buckets_);
+  return std::max<int64_t>(
+      0, static_cast<int64_t>(num_buckets_ * MAX_FILL_FACTOR) - num_filled_buckets_);
 }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/atomic_refcount.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomic_refcount.h b/be/src/gutil/atomic_refcount.h
index 9c80921..12bbdda 100644
--- a/be/src/gutil/atomic_refcount.h
+++ b/be/src/gutil/atomic_refcount.h
@@ -37,12 +37,12 @@
 //
 // If you need to do something very different from this, use a Mutex.
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/atomicops.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/dynamic_annotations.h"
+#include "gutil/atomicops.h"
+#include "gutil/integral_types.h"
+#include "gutil/logging-inl.h"
+#include "gutil/dynamic_annotations.h"
 
 namespace base {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/atomicops-internals-x86.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomicops-internals-x86.cc b/be/src/gutil/atomicops-internals-x86.cc
index 5d4529e..f02edc6 100644
--- a/be/src/gutil/atomicops-internals-x86.cc
+++ b/be/src/gutil/atomicops-internals-x86.cc
@@ -23,13 +23,13 @@
 // This module gets enough CPU information to optimize the
 // atomicops module on x86.
 
-#include "kudu/gutil/atomicops-internals-x86.h"
+#include "gutil/atomicops-internals-x86.h"
 
 #include <string.h>
 
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/integral_types.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/integral_types.h"
 
 // This file only makes sense with atomicops-internals-x86.h -- it
 // depends on structs that are defined in that file.  If atomicops.h
@@ -60,9 +60,8 @@
 // Set the flags so that code will run correctly and conservatively
 // until InitGoogle() is called.
 struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures = {
-  false,          // bug can't exist before process spawns multiple threads
   false,          // no SSE2
-  false,          // no cmpxchg16b
+  false           // no cmpxchg16b
 };
 
 // Initialize the AtomicOps_Internalx86CPUFeatures struct.
@@ -90,19 +89,6 @@ static void AtomicOps_Internalx86CPUFeaturesInit() {
     model += ((eax >> 16) & 0xf) << 4;
   }
 
-  // Opteron Rev E has a bug in which on very rare occasions a locked
-  // instruction doesn't act as a read-acquire barrier if followed by a
-  // non-locked read-modify-write instruction.  Rev F has this bug in
-  // pre-release versions, but not in versions released to customers,
-  // so we test only for Rev E, which is family 15, model 32..63 inclusive.
-  if (strcmp(vendor, "AuthenticAMD") == 0 &&       // AMD
-      family == 15 &&
-      32 <= model && model <= 63) {
-    AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = true;
-  } else {
-    AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = false;
-  }
-
   // edx bit 26 is SSE2 which we use to tell use whether we can use mfence
   AtomicOps_Internalx86CPUFeatures.has_sse2 = ((edx >> 26) & 1);
 
@@ -112,8 +98,6 @@ static void AtomicOps_Internalx86CPUFeaturesInit() {
   VLOG(1) << "vendor " << vendor <<
              "  family " << family <<
              "  model " << model <<
-             "  amd_lock_mb_bug " <<
-                   AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug <<
              "  sse2 " << AtomicOps_Internalx86CPUFeatures.has_sse2 <<
              "  cmpxchg16b " << AtomicOps_Internalx86CPUFeatures.has_cmpxchg16b;
 }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/atomicops-internals-x86.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomicops-internals-x86.h b/be/src/gutil/atomicops-internals-x86.h
index acbd2e3..90ae25a 100644
--- a/be/src/gutil/atomicops-internals-x86.h
+++ b/be/src/gutil/atomicops-internals-x86.h
@@ -29,7 +29,7 @@
 
 #include <stdint.h>
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
 #define BASE_HAS_ATOMIC64 1  // Use only in tests and base/atomic*
 
@@ -43,8 +43,6 @@
 // Features of this x86.  Values may not be correct before InitGoogle() is run,
 // but are set conservatively.
 struct AtomicOps_x86CPUFeatureStruct {
-  bool has_amd_lock_mb_bug;  // Processor has AMD memory-barrier bug; do lfence
-                             // after acquire compare-and-swap.
   bool has_sse2;             // Processor has SSE2.
   bool has_cmpxchg16b;       // Processor supports cmpxchg16b instruction.
 };
@@ -102,9 +100,6 @@ inline Atomic32 Acquire_AtomicExchange(volatile Atomic32* ptr,
                                        Atomic32 new_value) {
   CheckNaturalAlignment(ptr);
   Atomic32 old_val = NoBarrier_AtomicExchange(ptr, new_value);
-  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
-    __asm__ __volatile__("lfence" : : : "memory");
-  }
   return old_val;
 }
 
@@ -132,20 +127,15 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
                        : "+r" (temp), "+m" (*ptr)
                        : : "memory");
   // temp now holds the old value of *ptr
-  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
-    __asm__ __volatile__("lfence" : : : "memory");
-  }
   return temp + increment;
 }
 
+// On x86, the NoBarrier_CompareAndSwap() uses a locked instruction and so also
+// provides both acquire and release barriers.
 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
                                        Atomic32 old_value,
                                        Atomic32 new_value) {
-  Atomic32 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
-  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
-    __asm__ __volatile__("lfence" : : : "memory");
-  }
-  return x;
+  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
 }
 
 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
@@ -154,6 +144,12 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
   return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
 }
 
+inline Atomic32 Barrier_CompareAndSwap(volatile Atomic32* ptr,
+                                       Atomic32 old_value,
+                                       Atomic32 new_value) {
+  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+}
+
 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
   CheckNaturalAlignment(ptr);
   *ptr = value;
@@ -257,9 +253,6 @@ inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
 inline Atomic64 Acquire_AtomicExchange(volatile Atomic64* ptr,
                                        Atomic64 new_value) {
   Atomic64 old_val = NoBarrier_AtomicExchange(ptr, new_value);
-  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
-    __asm__ __volatile__("lfence" : : : "memory");
-  }
   return old_val;
 }
 
@@ -287,9 +280,6 @@ inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
                        : "+r" (temp), "+m" (*ptr)
                        : : "memory");
   // temp now contains the previous value of *ptr
-  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
-    __asm__ __volatile__("lfence" : : : "memory");
-  }
   return temp + increment;
 }
 
@@ -403,9 +393,6 @@ inline Atomic64 Acquire_AtomicExchange(volatile Atomic64* ptr,
                                        Atomic64 new_val) {
   CheckNaturalAlignment(ptr);
   Atomic64 old_val = NoBarrier_AtomicExchange(ptr, new_val);
-  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
-    __asm__ __volatile__("lfence" : : : "memory");
-  }
   return old_val;
 }
 
@@ -431,9 +418,6 @@ inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
                                         Atomic64 increment) {
   CheckNaturalAlignment(ptr);
   Atomic64 new_val = NoBarrier_AtomicIncrement(ptr, increment);
-  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
-    __asm__ __volatile__("lfence" : : : "memory");
-  }
   return new_val;
 }
 
@@ -492,11 +476,7 @@ inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
 inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
                                        Atomic64 old_value,
                                        Atomic64 new_value) {
-  Atomic64 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
-  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
-    __asm__ __volatile__("lfence" : : : "memory");
-  }
-  return x;
+  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
 }
 
 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
@@ -505,6 +485,12 @@ inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
   return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
 }
 
+inline Atomic64 Barrier_CompareAndSwap(volatile Atomic64* ptr,
+                                       Atomic64 old_value,
+                                       Atomic64 new_value) {
+  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+}
+
 }  // namespace subtle
 }  // namespace base
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/atomicops.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomicops.h b/be/src/gutil/atomicops.h
index fa4c44c..ad8d773 100644
--- a/be/src/gutil/atomicops.h
+++ b/be/src/gutil/atomicops.h
@@ -67,23 +67,23 @@
 // #endif
 // ------------------------------------------------------------------------
 
-#include "kudu/gutil/arm_instruction_set_select.h"
+#include "gutil/arm_instruction_set_select.h"
 
 // ThreadSanitizer provides own implementation of atomicops.
 #if defined(THREAD_SANITIZER)
-#include "kudu/gutil/atomicops-internals-tsan.h"
+#include "gutil/atomicops-internals-tsan.h"
 #elif defined(__APPLE__)
-#include "kudu/gutil/atomicops-internals-macosx.h"
+#include "gutil/atomicops-internals-macosx.h"
 #elif defined(__GNUC__) && defined(ARMV6)
-#include "kudu/gutil/atomicops-internals-arm-v6plus.h"
+#include "gutil/atomicops-internals-arm-v6plus.h"
 #elif defined(ARMV3)
-#include "kudu/gutil/atomicops-internals-arm-generic.h"
+#include "gutil/atomicops-internals-arm-generic.h"
 #elif defined(__GNUC__) && (defined(__i386) || defined(__x86_64__))
-#include "kudu/gutil/atomicops-internals-x86.h"
+#include "gutil/atomicops-internals-x86.h"
 #elif defined(__GNUC__) && defined(ARCH_POWERPC64)
-#include "kudu/gutil/atomicops-internals-powerpc.h"
+#include "gutil/atomicops-internals-powerpc.h"
 #elif defined(OS_WINDOWS)
-#include "kudu/gutil/atomicops-internals-windows.h"
+#include "gutil/atomicops-internals-windows.h"
 #else
 #error You need to implement atomic operations for this architecture
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h b/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h
index 417c6a0..0a73b85 100644
--- a/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h
+++ b/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h
@@ -11,8 +11,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "kudu/gutil/macros.h"  // For COMPILE_ASSERT
-#include "kudu/gutil/port.h"  // ATTRIBUTE_WEAK
+#include "gutil/macros.h"  // For COMPILE_ASSERT
+#include "gutil/port.h"  // ATTRIBUTE_WEAK
 
 typedef int32_t Atomic32;
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h b/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h
index edafc4e..631f0f0 100644
--- a/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h
+++ b/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h
@@ -12,7 +12,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "kudu/gutil/basictypes.h"  // For COMPILE_ASSERT
+#include "gutil/basictypes.h"  // For COMPILE_ASSERT
 
 // The LDREXD and STREXD instructions in ARM all v7 variants or above.  In v6,
 // only some variants support it.  For simplicity, we only use exclusive

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/auxiliary/atomicops-internals-windows.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/auxiliary/atomicops-internals-windows.h b/be/src/gutil/auxiliary/atomicops-internals-windows.h
index 96674dc..11d7d9d 100644
--- a/be/src/gutil/auxiliary/atomicops-internals-windows.h
+++ b/be/src/gutil/auxiliary/atomicops-internals-windows.h
@@ -11,7 +11,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "kudu/gutil/basictypes.h"  // For COMPILE_ASSERT
+#include "gutil/basictypes.h"  // For COMPILE_ASSERT
 
 typedef int32 Atomic32;
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/basictypes.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/basictypes.h b/be/src/gutil/basictypes.h
index 1c095ca..2f21d03 100644
--- a/be/src/gutil/basictypes.h
+++ b/be/src/gutil/basictypes.h
@@ -5,8 +5,8 @@
 #ifndef BASE_BASICTYPES_H_
 #define BASE_BASICTYPES_H_
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/macros.h"
+#include "gutil/integral_types.h"
+#include "gutil/macros.h"
 
 // Argument type used in interfaces that can optionally take ownership
 // of a passed in argument.  If TAKE_OWNERSHIP is passed, the called

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/bind.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/bind.h b/be/src/gutil/bind.h
index 8875f70..534f208 100644
--- a/be/src/gutil/bind.h
+++ b/be/src/gutil/bind.h
@@ -7,11 +7,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef KUDU_GUTIL_BIND_H_
-#define KUDU_GUTIL_BIND_H_
+#ifndef GUTIL_BIND_H_
+#define GUTIL_BIND_H_
 
-#include "kudu/gutil/bind_internal.h"
-#include "kudu/gutil/callback_internal.h"
+#include "gutil/bind_internal.h"
+#include "gutil/callback_internal.h"
 
 // -----------------------------------------------------------------------------
 // Usage documentation
@@ -536,4 +536,4 @@ Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
 
 }  // namespace kudu
 
-#endif  // KUDU_GUTIL_BIND_H_
+#endif  // GUTIL_BIND_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/bind_helpers.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/bind_helpers.h b/be/src/gutil/bind_helpers.h
index 8a106a6..a60b518 100644
--- a/be/src/gutil/bind_helpers.h
+++ b/be/src/gutil/bind_helpers.h
@@ -140,14 +140,14 @@
 //                        In most cases MessageLoop::DeleteSoon() is a better
 //                        fit.
 
-#ifndef KUDU_GUTIL_BIND_HELPERS_H_
-#define KUDU_GUTIL_BIND_HELPERS_H_
+#ifndef GUTIL_BIND_HELPERS_H_
+#define GUTIL_BIND_HELPERS_H_
 
 #include <assert.h>
 
-#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/callback.h"
-#include "kudu/gutil/template_util.h"
+#include "gutil/basictypes.h"
+#include "gutil/callback.h"
+#include "gutil/template_util.h"
 
 // Unneeded define from Chromium
 #define BASE_EXPORT

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/bind_internal.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/bind_internal.h b/be/src/gutil/bind_internal.h
index 6764d7e..639e077 100644
--- a/be/src/gutil/bind_internal.h
+++ b/be/src/gutil/bind_internal.h
@@ -7,16 +7,16 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef KUDU_GUTIL_BIND_INTERNAL_H_
-#define KUDU_GUTIL_BIND_INTERNAL_H_
+#ifndef GUTIL_BIND_INTERNAL_H_
+#define GUTIL_BIND_INTERNAL_H_
 
-#include "kudu/gutil/bind_helpers.h"
-#include "kudu/gutil/callback_internal.h"
-#include "kudu/gutil/raw_scoped_refptr_mismatch_checker.h"
-#include "kudu/gutil/template_util.h"
+#include "gutil/bind_helpers.h"
+#include "gutil/callback_internal.h"
+#include "gutil/raw_scoped_refptr_mismatch_checker.h"
+#include "gutil/template_util.h"
 
 #if defined(OS_WIN)
-#include "kudu/gutil/bind_internal_win.h"
+#include "gutil/bind_internal_win.h"
 #endif
 
 // During Chromium import, WeakPtr-related code was removed.
@@ -2692,4 +2692,4 @@ struct BindState<Runnable, RunType, void(P1, P2, P3, P4, P5, P6,
 }  // namespace internal
 }  // namespace kudu
 
-#endif  // KUDU_GUTIL_BIND_INTERNAL_H_
+#endif  // GUTIL_BIND_INTERNAL_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/bits.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/bits.cc b/be/src/gutil/bits.cc
index 333e464..bc4e451 100644
--- a/be/src/gutil/bits.cc
+++ b/be/src/gutil/bits.cc
@@ -2,7 +2,7 @@
 //
 // Derived from code by Moses Charikar
 
-#include "kudu/gutil/bits.h"
+#include "gutil/bits.h"
 
 #include <assert.h>
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/bits.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/bits.h b/be/src/gutil/bits.h
index 639186e..d2489be 100644
--- a/be/src/gutil/bits.h
+++ b/be/src/gutil/bits.h
@@ -2,12 +2,12 @@
 //
 // A collection of useful (static) bit-twiddling functions.
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/macros.h"
+#include "gutil/basictypes.h"
+#include "gutil/integral_types.h"
+#include "gutil/logging-inl.h"
+#include "gutil/macros.h"
 
 #ifndef _BITS_H_
 #define _BITS_H_
@@ -156,9 +156,9 @@ inline int Bits::FindLSBSetNonZero64(uint64 n) {
   return __builtin_ctzll(n);
 }
 #elif defined(_MSC_VER)
-#include "kudu/gutil/bits-internal-windows.h"
+#include "gutil/bits-internal-windows.h"
 #else
-#include "kudu/gutil/bits-internal-unknown.h"
+#include "gutil/bits-internal-unknown.h"
 #endif
 
 inline int Bits::CountOnesInByte(unsigned char n) {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/callback.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/callback.h b/be/src/gutil/callback.h
index 1a41622..b0b29b2 100644
--- a/be/src/gutil/callback.h
+++ b/be/src/gutil/callback.h
@@ -7,15 +7,15 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef KUDU_GUTIL_CALLBACK_H_
-#define KUDU_GUTIL_CALLBACK_H_
+#ifndef GUTIL_CALLBACK_H_
+#define GUTIL_CALLBACK_H_
 
-#include "kudu/gutil/callback_forward.h"
-#include "kudu/gutil/callback_internal.h"
-#include "kudu/gutil/template_util.h"
+#include "gutil/callback_forward.h"
+#include "gutil/callback_internal.h"
+#include "gutil/template_util.h"
 
 // NOTE: Header files that do not require the full definition of Callback or
-// Closure should #include "kudu/gutil/callback_forward.h" instead of this file.
+// Closure should #include "gutil/callback_forward.h" instead of this file.
 
 // -----------------------------------------------------------------------------
 // Introduction
@@ -762,4 +762,4 @@ typedef Callback<void(void)> Closure;
 
 }  // namespace kudu
 
-#endif  // KUDU_GUTIL_CALLBACK_H
+#endif  // GUTIL_CALLBACK_H

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/callback_forward.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/callback_forward.h b/be/src/gutil/callback_forward.h
index 956ff73..1f4958d 100644
--- a/be/src/gutil/callback_forward.h
+++ b/be/src/gutil/callback_forward.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef KUDU_GUTIL_CALLBACK_FORWARD_H_
-#define KUDU_GUTIL_CALLBACK_FORWARD_H_
+#ifndef GUTIL_CALLBACK_FORWARD_H_
+#define GUTIL_CALLBACK_FORWARD_H_
 
 namespace kudu {
 
@@ -14,4 +14,4 @@ typedef Callback<void(void)> Closure;
 
 }  // namespace kudu
 
-#endif  // KUDU_GUTIL_CALLBACK_FORWARD_H
+#endif  // GUTIL_CALLBACK_FORWARD_H

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/callback_internal.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/callback_internal.cc b/be/src/gutil/callback_internal.cc
index 05b9e8f..5a24836 100644
--- a/be/src/gutil/callback_internal.cc
+++ b/be/src/gutil/callback_internal.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "kudu/gutil/callback_internal.h"
+#include "gutil/callback_internal.h"
 
 namespace kudu {
 namespace internal {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/callback_internal.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/callback_internal.h b/be/src/gutil/callback_internal.h
index 47b5655..ed91f45 100644
--- a/be/src/gutil/callback_internal.h
+++ b/be/src/gutil/callback_internal.h
@@ -5,13 +5,13 @@
 // This file contains utility functions and classes that help the
 // implementation, and management of the Callback objects.
 
-#ifndef KUDU_GUTIL_CALLBACK_INTERNAL_H_
-#define KUDU_GUTIL_CALLBACK_INTERNAL_H_
+#ifndef GUTIL_CALLBACK_INTERNAL_H_
+#define GUTIL_CALLBACK_INTERNAL_H_
 
 #include <stddef.h>
 
-#include "kudu/gutil/gscoped_ptr.h"
-#include "kudu/gutil/ref_counted.h"
+#include "gutil/gscoped_ptr.h"
+#include "gutil/ref_counted.h"
 
 template <typename T>
 class ScopedVector;
@@ -174,4 +174,4 @@ typename base::enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward(T& t
 }  // namespace internal
 }  // namespace kudu
 
-#endif  // KUDU_GUTIL_CALLBACK_INTERNAL_H_
+#endif  // GUTIL_CALLBACK_INTERNAL_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/casts.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/casts.h b/be/src/gutil/casts.h
index 474e083..8f5966a 100644
--- a/be/src/gutil/casts.h
+++ b/be/src/gutil/casts.h
@@ -14,11 +14,11 @@
 #include <string.h>         // for memcpy
 #include <limits.h>         // for enumeration casts and tests
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/template_util.h"
-#include "kudu/gutil/type_traits.h"
+#include "gutil/macros.h"
+#include "gutil/template_util.h"
+#include "gutil/type_traits.h"
 
 // Use implicit_cast as a safe version of static_cast or const_cast
 // for implicit conversions. For example:

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/charmap.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/charmap.h b/be/src/gutil/charmap.h
index 2698bbe..1b8d3aa 100644
--- a/be/src/gutil/charmap.h
+++ b/be/src/gutil/charmap.h
@@ -18,9 +18,9 @@
 
 #include <string.h>
 
-#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/type_traits.h"
+#include "gutil/basictypes.h"
+#include "gutil/integral_types.h"
+#include "gutil/type_traits.h"
 
 class Charmap {
  public:

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/cpu.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/cpu.cc b/be/src/gutil/cpu.cc
index f4c3885..3ebfa4a 100644
--- a/be/src/gutil/cpu.cc
+++ b/be/src/gutil/cpu.cc
@@ -2,15 +2,15 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "kudu/gutil/cpu.h"
+#include "gutil/cpu.h"
 
 #include <stdlib.h>
 #include <string.h>
 
 #include <algorithm>
 
-#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/strings/stringpiece.h"
+#include "gutil/basictypes.h"
+#include "gutil/strings/stringpiece.h"
 
 #if defined(__x86_64__)
 #if defined(_MSC_VER)

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/cycleclock-inl.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/cycleclock-inl.h b/be/src/gutil/cycleclock-inl.h
index 7738592..7e83491 100644
--- a/be/src/gutil/cycleclock-inl.h
+++ b/be/src/gutil/cycleclock-inl.h
@@ -36,8 +36,8 @@
 
 #include <sys/time.h>
 
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/arm_instruction_set_select.h"
+#include "gutil/port.h"
+#include "gutil/arm_instruction_set_select.h"
 
 // Please do not nest #if directives.  Keep one section, and one #if per
 // platform.
@@ -148,7 +148,7 @@ inline int64 CycleClock::Now() {
 
 // ----------------------------------------------------------------
 #elif defined(ARMV6)  // V6 is the earliest arm that has a standard cyclecount
-#include "kudu/gutil/sysinfo.h"
+#include "gutil/sysinfo.h"
 inline int64 CycleClock::Now() {
   uint32 pmccntr;
   uint32 pmuseren;
@@ -171,7 +171,7 @@ inline int64 CycleClock::Now() {
 
 // ----------------------------------------------------------------
 #elif defined(ARMV3)
-#include "kudu/gutil/sysinfo.h"   // for CyclesPerSecond()
+#include "gutil/sysinfo.h"   // for CyclesPerSecond()
 inline int64 CycleClock::Now() {
   struct timeval tv;
   gettimeofday(&tv, NULL);
@@ -181,7 +181,7 @@ inline int64 CycleClock::Now() {
 
 // ----------------------------------------------------------------
 #elif defined(__mips__)
-#include "kudu/gutil/sysinfo.h"
+#include "gutil/sysinfo.h"
 inline int64 CycleClock::Now() {
   // mips apparently only allows rdtsc for superusers, so we fall
   // back to gettimeofday.  It's possible clock_gettime would be better.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/endian.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/endian.h b/be/src/gutil/endian.h
index 5ed8f38..8cd0f18 100644
--- a/be/src/gutil/endian.h
+++ b/be/src/gutil/endian.h
@@ -32,9 +32,9 @@
 
 #include <assert.h>
 
-#include "kudu/gutil/int128.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/port.h"
+#include "gutil/int128.h"
+#include "gutil/integral_types.h"
+#include "gutil/port.h"
 
 inline uint64 gbswap_64(uint64 host_int) {
 #if defined(__GNUC__) && defined(__x86_64__) && !defined(__APPLE__)

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/fixedarray.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/fixedarray.h b/be/src/gutil/fixedarray.h
index 3e9e072..4d54b6b 100644
--- a/be/src/gutil/fixedarray.h
+++ b/be/src/gutil/fixedarray.h
@@ -25,11 +25,11 @@
 
 #include <stddef.h>
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/manual_constructor.h"
+#include "gutil/logging-inl.h"
+#include "gutil/macros.h"
+#include "gutil/manual_constructor.h"
 
 // A FixedArray<T> represents a non-resizable array of T where the
 // length of the array does not need to be a compile time constant.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/gscoped_ptr.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/gscoped_ptr.h b/be/src/gutil/gscoped_ptr.h
index eee1ec7..be1bb48 100644
--- a/be/src/gutil/gscoped_ptr.h
+++ b/be/src/gutil/gscoped_ptr.h
@@ -91,8 +91,8 @@
 // some of the older compilers we have to support.
 // -------------------------------------------------------------------------
 
-#ifndef KUDU_GUTIL_GSCOPED_PTR_H_
-#define KUDU_GUTIL_GSCOPED_PTR_H_
+#ifndef GUTIL_GSCOPED_PTR_H_
+#define GUTIL_GSCOPED_PTR_H_
 
 // This is an implementation designed to match the anticipated future TR2
 // implementation of the scoped_ptr class, and its closely-related brethren,
@@ -104,10 +104,10 @@
 
 #include <algorithm>  // For std::swap().
 
-#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/template_util.h"
-#include "kudu/gutil/type_traits.h"
-#include "kudu/gutil/move.h"
+#include "gutil/basictypes.h"
+#include "gutil/template_util.h"
+#include "gutil/type_traits.h"
+#include "gutil/move.h"
 
 namespace kudu {
 
@@ -827,4 +827,4 @@ gscoped_ptr<T> make_gscoped_ptr(T* ptr) {
   return gscoped_ptr<T>(ptr);
 }
 
-#endif  // KUDU_GUTIL_GSCOPED_PTR_H_
+#endif  // GUTIL_GSCOPED_PTR_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/builtin_type_hash.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/builtin_type_hash.h b/be/src/gutil/hash/builtin_type_hash.h
index c979eb2..173839b 100644
--- a/be/src/gutil/hash/builtin_type_hash.h
+++ b/be/src/gutil/hash/builtin_type_hash.h
@@ -10,10 +10,10 @@
 #include <stddef.h>
 #include <stdint.h>
 
-#include "kudu/gutil/casts.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/hash/jenkins_lookup2.h"
+#include "gutil/casts.h"
+#include "gutil/integral_types.h"
+#include "gutil/macros.h"
+#include "gutil/hash/jenkins_lookup2.h"
 
 inline uint32 Hash32NumWithSeed(uint32 num, uint32 c) {
   uint32 b = 0x9e3779b9UL;            // the golden ratio; an arbitrary value

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/city.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/city.cc b/be/src/gutil/hash/city.cc
index cc00ff7..e9898a0 100644
--- a/be/src/gutil/hash/city.cc
+++ b/be/src/gutil/hash/city.cc
@@ -14,7 +14,7 @@
 // optimize the code here by writing a program that systematically explores
 // more of the space of possible hash functions, or by using SIMD instructions.
 
-#include "kudu/gutil/hash/city.h"
+#include "gutil/hash/city.h"
 
 #include <sys/types.h>
 #include <algorithm>
@@ -28,12 +28,12 @@ using std::swap;
 using std::make_pair;
 using std::pair;
 
-#include "kudu/gutil/int128.h"
-#include "kudu/gutil/integral_types.h"
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/hash/hash128to64.h"
-#include "kudu/gutil/endian.h"
+#include "gutil/int128.h"
+#include "gutil/integral_types.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/hash/hash128to64.h"
+#include "gutil/endian.h"
 
 namespace util_hash {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/city.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/city.h b/be/src/gutil/hash/city.h
index e99202e..d5925e5 100644
--- a/be/src/gutil/hash/city.h
+++ b/be/src/gutil/hash/city.h
@@ -23,8 +23,8 @@
 
 #include <stddef.h>  // for size_t.
 
-#include "kudu/gutil/int128.h"
-#include "kudu/gutil/integral_types.h"
+#include "gutil/int128.h"
+#include "gutil/integral_types.h"
 
 namespace util_hash {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/hash.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/hash.cc b/be/src/gutil/hash/hash.cc
index 92a8ca2..beceab3 100644
--- a/be/src/gutil/hash/hash.cc
+++ b/be/src/gutil/hash/hash.cc
@@ -7,13 +7,13 @@
 // To find the implementation of the core Bob Jenkins lookup2 hash, look in
 // jenkins.cc.
 
-#include "kudu/gutil/hash/hash.h"
+#include "gutil/hash/hash.h"
 
-#include "kudu/gutil/integral_types.h"
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/hash/jenkins.h"
-#include "kudu/gutil/hash/jenkins_lookup2.h"
+#include "gutil/integral_types.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/hash/jenkins.h"
+#include "gutil/hash/jenkins_lookup2.h"
 
 // For components that ship code externally (notably the Google Search
 // Appliance) we want to change the fingerprint function so that

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/hash.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/hash.h b/be/src/gutil/hash/hash.h
index 3c14f80..f6a8b0a 100644
--- a/be/src/gutil/hash/hash.h
+++ b/be/src/gutil/hash/hash.h
@@ -86,17 +86,17 @@ using __gnu_cxx::hash_set;
 #include <string>
 #include <utility>
 
-#include "kudu/gutil/casts.h"
-#include "kudu/gutil/int128.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/hash/city.h"
-#include "kudu/gutil/hash/hash128to64.h"
-#include "kudu/gutil/hash/jenkins.h"
-#include "kudu/gutil/hash/jenkins_lookup2.h"
-#include "kudu/gutil/hash/legacy_hash.h"
-#include "kudu/gutil/hash/string_hash.h"
+#include "gutil/casts.h"
+#include "gutil/int128.h"
+#include "gutil/integral_types.h"
+#include "gutil/macros.h"
+#include "gutil/port.h"
+#include "gutil/hash/city.h"
+#include "gutil/hash/hash128to64.h"
+#include "gutil/hash/jenkins.h"
+#include "gutil/hash/jenkins_lookup2.h"
+#include "gutil/hash/legacy_hash.h"
+#include "gutil/hash/string_hash.h"
 
 #include <ext/hash_set>
 namespace __gnu_cxx {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/hash128to64.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/hash128to64.h b/be/src/gutil/hash/hash128to64.h
index 481a010..af95662 100644
--- a/be/src/gutil/hash/hash128to64.h
+++ b/be/src/gutil/hash/hash128to64.h
@@ -4,8 +4,8 @@
 #ifndef UTIL_HASH_HASH128TO64_H_
 #define UTIL_HASH_HASH128TO64_H_
 
-#include "kudu/gutil/int128.h"
-#include "kudu/gutil/integral_types.h"
+#include "gutil/int128.h"
+#include "gutil/integral_types.h"
 
 // Hash 128 input bits down to 64 bits of output.
 // This is intended to be a reasonably good hash function.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/jenkins.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/jenkins.cc b/be/src/gutil/hash/jenkins.cc
index 70a7e30..5c19033 100644
--- a/be/src/gutil/hash/jenkins.cc
+++ b/be/src/gutil/hash/jenkins.cc
@@ -16,12 +16,12 @@
 // to load words from memory a byte at a time.  See gwshash.cc for an
 // implementation that is compatible with Bob Jenkins' lookup2.c.
 
-#include "kudu/gutil/hash/jenkins.h"
+#include "gutil/hash/jenkins.h"
 
-#include "kudu/gutil/integral_types.h"
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/hash/jenkins_lookup2.h"
+#include "gutil/integral_types.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/hash/jenkins_lookup2.h"
 
 static inline uint32 char2unsigned(char c) {
   return static_cast<uint32>(static_cast<unsigned char>(c));

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/jenkins.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/jenkins.h b/be/src/gutil/hash/jenkins.h
index 90a47ed..6837a66 100644
--- a/be/src/gutil/hash/jenkins.h
+++ b/be/src/gutil/hash/jenkins.h
@@ -10,7 +10,7 @@
 #ifndef UTIL_HASH_JENKINS_H_
 #define UTIL_HASH_JENKINS_H_
 
-#include "kudu/gutil/integral_types.h"
+#include "gutil/integral_types.h"
 
 // ----------------------------------------------------------------------
 // Hash32StringWithSeed()

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/jenkins_lookup2.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/jenkins_lookup2.h b/be/src/gutil/hash/jenkins_lookup2.h
index e6ffa84..6793809 100644
--- a/be/src/gutil/hash/jenkins_lookup2.h
+++ b/be/src/gutil/hash/jenkins_lookup2.h
@@ -15,8 +15,8 @@
 #ifndef UTIL_HASH_JENKINS_LOOKUP2_H_
 #define UTIL_HASH_JENKINS_LOOKUP2_H_
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/port.h"
+#include "gutil/integral_types.h"
+#include "gutil/port.h"
 
 // ----------------------------------------------------------------------
 // mix()

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/legacy_hash.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/legacy_hash.h b/be/src/gutil/hash/legacy_hash.h
index 3a69336..5a93599 100644
--- a/be/src/gutil/hash/legacy_hash.h
+++ b/be/src/gutil/hash/legacy_hash.h
@@ -10,9 +10,9 @@
 #ifndef UTIL_HASH_LEGACY_HASH_H_
 #define UTIL_HASH_LEGACY_HASH_H_
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/hash/builtin_type_hash.h"
-#include "kudu/gutil/hash/string_hash.h"
+#include "gutil/integral_types.h"
+#include "gutil/hash/builtin_type_hash.h"
+#include "gutil/hash/string_hash.h"
 
 // Hash8, Hash16 and Hash32 are for legacy use only.
 typedef uint32 Hash32;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/hash/string_hash.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/hash/string_hash.h b/be/src/gutil/hash/string_hash.h
index d8c20f3..4e39997 100644
--- a/be/src/gutil/hash/string_hash.h
+++ b/be/src/gutil/hash/string_hash.h
@@ -13,11 +13,11 @@
 
 #include <stddef.h>
 
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/hash/city.h"
-#include "kudu/gutil/hash/jenkins.h"
-#include "kudu/gutil/hash/jenkins_lookup2.h"
+#include "gutil/port.h"
+#include "gutil/integral_types.h"
+#include "gutil/hash/city.h"
+#include "gutil/hash/jenkins.h"
+#include "gutil/hash/jenkins_lookup2.h"
 
 namespace hash_internal {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/int128.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/int128.cc b/be/src/gutil/int128.cc
index eeaee2f..9e2ab18 100644
--- a/be/src/gutil/int128.cc
+++ b/be/src/gutil/int128.cc
@@ -6,8 +6,8 @@
 #include <iostream>
 using std::cout;
 using std::endl;
-#include "kudu/gutil/int128.h"
-#include "kudu/gutil/integral_types.h"
+#include "gutil/int128.h"
+#include "gutil/integral_types.h"
 
 const uint128_pod kuint128max = {
     static_cast<uint64>(GG_LONGLONG(0xFFFFFFFFFFFFFFFF)),

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/int128.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/int128.h b/be/src/gutil/int128.h
index 2a19cca..72b87cd 100644
--- a/be/src/gutil/int128.h
+++ b/be/src/gutil/int128.h
@@ -7,7 +7,7 @@
 
 #include <iosfwd>
 using std::ostream;
-#include "kudu/gutil/integral_types.h"
+#include "gutil/integral_types.h"
 
 struct uint128_pod;
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/macros.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/macros.h b/be/src/gutil/macros.h
index f271bd4..0318008 100644
--- a/be/src/gutil/macros.h
+++ b/be/src/gutil/macros.h
@@ -11,7 +11,7 @@
 #define BASE_MACROS_H_
 
 #include <stddef.h>         // For size_t
-#include "kudu/gutil/port.h"
+#include "gutil/port.h"
 
 // The swigged version of an abstract class must be concrete if any methods
 // return objects of the abstract type. We keep it abstract in C++ and
@@ -39,6 +39,8 @@ template <bool>
 struct CompileAssert {
 };
 
+#ifndef COMPILE_ASSERT
+
 #define COMPILE_ASSERT(expr, msg) \
   typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] ATTRIBUTE_UNUSED
 
@@ -82,6 +84,7 @@ struct CompileAssert {
 //
 //   This is to avoid running into a bug in MS VC 7.1, which
 //   causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
+#endif // COMPILE_ASSERT
 
 
 // A macro to disallow the copy constructor and operator= functions

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/manual_constructor.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/manual_constructor.h b/be/src/gutil/manual_constructor.h
index adcda07..1434f72 100644
--- a/be/src/gutil/manual_constructor.h
+++ b/be/src/gutil/manual_constructor.h
@@ -45,7 +45,7 @@
 
 #include <stddef.h>
 
-#include "kudu/gutil/port.h"
+#include "gutil/port.h"
 
 namespace base {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/map-util.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/map-util.h b/be/src/gutil/map-util.h
index 6fffedf..fb8d5c8 100644
--- a/be/src/gutil/map-util.h
+++ b/be/src/gutil/map-util.h
@@ -71,9 +71,9 @@ using std::pair;
 #include <vector>
 using std::vector;
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/logging-inl.h"
+#include "gutil/logging-inl.h"
 
 //
 // Find*()

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/mathlimits.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/mathlimits.cc b/be/src/gutil/mathlimits.cc
index dcc261d..6d8e536 100644
--- a/be/src/gutil/mathlimits.cc
+++ b/be/src/gutil/mathlimits.cc
@@ -21,9 +21,9 @@
 //
 //
 
-#include "kudu/gutil/mathlimits.h"
+#include "gutil/mathlimits.h"
 
-#include "kudu/gutil/integral_types.h"
+#include "gutil/integral_types.h"
 
 // MSVC++ 2005 thinks the header declaration was a definition, and
 // erroneously flags these as a duplicate definition.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/once.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/once.cc b/be/src/gutil/once.cc
index 1b97f8f..a59a8ef 100644
--- a/be/src/gutil/once.cc
+++ b/be/src/gutil/once.cc
@@ -1,10 +1,10 @@
 // Copyright 2008 Google Inc. All Rights Reserved.
 
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/once.h"
-#include "kudu/gutil/dynamic_annotations.h"
-#include "kudu/gutil/spinlock_internal.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/once.h"
+#include "gutil/dynamic_annotations.h"
+#include "gutil/spinlock_internal.h"
 
 // All modifications to a GoogleOnceType occur inside GoogleOnceInternalInit.
 // The fast path reads the variable with an acquire-load..

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/once.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/once.h b/be/src/gutil/once.h
index ff161c5..c81e871 100644
--- a/be/src/gutil/once.h
+++ b/be/src/gutil/once.h
@@ -24,12 +24,12 @@
 #ifndef BASE_ONCE_H_
 #define BASE_ONCE_H_
 
-#include "kudu/gutil/atomicops.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/dynamic_annotations.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/type_traits.h"
+#include "gutil/atomicops.h"
+#include "gutil/integral_types.h"
+#include "gutil/dynamic_annotations.h"
+#include "gutil/macros.h"
+#include "gutil/port.h"
+#include "gutil/type_traits.h"
 
 // The following enum values are not for use by clients
 enum {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/paranoid.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/paranoid.h b/be/src/gutil/paranoid.h
index 01f34b7..6bd0b7a 100644
--- a/be/src/gutil/paranoid.h
+++ b/be/src/gutil/paranoid.h
@@ -6,9 +6,9 @@
 #ifndef BASE_PARANOID_H_
 #define BASE_PARANOID_H_
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/logging-inl.h"
+#include "gutil/logging-inl.h"
 
 // Sanitize a bool value which might be sour.
 //

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/port.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/port.h b/be/src/gutil/port.h
index 6222cca..e204de7 100644
--- a/be/src/gutil/port.h
+++ b/be/src/gutil/port.h
@@ -18,7 +18,7 @@
 #include <malloc.h>         // for memalign()
 #endif
 
-#include "kudu/gutil/integral_types.h"
+#include "gutil/integral_types.h"
 
 // Must happens before inttypes.h inclusion */
 #if defined(__APPLE__)
@@ -936,7 +936,7 @@ inline int isinf(double x) {
   return 0;
 }
 
-// #include "kudu/conflict-signal.h"
+// #include "conflict-signal.h"
 typedef void (*sig_t)(int);
 
 // These actually belong in errno.h but there's a name confilict in errno
@@ -980,7 +980,7 @@ typedef short int16_t;
 #endif  // _MSC_VER
 
 #ifdef STL_MSVC  // not always the same as _MSC_VER
-#include "kudu/base/port_hash.h"
+#include "base/port_hash.h"
 #else
 struct PortableHashBase { };
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/raw_scoped_refptr_mismatch_checker.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/raw_scoped_refptr_mismatch_checker.h b/be/src/gutil/raw_scoped_refptr_mismatch_checker.h
index 63e4e71..756cab8 100644
--- a/be/src/gutil/raw_scoped_refptr_mismatch_checker.h
+++ b/be/src/gutil/raw_scoped_refptr_mismatch_checker.h
@@ -2,12 +2,12 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef KUDU_GUTIL_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_
-#define KUDU_GUTIL_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_
+#ifndef GUTIL_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_
+#define GUTIL_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_
 
 #include <type_traits>
 
-#include "kudu/gutil/ref_counted.h"
+#include "gutil/ref_counted.h"
 
 // It is dangerous to post a task with a T* argument where T is a subtype of
 // RefCounted(Base|ThreadSafeBase), since by the time the parameter is used, the
@@ -60,4 +60,4 @@ struct ParamsUseScopedRefptrCorrectly<std::tuple<Head, Tail...>> {
 
 }  // namespace kudu
 
-#endif  // KUDU_GUTIL_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_
+#endif  // GUTIL_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/ref_counted.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/ref_counted.cc b/be/src/gutil/ref_counted.cc
index a15a1e2..08c8dd2 100644
--- a/be/src/gutil/ref_counted.cc
+++ b/be/src/gutil/ref_counted.cc
@@ -2,10 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "kudu/gutil/ref_counted.h"
+#include "gutil/ref_counted.h"
 
-#include <glog/logging.h>
-#include "kudu/gutil/threading/thread_collision_warner.h"
+#include <common/logging.h>
+#include "gutil/threading/thread_collision_warner.h"
 
 namespace kudu {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/ref_counted.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/ref_counted.h b/be/src/gutil/ref_counted.h
index 8b6a553..59d0769 100644
--- a/be/src/gutil/ref_counted.h
+++ b/be/src/gutil/ref_counted.h
@@ -7,9 +7,9 @@
 
 #include <cassert>
 
-#include "kudu/gutil/atomic_refcount.h"
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/threading/thread_collision_warner.h"
+#include "gutil/atomic_refcount.h"
+#include "gutil/port.h"
+#include "gutil/threading/thread_collision_warner.h"
 
 namespace kudu {
 namespace subtle {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/ref_counted_memory.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/ref_counted_memory.cc b/be/src/gutil/ref_counted_memory.cc
index 1d695d9..b367f2a 100644
--- a/be/src/gutil/ref_counted_memory.cc
+++ b/be/src/gutil/ref_counted_memory.cc
@@ -2,11 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "kudu/gutil/ref_counted_memory.h"
+#include "gutil/ref_counted_memory.h"
 
 #include <stdlib.h>
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
 namespace kudu {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/ref_counted_memory.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/ref_counted_memory.h b/be/src/gutil/ref_counted_memory.h
index 550a142..ad51e83 100644
--- a/be/src/gutil/ref_counted_memory.h
+++ b/be/src/gutil/ref_counted_memory.h
@@ -2,15 +2,15 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef KUDU_GUTIL_REF_COUNTED_MEMORY_H_
-#define KUDU_GUTIL_REF_COUNTED_MEMORY_H_
+#ifndef GUTIL_REF_COUNTED_MEMORY_H_
+#define GUTIL_REF_COUNTED_MEMORY_H_
 
 #include <string>
 #include <vector>
 
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/ref_counted.h"
-#include "kudu/gutil/port.h"
+#include "gutil/macros.h"
+#include "gutil/ref_counted.h"
+#include "gutil/port.h"
 
 #ifndef BASE_EXPORT
 #define BASE_EXPORT
@@ -147,4 +147,4 @@ class BASE_EXPORT RefCountedMallocedMemory : public RefCountedMemory {
 
 }  // namespace kudu
 
-#endif  // KUDU_GUTIL_REF_COUNTED_MEMORY_H_
+#endif  // GUTIL_REF_COUNTED_MEMORY_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/singleton.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/singleton.h b/be/src/gutil/singleton.h
index 61e5ea5..ce58e13 100644
--- a/be/src/gutil/singleton.h
+++ b/be/src/gutil/singleton.h
@@ -59,10 +59,10 @@
 
 #include <stddef.h>
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/once.h"
+#include "gutil/logging-inl.h"
+#include "gutil/once.h"
 
 namespace util {
 namespace gtl {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/spinlock.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock.cc b/be/src/gutil/spinlock.cc
index 8a02c95..a5ca7c6 100644
--- a/be/src/gutil/spinlock.cc
+++ b/be/src/gutil/spinlock.cc
@@ -32,11 +32,11 @@
  * Author: Sanjay Ghemawat
  */
 
-#include "kudu/gutil/spinlock.h"
-#include "kudu/gutil/synchronization_profiling.h"
-#include "kudu/gutil/spinlock_internal.h"
-#include "kudu/gutil/walltime.h"
-#include "kudu/gutil/sysinfo.h"   /* for NumCPUs() */
+#include "gutil/spinlock.h"
+#include "gutil/synchronization_profiling.h"
+#include "gutil/spinlock_internal.h"
+#include "gutil/walltime.h"
+#include "gutil/sysinfo.h"   /* for NumCPUs() */
 
 namespace base {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/spinlock.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock.h b/be/src/gutil/spinlock.h
index fcd6287..3cf7d3e 100644
--- a/be/src/gutil/spinlock.h
+++ b/be/src/gutil/spinlock.h
@@ -39,10 +39,10 @@
 #ifndef BASE_SPINLOCK_H_
 #define BASE_SPINLOCK_H_
 
-#include "kudu/gutil/atomicops.h"
-#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/dynamic_annotations.h"
-#include "kudu/gutil/thread_annotations.h"
+#include "gutil/atomicops.h"
+#include "gutil/basictypes.h"
+#include "gutil/dynamic_annotations.h"
+#include "gutil/thread_annotations.h"
 
 // This isn't originally in the base:: namespace in tcmalloc,
 // but tcmalloc inadvertently exports these symbols. So, if we

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/spinlock_internal.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock_internal.cc b/be/src/gutil/spinlock_internal.cc
index 151b0dd..0850cf1 100644
--- a/be/src/gutil/spinlock_internal.cc
+++ b/be/src/gutil/spinlock_internal.cc
@@ -41,17 +41,17 @@
 // In all cases, it must return in bounded time even if SpinlockWake() is not
 // called.
 
-#include "kudu/gutil/spinlock_internal.h"
+#include "gutil/spinlock_internal.h"
 
 // forward declaration for use by spinlock_*-inl.h
 namespace base { namespace internal { static int SuggestedDelayNS(int loop); }}
 
 #if defined(_WIN32)
-#include "kudu/gutil/spinlock_win32-inl.h"
+#include "gutil/spinlock_win32-inl.h"
 #elif defined(__linux__)
-#include "kudu/gutil/spinlock_linux-inl.h"
+#include "gutil/spinlock_linux-inl.h"
 #else
-#include "kudu/gutil/spinlock_posix-inl.h"
+#include "gutil/spinlock_posix-inl.h"
 #endif
 
 namespace base {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/spinlock_internal.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock_internal.h b/be/src/gutil/spinlock_internal.h
index c235893..a7f5150 100644
--- a/be/src/gutil/spinlock_internal.h
+++ b/be/src/gutil/spinlock_internal.h
@@ -36,8 +36,8 @@
 #ifndef BASE_SPINLOCK_INTERNAL_H_
 #define BASE_SPINLOCK_INTERNAL_H_
 
-#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/atomicops.h"
+#include "gutil/basictypes.h"
+#include "gutil/atomicops.h"
 
 namespace base {
 namespace internal {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/spinlock_linux-inl.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock_linux-inl.h b/be/src/gutil/spinlock_linux-inl.h
index 41ef03a..c9838e4 100644
--- a/be/src/gutil/spinlock_linux-inl.h
+++ b/be/src/gutil/spinlock_linux-inl.h
@@ -36,7 +36,7 @@
 #include <sched.h>
 #include <time.h>
 #include <limits.h>
-#include "kudu/gutil/linux_syscall_support.h"
+#include "gutil/linux_syscall_support.h"
 
 #define FUTEX_WAIT 0
 #define FUTEX_WAKE 1

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/stl_util.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/stl_util.h b/be/src/gutil/stl_util.h
index 60cb587..7e72b25 100644
--- a/be/src/gutil/stl_util.h
+++ b/be/src/gutil/stl_util.h
@@ -52,9 +52,9 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/port.h"
+#include "gutil/integral_types.h"
+#include "gutil/macros.h"
+#include "gutil/port.h"
 
 // Sort and remove duplicates of an STL vector or deque.
 template<class T>

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/stringprintf.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/stringprintf.cc b/be/src/gutil/stringprintf.cc
index 112605c..13939fe 100644
--- a/be/src/gutil/stringprintf.cc
+++ b/be/src/gutil/stringprintf.cc
@@ -1,15 +1,15 @@
 // Copyright 2002 and onwards Google Inc.
 
-#include "kudu/gutil/stringprintf.h"
+#include "gutil/stringprintf.h"
 
 #include <errno.h>
 #include <stdarg.h> // For va_list and related operations
 #include <stdio.h> // MSVC requires this for _vsnprintf
 #include <vector>
 using std::vector;
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/macros.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/macros.h"
 
 #ifdef _MSC_VER
 enum { IS__MSC_VER = 1 };

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/stringprintf.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/stringprintf.h b/be/src/gutil/stringprintf.h
index 2083574..e486e72 100644
--- a/be/src/gutil/stringprintf.h
+++ b/be/src/gutil/stringprintf.h
@@ -16,7 +16,7 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include "kudu/gutil/port.h"
+#include "gutil/port.h"
 
 // Return a C++ string
 extern string StringPrintf(const char* format, ...)

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/ascii_ctype.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/ascii_ctype.cc b/be/src/gutil/strings/ascii_ctype.cc
index 50ea8c2..44608f8 100644
--- a/be/src/gutil/strings/ascii_ctype.cc
+++ b/be/src/gutil/strings/ascii_ctype.cc
@@ -4,7 +4,7 @@
 // The C++ style guide requires 80-column lines.
 // cpplint.py requires 2-space indentation.
 
-#include "kudu/gutil/strings/ascii_ctype.h"
+#include "gutil/strings/ascii_ctype.h"
 
 // # Table generated by this Python code (bit 0x02 is currently unused):
 // def Hex2(n):

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/charset.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/charset.cc b/be/src/gutil/strings/charset.cc
index 2e9d5b1..7725b0f 100644
--- a/be/src/gutil/strings/charset.cc
+++ b/be/src/gutil/strings/charset.cc
@@ -1,6 +1,6 @@
 // Copyright 2008 Google Inc. All Rights Reserved.
 
-#include "kudu/gutil/strings/charset.h"
+#include "gutil/strings/charset.h"
 
 #include <string.h>
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/charset.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/charset.h b/be/src/gutil/strings/charset.h
index a2dbca4..b6b7013 100644
--- a/be/src/gutil/strings/charset.h
+++ b/be/src/gutil/strings/charset.h
@@ -3,7 +3,7 @@
 #ifndef STRINGS_CHARSET_H_
 #define STRINGS_CHARSET_H_
 
-#include "kudu/gutil/integral_types.h"
+#include "gutil/integral_types.h"
 
 namespace strings {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/escaping.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/escaping.cc b/be/src/gutil/strings/escaping.cc
index cf49359..adb8093 100644
--- a/be/src/gutil/strings/escaping.cc
+++ b/be/src/gutil/strings/escaping.cc
@@ -1,7 +1,7 @@
 // Copyright 2008 Google Inc. All Rights Reserved.
 // Authors: Numerous. See the .h for contact people.
 
-#include "kudu/gutil/strings/escaping.h"
+#include "gutil/strings/escaping.h"
 
 #include <assert.h>
 #include <stdio.h>
@@ -12,13 +12,13 @@ using std::numeric_limits;
 #include <vector>
 using std::vector;
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/gscoped_ptr.h"
-#include "kudu/gutil/strings/join.h"
-#include "kudu/gutil/utf/utf.h"  // for runetochar
-#include "kudu/gutil/charmap.h"
-#include "kudu/gutil/stl_util.h"
+#include "gutil/integral_types.h"
+#include "gutil/port.h"
+#include "gutil/gscoped_ptr.h"
+#include "gutil/strings/join.h"
+#include "gutil/utf/utf.h"  // for runetochar
+#include "gutil/charmap.h"
+#include "gutil/stl_util.h"
 
 namespace strings {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/escaping.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/escaping.h b/be/src/gutil/strings/escaping.h
index 19e0860..67485ca 100644
--- a/be/src/gutil/strings/escaping.h
+++ b/be/src/gutil/strings/escaping.h
@@ -27,12 +27,12 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/strings/ascii_ctype.h"
-#include "kudu/gutil/strings/charset.h"
-#include "kudu/gutil/strings/stringpiece.h"
+#include "gutil/logging-inl.h"
+#include "gutil/strings/ascii_ctype.h"
+#include "gutil/strings/charset.h"
+#include "gutil/strings/stringpiece.h"
 
 namespace strings {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/fastmem.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/fastmem.h b/be/src/gutil/strings/fastmem.h
index 3beca6d..ec84071 100644
--- a/be/src/gutil/strings/fastmem.h
+++ b/be/src/gutil/strings/fastmem.h
@@ -22,8 +22,8 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/port.h"
+#include "gutil/integral_types.h"
+#include "gutil/port.h"
 
 namespace strings {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/human_readable.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/human_readable.cc b/be/src/gutil/strings/human_readable.cc
index fb3419a..db31c65 100644
--- a/be/src/gutil/strings/human_readable.cc
+++ b/be/src/gutil/strings/human_readable.cc
@@ -1,15 +1,15 @@
 // Copyright 2007 Google Inc. All Rights Reserved.
 
-#include "kudu/gutil/strings/human_readable.h"
+#include "gutil/strings/human_readable.h"
 
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/stringprintf.h"
-#include "kudu/gutil/strings/strip.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/stringprintf.h"
+#include "gutil/strings/strip.h"
 
 namespace {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/human_readable.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/human_readable.h b/be/src/gutil/strings/human_readable.h
index e05b169..8a05907 100644
--- a/be/src/gutil/strings/human_readable.h
+++ b/be/src/gutil/strings/human_readable.h
@@ -12,9 +12,9 @@ using std::less;
 #include <string>
 using std::string;
 
-#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/macros.h"
+#include "gutil/basictypes.h"
+#include "gutil/integral_types.h"
+#include "gutil/macros.h"
 
 //                                 WARNING
 // HumanReadable{NumBytes, Int} don't give you the standard set of SI prefixes.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/join.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/join.cc b/be/src/gutil/strings/join.cc
index c0035e1..e37d163 100644
--- a/be/src/gutil/strings/join.cc
+++ b/be/src/gutil/strings/join.cc
@@ -1,12 +1,12 @@
 // Copyright 2008 and onwards Google Inc.  All rights reserved.
 
-#include "kudu/gutil/strings/join.h"
+#include "gutil/strings/join.h"
 
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/gscoped_ptr.h"
-#include "kudu/gutil/strings/ascii_ctype.h"
-#include "kudu/gutil/strings/escaping.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/gscoped_ptr.h"
+#include "gutil/strings/ascii_ctype.h"
+#include "gutil/strings/escaping.h"
 
 // ----------------------------------------------------------------------
 // JoinUsing()

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/join.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/join.h b/be/src/gutil/strings/join.h
index 4369c4c..bd34c39 100644
--- a/be/src/gutil/strings/join.h
+++ b/be/src/gutil/strings/join.h
@@ -32,13 +32,13 @@ using std::pair;
 #include <vector>
 using std::vector;
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/template_util.h"
-#include "kudu/gutil/strings/numbers.h"
-#include "kudu/gutil/strings/strcat.h"    // For backward compatibility.
-#include "kudu/gutil/strings/stringpiece.h"
-#include "kudu/gutil/hash/hash.h"
+#include "gutil/integral_types.h"
+#include "gutil/macros.h"
+#include "gutil/template_util.h"
+#include "gutil/strings/numbers.h"
+#include "gutil/strings/strcat.h"    // For backward compatibility.
+#include "gutil/strings/stringpiece.h"
+#include "gutil/hash/hash.h"
 
 // ----------------------------------------------------------------------
 // JoinUsing()

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/memutil.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/memutil.cc b/be/src/gutil/strings/memutil.cc
index 390d2a0..ace02b3 100644
--- a/be/src/gutil/strings/memutil.cc
+++ b/be/src/gutil/strings/memutil.cc
@@ -2,11 +2,11 @@
 // Copyright (C) 2001 and onwards Google, Inc.
 //
 
-#include "kudu/gutil/strings/memutil.h"
+#include "gutil/strings/memutil.h"
 
 #include <stdlib.h>        // for malloc, NULL
 
-#include "kudu/gutil/strings/ascii_ctype.h"  // for ascii_tolower
+#include "gutil/strings/ascii_ctype.h"  // for ascii_tolower
 
 int memcasecmp(const char *s1, const char *s2, size_t len) {
   const unsigned char *us1 = reinterpret_cast<const unsigned char *>(s1);

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/memutil.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/memutil.h b/be/src/gutil/strings/memutil.h
index 9335735..b230149 100644
--- a/be/src/gutil/strings/memutil.h
+++ b/be/src/gutil/strings/memutil.h
@@ -56,7 +56,7 @@
 #include <stddef.h>
 #include <string.h>      // to get the POSIX mem*() routines
 
-#include "kudu/gutil/port.h"   // disable some warnings on Windows
+#include "gutil/port.h"   // disable some warnings on Windows
 
 inline char *memcat(char *dest, size_t destlen,
                     const char *src, size_t srclen) {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/numbers.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/numbers.cc b/be/src/gutil/strings/numbers.cc
index 7bdb57c..c7f7d19 100644
--- a/be/src/gutil/strings/numbers.cc
+++ b/be/src/gutil/strings/numbers.cc
@@ -4,7 +4,7 @@
 // This file contains string processing functions related to
 // numeric values.
 
-#include "kudu/gutil/strings/numbers.h"
+#include "gutil/strings/numbers.h"
 
 #include <assert.h>
 #include <ctype.h>
@@ -19,14 +19,14 @@ using std::numeric_limits;
 #include <string>
 using std::string;
 
-#include "kudu/gutil/int128.h"
-#include "kudu/gutil/integral_types.h"
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/gscoped_ptr.h"
-#include "kudu/gutil/stringprintf.h"
-#include "kudu/gutil/strtoint.h"
-#include "kudu/gutil/strings/ascii_ctype.h"
+#include "gutil/int128.h"
+#include "gutil/integral_types.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/gscoped_ptr.h"
+#include "gutil/stringprintf.h"
+#include "gutil/strtoint.h"
+#include "gutil/strings/ascii_ctype.h"
 
 // Reads a <double> in *text, which may not be whitespace-initiated.
 // *len is the length, or -1 if text is '\0'-terminated, which is more

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/numbers.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/numbers.h b/be/src/gutil/strings/numbers.h
index e9f5c1a..f035f23 100644
--- a/be/src/gutil/strings/numbers.h
+++ b/be/src/gutil/strings/numbers.h
@@ -20,11 +20,11 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include "kudu/gutil/int128.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/stringprintf.h"
+#include "gutil/int128.h"
+#include "gutil/integral_types.h"
+#include "gutil/macros.h"
+#include "gutil/port.h"
+#include "gutil/stringprintf.h"
 
 
 // START DOXYGEN NumbersFunctions grouping
@@ -540,36 +540,36 @@ bool ParseDoubleRange(const char* text, int len, const char** end,
 // These functions are deprecated.
 // Do not use in new code.
 
-// DEPRECATED(wadetregaskis).  Just call StringPrintf or SimpleFtoa.
-string FloatToString(float f, const char* format);
+// // DEPRECATED(wadetregaskis).  Just call StringPrintf or SimpleFtoa.
+// string FloatToString(float f, const char* format);
 
-// DEPRECATED(wadetregaskis).  Just call StringPrintf or SimpleItoa.
-string IntToString(int i, const char* format);
+// // DEPRECATED(wadetregaskis).  Just call StringPrintf or SimpleItoa.
+// string IntToString(int i, const char* format);
 
-// DEPRECATED(wadetregaskis).  Just call StringPrintf or SimpleItoa.
-string Int64ToString(int64 i64, const char* format);
+// // DEPRECATED(wadetregaskis).  Just call StringPrintf or SimpleItoa.
+// string Int64ToString(int64 i64, const char* format);
 
-// DEPRECATED(wadetregaskis).  Just call StringPrintf or SimpleItoa.
-string UInt64ToString(uint64 ui64, const char* format);
+// // DEPRECATED(wadetregaskis).  Just call StringPrintf or SimpleItoa.
+// string UInt64ToString(uint64 ui64, const char* format);
 
-// DEPRECATED(wadetregaskis).  Just call StringPrintf.
-inline string FloatToString(float f) {
-  return StringPrintf("%7f", f);
-}
+// // DEPRECATED(wadetregaskis).  Just call StringPrintf.
+// inline string FloatToString(float f) {
+//   return StringPrintf("%7f", f);
+// }
 
-// DEPRECATED(wadetregaskis).  Just call StringPrintf.
-inline string IntToString(int i) {
-  return StringPrintf("%7d", i);
-}
+// // DEPRECATED(wadetregaskis).  Just call StringPrintf.
+// inline string IntToString(int i) {
+//   return StringPrintf("%7d", i);
+// }
 
-// DEPRECATED(wadetregaskis).  Just call StringPrintf.
-inline string Int64ToString(int64 i64) {
-  return StringPrintf("%7" PRId64, i64);
-}
+// // DEPRECATED(wadetregaskis).  Just call StringPrintf.
+// inline string Int64ToString(int64 i64) {
+//   return StringPrintf("%7" PRId64, i64);
+// }
 
-// DEPRECATED(wadetregaskis).  Just call StringPrintf.
-inline string UInt64ToString(uint64 ui64) {
-  return StringPrintf("%7" PRIu64, ui64);
-}
+// // DEPRECATED(wadetregaskis).  Just call StringPrintf.
+// inline string UInt64ToString(uint64 ui64) {
+//   return StringPrintf("%7" PRIu64, ui64);
+// }
 
 #endif  // STRINGS_NUMBERS_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/serialize.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/serialize.cc b/be/src/gutil/strings/serialize.cc
index 5449ef7..a4e27c3 100644
--- a/be/src/gutil/strings/serialize.cc
+++ b/be/src/gutil/strings/serialize.cc
@@ -1,6 +1,6 @@
 // Copyright 2003, Google Inc.  All rights reserved.
 
-#include "kudu/gutil/strings/serialize.h"
+#include "gutil/strings/serialize.h"
 
 #include <stddef.h>
 #include <stdlib.h>
@@ -15,13 +15,13 @@ using std::pair;
 #include <vector>
 using std::vector;
 
-#include "kudu/gutil/casts.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/stringprintf.h"
-#include "kudu/gutil/strtoint.h"
-#include "kudu/gutil/strings/join.h"
-#include "kudu/gutil/strings/split.h"
-#include "kudu/gutil/hash/hash.h"
+#include "gutil/casts.h"
+#include "gutil/integral_types.h"
+#include "gutil/stringprintf.h"
+#include "gutil/strtoint.h"
+#include "gutil/strings/join.h"
+#include "gutil/strings/split.h"
+#include "gutil/hash/hash.h"
 
 // Convert a uint32 to a 4-byte string.
 string Uint32ToKey(uint32 u32) {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/serialize.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/serialize.h b/be/src/gutil/strings/serialize.h
index 7966cd2..d69382a 100644
--- a/be/src/gutil/strings/serialize.h
+++ b/be/src/gutil/strings/serialize.h
@@ -19,15 +19,15 @@ using std::pair;
 #include <vector>
 using std::vector;
 
-#include <glog/logging.h>
-
-#include "kudu/gutil/int128.h"
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/type_traits.h"
-#include "kudu/gutil/strings/stringpiece.h"
-#include "kudu/gutil/endian.h"
-#include "kudu/gutil/stl_util.h"
+#include <common/logging.h>
+
+#include "gutil/int128.h"
+#include "gutil/integral_types.h"
+#include "gutil/logging-inl.h"
+#include "gutil/type_traits.h"
+#include "gutil/strings/stringpiece.h"
+#include "gutil/endian.h"
+#include "gutil/stl_util.h"
 
 // Converts a 4-byte uint32 to a string such that the string keys sort in
 // the same order as the original uint32 value.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/split.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/split.cc b/be/src/gutil/strings/split.cc
index a42faa7..34a9d99 100644
--- a/be/src/gutil/strings/split.cc
+++ b/be/src/gutil/strings/split.cc
@@ -2,7 +2,7 @@
 //
 // Maintainer: Greg Miller <jg...@google.com>
 
-#include "kudu/gutil/strings/split.h"
+#include "gutil/strings/split.h"
 
 #include <assert.h>
 #include <stdlib.h>
@@ -13,14 +13,14 @@ using std::iterator_traits;
 #include <limits>
 using std::numeric_limits;
 
-#include "kudu/gutil/integral_types.h"
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/strtoint.h"
-#include "kudu/gutil/strings/ascii_ctype.h"
-#include "kudu/gutil/strings/util.h"
-#include "kudu/gutil/hash/hash.h"
+#include "gutil/integral_types.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/macros.h"
+#include "gutil/strtoint.h"
+#include "gutil/strings/ascii_ctype.h"
+#include "gutil/strings/util.h"
+#include "gutil/hash/hash.h"
 
 // Implementations for some of the Split2 API. Much of the Split2 API is
 // templated so it exists in header files, either strings/split.h or

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/split.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/split.h b/be/src/gutil/strings/split.h
index c487689..e2f74a7 100644
--- a/be/src/gutil/strings/split.h
+++ b/be/src/gutil/strings/split.h
@@ -51,14 +51,14 @@ using std::pair;
 #include <vector>
 using std::vector;
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/strings/charset.h"
-#include "kudu/gutil/strings/split_internal.h"
-#include "kudu/gutil/strings/stringpiece.h"
-#include "kudu/gutil/strings/strip.h"
+#include "gutil/integral_types.h"
+#include "gutil/logging-inl.h"
+#include "gutil/strings/charset.h"
+#include "gutil/strings/split_internal.h"
+#include "gutil/strings/stringpiece.h"
+#include "gutil/strings/strip.h"
 
 namespace strings {
 
@@ -854,11 +854,11 @@ bool SplitRange(const char* rangestr, int* from, int* to);
 // The following variants of SplitCSVLine() are not recommended for new code.
 // Please consider the CSV parser in //util/csv as an alternative.  Examples:
 // To parse a single line:
-//     #include "kudu/util/csv/parser.h"
+//     #include "util/csv/parser.h"
 //     vector<string> fields = util::csv::ParseLine(line).fields();
 //
 // To parse an entire file:
-//     #include "kudu/util/csv/parser.h"
+//     #include "util/csv/parser.h"
 //     for (Record rec : Parser(source)) {
 //       vector<string> fields = rec.fields();
 //     }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/split_internal.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/split_internal.h b/be/src/gutil/strings/split_internal.h
index 01b3fac..38e3d01 100644
--- a/be/src/gutil/strings/split_internal.h
+++ b/be/src/gutil/strings/split_internal.h
@@ -26,8 +26,8 @@ using std::multimap;
 #include <vector>
 using std::vector;
 
-#include "kudu/gutil/port.h"  // for LANG_CXX11
-#include "kudu/gutil/strings/stringpiece.h"
+#include "gutil/port.h"  // for LANG_CXX11
+#include "gutil/strings/stringpiece.h"
 
 #ifdef LANG_CXX11
 // This must be included after "base/port.h", which defines LANG_CXX11.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/strcat.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/strcat.cc b/be/src/gutil/strings/strcat.cc
index 93f8114..b91fab9 100644
--- a/be/src/gutil/strings/strcat.cc
+++ b/be/src/gutil/strings/strcat.cc
@@ -1,18 +1,18 @@
 // Copyright 2008 and onwards Google Inc.  All rights reserved.
 
-#include "kudu/gutil/strings/strcat.h"
+#include "gutil/strings/strcat.h"
 
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
 
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/gscoped_ptr.h"
-#include "kudu/gutil/strings/ascii_ctype.h"
-#include "kudu/gutil/strings/escaping.h"
-#include "kudu/gutil/stl_util.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/gscoped_ptr.h"
+#include "gutil/strings/ascii_ctype.h"
+#include "gutil/strings/escaping.h"
+#include "gutil/stl_util.h"
 
 AlphaNum gEmptyAlphaNum("");
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/strcat.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/strcat.h b/be/src/gutil/strings/strcat.h
index 40b888b..4493a0b 100644
--- a/be/src/gutil/strings/strcat.h
+++ b/be/src/gutil/strings/strcat.h
@@ -10,9 +10,9 @@
 #include <string>
 using std::string;
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/strings/numbers.h"
-#include "kudu/gutil/strings/stringpiece.h"
+#include "gutil/integral_types.h"
+#include "gutil/strings/numbers.h"
+#include "gutil/strings/stringpiece.h"
 
 // The AlphaNum type was designed to be used as the parameter type for StrCat().
 // I suppose that any routine accepting either a string or a number could accept

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/string_util-test.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/string_util-test.cc b/be/src/gutil/strings/string_util-test.cc
index 8849ca2..4d68e22 100644
--- a/be/src/gutil/strings/string_util-test.cc
+++ b/be/src/gutil/strings/string_util-test.cc
@@ -16,7 +16,7 @@
 // under the License.
 //
 // Some portions Copyright 2013 The Chromium Authors. All rights reserved.
-#include "kudu/gutil/strings/util.h"
+#include "gutil/strings/util.h"
 
 #include <gtest/gtest.h>
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/stringpiece.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/stringpiece.cc b/be/src/gutil/strings/stringpiece.cc
index d6f23ee..73a6690 100644
--- a/be/src/gutil/strings/stringpiece.cc
+++ b/be/src/gutil/strings/stringpiece.cc
@@ -2,18 +2,18 @@
 //
 //
 
-#include "kudu/gutil/strings/stringpiece.h"
+#include "gutil/strings/stringpiece.h"
 
 #include <algorithm>
 #include <climits>
-#include <glog/logging.h>
+#include <common/logging.h>
 #include <string.h>
 #include <string>
 
-#include "kudu/gutil/hash/hash.h"
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/stl_util.h"
-#include "kudu/gutil/strings/memutil.h"
+#include "gutil/hash/hash.h"
+#include "gutil/logging-inl.h"
+#include "gutil/stl_util.h"
+#include "gutil/strings/memutil.h"
 
 using std::copy;
 using std::max;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/stringpiece.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/stringpiece.h b/be/src/gutil/strings/stringpiece.h
index 0f28f2b..0f59b38 100644
--- a/be/src/gutil/strings/stringpiece.h
+++ b/be/src/gutil/strings/stringpiece.h
@@ -121,11 +121,11 @@
 #include <string.h>
 #include <string>
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/type_traits.h"
-#include "kudu/gutil/strings/fastmem.h"
-#include "kudu/gutil/hash/hash.h"
+#include "gutil/integral_types.h"
+#include "gutil/port.h"
+#include "gutil/type_traits.h"
+#include "gutil/strings/fastmem.h"
+#include "gutil/hash/hash.h"
 
 class StringPiece {
  private:



[05/14] incubator-impala git commit: IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

Posted by he...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/stl_util.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/stl_util.h b/be/src/gutil/stl_util.h
index 57007b1..60cb587 100644
--- a/be/src/gutil/stl_util.h
+++ b/be/src/gutil/stl_util.h
@@ -1,16 +1,21 @@
 // Copyright 2002 Google Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // ---
 //
@@ -47,10 +52,9 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include "gutil/integral_types.h"
-#include "gutil/macros.h"
-#include "gutil/port.h"
-#include "gutil/algorithm.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/port.h"
 
 // Sort and remove duplicates of an STL vector or deque.
 template<class T>
@@ -575,8 +579,8 @@ void STLSetDifference(const SortedSTLContainerA &a,
                       const SortedSTLContainerB &b,
                       SortedSTLContainerC *c) {
   // The qualified name avoids an ambiguity error, particularly with C++11:
-  assert(util::gtl::is_sorted(a.begin(), a.end()));
-  assert(util::gtl::is_sorted(b.begin(), b.end()));
+  assert(std::is_sorted(a.begin(), a.end()));
+  assert(std::is_sorted(b.begin(), b.end()));
   assert(static_cast<const void *>(&a) !=
          static_cast<const void *>(c));
   assert(static_cast<const void *>(&b) !=
@@ -599,8 +603,8 @@ template<typename SortedSTLContainerA,
 void STLSetUnion(const SortedSTLContainerA &a,
                  const SortedSTLContainerB &b,
                  SortedSTLContainerC *c) {
-  assert(util::gtl::is_sorted(a.begin(), a.end()));
-  assert(util::gtl::is_sorted(b.begin(), b.end()));
+  assert(std::is_sorted(a.begin(), a.end()));
+  assert(std::is_sorted(b.begin(), b.end()));
   assert(static_cast<const void *>(&a) !=
          static_cast<const void *>(c));
   assert(static_cast<const void *>(&b) !=
@@ -615,8 +619,8 @@ template<typename SortedSTLContainerA,
 void STLSetSymmetricDifference(const SortedSTLContainerA &a,
                                const SortedSTLContainerB &b,
                                SortedSTLContainerC *c) {
-  assert(util::gtl::is_sorted(a.begin(), a.end()));
-  assert(util::gtl::is_sorted(b.begin(), b.end()));
+  assert(std::is_sorted(a.begin(), a.end()));
+  assert(std::is_sorted(b.begin(), b.end()));
   assert(static_cast<const void *>(&a) !=
          static_cast<const void *>(c));
   assert(static_cast<const void *>(&b) !=
@@ -647,8 +651,8 @@ template<typename SortedSTLContainerA,
 void STLSetIntersection(const SortedSTLContainerA &a,
                         const SortedSTLContainerB &b,
                         SortedSTLContainerC *c) {
-  assert(util::gtl::is_sorted(a.begin(), a.end()));
-  assert(util::gtl::is_sorted(b.begin(), b.end()));
+  assert(std::is_sorted(a.begin(), a.end()));
+  assert(std::is_sorted(b.begin(), b.end()));
   assert(static_cast<const void *>(&a) !=
          static_cast<const void *>(c));
   assert(static_cast<const void *>(&b) !=
@@ -671,8 +675,8 @@ template<typename SortedSTLContainerA,
          typename SortedSTLContainerB>
 bool STLIncludes(const SortedSTLContainerA &a,
                  const SortedSTLContainerB &b) {
-  assert(util::gtl::is_sorted(a.begin(), a.end()));
-  assert(util::gtl::is_sorted(b.begin(), b.end()));
+  assert(std::is_sorted(a.begin(), a.end()));
+  assert(std::is_sorted(b.begin(), b.end()));
   return std::includes(a.begin(), a.end(),
                        b.begin(), b.end());
 }
@@ -909,8 +913,8 @@ struct STLEmptyBaseHandle : public Base {
 template<typename InputIterator1, typename InputIterator2>
 bool SortedRangesHaveIntersection(InputIterator1 begin1, InputIterator1 end1,
                                   InputIterator2 begin2, InputIterator2 end2) {
-  assert(util::gtl::is_sorted(begin1, end1));
-  assert(util::gtl::is_sorted(begin2, end2));
+  assert(std::is_sorted(begin1, end1));
+  assert(std::is_sorted(begin2, end2));
   while (begin1 != end1 && begin2 != end2) {
     if (*begin1 < *begin2) {
       ++begin1;
@@ -929,8 +933,8 @@ template<typename InputIterator1, typename InputIterator2, typename Comp>
 bool SortedRangesHaveIntersection(InputIterator1 begin1, InputIterator1 end1,
                                   InputIterator2 begin2, InputIterator2 end2,
                                   Comp comparator) {
-  assert(util::gtl::is_sorted(begin1, end1, comparator));
-  assert(util::gtl::is_sorted(begin2, end2, comparator));
+  assert(std::is_sorted(begin1, end1, comparator));
+  assert(std::is_sorted(begin2, end2, comparator));
   while (begin1 != end1 && begin2 != end2) {
     if (comparator(*begin1, *begin2)) {
       ++begin1;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/stringprintf.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/stringprintf.cc b/be/src/gutil/stringprintf.cc
index dd7b4cf..112605c 100644
--- a/be/src/gutil/stringprintf.cc
+++ b/be/src/gutil/stringprintf.cc
@@ -1,6 +1,6 @@
 // Copyright 2002 and onwards Google Inc.
 
-#include "gutil/stringprintf.h"
+#include "kudu/gutil/stringprintf.h"
 
 #include <errno.h>
 #include <stdarg.h> // For va_list and related operations
@@ -8,8 +8,8 @@
 #include <vector>
 using std::vector;
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/macros.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/macros.h"
 
 #ifdef _MSC_VER
 enum { IS__MSC_VER = 1 };
@@ -41,7 +41,7 @@ void StringAppendV(string* dst, const char* format, va_list ap) {
       // Error or MSVC running out of space.  MSVC 8.0 and higher
       // can be asked about space needed with the special idiom below:
       va_copy(backup_ap, ap);
-      result = vsnprintf(NULL, 0, format, backup_ap);
+      result = vsnprintf(nullptr, 0, format, backup_ap);
       va_end(backup_ap);
     }
 
@@ -54,7 +54,7 @@ void StringAppendV(string* dst, const char* format, va_list ap) {
   // Increase the buffer size to the size requested by vsnprintf,
   // plus one for the closing \0.
   int length = result+1;
-  char* buf = new char[length];
+  auto buf = new char[length];
 
   // Restore the va_list before we use it again
   va_copy(backup_ap, ap);

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/stringprintf.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/stringprintf.h b/be/src/gutil/stringprintf.h
index e486e72..2083574 100644
--- a/be/src/gutil/stringprintf.h
+++ b/be/src/gutil/stringprintf.h
@@ -16,7 +16,7 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include "gutil/port.h"
+#include "kudu/gutil/port.h"
 
 // Return a C++ string
 extern string StringPrintf(const char* format, ...)

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/ascii_ctype.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/ascii_ctype.cc b/be/src/gutil/strings/ascii_ctype.cc
index 44608f8..50ea8c2 100644
--- a/be/src/gutil/strings/ascii_ctype.cc
+++ b/be/src/gutil/strings/ascii_ctype.cc
@@ -4,7 +4,7 @@
 // The C++ style guide requires 80-column lines.
 // cpplint.py requires 2-space indentation.
 
-#include "gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
 
 // # Table generated by this Python code (bit 0x02 is currently unused):
 // def Hex2(n):

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/charset.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/charset.cc b/be/src/gutil/strings/charset.cc
index 7725b0f..2e9d5b1 100644
--- a/be/src/gutil/strings/charset.cc
+++ b/be/src/gutil/strings/charset.cc
@@ -1,6 +1,6 @@
 // Copyright 2008 Google Inc. All Rights Reserved.
 
-#include "gutil/strings/charset.h"
+#include "kudu/gutil/strings/charset.h"
 
 #include <string.h>
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/charset.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/charset.h b/be/src/gutil/strings/charset.h
index b6b7013..a2dbca4 100644
--- a/be/src/gutil/strings/charset.h
+++ b/be/src/gutil/strings/charset.h
@@ -3,7 +3,7 @@
 #ifndef STRINGS_CHARSET_H_
 #define STRINGS_CHARSET_H_
 
-#include "gutil/integral_types.h"
+#include "kudu/gutil/integral_types.h"
 
 namespace strings {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/escaping.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/escaping.cc b/be/src/gutil/strings/escaping.cc
index 8eb4114..cf49359 100644
--- a/be/src/gutil/strings/escaping.cc
+++ b/be/src/gutil/strings/escaping.cc
@@ -1,7 +1,7 @@
 // Copyright 2008 Google Inc. All Rights Reserved.
 // Authors: Numerous. See the .h for contact people.
 
-#include "gutil/strings/escaping.h"
+#include "kudu/gutil/strings/escaping.h"
 
 #include <assert.h>
 #include <stdio.h>
@@ -12,13 +12,13 @@ using std::numeric_limits;
 #include <vector>
 using std::vector;
 
-#include "gutil/integral_types.h"
-#include "gutil/port.h"
-#include "gutil/gscoped_ptr.h"
-#include "gutil/strings/join.h"
-#include "gutil/utf/utf.h"  // for runetochar
-#include "gutil/charmap.h"
-#include "gutil/stl_util.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/gscoped_ptr.h"
+#include "kudu/gutil/strings/join.h"
+#include "kudu/gutil/utf/utf.h"  // for runetochar
+#include "kudu/gutil/charmap.h"
+#include "kudu/gutil/stl_util.h"
 
 namespace strings {
 
@@ -75,7 +75,7 @@ int EscapeStrForCSV(const char* src, char* dest, int dest_len) {
 #define IS_OCTAL_DIGIT(c) (((c) >= '0') && ((c) <= '7'))
 
 int UnescapeCEscapeSequences(const char* source, char* dest) {
-  return UnescapeCEscapeSequences(source, dest, NULL);
+  return UnescapeCEscapeSequences(source, dest, nullptr);
 }
 
 int UnescapeCEscapeSequences(const char* source, char* dest,
@@ -215,7 +215,7 @@ int UnescapeCEscapeSequences(const char* source, char* dest,
 //
 // ----------------------------------------------------------------------
 int UnescapeCEscapeString(const string& src, string* dest) {
-  return UnescapeCEscapeString(src, dest, NULL);
+  return UnescapeCEscapeString(src, dest, nullptr);
 }
 
 int UnescapeCEscapeString(const string& src, string* dest,
@@ -230,7 +230,7 @@ int UnescapeCEscapeString(const string& src, string* dest,
 
 string UnescapeCEscapeString(const string& src) {
   gscoped_array<char> unescaped(new char[src.size() + 1]);
-  int len = UnescapeCEscapeSequences(src.c_str(), unescaped.get(), NULL);
+  int len = UnescapeCEscapeSequences(src.c_str(), unescaped.get(), nullptr);
   return string(unescaped.get(), len);
 }
 
@@ -1648,8 +1648,7 @@ void EscapeFileName(const StringPiece& src, string* dst) {
   // Reserve at least src.size() chars
   dst->reserve(dst->size() + src.size());
 
-  for (int i = 0; i < src.size(); ++i) {
-    const char c = src[i];
+  for (char c : src) {
     // We do not use "isalpha" because we want the behavior to be
     // independent of the current locale settings.
     if (escape_file_name_exceptions.contains(c)) {
@@ -1751,10 +1750,10 @@ static void b2a_hex_t(const unsigned char* b, T a, int num) {
 
 string b2a_bin(const string& b, bool byte_order_msb) {
   string result;
-  for (int byte_offset = 0; byte_offset < b.size(); ++byte_offset) {
+  for (char c : b) {
     for (int bit_offset = 0; bit_offset < 8; ++bit_offset) {
       int x = (byte_order_msb) ? 7-bit_offset : bit_offset;
-      result.append(1, (b[byte_offset] & (1 << x)) ? '1' : '0');
+      result.append(1, (c & (1 << x)) ? '1' : '0');
     }
   }
   return result;
@@ -1814,15 +1813,15 @@ string ShellEscape(StringPiece src) {
   } else {
     // needs double quote escaping
     string result = "\"";
-    for (size_t i = 0; i < src.size(); ++i) {
-      switch (src[i]) {
+    for (char c : src) {
+      switch (c) {
         case '\\':
         case '$':
         case '"':
         case '`':
           result.push_back('\\');
       };
-      result.push_back(src[i]);
+      result.push_back(c);
     }
     result.push_back('"');
     return result;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/escaping.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/escaping.h b/be/src/gutil/strings/escaping.h
index 5435d6d..19e0860 100644
--- a/be/src/gutil/strings/escaping.h
+++ b/be/src/gutil/strings/escaping.h
@@ -28,10 +28,11 @@ using std::string;
 using std::vector;
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/strings/ascii_ctype.h"
-#include "gutil/strings/charset.h"
-#include "gutil/strings/stringpiece.h"
+
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/strings/charset.h"
+#include "kudu/gutil/strings/stringpiece.h"
 
 namespace strings {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/fastmem.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/fastmem.h b/be/src/gutil/strings/fastmem.h
index ec84071..3beca6d 100644
--- a/be/src/gutil/strings/fastmem.h
+++ b/be/src/gutil/strings/fastmem.h
@@ -22,8 +22,8 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "gutil/integral_types.h"
-#include "gutil/port.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/port.h"
 
 namespace strings {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/human_readable.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/human_readable.cc b/be/src/gutil/strings/human_readable.cc
index 2820039..fb3419a 100644
--- a/be/src/gutil/strings/human_readable.cc
+++ b/be/src/gutil/strings/human_readable.cc
@@ -1,15 +1,15 @@
 // Copyright 2007 Google Inc. All Rights Reserved.
 
-#include "gutil/strings/human_readable.h"
+#include "kudu/gutil/strings/human_readable.h"
 
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/stringprintf.h"
-#include "gutil/strings/strip.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/stringprintf.h"
+#include "kudu/gutil/strings/strip.h"
 
 namespace {
 
@@ -122,7 +122,7 @@ string HumanReadableNumBytes::ToString(int64 num_bytes) {
   // Special case for bytes.
   if (num_bytes < GG_LONGLONG(1024)) {
     // No fractions for bytes.
-    return StringPrintf("%s%" GG_LL_FORMAT "dB", neg_str, num_bytes);
+    return StringPrintf("%s%" PRId64 "B", neg_str, num_bytes);
   }
 
   static const char units[] = "KMGTPE";  // int64 only goes up to E.
@@ -163,7 +163,7 @@ string HumanReadableNumBytes::ToStringWithoutRounding(int64 num_bytes) {
 
     num_units = next_units;
   }
-  return StringPrintf("%s%lld%c", neg_str, num_units, units[unit_type]);
+  return StringPrintf("%s%" PRId64 "%c", neg_str, num_units, units[unit_type]);
 }
 
 string HumanReadableInt::ToString(int64 value) {
@@ -173,7 +173,7 @@ string HumanReadableInt::ToString(int64 value) {
     value = -value;
   }
   if (value < GG_LONGLONG(1000)) {
-    StringAppendF(&s, "%" GG_LL_FORMAT "d", value);
+    StringAppendF(&s, "%" PRId64, value);
   } else if (value >= GG_LONGLONG(1000000000000000)) {
     // Number bigger than 1E15; use that notation.
     StringAppendF(&s, "%0.3G", static_cast<double>(value));
@@ -281,7 +281,11 @@ string HumanReadableElapsedTime::ToShortString(double seconds) {
     seconds = -seconds;
   }
 
-  // Start with us and keep going up to years.
+  // Start with ns and keep going up to years.
+  if (seconds < 0.000001) {
+    StringAppendF(&human_readable, "%0.3g ns", seconds * 1000000000.0);
+    return human_readable;
+  }
   if (seconds < 0.001) {
     StringAppendF(&human_readable, "%0.3g us", seconds * 1000000.0);
     return human_readable;
@@ -329,6 +333,7 @@ bool HumanReadableElapsedTime::ToDouble(const string& str, double* value) {
   // will match;
   static const TimeUnits kUnits[] = {
     // Long forms
+    { "nanosecond", 0.000000001 },
     { "microsecond", 0.000001 },
     { "millisecond", 0.001 },
     { "second", 1.0 },
@@ -340,6 +345,7 @@ bool HumanReadableElapsedTime::ToDouble(const string& str, double* value) {
     { "year", 365 * 86400.0 },
 
     // Abbreviated forms
+    { "nanosec", 0.000000001 },
     { "microsec", 0.000001 },
     { "millisec", 0.001 },
     { "sec", 1.0 },
@@ -350,6 +356,9 @@ bool HumanReadableElapsedTime::ToDouble(const string& str, double* value) {
     { "mon", 30 * 86400.0 },
     { "yr", 365 * 86400.0 },
 
+    // nano -> n
+    { "nsecond", 0.000000001 },
+    { "nsec", 0.000000001 },
     // micro -> u
     { "usecond", 0.000001 },
     { "usec", 0.000001 },
@@ -358,6 +367,7 @@ bool HumanReadableElapsedTime::ToDouble(const string& str, double* value) {
     { "msec", 0.001 },
 
     // Ultra-short form
+    { "ns", 0.000000001 },
     { "us", 0.000001 },
     { "ms", 0.001 },
     { "s", 1.0 },

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/human_readable.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/human_readable.h b/be/src/gutil/strings/human_readable.h
index 8a05907..e05b169 100644
--- a/be/src/gutil/strings/human_readable.h
+++ b/be/src/gutil/strings/human_readable.h
@@ -12,9 +12,9 @@ using std::less;
 #include <string>
 using std::string;
 
-#include "gutil/basictypes.h"
-#include "gutil/integral_types.h"
-#include "gutil/macros.h"
+#include "kudu/gutil/basictypes.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/macros.h"
 
 //                                 WARNING
 // HumanReadable{NumBytes, Int} don't give you the standard set of SI prefixes.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/join.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/join.cc b/be/src/gutil/strings/join.cc
index f3caa49..c0035e1 100644
--- a/be/src/gutil/strings/join.cc
+++ b/be/src/gutil/strings/join.cc
@@ -1,12 +1,12 @@
 // Copyright 2008 and onwards Google Inc.  All rights reserved.
 
-#include "gutil/strings/join.h"
+#include "kudu/gutil/strings/join.h"
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/gscoped_ptr.h"
-#include "gutil/strings/ascii_ctype.h"
-#include "gutil/strings/escaping.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/gscoped_ptr.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/strings/escaping.h"
 
 // ----------------------------------------------------------------------
 // JoinUsing()
@@ -30,7 +30,7 @@ char* JoinUsing(const vector<const char*>& components,
   for (int i = 0; i < num_components; ++i)
     num_chars += strlen(components[i]);
 
-  char* res_buffer = new char[num_chars+1];
+  auto res_buffer = new char[num_chars + 1];
   return JoinUsingToBuffer(components, delim, num_chars+1,
                            res_buffer, result_length_p);
 }
@@ -50,7 +50,7 @@ char* JoinUsingToBuffer(const vector<const char*>& components,
                          int result_buffer_size,
                          char* result_buffer,
                          int*  result_length_p) {
-  CHECK(result_buffer != NULL);
+  CHECK(result_buffer != nullptr);
   const int num_components = components.size();
   const int max_str_len = result_buffer_size - 1;
   char* curr_dest = result_buffer;
@@ -76,7 +76,7 @@ char* JoinUsingToBuffer(const vector<const char*>& components,
 
   if (result_buffer_size > 0)
     *curr_dest = '\0';  // add null termination
-  if (result_length_p != NULL)  // set string length value
+  if (result_length_p != nullptr)  // set string length value
     *result_length_p = num_chars;
 
   return result_buffer;
@@ -95,7 +95,7 @@ void JoinStringsInArray(string const* const* components,
                         int num_components,
                         const char* delim,
                         string * result) {
-  CHECK(result != NULL);
+  CHECK(result != nullptr);
   result->clear();
   for (int i = 0; i < num_components; i++) {
     if (i>0) {
@@ -172,17 +172,17 @@ void JoinCSVLineWithDelimiter(const vector<string>& cols, char delimiter,
   // whitespace (ie ascii_isspace() returns true), escape all double-quotes and
   // bracket the string in double quotes. string.rbegin() evaluates to the last
   // character of the string.
-  for (int i = 0; i < cols.size(); ++i) {
-    if ((cols[i].find_first_of(escape_chars) != string::npos) ||
-        (!cols[i].empty() && (ascii_isspace(*cols[i].begin()) ||
-                              ascii_isspace(*cols[i].rbegin())))) {
+  for (const auto& col : cols) {
+    if ((col.find_first_of(escape_chars) != string::npos) ||
+        (!col.empty() && (ascii_isspace(*col.begin()) ||
+                              ascii_isspace(*col.rbegin())))) {
       // Double the original size, for escaping, plus two bytes for
       // the bracketing double-quotes, and one byte for the closing \0.
-      int size = 2 * cols[i].size() + 3;
+      int size = 2 * col.size() + 3;
       gscoped_array<char> buf(new char[size]);
 
       // Leave space at beginning and end for bracketing double-quotes.
-      int escaped_size = strings::EscapeStrForCSV(cols[i].c_str(),
+      int escaped_size = strings::EscapeStrForCSV(col.c_str(),
                                                   buf.get() + 1, size - 2);
       CHECK_GE(escaped_size, 0) << "Buffer somehow wasn't large enough.";
       CHECK_GE(size, escaped_size + 3)
@@ -194,7 +194,7 @@ void JoinCSVLineWithDelimiter(const vector<string>& cols, char delimiter,
       *((buf.get() + 1) + escaped_size + 1) = '\0';
       quoted_cols.push_back(string(buf.get(), buf.get() + escaped_size + 2));
     } else {
-      quoted_cols.push_back(cols[i]);
+      quoted_cols.push_back(col);
     }
   }
   JoinStrings(quoted_cols, delimiter_str, output);

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/join.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/join.h b/be/src/gutil/strings/join.h
index bf946c4..4369c4c 100644
--- a/be/src/gutil/strings/join.h
+++ b/be/src/gutil/strings/join.h
@@ -32,13 +32,13 @@ using std::pair;
 #include <vector>
 using std::vector;
 
-#include "gutil/integral_types.h"
-#include "gutil/macros.h"
-#include "gutil/template_util.h"
-#include "gutil/strings/numbers.h"
-#include "gutil/strings/strcat.h"    // For backward compatibility.
-#include "gutil/strings/stringpiece.h"
-#include "gutil/hash/hash.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/template_util.h"
+#include "kudu/gutil/strings/numbers.h"
+#include "kudu/gutil/strings/strcat.h"    // For backward compatibility.
+#include "kudu/gutil/strings/stringpiece.h"
+#include "kudu/gutil/hash/hash.h"
 
 // ----------------------------------------------------------------------
 // JoinUsing()
@@ -115,6 +115,32 @@ string JoinStringsIterator(const ITERATOR& start,
                            const ITERATOR& end,
                            const StringPiece& delim);
 
+// Join the keys of a map using the specified delimiter.
+template<typename ITERATOR>
+void JoinKeysIterator(const ITERATOR& start,
+                      const ITERATOR& end,
+                      const StringPiece& delim,
+                      string *result) {
+  result->clear();
+  for (ITERATOR iter = start; iter != end; ++iter) {
+    if (iter == start) {
+      StrAppend(result, iter->first);
+    } else {
+      StrAppend(result, delim, iter->first);
+    }
+  }
+}
+
+template <typename ITERATOR>
+string JoinKeysIterator(const ITERATOR& start,
+                        const ITERATOR& end,
+                        const StringPiece& delim) {
+  string result;
+  JoinKeysIterator(start, end, delim, &result);
+  return result;
+}
+
+// Join the keys and values of a map using the specified delimiters.
 template<typename ITERATOR>
 void JoinKeysAndValuesIterator(const ITERATOR& start,
                                const ITERATOR& end,
@@ -174,6 +200,24 @@ inline string JoinStrings(const CONTAINER& components,
   return result;
 }
 
+// Join the strings produced by calling 'functor' on each element of
+// 'components'.
+template<class CONTAINER, typename FUNC>
+string JoinMapped(const CONTAINER& components,
+                  const FUNC& functor,
+                  const StringPiece& delim) {
+  string result;
+  for (typename CONTAINER::const_iterator iter = components.begin();
+      iter != components.end();
+      iter++) {
+    if (iter != components.begin()) {
+      result.append(delim.data(), delim.size());
+    }
+    result.append(functor(*iter));
+  }
+  return result;
+}
+
 template <class ITERATOR>
 void JoinStringsIterator(const ITERATOR& start,
                          const ITERATOR& end,

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/memutil.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/memutil.cc b/be/src/gutil/strings/memutil.cc
index 30e2153..390d2a0 100644
--- a/be/src/gutil/strings/memutil.cc
+++ b/be/src/gutil/strings/memutil.cc
@@ -2,11 +2,11 @@
 // Copyright (C) 2001 and onwards Google, Inc.
 //
 
-#include "gutil/strings/memutil.h"
+#include "kudu/gutil/strings/memutil.h"
 
 #include <stdlib.h>        // for malloc, NULL
 
-#include "gutil/strings/ascii_ctype.h"  // for ascii_tolower
+#include "kudu/gutil/strings/ascii_ctype.h"  // for ascii_tolower
 
 int memcasecmp(const char *s1, const char *s2, size_t len) {
   const unsigned char *us1 = reinterpret_cast<const unsigned char *>(s1);
@@ -23,8 +23,8 @@ int memcasecmp(const char *s1, const char *s2, size_t len) {
 
 char *memdup(const char *s, size_t slen) {
   void *copy;
-  if ( (copy=malloc(slen)) == NULL )
-    return NULL;
+  if ( (copy=malloc(slen)) == nullptr )
+    return nullptr;
   memcpy(copy, s, slen);
   return reinterpret_cast<char *>(copy);
 }
@@ -34,7 +34,7 @@ char *memrchr(const char *s, int c, size_t slen) {
     if (*e == c)
       return const_cast<char *>(e);
   }
-  return NULL;
+  return nullptr;
 }
 
 size_t memspn(const char *s, size_t slen, const char *accept) {
@@ -74,7 +74,7 @@ char *mempbrk(const char *s, size_t slen, const char *accept) {
       if (sc == *s)
         return const_cast<char *>(s);
   }
-  return NULL;
+  return nullptr;
 }
 
 template<bool case_sensitive>
@@ -104,7 +104,7 @@ const char *int_memmatch(const char *phaystack, size_t haylen,
       needle = needlestart;
     }
   }
-  return NULL;
+  return nullptr;
 }
 
 // explicit template instantiations
@@ -121,7 +121,7 @@ const char *memmatch(const char *phaystack, size_t haylen,
     return phaystack;  // even if haylen is 0
   }
   if (haylen < neelen)
-    return NULL;
+    return nullptr;
 
   const char* match;
   const char* hayend = phaystack + haylen - neelen + 1;
@@ -134,5 +134,5 @@ const char *memmatch(const char *phaystack, size_t haylen,
     else
       phaystack = match + 1;
   }
-  return NULL;
+  return nullptr;
 }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/memutil.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/memutil.h b/be/src/gutil/strings/memutil.h
index b230149..9335735 100644
--- a/be/src/gutil/strings/memutil.h
+++ b/be/src/gutil/strings/memutil.h
@@ -56,7 +56,7 @@
 #include <stddef.h>
 #include <string.h>      // to get the POSIX mem*() routines
 
-#include "gutil/port.h"   // disable some warnings on Windows
+#include "kudu/gutil/port.h"   // disable some warnings on Windows
 
 inline char *memcat(char *dest, size_t destlen,
                     const char *src, size_t srclen) {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/numbers.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/numbers.cc b/be/src/gutil/strings/numbers.cc
index 5568318..7bdb57c 100644
--- a/be/src/gutil/strings/numbers.cc
+++ b/be/src/gutil/strings/numbers.cc
@@ -4,7 +4,7 @@
 // This file contains string processing functions related to
 // numeric values.
 
-#include "gutil/strings/numbers.h"
+#include "kudu/gutil/strings/numbers.h"
 
 #include <assert.h>
 #include <ctype.h>
@@ -19,14 +19,14 @@ using std::numeric_limits;
 #include <string>
 using std::string;
 
-#include "gutil/int128.h"
-#include "gutil/integral_types.h"
+#include "kudu/gutil/int128.h"
+#include "kudu/gutil/integral_types.h"
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/gscoped_ptr.h"
-#include "gutil/stringprintf.h"
-#include "gutil/strtoint.h"
-#include "gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/gscoped_ptr.h"
+#include "kudu/gutil/stringprintf.h"
+#include "kudu/gutil/strtoint.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
 
 // Reads a <double> in *text, which may not be whitespace-initiated.
 // *len is the length, or -1 if text is '\0'-terminated, which is more
@@ -46,7 +46,7 @@ static inline bool EatADouble(const char** text, int* len, bool allow_question,
   const char* pos = *text;
   int rem = *len;  // remaining length, or -1 if null-terminated
 
-  if (pos == NULL || rem == 0)
+  if (pos == nullptr || rem == 0)
     return false;
 
   if (allow_question && (*pos == '?')) {
@@ -138,7 +138,7 @@ bool ParseDoubleRange(const char* text, int len, const char** end,
     *from = -HUGE_VAL;
     *to = HUGE_VAL;
   }
-  if (opts.allow_currency && (is_currency != NULL))
+  if (opts.allow_currency && (is_currency != nullptr))
     *is_currency = false;
 
   assert(len >= -1);
@@ -155,10 +155,10 @@ bool ParseDoubleRange(const char* text, int len, const char** end,
       double* dest = (comparator == '>') ? from : to;
       EatAChar(&text, &len, "=", true, false);
       if (opts.allow_currency && EatAChar(&text, &len, "$", true, false))
-        if (is_currency != NULL)
+        if (is_currency != nullptr)
           *is_currency = true;
-      if (!EatADouble(&text, &len, opts.allow_unbounded_markers, dest, NULL,
-                      NULL))
+      if (!EatADouble(&text, &len, opts.allow_unbounded_markers, dest, nullptr,
+                      nullptr))
         return false;
       *end = text;
       return EatAChar(&text, &len, opts.acceptable_terminators, false,
@@ -179,9 +179,9 @@ bool ParseDoubleRange(const char* text, int len, const char** end,
   bool final_period = false;
   bool* check_initial_minus = (strchr(opts.separators, '-') && !seen_dollar
                                && (opts.num_required_bounds < 2)) ?
-                              (&initial_minus_sign) : NULL;
+                              (&initial_minus_sign) : nullptr;
   bool* check_final_period = strchr(opts.separators, '.') ? (&final_period)
-                             : NULL;
+                             : nullptr;
   bool double_seen = EatADouble(&text, &len, opts.allow_unbounded_markers,
                                 from, check_initial_minus, check_final_period);
 
@@ -235,7 +235,7 @@ bool ParseDoubleRange(const char* text, int len, const char** end,
                                || (opts.allow_currency && !double_seen))
                               && EatAChar(&text, &len, "$", true, false);
     bool second_double_seen = EatADouble(
-      &text, &len, opts.allow_unbounded_markers, to, NULL, NULL);
+      &text, &len, opts.allow_unbounded_markers, to, nullptr, nullptr);
     if (opts.num_required_bounds > double_seen + second_double_seen)
       return false;
     if (second_dollar_seen && !second_double_seen) {
@@ -247,7 +247,7 @@ bool ParseDoubleRange(const char* text, int len, const char** end,
     seen_dollar = seen_dollar || second_dollar_seen;
   }
 
-  if (seen_dollar && (is_currency != NULL))
+  if (seen_dollar && (is_currency != nullptr))
     *is_currency = true;
   // We're done. But we have to check that the next char is a proper
   // terminator.
@@ -293,7 +293,7 @@ void ConsumeStrayLeadingZeroes(string *const str) {
 // --------------------------------------------------------------------
 
 int32 ParseLeadingInt32Value(const char *str, int32 deflt) {
-  char *error = NULL;
+  char *error = nullptr;
   long value = strtol(str, &error, 0);
   // Limit long values to int32 min/max.  Needed for lp64; no-op on 32 bits.
   if (value > numeric_limits<int32>::max()) {
@@ -307,7 +307,7 @@ int32 ParseLeadingInt32Value(const char *str, int32 deflt) {
 uint32 ParseLeadingUInt32Value(const char *str, uint32 deflt) {
   if (numeric_limits<unsigned long>::max() == numeric_limits<uint32>::max()) {
     // When long is 32 bits, we can use strtoul.
-    char *error = NULL;
+    char *error = nullptr;
     const uint32 value = strtoul(str, &error, 0);
     return (error == str) ? deflt : value;
   } else {
@@ -316,7 +316,7 @@ uint32 ParseLeadingUInt32Value(const char *str, uint32 deflt) {
     // it would be impossible to differentiate "-2" (that should wrap
     // around to the value UINT_MAX-1) from a string with ULONG_MAX-1
     // (that should be pegged to UINT_MAX due to overflow).
-    char *error = NULL;
+    char *error = nullptr;
     int64 value = strto64(str, &error, 0);
     if (value > numeric_limits<uint32>::max() ||
         value < -static_cast<int64>(numeric_limits<uint32>::max())) {
@@ -337,7 +337,7 @@ uint32 ParseLeadingUInt32Value(const char *str, uint32 deflt) {
 // --------------------------------------------------------------------
 
 int32 ParseLeadingDec32Value(const char *str, int32 deflt) {
-  char *error = NULL;
+  char *error = nullptr;
   long value = strtol(str, &error, 10);
   // Limit long values to int32 min/max.  Needed for lp64; no-op on 32 bits.
   if (value > numeric_limits<int32>::max()) {
@@ -351,7 +351,7 @@ int32 ParseLeadingDec32Value(const char *str, int32 deflt) {
 uint32 ParseLeadingUDec32Value(const char *str, uint32 deflt) {
   if (numeric_limits<unsigned long>::max() == numeric_limits<uint32>::max()) {
     // When long is 32 bits, we can use strtoul.
-    char *error = NULL;
+    char *error = nullptr;
     const uint32 value = strtoul(str, &error, 10);
     return (error == str) ? deflt : value;
   } else {
@@ -360,7 +360,7 @@ uint32 ParseLeadingUDec32Value(const char *str, uint32 deflt) {
     // it would be impossible to differentiate "-2" (that should wrap
     // around to the value UINT_MAX-1) from a string with ULONG_MAX-1
     // (that should be pegged to UINT_MAX due to overflow).
-    char *error = NULL;
+    char *error = nullptr;
     int64 value = strto64(str, &error, 10);
     if (value > numeric_limits<uint32>::max() ||
         value < -static_cast<int64>(numeric_limits<uint32>::max())) {
@@ -380,19 +380,19 @@ uint32 ParseLeadingUDec32Value(const char *str, uint32 deflt) {
 //    UInt64 and Int64 cannot handle decimal numbers with leading 0s.
 // --------------------------------------------------------------------
 uint64 ParseLeadingUInt64Value(const char *str, uint64 deflt) {
-  char *error = NULL;
+  char *error = nullptr;
   const uint64 value = strtou64(str, &error, 0);
   return (error == str) ? deflt : value;
 }
 
 int64 ParseLeadingInt64Value(const char *str, int64 deflt) {
-  char *error = NULL;
+  char *error = nullptr;
   const int64 value = strto64(str, &error, 0);
   return (error == str) ? deflt : value;
 }
 
 uint64 ParseLeadingHex64Value(const char *str, uint64 deflt) {
-  char *error = NULL;
+  char *error = nullptr;
   const uint64 value = strtou64(str, &error, 16);
   return (error == str) ? deflt : value;
 }
@@ -407,13 +407,13 @@ uint64 ParseLeadingHex64Value(const char *str, uint64 deflt) {
 // --------------------------------------------------------------------
 
 int64 ParseLeadingDec64Value(const char *str, int64 deflt) {
-  char *error = NULL;
+  char *error = nullptr;
   const int64 value = strto64(str, &error, 10);
   return (error == str) ? deflt : value;
 }
 
 uint64 ParseLeadingUDec64Value(const char *str, uint64 deflt) {
-  char *error = NULL;
+  char *error = nullptr;
   const uint64 value = strtou64(str, &error, 10);
   return (error == str) ? deflt : value;
 }
@@ -425,7 +425,7 @@ uint64 ParseLeadingUDec64Value(const char *str, uint64 deflt) {
 // --------------------------------------------------------------------
 
 double ParseLeadingDoubleValue(const char *str, double deflt) {
-  char *error = NULL;
+  char *error = nullptr;
   errno = 0;
   const double value = strtod(str, &error);
   if (errno != 0 ||  // overflow/underflow happened
@@ -494,16 +494,16 @@ bool ParseLeadingBoolValue(const char *str, bool deflt) {
 
 string FpToString(Fprint fp) {
   char buf[17];
-  snprintf(buf, sizeof(buf), "%016llx", fp);
+  snprintf(buf, sizeof(buf), "%016" PRIx64, fp);
   return string(buf);
 }
 
 // Default arguments
 string Uint128ToHexString(uint128 ui128) {
   char buf[33];
-  snprintf(buf, sizeof(buf), "%016" GG_LL_FORMAT "x",
+  snprintf(buf, sizeof(buf), "%016" PRIx64,
            Uint128High64(ui128));
-  snprintf(buf + 16, sizeof(buf) - 16, "%016" GG_LL_FORMAT "x",
+  snprintf(buf + 16, sizeof(buf) - 16, "%016" PRIx64,
            Uint128Low64(ui128));
   return string(buf);
 }
@@ -866,10 +866,6 @@ char *FastInt64ToBuffer(int64 i, char* buffer) {
   return buffer;
 }
 
-// Offset into buffer where FastInt32ToBuffer places the end of string
-// null character.  Also used by FastInt32ToBufferLeft
-static const int kFastInt32ToBufferOffset = 11;
-
 char *FastInt32ToBuffer(int32 i, char* buffer) {
   FastInt32ToBufferLeft(i, buffer);
   return buffer;
@@ -912,13 +908,6 @@ char *FastHex32ToBuffer(uint32 value, char* buffer) {
 // division and modulo operations.
 extern const char two_ASCII_digits[100][2];  // from strutil.cc
 
-static inline void PutTwoDigits(int i, char* p) {
-  DCHECK_GE(i, 0);
-  DCHECK_LT(i, 100);
-  p[0] = two_ASCII_digits[i][0];
-  p[1] = two_ASCII_digits[i][1];
-}
-
 // ----------------------------------------------------------------------
 // FastInt32ToBufferLeft()
 // FastUInt32ToBufferLeft()
@@ -936,8 +925,8 @@ static inline void PutTwoDigits(int i, char* p) {
 // ----------------------------------------------------------------------
 
 char* FastUInt32ToBufferLeft(uint32 u, char* buffer) {
-  int digits;
-  const char *ASCII_digits = NULL;
+  uint digits;
+  const char *ASCII_digits = nullptr;
   // The idea of this implementation is to trim the number of divides to as few
   // as possible by using multiplication and subtraction rather than mod (%),
   // and by outputting two digits at a time rather than one.
@@ -1030,8 +1019,8 @@ char* FastInt32ToBufferLeft(int32 i, char* buffer) {
 }
 
 char* FastUInt64ToBufferLeft(uint64 u64, char* buffer) {
-  int digits;
-  const char *ASCII_digits = NULL;
+  uint digits;
+  const char *ASCII_digits = nullptr;
 
   uint32 u = static_cast<uint32>(u64);
   if (u == u64) return FastUInt32ToBufferLeft(u, buffer);
@@ -1259,7 +1248,7 @@ char* DoubleToBuffer(double value, char* buffer) {
   // larger than the precision we asked for.
   DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
 
-  if (strtod(buffer, NULL) != value) {
+  if (strtod(buffer, nullptr) != value) {
     snprintf_result =
       snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value);
 
@@ -1448,7 +1437,7 @@ string ItoaKMGT(int64 i) {
     val = i;
   }
 
-  return StringPrintf("%s%" GG_LL_FORMAT "d%s", sign, val, suffix);
+  return StringPrintf("%s%" PRId64 "%s", sign, val, suffix);
 }
 
 // DEPRECATED(wadetregaskis).

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/numbers.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/numbers.h b/be/src/gutil/strings/numbers.h
index f5ad338..e9f5c1a 100644
--- a/be/src/gutil/strings/numbers.h
+++ b/be/src/gutil/strings/numbers.h
@@ -20,11 +20,11 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include "gutil/int128.h"
-#include "gutil/integral_types.h"
-#include "gutil/macros.h"
-#include "gutil/port.h"
-#include "gutil/stringprintf.h"
+#include "kudu/gutil/int128.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/stringprintf.h"
 
 
 // START DOXYGEN NumbersFunctions grouping
@@ -393,22 +393,6 @@ inline string SimpleItoa(uint64 i) {
   return string(buf, FastUInt64ToBufferLeft(i, buf));
 }
 
-inline string SimpleItoa(long i) {  // NOLINT long is OK here
-  if (sizeof(i) == 64 / 8) {
-    return SimpleItoa(static_cast<int64>(i));
-  } else if (sizeof(i) == 32 / 8) {
-    return SimpleItoa(static_cast<int32>(i));
-  }
-}
-
-inline string SimpleItoa(unsigned long i) {  // NOLINT long is OK here
-  if (sizeof(i) == 64 / 8) {
-    return SimpleItoa(static_cast<uint64>(i));
-  } else if (sizeof(i) == 32 / 8) {
-    return SimpleItoa(static_cast<uint32>(i));
-  }
-}
-
 // SimpleAtoi converts a string to an integer.
 // Uses safe_strto?() for actual parsing, so strict checking is
 // applied, which is to say, the string must be a base-10 integer, optionally
@@ -484,15 +468,6 @@ string SimpleItoaWithCommas(int32 i);
 string SimpleItoaWithCommas(uint32 i);
 string SimpleItoaWithCommas(int64 i);
 string SimpleItoaWithCommas(uint64 i);
-#ifdef _LP64
-inline string SimpleItoaWithCommas(size_t i) {
-  return SimpleItoaWithCommas(static_cast<uint64>(i));
-}
-
-inline string SimpleItoaWithCommas(ptrdiff_t i) {
-  return SimpleItoaWithCommas(static_cast<int64>(i));
-}
-#endif
 
 // ----------------------------------------------------------------------
 // ItoaKMGT()
@@ -589,12 +564,12 @@ inline string IntToString(int i) {
 
 // DEPRECATED(wadetregaskis).  Just call StringPrintf.
 inline string Int64ToString(int64 i64) {
-  return StringPrintf("%7" GG_LL_FORMAT "d", i64);
+  return StringPrintf("%7" PRId64, i64);
 }
 
 // DEPRECATED(wadetregaskis).  Just call StringPrintf.
 inline string UInt64ToString(uint64 ui64) {
-  return StringPrintf("%7" GG_LL_FORMAT "u", ui64);
+  return StringPrintf("%7" PRIu64, ui64);
 }
 
 #endif  // STRINGS_NUMBERS_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/serialize.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/serialize.cc b/be/src/gutil/strings/serialize.cc
index 59ef25e..5449ef7 100644
--- a/be/src/gutil/strings/serialize.cc
+++ b/be/src/gutil/strings/serialize.cc
@@ -1,6 +1,6 @@
 // Copyright 2003, Google Inc.  All rights reserved.
 
-#include "gutil/strings/serialize.h"
+#include "kudu/gutil/strings/serialize.h"
 
 #include <stddef.h>
 #include <stdlib.h>
@@ -15,13 +15,13 @@ using std::pair;
 #include <vector>
 using std::vector;
 
-#include "gutil/casts.h"
-#include "gutil/integral_types.h"
-#include "gutil/stringprintf.h"
-#include "gutil/strtoint.h"
-#include "gutil/strings/join.h"
-#include "gutil/strings/split.h"
-#include "gutil/hash/hash.h"
+#include "kudu/gutil/casts.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/stringprintf.h"
+#include "kudu/gutil/strtoint.h"
+#include "kudu/gutil/strings/join.h"
+#include "kudu/gutil/strings/split.h"
+#include "kudu/gutil/hash/hash.h"
 
 // Convert a uint32 to a 4-byte string.
 string Uint32ToKey(uint32 u32) {
@@ -223,9 +223,8 @@ int64 ReverseOrderedStringToInt64(const StringPiece& key) {
 
 string DictionaryInt32Encode(const hash_map<string, int32>* dictionary) {
   vector<string> entries;
-  for (hash_map<string, int32>::const_iterator iter = dictionary->begin();
-       iter != dictionary->end(); ++iter) {
-    entries.push_back(StringPrintf("%s:%d", iter->first.c_str(), iter->second));
+  for (const auto& entry : *dictionary) {
+    entries.push_back(StringPrintf("%s:%d", entry.first.c_str(), entry.second));
   }
 
   string result;
@@ -235,10 +234,9 @@ string DictionaryInt32Encode(const hash_map<string, int32>* dictionary) {
 
 string DictionaryInt64Encode(const hash_map<string, int64>* dictionary) {
   vector<string> entries;
-  for (hash_map<string, int64>::const_iterator iter = dictionary->begin();
-       iter != dictionary->end(); ++iter) {
-    entries.push_back(StringPrintf("%s:%" GG_LL_FORMAT "d",
-                                   iter->first.c_str(), iter->second));
+  for (const auto& entry : *dictionary) {
+    entries.push_back(StringPrintf("%s:%" PRId64,
+                                   entry.first.c_str(), entry.second));
   }
 
   string result;
@@ -248,9 +246,8 @@ string DictionaryInt64Encode(const hash_map<string, int64>* dictionary) {
 
 string DictionaryDoubleEncode(const hash_map<string, double>* dictionary) {
   vector<string> entries;
-  for (hash_map<string, double>::const_iterator iter = dictionary->begin();
-       iter != dictionary->end(); ++iter) {
-    entries.push_back(StringPrintf("%s:%g", iter->first.c_str(), iter->second));
+  for (const auto& entry : *dictionary) {
+    entries.push_back(StringPrintf("%s:%g", entry.first.c_str(), entry.second));
   }
 
   string result;
@@ -259,12 +256,12 @@ string DictionaryDoubleEncode(const hash_map<string, double>* dictionary) {
 }
 
 bool DictionaryParse(const string& encoded_str,
-                      vector<pair<string, string> >* items) {
+                     vector<pair<string, string> >* items) {
   vector<string> entries;
   SplitStringUsing(encoded_str, ",", &entries);
-  for (int i = 0; i < entries.size(); ++i) {
+  for (const auto& entry : entries) {
     vector<string> fields;
-    SplitStringAllowEmpty(entries[i], ":", &fields);
+    SplitStringAllowEmpty(entry, ":", &fields);
     if (fields.size() != 2)  // parsing error
       return false;
     items->push_back(make_pair(fields[0], fields[1]));
@@ -279,14 +276,14 @@ bool DictionaryInt32Decode(hash_map<string, int32>* dictionary,
     return false;
 
   dictionary->clear();
-  for (int i = 0; i < items.size(); ++i) {
-    char *error = NULL;
-    const int32 value = strto32(items[i].second.c_str(), &error, 0);
-    if (error == items[i].second.c_str() || *error != '\0') {
+  for (const auto& item : items) {
+    char *error = nullptr;
+    const int32 value = strto32(item.second.c_str(), &error, 0);
+    if (error == item.second.c_str() || *error != '\0') {
       // parsing error
       return false;
     }
-    (*dictionary)[items[i].first] = value;
+    (*dictionary)[item.first] = value;
   }
   return true;
 }
@@ -298,14 +295,14 @@ bool DictionaryInt64Decode(hash_map<string, int64>* dictionary,
     return false;
 
   dictionary->clear();
-  for (int i = 0; i < items.size(); ++i) {
-    char *error = NULL;
-    const int64 value = strto64(items[i].second.c_str(), &error, 0);
-    if (error == items[i].second.c_str() || *error != '\0')  {
+  for (const auto& item : items) {
+    char *error = nullptr;
+    const int64 value = strto64(item.second.c_str(), &error, 0);
+    if (error == item.second.c_str() || *error != '\0')  {
       // parsing error
       return false;
     }
-    (*dictionary)[items[i].first] = value;
+    (*dictionary)[item.first] = value;
   }
   return true;
 }
@@ -318,14 +315,14 @@ bool DictionaryDoubleDecode(hash_map<string, double>* dictionary,
     return false;
 
   dictionary->clear();
-  for (int i = 0; i < items.size(); ++i) {
-    char *error = NULL;
-    const double value = strtod(items[i].second.c_str(), &error);
-    if (error == items[i].second.c_str() || *error != '\0') {
+  for (const auto& item : items) {
+    char *error = nullptr;
+    const double value = strtod(item.second.c_str(), &error);
+    if (error == item.second.c_str() || *error != '\0') {
       // parsing error
       return false;
     }
-    (*dictionary)[items[i].first] = value;
+    (*dictionary)[item.first] = value;
   }
   return true;
 }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/serialize.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/serialize.h b/be/src/gutil/strings/serialize.h
index 1bbda05..7966cd2 100644
--- a/be/src/gutil/strings/serialize.h
+++ b/be/src/gutil/strings/serialize.h
@@ -19,14 +19,15 @@ using std::pair;
 #include <vector>
 using std::vector;
 
-#include "gutil/int128.h"
-#include "gutil/integral_types.h"
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/type_traits.h"
-#include "gutil/strings/stringpiece.h"
-#include "gutil/endian.h"
-#include "gutil/stl_util.h"
+
+#include "kudu/gutil/int128.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/type_traits.h"
+#include "kudu/gutil/strings/stringpiece.h"
+#include "kudu/gutil/endian.h"
+#include "kudu/gutil/stl_util.h"
 
 // Converts a 4-byte uint32 to a string such that the string keys sort in
 // the same order as the original uint32 value.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/split.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/split.cc b/be/src/gutil/strings/split.cc
index c0404c2..a42faa7 100644
--- a/be/src/gutil/strings/split.cc
+++ b/be/src/gutil/strings/split.cc
@@ -2,7 +2,7 @@
 //
 // Maintainer: Greg Miller <jg...@google.com>
 
-#include "gutil/strings/split.h"
+#include "kudu/gutil/strings/split.h"
 
 #include <assert.h>
 #include <stdlib.h>
@@ -13,14 +13,14 @@ using std::iterator_traits;
 #include <limits>
 using std::numeric_limits;
 
-#include "gutil/integral_types.h"
+#include "kudu/gutil/integral_types.h"
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/macros.h"
-#include "gutil/strtoint.h"
-#include "gutil/strings/ascii_ctype.h"
-#include "gutil/strings/util.h"
-#include "gutil/hash/hash.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/strtoint.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/strings/util.h"
+#include "kudu/gutil/hash/hash.h"
 
 // Implementations for some of the Split2 API. Much of the Split2 API is
 // templated so it exists in header files, either strings/split.h or
@@ -133,8 +133,8 @@ void AppendToImpl(vector<string>* container, Splitter splitter) {
   vector<StringPiece> vsp = splitter;  // Calls implicit conversion operator.
   size_t container_size = container->size();
   container->resize(container_size + vsp.size());
-  for (size_t i = 0; i < vsp.size(); ++i) {
-    vsp[i].CopyToString(&(*container)[container_size++]);
+  for (const auto& sp : vsp) {
+    sp.CopyToString(&(*container)[container_size++]);
   }
 }
 
@@ -464,7 +464,7 @@ void SplitStringPieceToVector(const StringPiece& full,
 // ----------------------------------------------------------------------
 
 vector<char*>* SplitUsing(char* full, const char* delim) {
-  vector<char*>* vec = new vector<char*>;
+  auto vec = new vector<char*>;
   SplitToVector(full, delim, vec, true);        // Omit empty strings
   return vec;
 }
@@ -472,12 +472,12 @@ vector<char*>* SplitUsing(char* full, const char* delim) {
 void SplitToVector(char* full, const char* delim, vector<char*>* vec,
                    bool omit_empty_strings) {
   char* next  = full;
-  while ((next = gstrsep(&full, delim)) != NULL) {
+  while ((next = gstrsep(&full, delim)) != nullptr) {
     if (omit_empty_strings && next[0] == '\0') continue;
     vec->push_back(next);
   }
   // Add last element (or full string if no delimeter found):
-  if (full != NULL) {
+  if (full != nullptr) {
     vec->push_back(full);
   }
 }
@@ -485,12 +485,12 @@ void SplitToVector(char* full, const char* delim, vector<char*>* vec,
 void SplitToVector(char* full, const char* delim, vector<const char*>* vec,
                    bool omit_empty_strings) {
   char* next  = full;
-  while ((next = gstrsep(&full, delim)) != NULL) {
+  while ((next = gstrsep(&full, delim)) != nullptr) {
     if (omit_empty_strings && next[0] == '\0') continue;
     vec->push_back(next);
   }
   // Add last element (or full string if no delimeter found):
-  if (full != NULL) {
+  if (full != nullptr) {
     vec->push_back(full);
   }
 }
@@ -691,7 +691,7 @@ DEFINE_SPLIT_ONE_NUMBER_TOKEN(HexUint64, uint64, strtou64_16)
 bool SplitRange(const char* rangestr, int* from, int* to) {
   // We need to do the const-cast because strol takes a char**, not const char**
   char* val = const_cast<char*>(rangestr);
-  if (val == NULL || EOS(*val))  return true;  // we'll say nothingness is ok
+  if (val == nullptr || EOS(*val))  return true;  // we'll say nothingness is ok
 
   if ( val[0] == '-' && EOS(val[1]) )    // CASE 1: -
     return true;                         // nothing changes
@@ -871,7 +871,7 @@ char* SplitStructuredLineInternal(char* line,
   if (!expected_to_close.empty()) {
     return current;  // Missing closing symbol(s)
   }
-  return NULL;  // Success
+  return nullptr;  // Success
 }
 
 bool SplitStructuredLineInternal(StringPiece line,
@@ -1004,10 +1004,10 @@ bool SplitStringIntoKeyValuePairs(const string& line,
   SplitStringUsing(line, key_value_pair_delimiters.c_str(), &pairs);
 
   bool success = true;
-  for (size_t i = 0; i < pairs.size(); ++i) {
+  for (const auto& pair : pairs) {
     string key;
     vector<string> value;
-    if (!SplitStringIntoKeyValues(pairs[i],
+    if (!SplitStringIntoKeyValues(pair,
                                   key_value_delimiters,
                                   "", &key, &value)) {
       // Don't return here, to allow for keys without associated
@@ -1033,7 +1033,7 @@ bool SplitStringIntoKeyValuePairs(const string& line,
 // --------------------------------------------------------------------
 const char* SplitLeadingDec32Values(const char *str, vector<int32> *result) {
   for (;;) {
-    char *end = NULL;
+    char *end = nullptr;
     long value = strtol(str, &end, 10);
     if (end == str)
       break;
@@ -1053,7 +1053,7 @@ const char* SplitLeadingDec32Values(const char *str, vector<int32> *result) {
 
 const char* SplitLeadingDec64Values(const char *str, vector<int64> *result) {
   for (;;) {
-    char *end = NULL;
+    char *end = nullptr;
     const int64 value = strtoll(str, &end, 10);
     if (end == str)
       break;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/split.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/split.h b/be/src/gutil/strings/split.h
index 869d121..c487689 100644
--- a/be/src/gutil/strings/split.h
+++ b/be/src/gutil/strings/split.h
@@ -51,13 +51,14 @@ using std::pair;
 #include <vector>
 using std::vector;
 
-#include "gutil/integral_types.h"
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/strings/charset.h"
-#include "gutil/strings/split_internal.h"
-#include "gutil/strings/stringpiece.h"
-#include "gutil/strings/strip.h"
+
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/strings/charset.h"
+#include "kudu/gutil/strings/split_internal.h"
+#include "kudu/gutil/strings/stringpiece.h"
+#include "kudu/gutil/strings/strip.h"
 
 namespace strings {
 
@@ -400,7 +401,7 @@ template <typename Delimiter>
 class LimitImpl {
  public:
   LimitImpl(Delimiter delimiter, int limit)
-      : delimiter_(delimiter), limit_(limit), count_(0) {}
+      : delimiter_(std::move(delimiter)), limit_(limit), count_(0) {}
   StringPiece Find(StringPiece text) {
     if (count_++ == limit_) {
       return StringPiece(text.end(), 0);  // No more matches.
@@ -853,11 +854,11 @@ bool SplitRange(const char* rangestr, int* from, int* to);
 // The following variants of SplitCSVLine() are not recommended for new code.
 // Please consider the CSV parser in //util/csv as an alternative.  Examples:
 // To parse a single line:
-//     #include "util/csv/parser.h"
+//     #include "kudu/util/csv/parser.h"
 //     vector<string> fields = util::csv::ParseLine(line).fields();
 //
 // To parse an entire file:
-//     #include "util/csv/parser.h"
+//     #include "kudu/util/csv/parser.h"
 //     for (Record rec : Parser(source)) {
 //       vector<string> fields = rec.fields();
 //     }
@@ -1155,9 +1156,9 @@ bool SplitStringAndParseToInserter(
   vector<StringPiece> pieces = strings::Split(source,
                                               strings::delimiter::AnyOf(delim),
                                               strings::SkipEmpty());
-  for (size_t i = 0; i < pieces.size(); ++i) {
+  for (const auto& piece : pieces) {
     typename Container::value_type t;
-    if (parse(pieces[i].as_string(), &t)) {
+    if (parse(piece.as_string(), &t)) {
       insert_policy(result, t);
     } else {
       retval = false;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/split_internal.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/split_internal.h b/be/src/gutil/strings/split_internal.h
index e50ddc8..01b3fac 100644
--- a/be/src/gutil/strings/split_internal.h
+++ b/be/src/gutil/strings/split_internal.h
@@ -26,8 +26,8 @@ using std::multimap;
 #include <vector>
 using std::vector;
 
-#include "gutil/port.h"  // for LANG_CXX11
-#include "gutil/strings/stringpiece.h"
+#include "kudu/gutil/port.h"  // for LANG_CXX11
+#include "kudu/gutil/strings/stringpiece.h"
 
 #ifdef LANG_CXX11
 // This must be included after "base/port.h", which defines LANG_CXX11.
@@ -72,16 +72,22 @@ class SplitIterator
  public:
   // Two constructors for "end" iterators.
   explicit SplitIterator(Delimiter d)
-      : delimiter_(d), predicate_(), is_end_(true) {}
+      : delimiter_(std::move(d)), predicate_(), is_end_(true) {}
   SplitIterator(Delimiter d, Predicate p)
-      : delimiter_(d), predicate_(p), is_end_(true) {}
+      : delimiter_(std::move(d)), predicate_(std::move(p)), is_end_(true) {}
   // Two constructors taking the text to iterator.
   SplitIterator(StringPiece text, Delimiter d)
-      : text_(text), delimiter_(d), predicate_(), is_end_(false) {
+      : text_(std::move(text)),
+        delimiter_(std::move(d)),
+        predicate_(),
+        is_end_(false) {
     ++(*this);
   }
   SplitIterator(StringPiece text, Delimiter d, Predicate p)
-      : text_(text), delimiter_(d), predicate_(p), is_end_(false) {
+      : text_(std::move(text)),
+        delimiter_(std::move(d)),
+        predicate_(std::move(p)),
+        is_end_(false) {
     ++(*this);
   }
 
@@ -323,8 +329,8 @@ class Splitter {
     Container c;
     ReserveCapacity(&c, v.size());
     std::insert_iterator<Container> inserter(c, c.begin());
-    for (size_t i = 0; i < v.size(); ++i) {
-      *inserter++ = converter(v[i]);
+    for (const auto& sp : v) {
+      *inserter++ = converter(sp);
     }
     return c;
   }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/strcat.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/strcat.cc b/be/src/gutil/strings/strcat.cc
index 70d389e..93f8114 100644
--- a/be/src/gutil/strings/strcat.cc
+++ b/be/src/gutil/strings/strcat.cc
@@ -1,6 +1,6 @@
 // Copyright 2008 and onwards Google Inc.  All rights reserved.
 
-#include "gutil/strings/strcat.h"
+#include "kudu/gutil/strings/strcat.h"
 
 #include <stdarg.h>
 #include <stdint.h>
@@ -8,11 +8,11 @@
 #include <string.h>
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/gscoped_ptr.h"
-#include "gutil/strings/ascii_ctype.h"
-#include "gutil/strings/escaping.h"
-#include "gutil/stl_util.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/gscoped_ptr.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/strings/escaping.h"
+#include "kudu/gutil/stl_util.h"
 
 AlphaNum gEmptyAlphaNum("");
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/strcat.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/strcat.h b/be/src/gutil/strings/strcat.h
index 72ac462..40b888b 100644
--- a/be/src/gutil/strings/strcat.h
+++ b/be/src/gutil/strings/strcat.h
@@ -10,9 +10,9 @@
 #include <string>
 using std::string;
 
-#include "gutil/integral_types.h"
-#include "gutil/strings/numbers.h"
-#include "gutil/strings/stringpiece.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/strings/numbers.h"
+#include "kudu/gutil/strings/stringpiece.h"
 
 // The AlphaNum type was designed to be used as the parameter type for StrCat().
 // I suppose that any routine accepting either a string or a number could accept
@@ -51,16 +51,9 @@ struct AlphaNum {
   AlphaNum(uint64 u64)  // NOLINT(runtime/explicit)
       : piece(digits, FastUInt64ToBufferLeft(u64, digits) - &digits[0]) {}
 
-#ifdef _LP64
-  AlphaNum(long x)  // NOLINT(runtime/explicit)
-    : piece(digits, FastInt64ToBufferLeft(x, digits) - &digits[0]) {}
-  AlphaNum(unsigned long x)  // NOLINT(runtime/explicit)
-    : piece(digits, FastUInt64ToBufferLeft(x, digits) - &digits[0]) {}
-#else
-  AlphaNum(long x)  // NOLINT(runtime/explicit)
-    : piece(digits, FastInt32ToBufferLeft(x, digits) - &digits[0]) {}
-  AlphaNum(unsigned long x)  // NOLINT(runtime/explicit)
-    : piece(digits, FastUInt32ToBufferLeft(x, digits) - &digits[0]) {}
+#if defined(__APPLE__)
+  AlphaNum(size_t size)  // NOLINT(runtime/explicit)
+      : piece(digits, FastUInt64ToBufferLeft(size, digits) - &digits[0]) {}
 #endif
 
   AlphaNum(float f)  // NOLINT(runtime/explicit)
@@ -69,7 +62,8 @@ struct AlphaNum {
     : piece(digits, strlen(DoubleToBuffer(f, digits))) {}
 
   AlphaNum(const char *c_str) : piece(c_str) {}  // NOLINT(runtime/explicit)
-  AlphaNum(const StringPiece &pc) : piece(pc) {}  // NOLINT(runtime/explicit)
+  AlphaNum(StringPiece pc)
+      : piece(std::move(pc)) {}            // NOLINT(runtime/explicit)
   AlphaNum(const string &s) : piece(s) {}  // NOLINT(runtime/explicit)
 
   StringPiece::size_type size() const { return piece.size(); }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/string_util-test.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/string_util-test.cc b/be/src/gutil/strings/string_util-test.cc
new file mode 100644
index 0000000..8849ca2
--- /dev/null
+++ b/be/src/gutil/strings/string_util-test.cc
@@ -0,0 +1,58 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// Some portions Copyright 2013 The Chromium Authors. All rights reserved.
+#include "kudu/gutil/strings/util.h"
+
+#include <gtest/gtest.h>
+
+namespace kudu {
+
+TEST(StringUtilTest, MatchPatternTest) {
+  EXPECT_TRUE(MatchPattern("www.google.com", "*.com"));
+  EXPECT_TRUE(MatchPattern("www.google.com", "*"));
+  EXPECT_FALSE(MatchPattern("www.google.com", "www*.g*.org"));
+  EXPECT_TRUE(MatchPattern("Hello", "H?l?o"));
+  EXPECT_FALSE(MatchPattern("www.google.com", "http://*)"));
+  EXPECT_FALSE(MatchPattern("www.msn.com", "*.COM"));
+  EXPECT_TRUE(MatchPattern("Hello*1234", "He??o\\*1*"));
+  EXPECT_FALSE(MatchPattern("", "*.*"));
+  EXPECT_TRUE(MatchPattern("", "*"));
+  EXPECT_TRUE(MatchPattern("", "?"));
+  EXPECT_TRUE(MatchPattern("", ""));
+  EXPECT_FALSE(MatchPattern("Hello", ""));
+  EXPECT_TRUE(MatchPattern("Hello*", "Hello*"));
+  // Stop after a certain recursion depth.
+  EXPECT_FALSE(MatchPattern("123456789012345678", "?????????????????*"));
+
+  // Test UTF8 matching.
+  EXPECT_TRUE(MatchPattern("heart: \xe2\x99\xa0", "*\xe2\x99\xa0"));
+  EXPECT_TRUE(MatchPattern("heart: \xe2\x99\xa0.", "heart: ?."));
+  EXPECT_TRUE(MatchPattern("hearts: \xe2\x99\xa0\xe2\x99\xa0", "*"));
+  // Invalid sequences should be handled as a single invalid character.
+  EXPECT_TRUE(MatchPattern("invalid: \xef\xbf\xbe", "invalid: ?"));
+  // If the pattern has invalid characters, it shouldn't match anything.
+  EXPECT_FALSE(MatchPattern("\xf4\x90\x80\x80", "\xf4\x90\x80\x80"));
+
+  // This test verifies that consecutive wild cards are collapsed into 1
+  // wildcard (when this doesn't occur, MatchPattern reaches it's maximum
+  // recursion depth).
+  EXPECT_TRUE(MatchPattern("Hello" ,
+                           "He********************************o")) ;
+}
+
+} // namespace kudu

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/stringpiece.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/stringpiece.cc b/be/src/gutil/strings/stringpiece.cc
index 285d646..d6f23ee 100644
--- a/be/src/gutil/strings/stringpiece.cc
+++ b/be/src/gutil/strings/stringpiece.cc
@@ -2,35 +2,32 @@
 //
 //
 
-#include "gutil/strings/stringpiece.h"
+#include "kudu/gutil/strings/stringpiece.h"
 
-#include <string.h>
 #include <algorithm>
+#include <climits>
+#include <glog/logging.h>
+#include <string.h>
+#include <string>
+
+#include "kudu/gutil/hash/hash.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/stl_util.h"
+#include "kudu/gutil/strings/memutil.h"
+
 using std::copy;
 using std::max;
 using std::min;
 using std::reverse;
 using std::sort;
 using std::swap;
-#include <climits>
-#include <string>
 using std::string;
 
-#include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/strings/memutil.h"
-#include "gutil/stl_util.h"
-#include "gutil/hash/hash.h"
-
-#include <ext/hash_set>
-namespace __gnu_cxx {
-
-size_t hash<StringPiece>::operator()(StringPiece s) const {
-  return HashTo32(s.data(), s.size());
-}
-
-}  // namespace __gnu_cxx
-
+namespace std {
+  size_t hash<StringPiece>::operator()(StringPiece s) const {
+    return HashTo32(s.data(), s.size());
+  }
+} // namespace std
 
 std::ostream& operator<<(std::ostream& o, StringPiece piece) {
   o.write(piece.data(), piece.size());
@@ -84,7 +81,7 @@ int StringPiece::find(char c, size_type pos) const {
   }
   const char* result = static_cast<const char*>(
       memchr(ptr_ + pos, c, length_ - pos));
-  return result != NULL ? result - ptr_ : npos;
+  return result != nullptr ? result - ptr_ : npos;
 }
 
 int StringPiece::rfind(StringPiece s, size_type pos) const {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/stringpiece.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/stringpiece.h b/be/src/gutil/strings/stringpiece.h
index 77afb70..0f28f2b 100644
--- a/be/src/gutil/strings/stringpiece.h
+++ b/be/src/gutil/strings/stringpiece.h
@@ -114,23 +114,18 @@
 
 
 #include <assert.h>
-#include <stddef.h>
-#include <string.h>
-#include <ext/hash_map>
-using __gnu_cxx::hash;
-using __gnu_cxx::hash_map;
+#include <functional>
 #include <iosfwd>
-using std::ostream;
 #include <limits>
-using std::numeric_limits;
+#include <stddef.h>
+#include <string.h>
 #include <string>
-using std::string;
 
-#include "gutil/integral_types.h"
-#include "gutil/port.h"
-#include "gutil/type_traits.h"
-#include "gutil/strings/fastmem.h"
-#include "gutil/hash/hash.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/type_traits.h"
+#include "kudu/gutil/strings/fastmem.h"
+#include "kudu/gutil/hash/hash.h"
 
 class StringPiece {
  private:
@@ -153,7 +148,7 @@ class StringPiece {
       length_ = static_cast<int>(length);
     }
   }
-  StringPiece(const string& str)  // NOLINT(runtime/explicit)
+  StringPiece(const std::string& str)  // NOLINT(runtime/explicit)
       : ptr_(str.data()), length_(0) {
     size_t length = str.size();
     assert(length <= static_cast<size_t>(std::numeric_limits<int>::max()));
@@ -231,7 +226,7 @@ class StringPiece {
     return 0;
   }
 
-  string as_string() const {
+  std::string as_string() const {
     return ToString();
   }
   // We also define ToString() here, since many other string-like
@@ -239,13 +234,13 @@ class StringPiece {
   // "ToString", and it's confusing to have the method that does that
   // for a StringPiece be called "as_string()".  We also leave the
   // "as_string()" method defined here for existing code.
-  string ToString() const {
-    if (ptr_ == NULL) return string();
-    return string(data(), size());
+  std::string ToString() const {
+    if (ptr_ == NULL) return std::string();
+    return std::string(data(), size());
   }
 
-  void CopyToString(string* target) const;
-  void AppendToString(string* target) const;
+  void CopyToString(std::string* target) const;
+  void AppendToString(std::string* target) const;
 
   bool starts_with(StringPiece x) const {
     return (length_ >= x.length_) && (memcmp(ptr_, x.ptr_, x.length_) == 0);
@@ -352,20 +347,12 @@ template <class X> struct GoodFastHash;
 
 // SWIG doesn't know how to parse this stuff properly. Omit it.
 #ifndef SWIG
-#include <ext/hash_set>
-namespace __gnu_cxx {
 
+namespace std {
 template<> struct hash<StringPiece> {
   size_t operator()(StringPiece s) const;
-  // Less than operator, for MSVC.
-  bool operator()(const StringPiece& s1, const StringPiece& s2) const {
-    return s1 < s2;
-  }
-  static const size_t bucket_size = 4;  // These are required by MSVC
-  static const size_t min_buckets = 8;  // 4 and 8 are defaults.
 };
-
-}  // namespace __gnu_cxx
+}  // namespace std
 
 
 // An implementation of GoodFastHash for StringPiece.  See

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/strip.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/strip.cc b/be/src/gutil/strings/strip.cc
index 8a51776..1a6a547 100644
--- a/be/src/gutil/strings/strip.cc
+++ b/be/src/gutil/strings/strip.cc
@@ -4,7 +4,7 @@
 // This file contains functions that remove a defined part from the string,
 // i.e., strip the string.
 
-#include "gutil/strings/strip.h"
+#include "kudu/gutil/strings/strip.h"
 
 #include <assert.h>
 #include <string.h>
@@ -18,8 +18,8 @@ using std::swap;
 #include <string>
 using std::string;
 
-#include "gutil/strings/ascii_ctype.h"
-#include "gutil/strings/stringpiece.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/strings/stringpiece.h"
 
 string StripPrefixString(StringPiece str, const StringPiece& prefix) {
   if (str.starts_with(prefix))
@@ -74,9 +74,9 @@ void StripString(char* str, int len, StringPiece remove, char replacewith) {
 }
 
 void StripString(string* s, StringPiece remove, char replacewith) {
-  for (string::iterator it = s->begin(), end = s->end(); it != end; ++it) {
-    if (remove.find(*it) != StringPiece::npos) {
-      *it = replacewith;
+  for (char& c : *s) {
+    if (remove.find(c) != StringPiece::npos) {
+      c = replacewith;
     }
   }
 }
@@ -286,7 +286,7 @@ int StripDupCharacters(string* s, char dup_char, int start_pos) {
 //   Remove leading, trailing, and duplicate internal whitespace.
 // ----------------------------------------------------------------------
 void RemoveExtraWhitespace(string* s) {
-  assert(s != NULL);
+  assert(s != nullptr);
   // Empty strings clearly have no whitespace, and this code assumes that
   // string length is greater than 0
   if (s->empty())
@@ -324,7 +324,7 @@ void RemoveExtraWhitespace(string* s) {
 void StripLeadingWhiteSpace(string* str) {
   char const* const leading = StripLeadingWhiteSpace(
       const_cast<char*>(str->c_str()));
-  if (leading != NULL) {
+  if (leading != nullptr) {
     string const tmp(leading);
     str->assign(tmp);
   } else {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/strip.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/strip.h b/be/src/gutil/strings/strip.h
index cdde845..8104b76 100644
--- a/be/src/gutil/strings/strip.h
+++ b/be/src/gutil/strings/strip.h
@@ -11,8 +11,8 @@
 #include <string>
 using std::string;
 
-#include "gutil/strings/ascii_ctype.h"
-#include "gutil/strings/stringpiece.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/strings/stringpiece.h"
 
 // Given a string and a putative prefix, returns the string minus the
 // prefix string if the prefix matches, otherwise the original

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/substitute.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/substitute.cc b/be/src/gutil/strings/substitute.cc
index d4b2a7b..245894b 100644
--- a/be/src/gutil/strings/substitute.cc
+++ b/be/src/gutil/strings/substitute.cc
@@ -1,13 +1,13 @@
 // Copyright 2008 Google Inc.  All rights reserved.
 
-#include "gutil/strings/substitute.h"
+#include "kudu/gutil/strings/substitute.h"
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/macros.h"
-#include "gutil/strings/ascii_ctype.h"
-#include "gutil/strings/escaping.h"
-#include "gutil/stl_util.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/strings/escaping.h"
+#include "kudu/gutil/stl_util.h"
 
 namespace strings {
 
@@ -93,7 +93,7 @@ void SubstituteAndAppend(
     const SubstituteArg& arg6, const SubstituteArg& arg7,
     const SubstituteArg& arg8, const SubstituteArg& arg9) {
   const SubstituteArg* const args_array[] = {
-    &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, NULL
+    &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, nullptr
   };
 
   // Determine total size needed.
@@ -112,7 +112,7 @@ void SubstituteAndAppend(
 SubstituteArg::SubstituteArg(const void* value) {
   COMPILE_ASSERT(sizeof(scratch_) >= sizeof(value) * 2 + 2,
                  fix_sizeof_scratch_);
-  if (value == NULL) {
+  if (value == nullptr) {
     text_ = "NULL";
     size_ = strlen(text_);
   } else {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/substitute.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/substitute.h b/be/src/gutil/strings/substitute.h
index 84d362a..0812c3f 100644
--- a/be/src/gutil/strings/substitute.h
+++ b/be/src/gutil/strings/substitute.h
@@ -4,9 +4,9 @@
 #include <string>
 using std::string;
 
-#include "gutil/basictypes.h"
-#include "gutil/strings/numbers.h"
-#include "gutil/strings/stringpiece.h"
+#include "kudu/gutil/basictypes.h"
+#include "kudu/gutil/strings/numbers.h"
+#include "kudu/gutil/strings/stringpiece.h"
 
 
 #ifndef STRINGS_SUBSTITUTE_H_


[07/14] incubator-impala git commit: IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

Posted by he...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/map-util.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/map-util.h b/be/src/gutil/map-util.h
index 9368a5a..6fffedf 100644
--- a/be/src/gutil/map-util.h
+++ b/be/src/gutil/map-util.h
@@ -72,7 +72,8 @@ using std::pair;
 using std::vector;
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
+
+#include "kudu/gutil/logging-inl.h"
 
 //
 // Find*()
@@ -94,29 +95,29 @@ using std::vector;
 // This version assumes the key is printable, and includes it in the fatal log
 // message.
 template <class Collection>
-const typename Collection::value_type::second_type&
+const typename Collection::mapped_type&
 FindOrDie(const Collection& collection,
-          const typename Collection::value_type::first_type& key) {
-  typename Collection::const_iterator it = collection.find(key);
+          const typename Collection::key_type& key) {
+  auto it = collection.find(key);
   CHECK(it != collection.end()) << "Map key not found: " << key;
   return it->second;
 }
 
 // Same as above, but returns a non-const reference.
 template <class Collection>
-typename Collection::value_type::second_type&
+typename Collection::mapped_type&
 FindOrDie(Collection& collection,  // NOLINT
-          const typename Collection::value_type::first_type& key) {
-  typename Collection::iterator it = collection.find(key);
+          const typename Collection::key_type& key) {
+  auto it = collection.find(key);
   CHECK(it != collection.end()) << "Map key not found: " << key;
   return it->second;
 }
 
 // Same as FindOrDie above, but doesn't log the key on failure.
 template <class Collection>
-const typename Collection::value_type::second_type&
+const typename Collection::mapped_type&
 FindOrDieNoPrint(const Collection& collection,
-                 const typename Collection::value_type::first_type& key) {
+                 const typename Collection::key_type& key) {
   typename Collection::const_iterator it = collection.find(key);
   CHECK(it != collection.end()) << "Map key not found";
   return it->second;
@@ -124,9 +125,9 @@ FindOrDieNoPrint(const Collection& collection,
 
 // Same as above, but returns a non-const reference.
 template <class Collection>
-typename Collection::value_type::second_type&
+typename Collection::mapped_type&
 FindOrDieNoPrint(Collection& collection,  // NOLINT
-                 const typename Collection::value_type::first_type& key) {
+                 const typename Collection::key_type& key) {
   typename Collection::iterator it = collection.find(key);
   CHECK(it != collection.end()) << "Map key not found";
   return it->second;
@@ -142,11 +143,11 @@ FindOrDieNoPrint(Collection& collection,  // NOLINT
 // string values, and you pass a char* as the default "value," either use the
 // returned value immediately or store it in a string (not string&). Details:
 template <class Collection>
-const typename Collection::value_type::second_type&
+const typename Collection::mapped_type&
 FindWithDefault(const Collection& collection,
-                const typename Collection::value_type::first_type& key,
-                const typename Collection::value_type::second_type& value) {
-  typename Collection::const_iterator it = collection.find(key);
+                const typename Collection::key_type& key,
+                const typename Collection::mapped_type& value) {
+  auto it = collection.find(key);
   if (it == collection.end()) {
     return value;
   }
@@ -156,10 +157,10 @@ FindWithDefault(const Collection& collection,
 // Returns a pointer to the const value associated with the given key if it
 // exists, or NULL otherwise.
 template <class Collection>
-const typename Collection::value_type::second_type*
+const typename Collection::mapped_type*
 FindOrNull(const Collection& collection,
-           const typename Collection::value_type::first_type& key) {
-  typename Collection::const_iterator it = collection.find(key);
+           const typename Collection::key_type& key) {
+  auto it = collection.find(key);
   if (it == collection.end()) {
     return 0;
   }
@@ -168,16 +169,62 @@ FindOrNull(const Collection& collection,
 
 // Same as above but returns a pointer to the non-const value.
 template <class Collection>
-typename Collection::value_type::second_type*
+typename Collection::mapped_type*
 FindOrNull(Collection& collection,  // NOLINT
-           const typename Collection::value_type::first_type& key) {
-  typename Collection::iterator it = collection.find(key);
+           const typename Collection::key_type& key) {
+  auto it = collection.find(key);
   if (it == collection.end()) {
     return 0;
   }
   return &it->second;
 }
 
+// Returns a pointer to the const value associated with the greatest key
+// that's less than or equal to the given key, or NULL if no such key exists.
+template <class Collection>
+const typename Collection::mapped_type*
+FindFloorOrNull(const Collection& collection,
+                const typename Collection::key_type& key) {
+  auto it = collection.upper_bound(key);
+  if (it == collection.begin()) {
+    return 0;
+  }
+  return &(--it)->second;
+}
+
+// Same as above but returns a pointer to the non-const value.
+template <class Collection>
+typename Collection::mapped_type*
+FindFloorOrNull(Collection& collection,  // NOLINT
+                const typename Collection::key_type& key) {
+  auto it = collection.upper_bound(key);
+  if (it == collection.begin()) {
+    return 0;
+  }
+  return &(--it)->second;
+}
+
+// Returns a const-reference to the value associated with the greatest key
+// that's less than or equal to the given key, or crashes if it does not exist.
+template <class Collection>
+const typename Collection::mapped_type&
+FindFloorOrDie(const Collection& collection,
+               const typename Collection::key_type& key) {
+  auto it = collection.upper_bound(key);
+  CHECK(it != collection.begin());
+  return (--it)->second;
+}
+
+// Same as above, but returns a non-const reference.
+template <class Collection>
+typename Collection::mapped_type&
+FindFloorOrDie(Collection& collection,
+               const typename Collection::key_type& key) {
+  auto it = collection.upper_bound(key);
+  CHECK(it != collection.begin());
+  return (--it)->second;
+}
+
 // Returns the pointer value associated with the given key. If none is found,
 // NULL is returned. The function is designed to be used with a map of keys to
 // pointers.
@@ -185,12 +232,12 @@ FindOrNull(Collection& collection,  // NOLINT
 // This function does not distinguish between a missing key and a key mapped
 // to a NULL value.
 template <class Collection>
-typename Collection::value_type::second_type
+typename Collection::mapped_type
 FindPtrOrNull(const Collection& collection,
-              const typename Collection::value_type::first_type& key) {
-  typename Collection::const_iterator it = collection.find(key);
+              const typename Collection::key_type& key) {
+  auto it = collection.find(key);
   if (it == collection.end()) {
-    return typename Collection::value_type::second_type(0);
+    return typename Collection::mapped_type(0);
   }
   return it->second;
 }
@@ -200,23 +247,38 @@ FindPtrOrNull(const Collection& collection,
 // This function is needed for containers that propagate constness to the
 // pointee, such as boost::ptr_map.
 template <class Collection>
-typename Collection::value_type::second_type
+typename Collection::mapped_type
 FindPtrOrNull(Collection& collection,  // NOLINT
-              const typename Collection::value_type::first_type& key) {
-  typename Collection::iterator it = collection.find(key);
+              const typename Collection::key_type& key) {
+  auto it = collection.find(key);
   if (it == collection.end()) {
-    return typename Collection::value_type::second_type(0);
+    return typename Collection::mapped_type(0);
   }
   return it->second;
 }
 
+// FindPtrOrNull like function for maps whose value is a smart pointer like shared_ptr or
+// unique_ptr.
+// Returns the raw pointer contained in the smart pointer for the first found key, if it exists,
+// or null if it doesn't.
+template <class Collection>
+typename Collection::mapped_type::element_type*
+FindPointeeOrNull(const Collection& collection,  // NOLINT,
+                  const typename Collection::key_type& key) {
+  auto it = collection.find(key);
+  if (it == collection.end()) {
+    return nullptr;
+  }
+  return it->second.get();
+}
+
 // Finds the value associated with the given key and copies it to *value (if not
 // NULL). Returns false if the key was not found, true otherwise.
 template <class Collection, class Key, class Value>
 bool FindCopy(const Collection& collection,
               const Key& key,
               Value* const value) {
-  typename Collection::const_iterator it = collection.find(key);
+  auto it = collection.find(key);
   if (it == collection.end()) {
     return false;
   }
@@ -233,7 +295,7 @@ bool FindCopy(const Collection& collection,
 // Returns true iff the given collection contains the given key.
 template <class Collection, class Key>
 bool ContainsKey(const Collection& collection, const Key& key) {
-  typename Collection::const_iterator it = collection.find(key);
+  auto it = collection.find(key);
   return it != collection.end();
 }
 
@@ -274,8 +336,8 @@ bool InsertOrUpdate(Collection* const collection,
 // Same as above, except that the key and value are passed separately.
 template <class Collection>
 bool InsertOrUpdate(Collection* const collection,
-                    const typename Collection::value_type::first_type& key,
-                    const typename Collection::value_type::second_type& value) {
+                    const typename Collection::key_type& key,
+                    const typename Collection::mapped_type& value) {
   return InsertOrUpdate(
       collection, typename Collection::value_type(key, value));
 }
@@ -297,8 +359,8 @@ void InsertOrUpdateMany(Collection* const collection,
 template <class Collection>
 bool InsertAndDeleteExisting(
     Collection* const collection,
-    const typename Collection::value_type::first_type& key,
-    const typename Collection::value_type::second_type& value) {
+    const typename Collection::key_type& key,
+    const typename Collection::mapped_type& value) {
   pair<typename Collection::iterator, bool> ret =
       collection->insert(typename Collection::value_type(key, value));
   if (!ret.second) {
@@ -323,8 +385,8 @@ bool InsertIfNotPresent(Collection* const collection,
 template <class Collection>
 bool InsertIfNotPresent(
     Collection* const collection,
-    const typename Collection::value_type::first_type& key,
-    const typename Collection::value_type::second_type& value) {
+    const typename Collection::key_type& key,
+    const typename Collection::mapped_type& value) {
   return InsertIfNotPresent(
       collection, typename Collection::value_type(key, value));
 }
@@ -347,9 +409,8 @@ void InsertOrDieNoPrint(Collection* const collection,
 // present.
 template <class Collection>
 void InsertOrDie(Collection* const collection,
-                 const typename Collection::value_type::first_type& key,
-                 const typename Collection::value_type::second_type& data) {
-  typedef typename Collection::value_type value_type;
+                 const typename Collection::key_type& key,
+                 const typename Collection::mapped_type& data) {
   CHECK(InsertIfNotPresent(collection, key, data))
       << "duplicate key: " << key;
 }
@@ -358,9 +419,8 @@ void InsertOrDie(Collection* const collection,
 template <class Collection>
 void InsertOrDieNoPrint(
     Collection* const collection,
-    const typename Collection::value_type::first_type& key,
-    const typename Collection::value_type::second_type& data) {
-  typedef typename Collection::value_type value_type;
+    const typename Collection::key_type& key,
+    const typename Collection::mapped_type& data) {
   CHECK(InsertIfNotPresent(collection, key, data)) << "duplicate key.";
 }
 
@@ -371,12 +431,12 @@ void InsertOrDieNoPrint(
 // SomeProto& proto = InsertKeyOrDie(&m, 3);
 // proto.set_field("foo");
 template <class Collection>
-typename Collection::value_type::second_type& InsertKeyOrDie(
+typename Collection::mapped_type& InsertKeyOrDie(
     Collection* const collection,
-    const typename Collection::value_type::first_type& key) {
+    const typename Collection::key_type& key) {
   typedef typename Collection::value_type value_type;
   pair<typename Collection::iterator, bool> res =
-      collection->insert(value_type(key, typename value_type::second_type()));
+      collection->insert(value_type(key, typename Collection::mapped_type()));
   CHECK(res.second) << "duplicate key: " << key;
   return res.first->second;
 }
@@ -389,7 +449,7 @@ typename Collection::value_type::second_type& InsertKeyOrDie(
 // pair if it's not already present. Returns a reference to the value associated
 // with the key.
 template <class Collection>
-typename Collection::value_type::second_type&
+typename Collection::mapped_type&
 LookupOrInsert(Collection* const collection,
                const typename Collection::value_type& vt) {
   return collection->insert(vt).first->second;
@@ -397,10 +457,10 @@ LookupOrInsert(Collection* const collection,
 
 // Same as above except the key-value are passed separately.
 template <class Collection>
-typename Collection::value_type::second_type&
+typename Collection::mapped_type&
 LookupOrInsert(Collection* const collection,
-               const typename Collection::value_type::first_type& key,
-               const typename Collection::value_type::second_type& value) {
+               const typename Collection::key_type& key,
+               const typename Collection::mapped_type& value) {
   return LookupOrInsert(
       collection, typename Collection::value_type(key, value));
 }
@@ -418,13 +478,13 @@ LookupOrInsert(Collection* const collection,
 template <typename Sequence, typename Collection>
 void AddTokenCounts(
     const Sequence& sequence,
-    const typename Collection::value_type::second_type& increment,
+    const typename Collection::mapped_type& increment,
     Collection* const count_map) {
   for (typename Sequence::const_iterator it = sequence.begin();
        it != sequence.end(); ++it) {
-    typename Collection::value_type::second_type& value =
+    typename Collection::mapped_type& value =
         LookupOrInsert(count_map, *it,
-                       typename Collection::value_type::second_type());
+                       typename Collection::mapped_type());
     value += increment;
   }
 }
@@ -448,13 +508,13 @@ void MapUtilAssignNewInstance(T** location, const Arg &arg) {
 // inserting a new key, value pair involves constructing a new heap-allocated
 // Value, and storing a pointer to that in the collection.
 template <class Collection>
-typename Collection::value_type::second_type&
+typename Collection::mapped_type&
 LookupOrInsertNew(Collection* const collection,
-                  const typename Collection::value_type::first_type& key) {
+                  const typename Collection::key_type& key) {
   pair<typename Collection::iterator, bool> ret =
       collection->insert(
           typename Collection::value_type(key,
-              static_cast<typename Collection::value_type::second_type>(NULL)));
+              static_cast<typename Collection::mapped_type>(NULL)));
   if (ret.second) {
     // This helper is needed to 'extract' the Value type from the type of the
     // container value, which is (Value*).
@@ -466,15 +526,15 @@ LookupOrInsertNew(Collection* const collection,
 // Same as above but constructs the value using the single-argument constructor
 // and the given "arg".
 template <class Collection, class Arg>
-typename Collection::value_type::second_type&
+typename Collection::mapped_type&
 LookupOrInsertNew(Collection* const collection,
-                  const typename Collection::value_type::first_type& key,
+                  const typename Collection::key_type& key,
                   const Arg& arg) {
   pair<typename Collection::iterator, bool> ret =
       collection->insert(
           typename Collection::value_type(
               key,
-              static_cast<typename Collection::value_type::second_type>(NULL)));
+              static_cast<typename Collection::mapped_type>(NULL)));
   if (ret.second) {
     // This helper is needed to 'extract' the Value type from the type of the
     // container value, which is (Value*).
@@ -497,12 +557,12 @@ LookupOrInsertNew(Collection* const collection,
 // LookupOrInsertNewLinkedPtr, this function returns the shared_ptr instead of
 // the raw pointer. Value::element_type must be default constructable.
 template <class Collection>
-typename Collection::value_type::second_type&
+typename Collection::mapped_type&
 LookupOrInsertNewSharedPtr(
     Collection* const collection,
-    const typename Collection::value_type::first_type& key) {
-  typedef typename Collection::value_type::second_type SharedPtr;
-  typedef typename Collection::value_type::second_type::element_type Element;
+    const typename Collection::key_type& key) {
+  typedef typename Collection::mapped_type SharedPtr;
+  typedef typename Collection::mapped_type::element_type Element;
   pair<typename Collection::iterator, bool> ret =
       collection->insert(typename Collection::value_type(key, SharedPtr()));
   if (ret.second) {
@@ -517,13 +577,13 @@ LookupOrInsertNewSharedPtr(
 // here.  On the other hand it does not matter how expensive the construction of
 // the actual stored value is, as that only occurs if necessary.
 template <class Collection, class Arg>
-typename Collection::value_type::second_type&
+typename Collection::mapped_type&
 LookupOrInsertNewSharedPtr(
     Collection* const collection,
-    const typename Collection::value_type::first_type& key,
+    const typename Collection::key_type& key,
     const Arg& arg) {
-  typedef typename Collection::value_type::second_type SharedPtr;
-  typedef typename Collection::value_type::second_type::element_type Element;
+  typedef typename Collection::mapped_type SharedPtr;
+  typedef typename Collection::mapped_type::element_type Element;
   pair<typename Collection::iterator, bool> ret =
       collection->insert(typename Collection::value_type(key, SharedPtr()));
   if (ret.second) {
@@ -545,9 +605,9 @@ LookupOrInsertNewSharedPtr(
 // address of an already existing value, rather than updating it.
 template <class Collection>
 bool UpdateReturnCopy(Collection* const collection,
-                      const typename Collection::value_type::first_type& key,
-                      const typename Collection::value_type::second_type& value,
-                      typename Collection::value_type::second_type* previous) {
+                      const typename Collection::key_type& key,
+                      const typename Collection::mapped_type& value,
+                      typename Collection::mapped_type* previous) {
   pair<typename Collection::iterator, bool> ret =
       collection->insert(typename Collection::value_type(key, value));
   if (!ret.second) {
@@ -565,7 +625,7 @@ bool UpdateReturnCopy(Collection* const collection,
 template <class Collection>
 bool UpdateReturnCopy(Collection* const collection,
                       const typename Collection::value_type& vt,
-                      typename Collection::value_type::second_type* previous) {
+                      typename Collection::mapped_type* previous) {
   pair<typename Collection::iterator, bool> ret =
     collection->insert(vt);
   if (!ret.second) {
@@ -587,7 +647,7 @@ bool UpdateReturnCopy(Collection* const collection,
 // twice. Unlike UpdateReturnCopy this also does not come with the issue of an
 // undefined previous* in case new data was inserted.
 template <class Collection>
-typename Collection::value_type::second_type* const
+typename Collection::mapped_type* const
 InsertOrReturnExisting(Collection* const collection,
                        const typename Collection::value_type& vt) {
   pair<typename Collection::iterator, bool> ret = collection->insert(vt);
@@ -600,11 +660,11 @@ InsertOrReturnExisting(Collection* const collection,
 
 // Same as above, except for explicit key and data.
 template <class Collection>
-typename Collection::value_type::second_type* const
+typename Collection::mapped_type* const
 InsertOrReturnExisting(
     Collection* const collection,
-    const typename Collection::value_type::first_type& key,
-    const typename Collection::value_type::second_type& data) {
+    const typename Collection::key_type& key,
+    const typename Collection::mapped_type& data) {
   return InsertOrReturnExisting(collection,
                                 typename Collection::value_type(key, data));
 }
@@ -638,15 +698,17 @@ void ReverseMap(const Collection& collection,
 //     if (value_ptr.get())
 //       value_ptr->DoSomething();
 //
+// Note: if 'collection' is a multimap, this will only erase and return the
+// first value.
 template <class Collection>
-typename Collection::value_type::second_type EraseKeyReturnValuePtr(
+typename Collection::mapped_type EraseKeyReturnValuePtr(
     Collection* const collection,
-    const typename Collection::value_type::first_type& key) {
-  typename Collection::iterator it = collection->find(key);
+    const typename Collection::key_type& key) {
+  auto it = collection->find(key);
   if (it == collection->end()) {
-    return NULL;
+    return typename Collection::mapped_type();
   }
-  typename Collection::value_type::second_type v = it->second;
+  typename Collection::mapped_type v = std::move(it->second);
   collection->erase(it);
   return v;
 }
@@ -738,10 +800,59 @@ void AppendValuesFromMap(const MapContainer& map_container,
   if (value_container->empty()) {
     value_container->reserve(map_container.size());
   }
-  for (typename MapContainer::const_iterator it = map_container.begin();
-       it != map_container.end(); ++it) {
-    value_container->push_back(it->second);
+  for (const auto& entry : map_container) {
+    value_container->push_back(entry.second);
   }
 }
 
+// Compute and insert new value if it's absent from the map. Return a pair with a reference to the
+// value and a bool indicating whether it was absent at first.
+//
+// This inspired on a similar java construct (url split in two lines):
+// https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html
+// #computeIfAbsent-K-java.util.function.Function
+//
+// It takes a reference to the key and a lambda function. If the key exists in the map, returns
+// a pair with a pointer to the current value and 'false'. If the key does not exist in the map,
+// it uses the lambda function to create a value, inserts it into the map, and returns a pair with
+// a pointer to the new value and 'true'.
+//
+// Example usage:
+//
+// auto result = ComputeIfAbsentReturnAbsense(&my_collection,
+//                                            my_key,
+//                                            [] { return new_value; });
+// MyValue* const value = result.first;
+// if (result.second) ....
+//
+template <class MapContainer, typename Function>
+pair<typename MapContainer::mapped_type* const, bool>
+ComputeIfAbsentReturnAbsense(MapContainer* container,
+                             const typename MapContainer::key_type& key,
+                             Function compute_func) {
+  typename MapContainer::iterator iter = container->find(key);
+  bool new_value = iter == container->end();
+  if (new_value) {
+    pair<typename MapContainer::iterator, bool> result = container->emplace(key, compute_func());
+    DCHECK(result.second) << "duplicate key: " << key;
+    iter = result.first;
+  }
+  return make_pair(&iter->second, new_value);
+};
+
+// Like the above but doesn't return a pair, just returns a pointer to the value.
+// Example usage:
+//
+// MyValue* const value = ComputeIfAbsent(&my_collection,
+//                                        my_key,
+//                                        [] { return new_value; });
+//
+template <class MapContainer, typename Function>
+typename MapContainer::mapped_type* const
+ComputeIfAbsent(MapContainer* container,
+                const typename MapContainer::key_type& key,
+                Function compute_func) {
+  return ComputeIfAbsentReturnAbsense(container, key, compute_func).first;
+};
+
 #endif  // UTIL_GTL_MAP_UTIL_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/mathlimits.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/mathlimits.cc b/be/src/gutil/mathlimits.cc
index 0311d0d..dcc261d 100644
--- a/be/src/gutil/mathlimits.cc
+++ b/be/src/gutil/mathlimits.cc
@@ -1,24 +1,29 @@
 // Copyright 2005 Google Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // ---
 //
 //
 
-#include "gutil/mathlimits.h"
+#include "kudu/gutil/mathlimits.h"
 
-#include "gutil/integral_types.h"
+#include "kudu/gutil/integral_types.h"
 
 // MSVC++ 2005 thinks the header declaration was a definition, and
 // erroneously flags these as a duplicate definition.
@@ -107,9 +112,6 @@ DEF_UNSIGNED_INT_LIMITS(uint16)
 DEF_UNSIGNED_INT_LIMITS(uint32)
 DEF_UNSIGNED_INT_LIMITS(uint64)
 
-DEF_SIGNED_INT_LIMITS(long int)
-DEF_UNSIGNED_INT_LIMITS(unsigned long int)
-
 DEF_FP_LIMITS(float, FLT)
 DEF_FP_LIMITS(double, DBL)
 DEF_FP_LIMITS(long double, LDBL);

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/mathlimits.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/mathlimits.h b/be/src/gutil/mathlimits.h
index 48f1d8e..9d69733 100644
--- a/be/src/gutil/mathlimits.h
+++ b/be/src/gutil/mathlimits.h
@@ -1,16 +1,21 @@
 // Copyright 2005 Google Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // ---
 //
@@ -29,6 +34,7 @@
 #include <math.h>
 #include <string.h>
 #include <cfloat>
+#include <cmath>
 
 // ========================================================================= //
 
@@ -203,11 +209,11 @@ DECL_UNSIGNED_INT_LIMITS(unsigned long long int)
   static bool IsNegInf(const Type x) { return _fpclass(x) == _FPCLASS_NINF; }
 #else
 #define DECL_FP_LIMIT_FUNCS \
-  static bool IsFinite(const Type x) { return !isinf(x)  &&  !isnan(x); } \
-  static bool IsNaN(const Type x) { return isnan(x); } \
-  static bool IsInf(const Type x) { return isinf(x); } \
-  static bool IsPosInf(const Type x) { return isinf(x)  &&  x > 0; } \
-  static bool IsNegInf(const Type x) { return isinf(x)  &&  x < 0; }
+  static bool IsFinite(const Type x) { return !std::isinf(x)  &&  !std::isnan(x); } \
+  static bool IsNaN(const Type x) { return std::isnan(x); } \
+  static bool IsInf(const Type x) { return std::isinf(x); } \
+  static bool IsPosInf(const Type x) { return std::isinf(x)  &&  x > 0; } \
+  static bool IsNegInf(const Type x) { return std::isinf(x)  &&  x < 0; }
 #endif
 
 // We can't put floating-point constant values in the header here because

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/move.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/move.h b/be/src/gutil/move.h
index d2cd3df..1765108 100644
--- a/be/src/gutil/move.h
+++ b/be/src/gutil/move.h
@@ -105,8 +105,8 @@
 //
 //
 //    Foo f(MakeFoo());      // R-value so alternate conversion executed.
-//    Foo f_copy(f.Pass());  // R-value so alternate conversion executed.
-//    f = f_copy.Pass();     // R-value so alternate conversion executed.
+//    Foo f_copy(std::move(f));  // R-value so alternate conversion executed.
+//    f = std::move(f_copy);     // R-value so alternate conversion executed.
 //
 //
 // IMPLEMENTATION SUBTLETIES WITH RValue
@@ -136,6 +136,16 @@
 // choose the one that adheres to the standard.
 //
 //
+// WHY HAVE typedef void MoveOnlyTypeForCPP03
+//
+// Callback<>/Bind() needs to understand movable-but-not-copyable semantics
+// to call .Pass() appropriately when it is expected to transfer the value.
+// The cryptic typedef MoveOnlyTypeForCPP03 is added to make this check
+// easy and automatic in helper templates for Callback<>/Bind().
+// See IsMoveOnlyType template and its usage in base/callback_internal.h
+// for more details.
+//
+//
 // COMPARED TO C++11
 //
 // In C++11, you would implement this functionality using an r-value reference
@@ -202,6 +212,7 @@
  public: \
   operator rvalue_type() { return rvalue_type(this); } \
   type Pass() { return type(rvalue_type(this)); } \
+  typedef void MoveOnlyTypeForCPP03; \
  private:
 
 #endif  // BASE_MOVE_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/once.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/once.cc b/be/src/gutil/once.cc
index a50c34a..1b97f8f 100644
--- a/be/src/gutil/once.cc
+++ b/be/src/gutil/once.cc
@@ -1,10 +1,10 @@
 // Copyright 2008 Google Inc. All Rights Reserved.
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/once.h"
-#include "gutil/dynamic_annotations.h"
-#include "gutil/spinlock_internal.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/once.h"
+#include "kudu/gutil/dynamic_annotations.h"
+#include "kudu/gutil/spinlock_internal.h"
 
 // All modifications to a GoogleOnceType occur inside GoogleOnceInternalInit.
 // The fast path reads the variable with an acquire-load..

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/once.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/once.h b/be/src/gutil/once.h
index c81e871..ff161c5 100644
--- a/be/src/gutil/once.h
+++ b/be/src/gutil/once.h
@@ -24,12 +24,12 @@
 #ifndef BASE_ONCE_H_
 #define BASE_ONCE_H_
 
-#include "gutil/atomicops.h"
-#include "gutil/integral_types.h"
-#include "gutil/dynamic_annotations.h"
-#include "gutil/macros.h"
-#include "gutil/port.h"
-#include "gutil/type_traits.h"
+#include "kudu/gutil/atomicops.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/dynamic_annotations.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/type_traits.h"
 
 // The following enum values are not for use by clients
 enum {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/paranoid.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/paranoid.h b/be/src/gutil/paranoid.h
index 53159a0..01f34b7 100644
--- a/be/src/gutil/paranoid.h
+++ b/be/src/gutil/paranoid.h
@@ -7,7 +7,8 @@
 #define BASE_PARANOID_H_
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
+
+#include "kudu/gutil/logging-inl.h"
 
 // Sanitize a bool value which might be sour.
 //

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/port.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/port.h b/be/src/gutil/port.h
index c9f19f4..6222cca 100644
--- a/be/src/gutil/port.h
+++ b/be/src/gutil/port.h
@@ -18,7 +18,7 @@
 #include <malloc.h>         // for memalign()
 #endif
 
-#include "gutil/integral_types.h"
+#include "kudu/gutil/integral_types.h"
 
 // Must happens before inttypes.h inclusion */
 #if defined(__APPLE__)
@@ -223,66 +223,6 @@ typedef int uid_t;
 // Linux has this in <linux/errno.h>
 #define EXFULL      ENOMEM  // not really that great a translation...
 
-// Mach-O supports sections (albeit with small names), but doesn't have
-// vars at the beginning and end.  Instead you should call the function
-// getsectdata("__DATA", name, &size).
-#define HAVE_ATTRIBUTE_SECTION 1
-
-// Any function with ATTRIBUTE_SECTION must not be inlined, or it will
-// be placed into whatever section its caller is placed into.
-#define ATTRIBUTE_SECTION(name) \
-  __attribute__ ((section ("__DATA, " #name))) __attribute__ ((noinline))
-
-#define ENUM_DYLD_BOOL  // so that we don't pollute the global namespace
-extern "C" {
-  #include <mach-o/getsect.h>
-  #include <mach-o/dyld.h>
-}
-class AssignAttributeStartEnd {
- public:
-  AssignAttributeStartEnd(const char* name, char** pstart, char** pend) {
-    // Find out what dynamic library name is defined in
-    for (int i = _dyld_image_count() - 1; i >= 0; --i) {
-      const mach_header* hdr = _dyld_get_image_header(i);
-      uint32_t len;
-      *pstart = getsectdatafromheader(hdr, "__DATA", name, &len);
-      if (*pstart) {   // NULL if not defined in this dynamic library
-        *pstart += _dyld_get_image_vmaddr_slide(i);   // correct for reloc
-        *pend = *pstart + len;
-        return;
-      }
-    }
-    // If we get here, not defined in a dll at all.  See if defined statically.
-    unsigned long len;    // don't ask me why this type isn't uint32_t too...
-    *pstart = getsectdata("__DATA", name, &len);
-    *pend = *pstart + len;
-  }
-};
-
-// 1) DEFINE_ATTRIBUTE_SECTION_VARS: must be called once per unique
-//    name.  You want to make sure this is executed before any
-//    DECLARE_ATTRIBUTE_SECTION_VARS; the easiest way is to put them
-//    in the same .cc file.  Put this call at the global level.
-// 2) INIT_ATTRIBUTE_SECTION_VARS: you can scatter calls to this in
-//    multiple places to help ensure execution before any
-//    DECLARE_ATTRIBUTE_SECTION_VARS.  You must have at least one
-//    DEFINE, but you can have many INITs.  Put each in its own scope.
-// 3) DECLARE_ATTRIBUTE_SECTION_VARS: must be called before using
-//    ATTRIBUTE_SECTION_START or ATTRIBUTE_SECTION_STOP on a name.
-//    Put this call at the global level.
-#define DECLARE_ATTRIBUTE_SECTION_VARS(name) \
-  extern char* __start_##name; \
-  extern char* __stop_##name;
-
-#define INIT_ATTRIBUTE_SECTION_VARS(name)               \
-  DECLARE_ATTRIBUTE_SECTION_VARS(name);                 \
-  static const AssignAttributeStartEnd __assign_##name( \
-    #name, &__start_##name, &__stop_##name)
-
-#define DEFINE_ATTRIBUTE_SECTION_VARS(name)             \
-  char* __start_##name, *__stop_##name;                 \
-  INIT_ATTRIBUTE_SECTION_VARS(name)
-
 // Darwin doesn't have strnlen. No comment.
 inline size_t strnlen(const char *s, size_t maxlen) {
   const char* end = (const char *)memchr(s, '\0', maxlen);
@@ -434,6 +374,17 @@ inline void* memrchr(const void* bytes, int find_char, size_t len) {
 #define ATTRIBUTE_WEAK __attribute__ ((weak))
 #define HAVE_ATTRIBUTE_WEAK 1
 
+// For deprecated functions or variables, generate a warning at usage sites.
+// Verified to work as early as GCC 3.1.1 and clang 3.2 (so we'll assume any
+// clang is new enough).
+#if defined(__clang__) || \
+  (defined(COMPILER_GCC) && \
+   (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 30200)
+#define ATTRIBUTE_DEPRECATED(msg) __attribute__ ((deprecated (msg) ))
+#else
+#define ATTRIBUTE_DEPRECATED(msg)
+#endif
+
 // Tell the compiler to use "initial-exec" mode for a thread-local variable.
 // See http://people.redhat.com/drepper/tls.pdf for the gory details.
 #define ATTRIBUTE_INITIAL_EXEC __attribute__ ((tls_model ("initial-exec")))
@@ -462,54 +413,20 @@ inline void* memrchr(const void* bytes, int find_char, size_t len) {
 #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
 #endif
 
+// Tell ThreadSanitizer to ignore a given function. This can dramatically reduce
+// the running time and memory requirements for racy code when TSAN is active.
+// GCC does not support this attribute at the time of this writing (GCC 4.8).
+#if defined(__llvm__)
+#define ATTRIBUTE_NO_SANITIZE_THREAD \
+    __attribute__((no_sanitize_thread))
+#else
+#define ATTRIBUTE_NO_SANITIZE_THREAD
+#endif
 
 #ifndef HAVE_ATTRIBUTE_SECTION  // may have been pre-set to 0, e.g. for Darwin
 #define HAVE_ATTRIBUTE_SECTION 1
 #endif
 
-#if HAVE_ATTRIBUTE_SECTION  // define section support for the case of GCC
-
-//
-// Tell the compiler/linker to put a given function into a section and define
-// "__start_ ## name" and "__stop_ ## name" symbols to bracket the section.
-// Sections can not span more than none compilation unit.
-// This functionality is supported by GNU linker.
-// Any function with ATTRIBUTE_SECTION must not be inlined, or it will
-// be placed into whatever section its caller is placed into.
-//
-#ifndef ATTRIBUTE_SECTION
-#define ATTRIBUTE_SECTION(name) \
-  __attribute__ ((section (#name))) __attribute__ ((noinline))
-#endif
-
-//
-// Weak section declaration to be used as a global declaration
-// for ATTRIBUTE_SECTION_START|STOP(name) to compile and link
-// even without functions with ATTRIBUTE_SECTION(name).
-// DEFINE_ATTRIBUTE_SECTION should be in the exactly one file; it's
-// a no-op on ELF but not on Mach-O.
-//
-#ifndef DECLARE_ATTRIBUTE_SECTION_VARS
-#define DECLARE_ATTRIBUTE_SECTION_VARS(name) \
-  extern char __start_##name[] ATTRIBUTE_WEAK; \
-  extern char __stop_##name[] ATTRIBUTE_WEAK
-#endif
-#ifndef DEFINE_ATTRIBUTE_SECTION_VARS
-#define INIT_ATTRIBUTE_SECTION_VARS(name)
-#define DEFINE_ATTRIBUTE_SECTION_VARS(name)
-#endif
-
-//
-// Return void* pointers to start/end of a section of code with
-// functions having ATTRIBUTE_SECTION(name).
-// Returns 0 if no such functions exits.
-// One must DECLARE_ATTRIBUTE_SECTION_VARS(name) for this to compile and link.
-//
-#define ATTRIBUTE_SECTION_START(name) (reinterpret_cast<void*>(__start_##name))
-#define ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast<void*>(__stop_##name))
-
-#endif  // HAVE_ATTRIBUTE_SECTION
-
 //
 // The legacy prod71 libc does not provide the stack alignment required for use
 // of SSE intrinsics.  In order to properly use the intrinsics you need to use
@@ -551,6 +468,40 @@ inline void* memrchr(const void* bytes, int find_char, size_t len) {
 #define MUST_USE_RESULT
 #endif
 
+// Annotate a virtual method indicating it must be overriding a virtual
+// method in the parent class.
+// Use like:
+//   virtual void foo() OVERRIDE;
+#if defined(COMPILER_MSVC)
+#define OVERRIDE override
+#elif defined(__clang__)
+#define OVERRIDE override
+#elif defined(COMPILER_GCC) && __cplusplus >= 201103 && \
+      (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40700
+// GCC 4.7 supports explicit virtual overrides when C++11 support is enabled.
+#define OVERRIDE override
+#else
+#define OVERRIDE
+#endif
+
+// Annotate a virtual method indicating that subclasses must not override it,
+// or annotate a class to indicate that it cannot be subclassed.
+// Use like:
+//   virtual void foo() FINAL;
+//   class B FINAL : public A {};
+#if defined(COMPILER_MSVC)
+// TODO(jered): Change this to "final" when chromium no longer uses MSVC 2010.
+#define FINAL sealed
+#elif defined(__clang__)
+#define FINAL final
+#elif defined(COMPILER_GCC) && __cplusplus >= 201103 && \
+      (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40700
+// GCC 4.7 supports explicit virtual overrides when C++11 support is enabled.
+#define FINAL final
+#else
+#define FINAL
+#endif
+
 #if defined(__GNUC__)
 // Defined behavior on some of the uarchs:
 // PREFETCH_HINT_T0:
@@ -570,7 +521,7 @@ enum PrefetchHint {
 #endif
 
 extern inline void prefetch(const char *x, int hint) {
-#if defined(__llvm__) || defined(__INTEL_COMPILER)
+#if defined(__llvm__)
   // In the gcc version of prefetch(), hint is only a constant _after_ inlining
   // (assumed to have been successful).  llvm views things differently, and
   // checks constant-ness _before_ inlining.  This leads to compilation errors
@@ -714,7 +665,6 @@ inline void aligned_free(void *aligned_memory) {
 #define ATTRIBUTE_INITIAL_EXEC
 #define ATTRIBUTE_NONNULL(arg_index)
 #define ATTRIBUTE_NORETURN
-#define HAVE_ATTRIBUTE_SECTION 0
 #define ATTRIBUTE_STACK_ALIGN_FOR_OLD_LIBC
 #define REQUIRE_STACK_ALIGN_TRAMPOLINE (0)
 #define MUST_USE_RESULT
@@ -798,18 +748,6 @@ struct AlignType { typedef char result[Size]; };
 #define ALIGNED_CHAR_ARRAY ALIGNED_CHAR_ARRAY_is_not_available_without_Cplusplus
 #endif // __cplusplus
 
-#if !HAVE_ATTRIBUTE_SECTION  // provide dummy definitions
-
-#define ATTRIBUTE_SECTION(name)
-#define INIT_ATTRIBUTE_SECTION_VARS(name)
-#define DEFINE_ATTRIBUTE_SECTION_VARS(name)
-#define DECLARE_ATTRIBUTE_SECTION_VARS(name)
-#define ATTRIBUTE_SECTION_START(name) (reinterpret_cast<void*>(0))
-#define ATTRIBUTE_SECTION_STOP(name) (reinterpret_cast<void*>(0))
-
-#endif  // !HAVE_ATTRIBUTE_SECTION
-
-
 #ifdef _MSC_VER     /* if Visual C++ */
 
 // This compiler flag can be easily overlooked on MSVC.
@@ -998,7 +936,7 @@ inline int isinf(double x) {
   return 0;
 }
 
-// #include "conflict-signal.h"
+// #include "kudu/conflict-signal.h"
 typedef void (*sig_t)(int);
 
 // These actually belong in errno.h but there's a name confilict in errno
@@ -1042,7 +980,7 @@ typedef short int16_t;
 #endif  // _MSC_VER
 
 #ifdef STL_MSVC  // not always the same as _MSC_VER
-#include "base/port_hash.h"
+#include "kudu/base/port_hash.h"
 #else
 struct PortableHashBase { };
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/proto/types.pb.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/proto/types.pb.cc b/be/src/gutil/proto/types.pb.cc
deleted file mode 100644
index b3ebe01..0000000
--- a/be/src/gutil/proto/types.pb.cc
+++ /dev/null
@@ -1,107 +0,0 @@
-// Generated by the protocol buffer compiler.  DO NOT EDIT!
-
-#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
-#include "gutil/proto/types.pb.h"
-
-#include <algorithm>
-
-#include <google/protobuf/stubs/once.h>
-#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/wire_format_lite_inl.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/reflection_ops.h>
-#include <google/protobuf/wire_format.h>
-// @@protoc_insertion_point(includes)
-
-namespace common {
-
-namespace {
-
-const ::google::protobuf::EnumDescriptor* DataType_descriptor_ = NULL;
-
-}  // namespace
-
-
-void protobuf_AssignDesc_gutil_2fproto_2ftypes_2eproto() {
-  protobuf_AddDesc_gutil_2fproto_2ftypes_2eproto();
-  const ::google::protobuf::FileDescriptor* file =
-    ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
-      "gutil/proto/types.proto");
-  GOOGLE_CHECK(file != NULL);
-  DataType_descriptor_ = file->enum_type(0);
-}
-
-namespace {
-
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
-  ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
-                 &protobuf_AssignDesc_gutil_2fproto_2ftypes_2eproto);
-}
-
-void protobuf_RegisterTypes(const ::std::string&) {
-  protobuf_AssignDescriptorsOnce();
-}
-
-}  // namespace
-
-void protobuf_ShutdownFile_gutil_2fproto_2ftypes_2eproto() {
-}
-
-void protobuf_AddDesc_gutil_2fproto_2ftypes_2eproto() {
-  static bool already_here = false;
-  if (already_here) return;
-  already_here = true;
-  GOOGLE_PROTOBUF_VERIFY_VERSION;
-
-  ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
-    "\n\027gutil/proto/types.proto\022\006common*\247\001\n\010Da"
-    "taType\022\t\n\005INT32\020\001\022\t\n\005INT64\020\002\022\n\n\006UINT32\020\010"
-    "\022\n\n\006UINT64\020\003\022\t\n\005FLOAT\020\t\022\n\n\006DOUBLE\020\005\022\010\n\004B"
-    "OOL\020\006\022\010\n\004DATE\020\n\022\014\n\010DATETIME\020\004\022\n\n\006STRING\020"
-    "\000\022\n\n\006BINARY\020\007\022\r\n\tDATA_TYPE\020\013\022\r\n\tNULL_TYP"
-    "E\020\014B4\n%com.google.datawarehouse.common.p"
-    "rotoB\013CommonEnums", 257);
-  ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
-    "gutil/proto/types.proto", &protobuf_RegisterTypes);
-  ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_gutil_2fproto_2ftypes_2eproto);
-}
-
-// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_gutil_2fproto_2ftypes_2eproto {
-  StaticDescriptorInitializer_gutil_2fproto_2ftypes_2eproto() {
-    protobuf_AddDesc_gutil_2fproto_2ftypes_2eproto();
-  }
-} static_descriptor_initializer_gutil_2fproto_2ftypes_2eproto_;
-
-const ::google::protobuf::EnumDescriptor* DataType_descriptor() {
-  protobuf_AssignDescriptorsOnce();
-  return DataType_descriptor_;
-}
-bool DataType_IsValid(int value) {
-  switch(value) {
-    case 0:
-    case 1:
-    case 2:
-    case 3:
-    case 4:
-    case 5:
-    case 6:
-    case 7:
-    case 8:
-    case 9:
-    case 10:
-    case 11:
-    case 12:
-      return true;
-    default:
-      return false;
-  }
-}
-
-
-// @@protoc_insertion_point(namespace_scope)
-
-}  // namespace common
-
-// @@protoc_insertion_point(global_scope)

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/proto/types.pb.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/proto/types.pb.h b/be/src/gutil/proto/types.pb.h
deleted file mode 100644
index 88f6551..0000000
--- a/be/src/gutil/proto/types.pb.h
+++ /dev/null
@@ -1,94 +0,0 @@
-// Generated by the protocol buffer compiler.  DO NOT EDIT!
-// source: gutil/proto/types.proto
-
-#ifndef PROTOBUF_gutil_2fproto_2ftypes_2eproto__INCLUDED
-#define PROTOBUF_gutil_2fproto_2ftypes_2eproto__INCLUDED
-
-#include <string>
-
-#include <google/protobuf/stubs/common.h>
-
-#if GOOGLE_PROTOBUF_VERSION < 2004000
-#error This file was generated by a newer version of protoc which is
-#error incompatible with your Protocol Buffer headers.  Please update
-#error your headers.
-#endif
-#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
-#error This file was generated by an older version of protoc which is
-#error incompatible with your Protocol Buffer headers.  Please
-#error regenerate this file with a newer version of protoc.
-#endif
-
-#include <google/protobuf/generated_message_util.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
-#include <google/protobuf/generated_message_reflection.h>
-// @@protoc_insertion_point(includes)
-
-namespace common {
-
-// Internal implementation detail -- do not call these.
-void  protobuf_AddDesc_gutil_2fproto_2ftypes_2eproto();
-void protobuf_AssignDesc_gutil_2fproto_2ftypes_2eproto();
-void protobuf_ShutdownFile_gutil_2fproto_2ftypes_2eproto();
-
-
-enum DataType {
-  INT32 = 1,
-  INT64 = 2,
-  UINT32 = 8,
-  UINT64 = 3,
-  FLOAT = 9,
-  DOUBLE = 5,
-  BOOL = 6,
-  DATE = 10,
-  DATETIME = 4,
-  STRING = 0,
-  BINARY = 7,
-  DATA_TYPE = 11,
-  NULL_TYPE = 12
-};
-bool DataType_IsValid(int value);
-const DataType DataType_MIN = STRING;
-const DataType DataType_MAX = NULL_TYPE;
-const int DataType_ARRAYSIZE = DataType_MAX + 1;
-
-const ::google::protobuf::EnumDescriptor* DataType_descriptor();
-inline const ::std::string& DataType_Name(DataType value) {
-  return ::google::protobuf::internal::NameOfEnum(
-    DataType_descriptor(), value);
-}
-inline bool DataType_Parse(
-    const ::std::string& name, DataType* value) {
-  return ::google::protobuf::internal::ParseNamedEnum<DataType>(
-    DataType_descriptor(), name, value);
-}
-// ===================================================================
-
-
-// ===================================================================
-
-
-// ===================================================================
-
-
-// @@protoc_insertion_point(namespace_scope)
-
-}  // namespace common
-
-#ifndef SWIG
-namespace google {
-namespace protobuf {
-
-template <>
-inline const EnumDescriptor* GetEnumDescriptor< common::DataType>() {
-  return common::DataType_descriptor();
-}
-
-}  // namespace google
-}  // namespace protobuf
-#endif  // SWIG
-
-// @@protoc_insertion_point(global_scope)
-
-#endif  // PROTOBUF_gutil_2fproto_2ftypes_2eproto__INCLUDED

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/proto/types.proto
----------------------------------------------------------------------
diff --git a/be/src/gutil/proto/types.proto b/be/src/gutil/proto/types.proto
deleted file mode 100644
index aae0557..0000000
--- a/be/src/gutil/proto/types.proto
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2010 Google Inc. All Rights Reserved.
-
-option java_package = "com.google.datawarehouse.common.proto";
-option java_outer_classname = "CommonEnums";
-
-package common;
-
-// Supported types.
-enum DataType {
-  INT32     = 1;
-  INT64     = 2;
-  UINT32    = 8;
-  UINT64    = 3;
-  FLOAT     = 9;
-  DOUBLE    = 5;
-  BOOL      = 6;
-  DATE      = 10; // Fixed-precision, daily granularity.
-  DATETIME  = 4;  // Fixed-precision, microsecond granularity.
-
-  STRING    = 0;
-  BINARY    = 7;
-
-  DATA_TYPE = 11; // For representing the DataType enum itself.
-  NULL_TYPE = 12; // Untyped NULL literal.
-
-  // Note: next available: 13
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/raw_scoped_refptr_mismatch_checker.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/raw_scoped_refptr_mismatch_checker.h b/be/src/gutil/raw_scoped_refptr_mismatch_checker.h
new file mode 100644
index 0000000..63e4e71
--- /dev/null
+++ b/be/src/gutil/raw_scoped_refptr_mismatch_checker.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef KUDU_GUTIL_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_
+#define KUDU_GUTIL_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_
+
+#include <type_traits>
+
+#include "kudu/gutil/ref_counted.h"
+
+// It is dangerous to post a task with a T* argument where T is a subtype of
+// RefCounted(Base|ThreadSafeBase), since by the time the parameter is used, the
+// object may already have been deleted since it was not held with a
+// scoped_refptr. Example: http://crbug.com/27191
+// The following set of traits are designed to generate a compile error
+// whenever this antipattern is attempted.
+
+namespace kudu {
+
+// This is a base internal implementation file used by task.h and callback.h.
+// Not for public consumption, so we wrap it in namespace internal.
+namespace internal {
+
+template <typename T>
+struct NeedsScopedRefptrButGetsRawPtr {
+#if defined(OS_WIN)
+  enum {
+    value = base::false_type::value
+  };
+#else
+  enum {
+    // Human readable translation: you needed to be a scoped_refptr if you are a
+    // raw pointer type and are convertible to a RefCounted(Base|ThreadSafeBase)
+    // type.
+    value = (std::is_pointer<T>::value &&
+             (std::is_convertible<T, subtle::RefCountedBase*>::value ||
+              std::is_convertible<T, subtle::RefCountedThreadSafeBase*>::value))
+  };
+#endif
+};
+
+template <typename Params>
+struct ParamsUseScopedRefptrCorrectly {
+  enum { value = 0 };
+};
+
+template <>
+struct ParamsUseScopedRefptrCorrectly<std::tuple<>> {
+  enum { value = 1 };
+};
+
+template <typename Head, typename... Tail>
+struct ParamsUseScopedRefptrCorrectly<std::tuple<Head, Tail...>> {
+  enum { value = !NeedsScopedRefptrButGetsRawPtr<Head>::value &&
+                  ParamsUseScopedRefptrCorrectly<std::tuple<Tail...>>::value };
+};
+
+}  // namespace internal
+
+}  // namespace kudu
+
+#endif  // KUDU_GUTIL_RAW_SCOPED_REFPTR_MISMATCH_CHECKER_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/ref_counted.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/ref_counted.cc b/be/src/gutil/ref_counted.cc
new file mode 100644
index 0000000..a15a1e2
--- /dev/null
+++ b/be/src/gutil/ref_counted.cc
@@ -0,0 +1,95 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "kudu/gutil/ref_counted.h"
+
+#include <glog/logging.h>
+#include "kudu/gutil/threading/thread_collision_warner.h"
+
+namespace kudu {
+
+namespace subtle {
+
+RefCountedBase::RefCountedBase()
+    : ref_count_(0)
+#ifndef NDEBUG
+    , in_dtor_(false)
+#endif
+    {
+}
+
+RefCountedBase::~RefCountedBase() {
+#ifndef NDEBUG
+  DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()";
+#endif
+}
+
+void RefCountedBase::AddRef() const {
+  // TODO(maruel): Add back once it doesn't assert 500 times/sec.
+  // Current thread books the critical section "AddRelease" without release it.
+  // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
+#ifndef NDEBUG
+  DCHECK(!in_dtor_);
+#endif
+  ++ref_count_;
+}
+
+bool RefCountedBase::Release() const {
+  // TODO(maruel): Add back once it doesn't assert 500 times/sec.
+  // Current thread books the critical section "AddRelease" without release it.
+  // DFAKE_SCOPED_LOCK_THREAD_LOCKED(add_release_);
+#ifndef NDEBUG
+  DCHECK(!in_dtor_);
+#endif
+  if (--ref_count_ == 0) {
+#ifndef NDEBUG
+    in_dtor_ = true;
+#endif
+    return true;
+  }
+  return false;
+}
+
+bool RefCountedThreadSafeBase::HasOneRef() const {
+  return base::RefCountIsOne(
+      &const_cast<RefCountedThreadSafeBase*>(this)->ref_count_);
+}
+
+RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) {
+#ifndef NDEBUG
+  in_dtor_ = false;
+#endif
+}
+
+RefCountedThreadSafeBase::~RefCountedThreadSafeBase() {
+#ifndef NDEBUG
+  DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without "
+                      "calling Release()";
+#endif
+}
+
+void RefCountedThreadSafeBase::AddRef() const {
+#ifndef NDEBUG
+  DCHECK(!in_dtor_);
+#endif
+  base::RefCountInc(&ref_count_);
+}
+
+bool RefCountedThreadSafeBase::Release() const {
+#ifndef NDEBUG
+  DCHECK(!in_dtor_);
+  DCHECK(!base::RefCountIsZero(&ref_count_));
+#endif
+  if (!base::RefCountDec(&ref_count_)) {
+#ifndef NDEBUG
+    in_dtor_ = true;
+#endif
+    return true;
+  }
+  return false;
+}
+
+}  // namespace subtle
+
+}  // namespace kudu

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/ref_counted.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/ref_counted.h b/be/src/gutil/ref_counted.h
new file mode 100644
index 0000000..8b6a553
--- /dev/null
+++ b/be/src/gutil/ref_counted.h
@@ -0,0 +1,354 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_MEMORY_REF_COUNTED_H_
+#define BASE_MEMORY_REF_COUNTED_H_
+
+#include <cassert>
+
+#include "kudu/gutil/atomic_refcount.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/threading/thread_collision_warner.h"
+
+namespace kudu {
+namespace subtle {
+
+typedef Atomic32 AtomicRefCount;
+
+class RefCountedBase {
+ public:
+  bool HasOneRef() const { return ref_count_ == 1; }
+
+ protected:
+  RefCountedBase();
+  ~RefCountedBase();
+
+  void AddRef() const;
+
+  // Returns true if the object should self-delete.
+  bool Release() const;
+
+ private:
+  mutable int ref_count_;
+#ifndef NDEBUG
+  mutable bool in_dtor_;
+#endif
+
+  DFAKE_MUTEX(add_release_);
+
+  DISALLOW_COPY_AND_ASSIGN(RefCountedBase);
+};
+
+class RefCountedThreadSafeBase {
+ public:
+  bool HasOneRef() const;
+
+ protected:
+  RefCountedThreadSafeBase();
+  ~RefCountedThreadSafeBase();
+
+  void AddRef() const;
+
+  // Returns true if the object should self-delete.
+  bool Release() const;
+
+ private:
+  mutable AtomicRefCount ref_count_;
+#ifndef NDEBUG
+  mutable bool in_dtor_;
+#endif
+
+  DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafeBase);
+};
+
+}  // namespace subtle
+
+//
+// A base class for reference counted classes.  Otherwise, known as a cheap
+// knock-off of WebKit's RefCounted<T> class.  To use this guy just extend your
+// class from it like so:
+//
+//   class MyFoo : public RefCounted<MyFoo> {
+//    ...
+//    private:
+//     friend class RefCounted<MyFoo>;
+//     ~MyFoo();
+//   };
+//
+// You should always make your destructor private, to avoid any code deleting
+// the object accidently while there are references to it.
+template <class T>
+class RefCounted : public subtle::RefCountedBase {
+ public:
+  RefCounted() {}
+
+  void AddRef() const {
+    subtle::RefCountedBase::AddRef();
+  }
+
+  void Release() const {
+    if (subtle::RefCountedBase::Release()) {
+      delete static_cast<const T*>(this);
+    }
+  }
+
+ protected:
+  ~RefCounted() {}
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(RefCounted<T>);
+};
+
+// Forward declaration.
+template <class T, typename Traits> class RefCountedThreadSafe;
+
+// Default traits for RefCountedThreadSafe<T>.  Deletes the object when its ref
+// count reaches 0.  Overload to delete it on a different thread etc.
+template<typename T>
+struct DefaultRefCountedThreadSafeTraits {
+  static void Destruct(const T* x) {
+    // Delete through RefCountedThreadSafe to make child classes only need to be
+    // friend with RefCountedThreadSafe instead of this struct, which is an
+    // implementation detail.
+    RefCountedThreadSafe<T,
+                         DefaultRefCountedThreadSafeTraits>::DeleteInternal(x);
+  }
+};
+
+//
+// A thread-safe variant of RefCounted<T>
+//
+//   class MyFoo : public RefCountedThreadSafe<MyFoo> {
+//    ...
+//   };
+//
+// If you're using the default trait, then you should add compile time
+// asserts that no one else is deleting your object.  i.e.
+//    private:
+//     friend class RefCountedThreadSafe<MyFoo>;
+//     ~MyFoo();
+template <class T, typename Traits = DefaultRefCountedThreadSafeTraits<T> >
+class RefCountedThreadSafe : public subtle::RefCountedThreadSafeBase {
+ public:
+  RefCountedThreadSafe() {}
+
+  void AddRef() const {
+    subtle::RefCountedThreadSafeBase::AddRef();
+  }
+
+  void Release() const {
+    if (subtle::RefCountedThreadSafeBase::Release()) {
+      Traits::Destruct(static_cast<const T*>(this));
+    }
+  }
+
+ protected:
+  ~RefCountedThreadSafe() {}
+
+ private:
+  friend struct DefaultRefCountedThreadSafeTraits<T>;
+  static void DeleteInternal(const T* x) { delete x; }
+
+  DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafe);
+};
+
+//
+// A thread-safe wrapper for some piece of data so we can place other
+// things in scoped_refptrs<>.
+//
+template<typename T>
+class RefCountedData
+    : public kudu::RefCountedThreadSafe< kudu::RefCountedData<T> > {
+ public:
+  RefCountedData() : data() {}
+  RefCountedData(const T& in_value) : data(in_value) {}
+
+  T data;
+
+ private:
+  friend class kudu::RefCountedThreadSafe<kudu::RefCountedData<T> >;
+  ~RefCountedData() {}
+};
+
+}  // namespace kudu
+
+//
+// A smart pointer class for reference counted objects.  Use this class instead
+// of calling AddRef and Release manually on a reference counted object to
+// avoid common memory leaks caused by forgetting to Release an object
+// reference.  Sample usage:
+//
+//   class MyFoo : public RefCounted<MyFoo> {
+//    ...
+//   };
+//
+//   void some_function() {
+//     scoped_refptr<MyFoo> foo = new MyFoo();
+//     foo->Method(param);
+//     // |foo| is released when this function returns
+//   }
+//
+//   void some_other_function() {
+//     scoped_refptr<MyFoo> foo = new MyFoo();
+//     ...
+//     foo = NULL;  // explicitly releases |foo|
+//     ...
+//     if (foo)
+//       foo->Method(param);
+//   }
+//
+// The above examples show how scoped_refptr<T> acts like a pointer to T.
+// Given two scoped_refptr<T> classes, it is also possible to exchange
+// references between the two objects, like so:
+//
+//   {
+//     scoped_refptr<MyFoo> a = new MyFoo();
+//     scoped_refptr<MyFoo> b;
+//
+//     b.swap(a);
+//     // now, |b| references the MyFoo object, and |a| references NULL.
+//   }
+//
+// To make both |a| and |b| in the above example reference the same MyFoo
+// object, simply use the assignment operator:
+//
+//   {
+//     scoped_refptr<MyFoo> a = new MyFoo();
+//     scoped_refptr<MyFoo> b;
+//
+//     b = a;
+//     // now, |a| and |b| each own a reference to the same MyFoo object.
+//   }
+//
+template <class T>
+class scoped_refptr {
+ public:
+  typedef T element_type;
+
+  scoped_refptr() : ptr_(NULL) {
+  }
+
+  scoped_refptr(T* p) : ptr_(p) {
+    if (ptr_)
+      ptr_->AddRef();
+  }
+
+  scoped_refptr(const scoped_refptr<T>& r) : ptr_(r.ptr_) {
+    if (ptr_)
+      ptr_->AddRef();
+  }
+
+  template <typename U>
+  scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) {
+    if (ptr_)
+      ptr_->AddRef();
+  }
+
+  template <typename U>
+  scoped_refptr(scoped_refptr<U>&& r) : ptr_(r.get()) {
+    r.ptr_ = nullptr;
+  }
+
+  ~scoped_refptr() {
+    if (ptr_)
+      ptr_->Release();
+  }
+
+  T* get() const { return ptr_; }
+
+// The following is disabled in Cloudera's version of this file since it's
+// relatively dangerous. Chromium is planning on doing the same in their
+// tree, but hasn't done so yet. See http://code.google.com/p/chromium/issues/detail?id=110610
+#if SCOPED_REFPTR_ALLOW_IMPLICIT_CONVERSION_TO_PTR
+  // Allow scoped_refptr<C> to be used in boolean expression
+  // and comparison operations.
+  operator T*() const { return ptr_; }
+#else
+  typedef T* scoped_refptr::*Testable;
+  operator Testable() const { return ptr_ ? &scoped_refptr::ptr_ : NULL; }
+#endif
+
+  T* operator->() const {
+    assert(ptr_ != NULL);
+    return ptr_;
+  }
+
+  scoped_refptr<T>& operator=(T* p) {
+    // AddRef first so that self assignment should work
+    if (p)
+      p->AddRef();
+    T* old_ptr = ptr_;
+    ptr_ = p;
+    if (old_ptr)
+      old_ptr->Release();
+    return *this;
+  }
+
+  scoped_refptr<T>& operator=(const scoped_refptr<T>& r) {
+    return *this = r.ptr_;
+  }
+
+  template <typename U>
+  scoped_refptr<T>& operator=(const scoped_refptr<U>& r) {
+    return *this = r.get();
+  }
+
+  scoped_refptr<T>& operator=(scoped_refptr<T>&& r) {
+    scoped_refptr<T>(r).swap(*this);
+    return *this;
+  }
+
+  template <typename U>
+  scoped_refptr<T>& operator=(scoped_refptr<U>&& r) {
+    scoped_refptr<T>(r).swap(*this);
+    return *this;
+  }
+
+  void swap(T** pp) {
+    T* p = ptr_;
+    ptr_ = *pp;
+    *pp = p;
+  }
+
+  void swap(scoped_refptr<T>& r) {
+    swap(&r.ptr_);
+  }
+
+  // Like gscoped_ptr::reset(), drops a reference on the currently held object
+  // (if any), and adds a reference to the passed-in object (if not NULL).
+  void reset(T* p = NULL) {
+    *this = p;
+  }
+
+ protected:
+  T* ptr_;
+
+ private:
+  template <typename U> friend class scoped_refptr;
+};
+
+// Handy utility for creating a scoped_refptr<T> out of a T* explicitly without
+// having to retype all the template arguments
+template <typename T>
+scoped_refptr<T> make_scoped_refptr(T* t) {
+  return scoped_refptr<T>(t);
+}
+
+// equal_to and hash implementations for templated scoped_refptrs suitable for
+// use with STL unordered_* containers.
+template <class T>
+struct ScopedRefPtrEqualToFunctor {
+  bool operator()(const scoped_refptr<T>& x, const scoped_refptr<T>& y) const {
+    return x.get() == y.get();
+  }
+};
+
+template <class T>
+struct ScopedRefPtrHashFunctor {
+  size_t operator()(const scoped_refptr<T>& p) const {
+    return reinterpret_cast<size_t>(p.get());
+  }
+};
+
+#endif  // BASE_MEMORY_REF_COUNTED_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/ref_counted_memory.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/ref_counted_memory.cc b/be/src/gutil/ref_counted_memory.cc
new file mode 100644
index 0000000..1d695d9
--- /dev/null
+++ b/be/src/gutil/ref_counted_memory.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "kudu/gutil/ref_counted_memory.h"
+
+#include <stdlib.h>
+
+#include <glog/logging.h>
+
+namespace kudu {
+
+bool RefCountedMemory::Equals(
+    const scoped_refptr<RefCountedMemory>& other) const {
+  return other.get() &&
+         size() == other->size() &&
+         (memcmp(front(), other->front(), size()) == 0);
+}
+
+RefCountedMemory::RefCountedMemory() {}
+
+RefCountedMemory::~RefCountedMemory() {}
+
+const unsigned char* RefCountedStaticMemory::front() const {
+  return data_;
+}
+
+size_t RefCountedStaticMemory::size() const {
+  return length_;
+}
+
+RefCountedStaticMemory::~RefCountedStaticMemory() {}
+
+RefCountedBytes::RefCountedBytes() {}
+
+RefCountedBytes::RefCountedBytes(std::vector<unsigned char> initializer)
+    : data_(std::move(initializer)) {}
+
+RefCountedBytes::RefCountedBytes(const unsigned char* p, size_t size)
+    : data_(p, p + size) {}
+
+RefCountedBytes* RefCountedBytes::TakeVector(
+    std::vector<unsigned char>* to_destroy) {
+  auto bytes = new RefCountedBytes;
+  bytes->data_.swap(*to_destroy);
+  return bytes;
+}
+
+const unsigned char* RefCountedBytes::front() const {
+  // STL will assert if we do front() on an empty vector, but calling code
+  // expects a NULL.
+  return size() ? &data_.front() : nullptr;
+}
+
+size_t RefCountedBytes::size() const {
+  return data_.size();
+}
+
+RefCountedBytes::~RefCountedBytes() {}
+
+RefCountedString::RefCountedString() {}
+
+RefCountedString::~RefCountedString() {}
+
+// static
+RefCountedString* RefCountedString::TakeString(std::string* to_destroy) {
+  auto self = new RefCountedString;
+  to_destroy->swap(self->data_);
+  return self;
+}
+
+const unsigned char* RefCountedString::front() const {
+  return data_.empty() ? nullptr :
+         reinterpret_cast<const unsigned char*>(data_.data());
+}
+
+size_t RefCountedString::size() const {
+  return data_.size();
+}
+
+RefCountedMallocedMemory::RefCountedMallocedMemory(
+    void* data, size_t length)
+    : data_(reinterpret_cast<unsigned char*>(data)), length_(length) {
+  DCHECK(data || length == 0);
+}
+
+const unsigned char* RefCountedMallocedMemory::front() const {
+  return length_ ? data_ : nullptr;
+}
+
+size_t RefCountedMallocedMemory::size() const {
+  return length_;
+}
+
+RefCountedMallocedMemory::~RefCountedMallocedMemory() {
+  free(data_);
+}
+
+}  //  namespace kudu

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/ref_counted_memory.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/ref_counted_memory.h b/be/src/gutil/ref_counted_memory.h
new file mode 100644
index 0000000..550a142
--- /dev/null
+++ b/be/src/gutil/ref_counted_memory.h
@@ -0,0 +1,150 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef KUDU_GUTIL_REF_COUNTED_MEMORY_H_
+#define KUDU_GUTIL_REF_COUNTED_MEMORY_H_
+
+#include <string>
+#include <vector>
+
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/ref_counted.h"
+#include "kudu/gutil/port.h"
+
+#ifndef BASE_EXPORT
+#define BASE_EXPORT
+#endif
+
+namespace kudu {
+
+// A generic interface to memory. This object is reference counted because one
+// of its two subclasses own the data they carry, and we need to have
+// heterogeneous containers of these two types of memory.
+class BASE_EXPORT RefCountedMemory
+    : public RefCountedThreadSafe<RefCountedMemory> {
+ public:
+  // Retrieves a pointer to the beginning of the data we point to. If the data
+  // is empty, this will return NULL.
+  virtual const unsigned char* front() const = 0;
+
+  // Size of the memory pointed to.
+  virtual size_t size() const = 0;
+
+  // Returns true if |other| is byte for byte equal.
+  bool Equals(const scoped_refptr<RefCountedMemory>& other) const;
+
+  // Handy method to simplify calling front() with a reinterpret_cast.
+  template<typename T> const T* front_as() const {
+    return reinterpret_cast<const T*>(front());
+  }
+
+ protected:
+  friend class RefCountedThreadSafe<RefCountedMemory>;
+  RefCountedMemory();
+  virtual ~RefCountedMemory();
+};
+
+// An implementation of RefCountedMemory, where the ref counting does not
+// matter.
+class BASE_EXPORT RefCountedStaticMemory : public RefCountedMemory {
+ public:
+  RefCountedStaticMemory()
+      : data_(NULL), length_(0) {}
+  RefCountedStaticMemory(const void* data, size_t length)
+      : data_(static_cast<const unsigned char*>(length ? data : NULL)),
+        length_(length) {}
+
+  // Overridden from RefCountedMemory:
+  virtual const unsigned char* front() const OVERRIDE;
+  virtual size_t size() const OVERRIDE;
+
+ private:
+  virtual ~RefCountedStaticMemory();
+
+  const unsigned char* data_;
+  size_t length_;
+
+  DISALLOW_COPY_AND_ASSIGN(RefCountedStaticMemory);
+};
+
+// An implementation of RefCountedMemory, where we own the data in a vector.
+class BASE_EXPORT RefCountedBytes : public RefCountedMemory {
+ public:
+  RefCountedBytes();
+
+  // Constructs a RefCountedBytes object by _copying_ from |initializer|.
+  explicit RefCountedBytes(std::vector<unsigned char> initializer);
+
+  // Constructs a RefCountedBytes object by copying |size| bytes from |p|.
+  RefCountedBytes(const unsigned char* p, size_t size);
+
+  // Constructs a RefCountedBytes object by performing a swap. (To non
+  // destructively build a RefCountedBytes, use the constructor that takes a
+  // vector.)
+  static RefCountedBytes* TakeVector(std::vector<unsigned char>* to_destroy);
+
+  // Overridden from RefCountedMemory:
+  virtual const unsigned char* front() const OVERRIDE;
+  virtual size_t size() const OVERRIDE;
+
+  const std::vector<unsigned char>& data() const { return data_; }
+  std::vector<unsigned char>& data() { return data_; }
+
+ private:
+  virtual ~RefCountedBytes();
+
+  std::vector<unsigned char> data_;
+
+  DISALLOW_COPY_AND_ASSIGN(RefCountedBytes);
+};
+
+// An implementation of RefCountedMemory, where the bytes are stored in an STL
+// string. Use this if your data naturally arrives in that format.
+class BASE_EXPORT RefCountedString : public RefCountedMemory {
+ public:
+  RefCountedString();
+
+  // Constructs a RefCountedString object by performing a swap. (To non
+  // destructively build a RefCountedString, use the default constructor and
+  // copy into object->data()).
+  static RefCountedString* TakeString(std::string* to_destroy);
+
+  // Overridden from RefCountedMemory:
+  virtual const unsigned char* front() const OVERRIDE;
+  virtual size_t size() const OVERRIDE;
+
+  const std::string& data() const { return data_; }
+  std::string& data() { return data_; }
+
+ private:
+  virtual ~RefCountedString();
+
+  std::string data_;
+
+  DISALLOW_COPY_AND_ASSIGN(RefCountedString);
+};
+
+// An implementation of RefCountedMemory that holds a chunk of memory
+// previously allocated with malloc or calloc, and that therefore must be freed
+// using free().
+class BASE_EXPORT RefCountedMallocedMemory : public RefCountedMemory {
+ public:
+  RefCountedMallocedMemory(void* data, size_t length);
+
+  // Overridden from RefCountedMemory:
+  virtual const unsigned char* front() const OVERRIDE;
+  virtual size_t size() const OVERRIDE;
+
+ private:
+  virtual ~RefCountedMallocedMemory();
+
+  unsigned char* data_;
+  size_t length_;
+
+  DISALLOW_COPY_AND_ASSIGN(RefCountedMallocedMemory);
+};
+
+}  // namespace kudu
+
+#endif  // KUDU_GUTIL_REF_COUNTED_MEMORY_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/singleton.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/singleton.h b/be/src/gutil/singleton.h
index d1e1667..61e5ea5 100644
--- a/be/src/gutil/singleton.h
+++ b/be/src/gutil/singleton.h
@@ -60,8 +60,9 @@
 #include <stddef.h>
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/once.h"
+
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/once.h"
 
 namespace util {
 namespace gtl {


[12/14] incubator-impala git commit: IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

Posted by he...@apache.org.
IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

* Copy gutil from Kudu
* Minimal changes to gutil/CMakeLists.txt

Change-Id: Ic708a9c4e76ede17af9b06e0a0a8e9ae7d357960
Reviewed-on: http://gerrit.cloudera.org:8080/5687
Reviewed-by: Dan Hecht <dh...@cloudera.com>
Tested-by: Henry Robinson <he...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/02f3e3fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/02f3e3fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/02f3e3fc

Branch: refs/heads/master
Commit: 02f3e3fcc1c58bcaf5080ddee939c9081412a553
Parents: ff095f1
Author: Henry Robinson <he...@cloudera.com>
Authored: Tue Oct 25 14:45:32 2016 -0700
Committer: Henry Robinson <he...@cloudera.com>
Committed: Wed Mar 29 02:52:21 2017 +0000

----------------------------------------------------------------------
 be/src/gutil/CMakeLists.txt                     |  110 +-
 be/src/gutil/algorithm.h                        |  463 ---
 be/src/gutil/atomic_refcount.h                  |   35 +-
 be/src/gutil/atomicops-internals-powerpc.h      |   29 +-
 be/src/gutil/atomicops-internals-tsan.h         |  217 ++
 be/src/gutil/atomicops-internals-x86.cc         |   47 +-
 be/src/gutil/atomicops-internals-x86.h          |   71 +-
 be/src/gutil/atomicops.h                        |   16 +-
 .../auxiliary/atomicops-internals-arm-generic.h |    4 +-
 .../auxiliary/atomicops-internals-arm-v6plus.h  |    2 +-
 .../auxiliary/atomicops-internals-macosx.h      |  397 ---
 .../auxiliary/atomicops-internals-windows.h     |    2 +-
 be/src/gutil/basictypes.h                       |    4 +-
 be/src/gutil/bind.h                             |  539 ++++
 be/src/gutil/bind.h.pump                        |  153 +
 be/src/gutil/bind_helpers.h                     |  551 ++++
 be/src/gutil/bind_internal.h                    | 2695 ++++++++++++++++++
 be/src/gutil/bind_internal.h.pump               |  464 +++
 be/src/gutil/bits.cc                            |   18 +-
 be/src/gutil/bits.h                             |   46 +-
 be/src/gutil/callback.h                         |  765 +++++
 be/src/gutil/callback.h.pump                    |  436 +++
 be/src/gutil/callback_forward.h                 |   17 +
 be/src/gutil/callback_internal.cc               |   36 +
 be/src/gutil/callback_internal.h                |  177 ++
 be/src/gutil/casts.h                            |   18 +-
 be/src/gutil/charmap.h                          |   10 +-
 be/src/gutil/cpu.cc                             |  289 ++
 be/src/gutil/cpu.h                              |   90 +
 be/src/gutil/cycleclock-inl.h                   |   39 +-
 be/src/gutil/dynamic_annotations.c              |  173 ++
 be/src/gutil/dynamic_annotations.cc             |  173 --
 be/src/gutil/dynamic_annotations.h              |   62 +-
 be/src/gutil/endian.h                           |   35 +-
 be/src/gutil/fixedarray.h                       |   31 +-
 be/src/gutil/gscoped_ptr.h                      |   50 +-
 be/src/gutil/hash/builtin_type_hash.h           |    8 +-
 be/src/gutil/hash/city.cc                       |   14 +-
 be/src/gutil/hash/city.h                        |    4 +-
 be/src/gutil/hash/hash.cc                       |   18 +-
 be/src/gutil/hash/hash.h                        |   59 +-
 be/src/gutil/hash/hash128to64.h                 |    4 +-
 be/src/gutil/hash/jenkins.cc                    |    8 +-
 be/src/gutil/hash/jenkins.h                     |    2 +-
 be/src/gutil/hash/jenkins_lookup2.h             |    4 +-
 be/src/gutil/hash/legacy_hash.h                 |    9 +-
 be/src/gutil/hash/string_hash.h                 |   10 +-
 be/src/gutil/int128.cc                          |    4 +-
 be/src/gutil/int128.h                           |    2 +-
 be/src/gutil/integral_types.h                   |   26 +-
 be/src/gutil/linux_syscall_support.h            |   16 +-
 be/src/gutil/logging-inl.h                      |   23 +-
 be/src/gutil/macros.h                           |   27 +-
 be/src/gutil/manual_constructor.h               |    2 +-
 be/src/gutil/map-util.h                         |  277 +-
 be/src/gutil/mathlimits.cc                      |   30 +-
 be/src/gutil/mathlimits.h                       |   34 +-
 be/src/gutil/move.h                             |   15 +-
 be/src/gutil/once.cc                            |    8 +-
 be/src/gutil/once.h                             |   12 +-
 be/src/gutil/paranoid.h                         |    3 +-
 be/src/gutil/port.h                             |  178 +-
 be/src/gutil/proto/types.pb.cc                  |  107 -
 be/src/gutil/proto/types.pb.h                   |   94 -
 be/src/gutil/proto/types.proto                  |   28 -
 .../gutil/raw_scoped_refptr_mismatch_checker.h  |   63 +
 be/src/gutil/ref_counted.cc                     |   95 +
 be/src/gutil/ref_counted.h                      |  354 +++
 be/src/gutil/ref_counted_memory.cc              |   99 +
 be/src/gutil/ref_counted_memory.h               |  150 +
 be/src/gutil/singleton.h                        |    5 +-
 be/src/gutil/sparsetable.h                      | 1838 ------------
 be/src/gutil/spinlock.cc                        |   10 +-
 be/src/gutil/spinlock.h                         |    8 +-
 be/src/gutil/spinlock_internal.cc               |    8 +-
 be/src/gutil/spinlock_internal.h                |    4 +-
 be/src/gutil/spinlock_linux-inl.h               |    2 +-
 be/src/gutil/spinlock_win32-inl.h               |   55 +-
 be/src/gutil/stl_util.h                         |   58 +-
 be/src/gutil/stringprintf.cc                    |   10 +-
 be/src/gutil/stringprintf.h                     |    2 +-
 be/src/gutil/strings/ascii_ctype.cc             |    2 +-
 be/src/gutil/strings/charset.cc                 |    2 +-
 be/src/gutil/strings/charset.h                  |    2 +-
 be/src/gutil/strings/escaping.cc                |   35 +-
 be/src/gutil/strings/escaping.h                 |    9 +-
 be/src/gutil/strings/fastmem.h                  |    4 +-
 be/src/gutil/strings/human_readable.cc          |   26 +-
 be/src/gutil/strings/human_readable.h           |    6 +-
 be/src/gutil/strings/join.cc                    |   32 +-
 be/src/gutil/strings/join.h                     |   58 +-
 be/src/gutil/strings/memutil.cc                 |   18 +-
 be/src/gutil/strings/memutil.h                  |    2 +-
 be/src/gutil/strings/numbers.cc                 |   87 +-
 be/src/gutil/strings/numbers.h                  |   39 +-
 be/src/gutil/strings/serialize.cc               |   69 +-
 be/src/gutil/strings/serialize.h                |   15 +-
 be/src/gutil/strings/split.cc                   |   42 +-
 be/src/gutil/strings/split.h                    |   23 +-
 be/src/gutil/strings/split_internal.h           |   22 +-
 be/src/gutil/strings/strcat.cc                  |   12 +-
 be/src/gutil/strings/strcat.h                   |   22 +-
 be/src/gutil/strings/string_util-test.cc        |   58 +
 be/src/gutil/strings/stringpiece.cc             |   37 +-
 be/src/gutil/strings/stringpiece.h              |   47 +-
 be/src/gutil/strings/strip.cc                   |   16 +-
 be/src/gutil/strings/strip.h                    |    4 +-
 be/src/gutil/strings/substitute.cc              |   16 +-
 be/src/gutil/strings/substitute.h               |    6 +-
 be/src/gutil/strings/util.cc                    |  289 +-
 be/src/gutil/strings/util.h                     |   26 +-
 be/src/gutil/strtoint.cc                        |    4 +-
 be/src/gutil/strtoint.h                         |    6 +-
 be/src/gutil/synchronization_profiling.h        |    2 +-
 be/src/gutil/sysinfo.cc                         |   41 +-
 be/src/gutil/sysinfo.h                          |    4 +
 be/src/gutil/template_util.h                    |   31 +
 .../gutil/threading/thread_collision_warner.cc  |   82 +
 .../gutil/threading/thread_collision_warner.h   |  248 ++
 be/src/gutil/type_traits.h                      |   12 +-
 be/src/gutil/utf/rune.c                         |  350 +++
 be/src/gutil/utf/rune.cc                        |  354 ---
 be/src/gutil/walltime.cc                        |   47 +-
 be/src/gutil/walltime.h                         |   66 +-
 124 files changed, 9709 insertions(+), 4615 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/be/src/gutil/CMakeLists.txt b/be/src/gutil/CMakeLists.txt
index bb24bc1..f895679 100644
--- a/be/src/gutil/CMakeLists.txt
+++ b/be/src/gutil/CMakeLists.txt
@@ -15,69 +15,59 @@
 # specific language governing permissions and limitations
 # under the License.
 
-cmake_minimum_required(VERSION 2.6)
-
-set(LIBRARY_OUTPUT_PATH "${BUILD_OUTPUT_ROOT_DIRECTORY}/gutil")
-set(EXECUTABLE_OUTPUT_PATH "${BUILD_OUTPUT_ROOT_DIRECTORY}/gutil")
-
-# Ignore the code in proto/ for now until needed; otherwise this adds an extra dependency
-# on protoc to the build for no gain.
-
-# PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS
-#   SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../
-#   BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR}/../
-#   )
-# SET(GUTIL_SRCS ${PROTO_SRCS})
-
-# PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS
-#   SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../
-#   BINARY_ROOT ${CMAKE_CURRENT_BINARY_DIR}/../
-#   PROTO_FILES proto/types.proto
-#   )
-# SET(GUTIL_SRCS ${GUTIL_SRCS} ${PROTO_SRCS})
-
-INCLUDE_DIRECTORIES($ENV{IMPALA_HOME}/thirdparty/)
 INCLUDE_DIRECTORIES(${GLOG_INCLUDE_DIR})
 
-ADD_LIBRARY(gutil
-#  ${GUTIL_SRCS}
-./bits.cc
-./dynamic_annotations.cc
-./stringprintf.cc
-./strings/memutil.cc
-./strings/charset.cc
-./strings/util.cc
-./strings/human_readable.cc
-./strings/join.cc
-./strings/numbers.cc
-./strings/split.cc
-./strings/strip.cc
-./strings/ascii_ctype.cc
-./strings/escaping.cc
-./strings/stringpiece.cc
-./strings/substitute.cc
-./strings/strcat.cc
-./strings/serialize.cc
-./mathlimits.cc
-./int128.cc
-./strtoint.cc
-./once.cc
-./atomicops-internals-x86.cc
-./spinlock.cc
-./spinlock_internal.cc
-./sysinfo.cc
-./walltime.cc
-./hash/hash.cc
-./hash/jenkins.cc
-./hash/city.cc
-./utf/rune.cc
-)
+set(GUTIL_SRCS
+  atomicops-internals-x86.cc
+  bits.cc
+  callback_internal.cc
+  cpu.cc
+  dynamic_annotations.c
+  hash/city.cc
+  hash/hash.cc
+  hash/jenkins.cc
+  int128.cc
+  mathlimits.cc
+  once.cc
+  ref_counted.cc
+  ref_counted_memory.cc
+  spinlock.cc
+  spinlock_internal.cc
+  stringprintf.cc
+  strings/ascii_ctype.cc
+  strings/charset.cc
+  strings/escaping.cc
+  strings/human_readable.cc
+  strings/join.cc
+  strings/memutil.cc
+  strings/numbers.cc
+  strings/serialize.cc
+  strings/split.cc
+  strings/strcat.cc
+  strings/stringpiece.cc
+  strings/strip.cc
+  strings/substitute.cc
+  strings/util.cc
+  strtoint.cc
+  sysinfo.cc
+  threading/thread_collision_warner.cc
+  utf/rune.c
+  walltime.cc)
 
+set(GUTIL_LIBS
+  glog
+  protobuf)
 
+if (NOT APPLE)
+  set(GUTIL_LIBS
+    ${GUTIL_LIBS}
+    rt) # clock_gettime() requires -lrt
+endif()
 
-# Disable warnings which trigger a lot in the Google code:
-SET_TARGET_PROPERTIES(gutil PROPERTIES
-  COMPILE_FLAGS "${CXX_COMMON_FLAGS} -funsigned-char -Wno-deprecated -Wno-char-subscripts -fPIC")
+ADD_EXPORTABLE_LIBRARY(gutil
+  SRCS ${GUTIL_SRCS}
+  DEPS ${GUTIL_LIBS}
+  # Disable warnings which trigger a lot in the Google code:
+  COMPILE_FLAGS "-funsigned-char -Wno-deprecated -Wno-char-subscripts")
 
-TARGET_LINK_LIBRARIES(gutil glogstatic gflagsstatic)
-SET(GUTIL_LIBS gutil)
+add_kudu_test(strings/string_util-test)

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/algorithm.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/algorithm.h b/be/src/gutil/algorithm.h
deleted file mode 100644
index 3322df3..0000000
--- a/be/src/gutil/algorithm.h
+++ /dev/null
@@ -1,463 +0,0 @@
-// Copyright 2006 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-// ---
-//
-//
-// This file contains some Google extensions to the standard
-// <algorithm> C++ header. Many of these algorithms were in the
-// original STL before it was proposed for standardization.
-
-#ifndef UTIL_GTL_ALGORITHM_H_
-#define UTIL_GTL_ALGORITHM_H_
-
-#include <stddef.h>
-#include <algorithm>
-using std::copy;
-using std::max;
-using std::min;
-using std::reverse;
-using std::sort;
-using std::swap;
-#include <functional>
-using std::binary_function;
-using std::less;
-#include <iterator>
-using std::back_insert_iterator;
-using std::iterator_traits;
-#include <utility>
-using std::make_pair;
-using std::pair;
-
-namespace util {
-namespace gtl {
-
-// Returns true if [first, last) contains an element equal to value.
-// Complexity: linear.
-template<typename InputIterator, typename EqualityComparable>
-bool contains(InputIterator first, InputIterator last,
-              const EqualityComparable& value) {
-  return std::find(first, last, value) != last;
-}
-
-// There is no contains_if().  Use any() instead.
-
-template<typename InputIterator, typename ForwardIterator>
-bool contains_some_of(InputIterator first1, InputIterator last1,
-                      ForwardIterator first2, ForwardIterator last2) {
-  return std::find_first_of(first1, last1, first2, last2) != last1;
-}
-
-template<typename InputIterator, typename ForwardIterator, typename Predicate>
-bool contains_some_of(InputIterator first1, InputIterator last1,
-                      ForwardIterator first2, ForwardIterator last2,
-                      Predicate pred) {
-  return std::find_first_of(first1, last1, first2, last2, pred) != last1;
-}
-
-template<typename InputIterator, typename EqualityComparable>
-typename std::iterator_traits<InputIterator>::pointer
-find_or_null(InputIterator first, InputIterator last,
-             const EqualityComparable& value) {
-  const InputIterator it = std::find(first, last, value);
-  return it != last ? &*it : NULL;
-}
-
-template<typename InputIterator, typename Predicate>
-typename std::iterator_traits<InputIterator>::pointer
-find_if_or_null(InputIterator first, InputIterator last, Predicate pred) {
-  const InputIterator it = std::find_if(first, last, pred);
-  return it != last ? &*it : NULL;
-}
-
-// Copies all elements that satisfy the predicate pred from [first,
-// last) to out. This is the complement of remove_copy_if. Complexity:
-// exactly last-first applications of pred.
-template <typename InputIterator, typename OutputIterator, typename Predicate>
-OutputIterator copy_if(InputIterator first, InputIterator last,
-                       OutputIterator out,
-                       Predicate pred) {
-  for (; first != last; ++first) {
-    if (pred(*first))
-      *out++ = *first;
-  }
-  return out;
-}
-
-// Copies n elements to out.  Equivalent to copy(first, first + n, out) for
-// random access iterators and a longer code block for lesser iterators.
-template <typename InputIterator, typename Size, typename OutputIterator>
-OutputIterator copy_n(InputIterator first, Size n, OutputIterator out) {
-  while (n > 0) {
-    *out = *first;
-    ++out;
-    ++first;
-    --n;
-  }
-  return out;
-}
-
-// Returns true if pred is true for every element in [first, last). Complexity:
-// at most last-first applications of pred.
-template <typename InputIterator, typename Predicate>
-bool all(InputIterator first, InputIterator last, Predicate pred) {
-  for (; first != last; ++first) {
-    if (!pred(*first))
-      return false;
-  }
-  return true;
-}
-
-// Returns true if pred is false for every element in [first,
-// last). Complexity: at most last-first applications of pred.
-template <typename InputIterator, typename Predicate>
-bool none(InputIterator first, InputIterator last, Predicate pred) {
-  return find_if(first, last, pred) == last;
-}
-
-// Returns true if pred is true for at least one element in [first, last).
-// Complexity: at most last-first applications of pred.
-template <typename InputIterator, typename Predicate>
-bool any(InputIterator first, InputIterator last, Predicate pred) {
-  return !none(first, last, pred);
-}
-
-// Returns a pair of iterators p such that p.first points to the
-// minimum element in the range and p.second points to the maximum,
-// ordered by comp. Complexity: at most floor((3/2) (N-1))
-// comparisons. Postcondition: If the return value is <min, max>, min is
-// the first iterator i in [first, last) such that comp(*j, *i) is
-// false for every other iterator j, and max is the last iterator i
-// such that comp(*i, *j) is false for every other iterator j. Or less
-// formally, min is the first minimum and max is the last maximum.
-template <typename ForwardIter, typename Compare>
-std::pair<ForwardIter, ForwardIter> minmax_element(ForwardIter first,
-                                                   const ForwardIter last,
-                                                   Compare comp) {
-  // Initialization: for N<2, set min=max=first. For N >= 2, set min
-  // to be the smaller of the first two and max to be the larger. (Taking
-  // care that min is the first, and max the second, if the two compare
-  // equivalent.)
-  ForwardIter min(first);
-  ForwardIter max(first);
-
-  if (first != last) {
-    ++first;
-  }
-
-  if (first != last) {
-    max = first;
-    if (comp(*max, *min))
-      swap(min, max);
-    ++first;
-  }
-
-  while (first != last) {
-    ForwardIter next(first);
-    ++next;
-
-    if (next != last) {
-      // We have two elements to look at that we haven't seen already,
-      // *first and *next. Compare the smaller of them with the
-      // current min, and the larger against the current max. The
-      // subtle point: write all of the comparisons so that, if the
-      // two things being compared are equivalent, we take the first
-      // one as the smaller and the last as the larger.
-      if (comp(*next, *first)) {
-        if (comp(*next, *min))
-          min = next;
-        if (!comp(*first, *max))
-          max = first;
-      } else {
-        if (comp(*first, *min))
-          min = first;
-        if (!comp(*next, *max))
-          max = next;
-      }
-    } else {
-      // There is only one element left that we haven't seen already, *first.
-      // Adjust min or max, as appropriate, and exit the loop.
-      if (comp(*first, *min)) {
-        min = first;
-      } else if (!comp(*first, *max)) {
-        max = first;
-      }
-      break;
-    }
-
-    first = next;
-    ++first;
-  }
-
-  return make_pair(min, max);
-}
-
-// Returns a pair of iterators p such that p.first points to the first
-// minimum element in the range and p.second points to the last
-// maximum, ordered by operator<.
-template <typename ForwardIter>
-inline std::pair<ForwardIter, ForwardIter> minmax_element(ForwardIter first,
-                                                          ForwardIter last) {
-  typedef typename std::iterator_traits<ForwardIter>::value_type value_type;
-  return util::gtl::minmax_element(first, last, std::less<value_type>());
-}
-
-// Returns true if [first, last) is sorted in nondescending order by
-// pred.  Complexity: for nonempty ranges, at most last-first - 1
-// applications of comp.
-template <typename ForwardIterator, typename Compare>
-bool is_sorted(ForwardIterator first, ForwardIterator last, Compare comp) {
-  if (first != last) {
-    ForwardIterator next(first);
-    ++next;
-    while (next != last) {
-      if (comp(*next, *first))
-        return false;
-      first = next;
-      ++next;
-    }
-  }
-  return true;
-}
-
-// Returns true if [first, last) is sorted in nondescending order by
-// operator<.  Complexity: for nonempty ranges, exactly last-first - 1
-// applications of operator<.
-template <typename ForwardIterator>
-inline bool is_sorted(ForwardIterator first, ForwardIterator last) {
-  typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
-  return util::gtl::is_sorted(first, last, std::less<value_type>());
-}
-
-// Returns true if [first, last) is partitioned by pred, i.e. if all
-// elements that satisfy pred appear before those that do
-// not. Complexity: linear.
-template <typename ForwardIterator, typename Predicate>
-inline bool is_partitioned(ForwardIterator first, ForwardIterator last,
-                           Predicate pred) {
-  for (; first != last; ++first) {
-    if (!pred(*first)) {
-      ++first;
-      return util::gtl::none(first, last, pred);
-    }
-  }
-  return true;
-}
-
-// Precondition: is_partitioned(first, last, pred). Returns: the
-// partition point p, i.e. an iterator mid satisfying the conditions
-// all(first, mid, pred) and none(mid, last, pred).  Complexity:
-// O(log(last-first)) applications of pred.
-template <typename ForwardIterator, typename Predicate>
-ForwardIterator partition_point(ForwardIterator first, ForwardIterator last,
-                                Predicate pred) {
-  typedef typename std::iterator_traits<ForwardIterator>::difference_type diff;
-  diff n = distance(first, last);
-
-  // Loop invariant: n == distance(first, last)
-  while (first != last) {
-    diff half = n/2;
-    ForwardIterator mid = first;
-    advance(mid, half);
-    if (pred(*mid)) {
-      first = mid;
-      ++first;
-      n -= half+1;
-    } else {
-      n = half;
-      last = mid;
-    }
-  }
-
-  return first;
-}
-
-// Copies all elements that satisfy pred to out_true and all elements
-// that don't satisfy it to out_false. Returns: a pair p such that
-// p.first is the end of the range beginning at out_t and p.second is
-// the end of the range beginning at out_f. Complexity: exactly
-// last-first applications of pred.
-template <typename InputIterator,
-          typename OutputIterator1, typename OutputIterator2,
-          typename Predicate>
-std::pair<OutputIterator1, OutputIterator2>
-partition_copy(InputIterator first, InputIterator last,
-               OutputIterator1 out_true, OutputIterator2 out_false,
-               Predicate pred) {
-  for (; first != last; ++first) {
-    if (pred(*first))
-      *out_true++ = *first;
-    else
-      *out_false++ = *first;
-  }
-  return make_pair(out_true, out_false);
-}
-
-// Reorders elements in [first, last), so that for each consecutive group
-// of duplicate elements (according to eq predicate) the first one is left and
-// others are moved at the end of the range. Returns: iterator middle such that
-// [first, middle) contains no two consecutive elements that are duplicates and
-// [middle, last) contains elements removed from all groups. It's stable for
-// range [first, middle) meaning the order of elements are the same as order of
-// their corresponding groups in input, but the order in range [middle, last)
-// is not preserved. Function is similar to std::unique, but ensures that
-// removed elements are properly copied and accessible at the range's end.
-// Complexity: exactly last-first-1 applications of eq; at most middle-first-1
-// swap operations.
-template <typename ForwardIterator, typename Equals>
-ForwardIterator unique_partition(ForwardIterator first, ForwardIterator last,
-                                 Equals eq) {
-  first = adjacent_find(first, last, eq);
-  if (first == last)
-    return last;
-
-  // Points to right-most element within range of unique elements being built.
-  ForwardIterator result = first;
-
-  // 'first' iterator goes through the sequence starting from element after
-  // first equal elements pair (found by adjacent_find above).
-  ++first;
-  while (++first != last) {
-    // If we encounter an element that isn't equal to right-most element in
-    // result, then extend the range and swap this element into it.
-    // Otherwise just continue incrementing 'first'.
-    if (!eq(*result, *first)) {
-      swap(*++result, *first);
-    }
-  }
-  // Return past-the-end upper-bound of the resulting range.
-  return ++result;
-}
-
-// Reorders elements in [first, last) range moving duplicates for each
-// consecutive group of elements to the end. Equality is checked using ==.
-template <typename ForwardIterator>
-inline ForwardIterator unique_partition(ForwardIterator first,
-                                        ForwardIterator last) {
-  typedef typename std::iterator_traits<ForwardIterator>::value_type T;
-  return unique_partition(first, last, std::equal_to<T>());
-}
-
-// Samples k elements from the next n.
-// Elements have the same order in the output stream as they did on input.
-//
-// This is Algorithm S from section 3.4.2 of Knuth, TAOCP, 2nd edition.
-// My k corresponds to Knuth n-m.
-// My n corrsponds to Knuth N-t.
-//
-// RngFunctor is any functor that can be called as:
-//   size_t RngFunctor(size_t x)
-// The return value is an integral value in the half-open range [0, x)
-// such that all values are equally likely.  Behavior is unspecified if x==0.
-// (This function never calls RngFunctor with x==0).
-
-template <typename InputIterator, typename OutputIterator, typename RngFunctor>
-inline void sample_k_of_n(InputIterator in, size_t k, size_t n,
-                          RngFunctor& rng, OutputIterator out) {
-  if (k > n) {
-    k = n;
-  }
-  while (k > 0) {
-    if (rng(n) < k) {
-      *out++ = *in;
-      k--;
-    }
-    ++in;
-    --n;
-  }
-}
-
-// Finds the longest prefix of a range that is a binary max heap with
-// respect to a given StrictWeakOrdering.  If first == last, returns last.
-// Otherwise, return an iterator it such that [first,it) is a heap but
-// no longer prefix is -- in other words, first + i for the lowest i
-// such that comp(first[(i-1)/2], first[i]) returns true.
-template <typename RandomAccessIterator, typename StrictWeakOrdering>
-RandomAccessIterator gtl_is_binary_heap_until(RandomAccessIterator first,
-                                              RandomAccessIterator last,
-                                              StrictWeakOrdering comp) {
-  if (last - first < 2) return last;
-  RandomAccessIterator parent = first;
-  bool is_right_child = false;
-  for (RandomAccessIterator child = first + 1; child != last; ++child) {
-    if (comp(*parent, *child)) return child;
-    if (is_right_child) ++parent;
-    is_right_child = !is_right_child;
-  }
-  return last;
-}
-
-// Special case of gtl_is_binary_heap_until where the order is std::less,
-// i.e., where we're working with a simple max heap.
-template <typename RandomAccessIterator>
-RandomAccessIterator gtl_is_binary_heap_until(RandomAccessIterator first,
-                                              RandomAccessIterator last) {
-  typedef typename std::iterator_traits<RandomAccessIterator>::value_type T;
-  return gtl_is_binary_heap_until(first, last, std::less<T>());
-}
-
-// Checks whether a range of values is a binary heap, i.e., checks that
-// no node is less (as defined by a StrictWeakOrdering) than a child.
-template <typename RandomAccessIterator, typename StrictWeakOrdering>
-bool gtl_is_binary_heap(RandomAccessIterator begin,
-                        RandomAccessIterator end,
-                        StrictWeakOrdering comp) {
-  return gtl_is_binary_heap_until(begin, end, comp) == end;
-}
-
-// Special case of gtl_is_binary_heap where the order is std::less (i.e.,
-// where we're working on a simple max heap).
-template <typename RandomAccessIterator>
-bool gtl_is_binary_heap(RandomAccessIterator begin,
-                        RandomAccessIterator end) {
-  return gtl_is_binary_heap_until(begin, end) == end;
-}
-
-// Unqualified calls to is_heap are ambiguous with some build types,
-// namespace that can clash with names that C++11 added to ::std.
-// By calling util::gtl::is_heap, clients can avoid those errors,
-// and by using the underlying is_heap call we ensure consistency
-// with the standard library's heap implementation just in case a
-// standard library ever uses anything other than a binary heap.
-#if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus > 199711L \
-  || defined(LIBCXX) || _MSC_VER >= 1600 /* Visual Studio 2010 */
-using std::is_heap;
-#elif defined __GNUC__
-/* using __gnu_cxx::is_heap; */
-#elif defined _MSC_VER
-// For old versions of MSVC++, we know by inspection that make_heap()
-// traffics in binary max heaps, so gtl_is_binary_heap is an acceptable
-// implementation for is_heap.
-template <typename RandomAccessIterator>
-bool is_heap(RandomAccessIterator begin, RandomAccessIterator end) {
-  return gtl_is_binary_heap(begin, end);
-}
-
-template <typename RandomAccessIterator, typename StrictWeakOrdering>
-bool is_heap(RandomAccessIterator begin,
-             RandomAccessIterator end,
-             StrictWeakOrdering comp) {
-  return gtl_is_binary_heap(begin, end, comp);
-}
-#else
-// We need an implementation of is_heap that matches the library's
-// implementation of make_heap() and friends.  gtl_is_binary_heap will
-// *probably* work, but let's be safe and not make that assumption.
-#error No implementation of is_heap defined for this toolchain.
-#endif
-
-}  // namespace gtl
-}  // namespace util
-
-#endif  // UTIL_GTL_ALGORITHM_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/atomic_refcount.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomic_refcount.h b/be/src/gutil/atomic_refcount.h
index 9560a03..9c80921 100644
--- a/be/src/gutil/atomic_refcount.h
+++ b/be/src/gutil/atomic_refcount.h
@@ -37,11 +37,12 @@
 //
 // If you need to do something very different from this, use a Mutex.
 
-#include "gutil/atomicops.h"
-#include "gutil/integral_types.h"
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/dynamic_annotations.h"
+
+#include "kudu/gutil/atomicops.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/dynamic_annotations.h"
 
 namespace base {
 
@@ -100,7 +101,16 @@ inline bool RefCountIsOne(const volatile Atomic32 *ptr) {
   return res;
 }
 
-
+// Return whether the reference count is zero.  With conventional object
+// referencing counting, the object will be destroyed, so the reference count
+// should never be zero.  Hence this is generally used for a debug check.
+inline bool RefCountIsZero(const volatile Atomic32 *ptr) {
+  bool res = (subtle::Acquire_Load(ptr) == 0);
+  if (res) {
+    ANNOTATE_HAPPENS_AFTER(ptr);
+  }
+  return res;
+}
 
 #if BASE_HAS_ATOMIC64
 // Implementations for Atomic64, if available.
@@ -132,6 +142,13 @@ inline bool RefCountIsOne(const volatile base::subtle::Atomic64 *ptr) {
   }
   return res;
 }
+inline bool RefCountIsZero(const volatile base::subtle::Atomic64 *ptr) {
+  bool res = (base::subtle::Acquire_Load(ptr) == 0);
+  if (res) {
+    ANNOTATE_HAPPENS_AFTER(ptr);
+  }
+  return res;
+}
 #endif
 
 #ifdef AtomicWordCastType
@@ -163,6 +180,14 @@ inline bool RefCountIsOne(const volatile AtomicWord *ptr) {
   }
   return res;
 }
+inline bool RefCountIsZero(const volatile AtomicWord *ptr) {
+  bool res = base::subtle::Acquire_Load(
+      reinterpret_cast<const volatile AtomicWordCastType *>(ptr)) == 0;
+  if (res) {
+    ANNOTATE_HAPPENS_AFTER(ptr);
+  }
+  return res;
+}
 #endif
 
 } // namespace base

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/atomicops-internals-powerpc.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomicops-internals-powerpc.h b/be/src/gutil/atomicops-internals-powerpc.h
index 98ca0a6..0e56475 100644
--- a/be/src/gutil/atomicops-internals-powerpc.h
+++ b/be/src/gutil/atomicops-internals-powerpc.h
@@ -1,16 +1,21 @@
 // Copyright 2012 Google Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // All Rights Reserved.
 //
@@ -23,8 +28,8 @@
 // This is not tested and may contain bugs.  Until we have bootstrapped
 // this.
 
-#ifndef SUPERSONIC_OPENSOURCE_AUXILIARY_ATOMICOPS_INTERNALS_POWERPC_H_
-#define SUPERSONIC_OPENSOURCE_AUXILIARY_ATOMICOPS_INTERNALS_POWERPC_H_
+#ifndef GUTIL_ATOMICOPS_INTERNALS_POWERPC_H_
+#define GUTIL_ATOMICOPS_INTERNALS_POWERPC_H_
 
 typedef int32_t Atomic32;
 #define BASE_HAS_ATOMIC64 1  // Use only in tests and base/atomic*
@@ -296,4 +301,4 @@ inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
 
 #undef ATOMICOPS_COMPILER_BARRIER
 
-#endif  // SUPERSONIC_OPENSOURCE_AUXILIARY_ATOMICOPS_INTERNALS_POWERPC_H_
+#endif  // GUTIL_ATOMICOPS_INTERNALS_POWERPC_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/atomicops-internals-tsan.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomicops-internals-tsan.h b/be/src/gutil/atomicops-internals-tsan.h
new file mode 100644
index 0000000..aecaefc
--- /dev/null
+++ b/be/src/gutil/atomicops-internals-tsan.h
@@ -0,0 +1,217 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file is an internal atomic implementation for compiler-based
+// ThreadSanitizer. Use base/atomicops.h instead.
+
+#ifndef BASE_ATOMICOPS_INTERNALS_TSAN_H_
+#define BASE_ATOMICOPS_INTERNALS_TSAN_H_
+
+// Workaround for Chromium BASE_EXPORT definition
+#ifndef BASE_EXPORT
+#define BASE_EXPORT
+#endif
+
+// This struct is not part of the public API of this module; clients may not
+// use it.  (However, it's exported via BASE_EXPORT because clients implicitly
+// do use it at link time by inlining these functions.)
+// Features of this x86.  Values may not be correct before main() is run,
+// but are set conservatively.
+struct AtomicOps_x86CPUFeatureStruct {
+  bool has_amd_lock_mb_bug;  // Processor has AMD memory-barrier bug; do lfence
+                             // after acquire compare-and-swap.
+  bool has_sse2;             // Processor has SSE2.
+};
+BASE_EXPORT extern struct AtomicOps_x86CPUFeatureStruct
+    AtomicOps_Internalx86CPUFeatures;
+
+#define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory")
+
+#include <sanitizer/tsan_interface_atomic.h>
+
+typedef int32_t Atomic32;
+typedef int64_t Atomic64;
+
+namespace base {
+namespace subtle {
+
+typedef int32_t Atomic32;
+typedef int64_t Atomic64;
+
+inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32 *ptr,
+                                  Atomic32 old_value,
+                                  Atomic32 new_value) {
+  Atomic32 cmp = old_value;
+  __tsan_atomic32_compare_exchange_strong(ptr, &cmp, new_value,
+      __tsan_memory_order_relaxed, __tsan_memory_order_relaxed);
+  return cmp;
+}
+
+inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32 *ptr,
+                                  Atomic32 new_value) {
+  return __tsan_atomic32_exchange(ptr, new_value,
+      __tsan_memory_order_relaxed);
+}
+
+inline Atomic32 Acquire_AtomicExchange(volatile Atomic32 *ptr,
+                                Atomic32 new_value) {
+  return __tsan_atomic32_exchange(ptr, new_value,
+      __tsan_memory_order_acquire);
+}
+
+inline Atomic32 Release_AtomicExchange(volatile Atomic32 *ptr,
+                                Atomic32 new_value) {
+  return __tsan_atomic32_exchange(ptr, new_value,
+      __tsan_memory_order_release);
+}
+
+inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr,
+                                   Atomic32 increment) {
+  return increment + __tsan_atomic32_fetch_add(ptr, increment,
+      __tsan_memory_order_relaxed);
+}
+
+inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr,
+                                 Atomic32 increment) {
+  return increment + __tsan_atomic32_fetch_add(ptr, increment,
+      __tsan_memory_order_acq_rel);
+}
+
+inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr,
+                                Atomic32 old_value,
+                                Atomic32 new_value) {
+  Atomic32 cmp = old_value;
+  __tsan_atomic32_compare_exchange_strong(ptr, &cmp, new_value,
+      __tsan_memory_order_acquire, __tsan_memory_order_acquire);
+  return cmp;
+}
+
+inline Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr,
+                                Atomic32 old_value,
+                                Atomic32 new_value) {
+  Atomic32 cmp = old_value;
+  __tsan_atomic32_compare_exchange_strong(ptr, &cmp, new_value,
+      __tsan_memory_order_release, __tsan_memory_order_relaxed);
+  return cmp;
+}
+
+inline void NoBarrier_Store(volatile Atomic32 *ptr, Atomic32 value) {
+  __tsan_atomic32_store(ptr, value, __tsan_memory_order_relaxed);
+}
+
+inline void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value) {
+  __tsan_atomic32_store(ptr, value, __tsan_memory_order_relaxed);
+  __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst);
+}
+
+inline void Release_Store(volatile Atomic32 *ptr, Atomic32 value) {
+  __tsan_atomic32_store(ptr, value, __tsan_memory_order_release);
+}
+
+inline Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr) {
+  return __tsan_atomic32_load(ptr, __tsan_memory_order_relaxed);
+}
+
+inline Atomic32 Acquire_Load(volatile const Atomic32 *ptr) {
+  return __tsan_atomic32_load(ptr, __tsan_memory_order_acquire);
+}
+
+inline Atomic32 Release_Load(volatile const Atomic32 *ptr) {
+  __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst);
+  return __tsan_atomic32_load(ptr, __tsan_memory_order_relaxed);
+}
+
+inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64 *ptr,
+                                      Atomic64 old_value,
+                                      Atomic64 new_value) {
+  Atomic64 cmp = old_value;
+  __tsan_atomic64_compare_exchange_strong(ptr, &cmp, new_value,
+      __tsan_memory_order_relaxed, __tsan_memory_order_relaxed);
+  return cmp;
+}
+
+inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64 *ptr,
+                                      Atomic64 new_value) {
+  return __tsan_atomic64_exchange(ptr, new_value, __tsan_memory_order_relaxed);
+}
+
+inline Atomic64 Acquire_AtomicExchange(volatile Atomic64 *ptr,
+                                    Atomic64 new_value) {
+  return __tsan_atomic64_exchange(ptr, new_value, __tsan_memory_order_acquire);
+}
+
+inline Atomic64 Release_AtomicExchange(volatile Atomic64 *ptr,
+                                    Atomic64 new_value) {
+  return __tsan_atomic64_exchange(ptr, new_value, __tsan_memory_order_release);
+}
+
+inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64 *ptr,
+                                       Atomic64 increment) {
+  return increment + __tsan_atomic64_fetch_add(ptr, increment,
+      __tsan_memory_order_relaxed);
+}
+
+inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64 *ptr,
+                                     Atomic64 increment) {
+  return increment + __tsan_atomic64_fetch_add(ptr, increment,
+      __tsan_memory_order_acq_rel);
+}
+
+inline void NoBarrier_Store(volatile Atomic64 *ptr, Atomic64 value) {
+  __tsan_atomic64_store(ptr, value, __tsan_memory_order_relaxed);
+}
+
+inline void Acquire_Store(volatile Atomic64 *ptr, Atomic64 value) {
+  __tsan_atomic64_store(ptr, value, __tsan_memory_order_relaxed);
+  __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst);
+}
+
+inline void Release_Store(volatile Atomic64 *ptr, Atomic64 value) {
+  __tsan_atomic64_store(ptr, value, __tsan_memory_order_release);
+}
+
+inline Atomic64 NoBarrier_Load(volatile const Atomic64 *ptr) {
+  return __tsan_atomic64_load(ptr, __tsan_memory_order_relaxed);
+}
+
+inline Atomic64 Acquire_Load(volatile const Atomic64 *ptr) {
+  return __tsan_atomic64_load(ptr, __tsan_memory_order_acquire);
+}
+
+inline Atomic64 Release_Load(volatile const Atomic64 *ptr) {
+  __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst);
+  return __tsan_atomic64_load(ptr, __tsan_memory_order_relaxed);
+}
+
+inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64 *ptr,
+                                    Atomic64 old_value,
+                                    Atomic64 new_value) {
+  Atomic64 cmp = old_value;
+  __tsan_atomic64_compare_exchange_strong(ptr, &cmp, new_value,
+      __tsan_memory_order_acquire, __tsan_memory_order_acquire);
+  return cmp;
+}
+
+inline Atomic64 Release_CompareAndSwap(volatile Atomic64 *ptr,
+                                    Atomic64 old_value,
+                                    Atomic64 new_value) {
+  Atomic64 cmp = old_value;
+  __tsan_atomic64_compare_exchange_strong(ptr, &cmp, new_value,
+      __tsan_memory_order_release, __tsan_memory_order_relaxed);
+  return cmp;
+}
+
+inline void MemoryBarrier() {
+  __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst);
+}
+
+inline void PauseCPU() {
+}
+
+}  // namespace base::subtle
+}  // namespace base
+
+#undef ATOMICOPS_COMPILER_BARRIER
+
+#endif  // BASE_ATOMICOPS_INTERNALS_TSAN_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/atomicops-internals-x86.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomicops-internals-x86.cc b/be/src/gutil/atomicops-internals-x86.cc
index 7637b46..5d4529e 100644
--- a/be/src/gutil/atomicops-internals-x86.cc
+++ b/be/src/gutil/atomicops-internals-x86.cc
@@ -1,16 +1,21 @@
 // Copyright 2007 Google, Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // All rights reserved.
 
@@ -18,13 +23,13 @@
 // This module gets enough CPU information to optimize the
 // atomicops module on x86.
 
-#include "gutil/atomicops-internals-x86.h"
+#include "kudu/gutil/atomicops-internals-x86.h"
 
 #include <string.h>
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/integral_types.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/integral_types.h"
 
 // This file only makes sense with atomicops-internals-x86.h -- it
 // depends on structs that are defined in that file.  If atomicops.h
@@ -55,8 +60,9 @@
 // Set the flags so that code will run correctly and conservatively
 // until InitGoogle() is called.
 struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures = {
+  false,          // bug can't exist before process spawns multiple threads
   false,          // no SSE2
-  false           // no cmpxchg16b
+  false,          // no cmpxchg16b
 };
 
 // Initialize the AtomicOps_Internalx86CPUFeatures struct.
@@ -84,6 +90,19 @@ static void AtomicOps_Internalx86CPUFeaturesInit() {
     model += ((eax >> 16) & 0xf) << 4;
   }
 
+  // Opteron Rev E has a bug in which on very rare occasions a locked
+  // instruction doesn't act as a read-acquire barrier if followed by a
+  // non-locked read-modify-write instruction.  Rev F has this bug in
+  // pre-release versions, but not in versions released to customers,
+  // so we test only for Rev E, which is family 15, model 32..63 inclusive.
+  if (strcmp(vendor, "AuthenticAMD") == 0 &&       // AMD
+      family == 15 &&
+      32 <= model && model <= 63) {
+    AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = true;
+  } else {
+    AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = false;
+  }
+
   // edx bit 26 is SSE2 which we use to tell use whether we can use mfence
   AtomicOps_Internalx86CPUFeatures.has_sse2 = ((edx >> 26) & 1);
 
@@ -93,6 +112,8 @@ static void AtomicOps_Internalx86CPUFeaturesInit() {
   VLOG(1) << "vendor " << vendor <<
              "  family " << family <<
              "  model " << model <<
+             "  amd_lock_mb_bug " <<
+                   AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug <<
              "  sse2 " << AtomicOps_Internalx86CPUFeatures.has_sse2 <<
              "  cmpxchg16b " << AtomicOps_Internalx86CPUFeatures.has_cmpxchg16b;
 }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/atomicops-internals-x86.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomicops-internals-x86.h b/be/src/gutil/atomicops-internals-x86.h
index f9ae60a..acbd2e3 100644
--- a/be/src/gutil/atomicops-internals-x86.h
+++ b/be/src/gutil/atomicops-internals-x86.h
@@ -1,16 +1,21 @@
 // Copyright 2003 Google Inc.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // All Rights Reserved.
 //
@@ -24,7 +29,7 @@
 
 #include <stdint.h>
 
-#include "common/logging.h"
+#include <glog/logging.h>
 
 #define BASE_HAS_ATOMIC64 1  // Use only in tests and base/atomic*
 
@@ -38,6 +43,8 @@
 // Features of this x86.  Values may not be correct before InitGoogle() is run,
 // but are set conservatively.
 struct AtomicOps_x86CPUFeatureStruct {
+  bool has_amd_lock_mb_bug;  // Processor has AMD memory-barrier bug; do lfence
+                             // after acquire compare-and-swap.
   bool has_sse2;             // Processor has SSE2.
   bool has_cmpxchg16b;       // Processor supports cmpxchg16b instruction.
 };
@@ -95,6 +102,9 @@ inline Atomic32 Acquire_AtomicExchange(volatile Atomic32* ptr,
                                        Atomic32 new_value) {
   CheckNaturalAlignment(ptr);
   Atomic32 old_val = NoBarrier_AtomicExchange(ptr, new_value);
+  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
+    __asm__ __volatile__("lfence" : : : "memory");
+  }
   return old_val;
 }
 
@@ -122,15 +132,20 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
                        : "+r" (temp), "+m" (*ptr)
                        : : "memory");
   // temp now holds the old value of *ptr
+  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
+    __asm__ __volatile__("lfence" : : : "memory");
+  }
   return temp + increment;
 }
 
-// On x86, the NoBarrier_CompareAndSwap() uses a locked instruction and so also
-// provides both acquire and release barriers.
 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
                                        Atomic32 old_value,
                                        Atomic32 new_value) {
-  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+  Atomic32 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
+    __asm__ __volatile__("lfence" : : : "memory");
+  }
+  return x;
 }
 
 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
@@ -139,12 +154,6 @@ inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
   return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
 }
 
-inline Atomic32 Barrier_CompareAndSwap(volatile Atomic32* ptr,
-                                       Atomic32 old_value,
-                                       Atomic32 new_value) {
-  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
-}
-
 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
   CheckNaturalAlignment(ptr);
   *ptr = value;
@@ -248,6 +257,9 @@ inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
 inline Atomic64 Acquire_AtomicExchange(volatile Atomic64* ptr,
                                        Atomic64 new_value) {
   Atomic64 old_val = NoBarrier_AtomicExchange(ptr, new_value);
+  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
+    __asm__ __volatile__("lfence" : : : "memory");
+  }
   return old_val;
 }
 
@@ -275,6 +287,9 @@ inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
                        : "+r" (temp), "+m" (*ptr)
                        : : "memory");
   // temp now contains the previous value of *ptr
+  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
+    __asm__ __volatile__("lfence" : : : "memory");
+  }
   return temp + increment;
 }
 
@@ -388,6 +403,9 @@ inline Atomic64 Acquire_AtomicExchange(volatile Atomic64* ptr,
                                        Atomic64 new_val) {
   CheckNaturalAlignment(ptr);
   Atomic64 old_val = NoBarrier_AtomicExchange(ptr, new_val);
+  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
+    __asm__ __volatile__("lfence" : : : "memory");
+  }
   return old_val;
 }
 
@@ -413,6 +431,9 @@ inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
                                         Atomic64 increment) {
   CheckNaturalAlignment(ptr);
   Atomic64 new_val = NoBarrier_AtomicIncrement(ptr, increment);
+  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
+    __asm__ __volatile__("lfence" : : : "memory");
+  }
   return new_val;
 }
 
@@ -471,7 +492,11 @@ inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
 inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
                                        Atomic64 old_value,
                                        Atomic64 new_value) {
-  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+  Atomic64 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+  if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
+    __asm__ __volatile__("lfence" : : : "memory");
+  }
+  return x;
 }
 
 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
@@ -480,12 +505,6 @@ inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
   return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
 }
 
-inline Atomic64 Barrier_CompareAndSwap(volatile Atomic64* ptr,
-                                       Atomic64 old_value,
-                                       Atomic64 new_value) {
-  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
-}
-
 }  // namespace subtle
 }  // namespace base
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/atomicops.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/atomicops.h b/be/src/gutil/atomicops.h
index ad8d773..fa4c44c 100644
--- a/be/src/gutil/atomicops.h
+++ b/be/src/gutil/atomicops.h
@@ -67,23 +67,23 @@
 // #endif
 // ------------------------------------------------------------------------
 
-#include "gutil/arm_instruction_set_select.h"
+#include "kudu/gutil/arm_instruction_set_select.h"
 
 // ThreadSanitizer provides own implementation of atomicops.
 #if defined(THREAD_SANITIZER)
-#include "gutil/atomicops-internals-tsan.h"
+#include "kudu/gutil/atomicops-internals-tsan.h"
 #elif defined(__APPLE__)
-#include "gutil/atomicops-internals-macosx.h"
+#include "kudu/gutil/atomicops-internals-macosx.h"
 #elif defined(__GNUC__) && defined(ARMV6)
-#include "gutil/atomicops-internals-arm-v6plus.h"
+#include "kudu/gutil/atomicops-internals-arm-v6plus.h"
 #elif defined(ARMV3)
-#include "gutil/atomicops-internals-arm-generic.h"
+#include "kudu/gutil/atomicops-internals-arm-generic.h"
 #elif defined(__GNUC__) && (defined(__i386) || defined(__x86_64__))
-#include "gutil/atomicops-internals-x86.h"
+#include "kudu/gutil/atomicops-internals-x86.h"
 #elif defined(__GNUC__) && defined(ARCH_POWERPC64)
-#include "gutil/atomicops-internals-powerpc.h"
+#include "kudu/gutil/atomicops-internals-powerpc.h"
 #elif defined(OS_WINDOWS)
-#include "gutil/atomicops-internals-windows.h"
+#include "kudu/gutil/atomicops-internals-windows.h"
 #else
 #error You need to implement atomic operations for this architecture
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h b/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h
index 0a73b85..417c6a0 100644
--- a/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h
+++ b/be/src/gutil/auxiliary/atomicops-internals-arm-generic.h
@@ -11,8 +11,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "gutil/macros.h"  // For COMPILE_ASSERT
-#include "gutil/port.h"  // ATTRIBUTE_WEAK
+#include "kudu/gutil/macros.h"  // For COMPILE_ASSERT
+#include "kudu/gutil/port.h"  // ATTRIBUTE_WEAK
 
 typedef int32_t Atomic32;
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h b/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h
index 631f0f0..edafc4e 100644
--- a/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h
+++ b/be/src/gutil/auxiliary/atomicops-internals-arm-v6plus.h
@@ -12,7 +12,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "gutil/basictypes.h"  // For COMPILE_ASSERT
+#include "kudu/gutil/basictypes.h"  // For COMPILE_ASSERT
 
 // The LDREXD and STREXD instructions in ARM all v7 variants or above.  In v6,
 // only some variants support it.  For simplicity, we only use exclusive

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/auxiliary/atomicops-internals-macosx.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/auxiliary/atomicops-internals-macosx.h b/be/src/gutil/auxiliary/atomicops-internals-macosx.h
deleted file mode 100644
index 7a63bd5..0000000
--- a/be/src/gutil/auxiliary/atomicops-internals-macosx.h
+++ /dev/null
@@ -1,397 +0,0 @@
-// Copyright 2006 Google Inc.
-// All Rights Reserved.
-//
-//
-// Implementation of atomic operations for Mac OS X.  This file should not
-// be included directly.  Clients should instead include
-// "base/atomicops.h".
-
-#ifndef BASE_AUXILIARY_ATOMICOPS_INTERNALS_MACOSX_H_
-#define BASE_AUXILIARY_ATOMICOPS_INTERNALS_MACOSX_H_
-
-typedef int32_t Atomic32;
-
-// MacOS uses long for intptr_t, AtomicWord and Atomic32 are always different
-// on the Mac, even when they are the same size.  Similarly, on __ppc64__,
-// AtomicWord and Atomic64 are always different.  Thus, we need explicit
-// casting.
-#ifdef __LP64__
-#define AtomicWordCastType base::subtle::Atomic64
-#else
-#define AtomicWordCastType Atomic32
-#endif
-
-#if defined(__LP64__) || defined(__i386__)
-#define BASE_HAS_ATOMIC64 1  // Use only in tests and base/atomic*
-#endif
-
-#include <libkern/OSAtomic.h>
-
-#if !defined(__LP64__) && defined(__ppc__)
-
-// The Mac 64-bit OSAtomic implementations are not available for 32-bit PowerPC,
-// while the underlying assembly instructions are available only some
-// implementations of PowerPC.
-
-// The following inline functions will fail with the error message at compile
-// time ONLY IF they are called.  So it is safe to use this header if user
-// code only calls AtomicWord and Atomic32 operations.
-//
-// NOTE(user): Implementation notes to implement the atomic ops below may
-// be found in "PowerPC Virtual Environment Architecture, Book II,
-// Version 2.02", January 28, 2005, Appendix B, page 46.  Unfortunately,
-// extra care must be taken to ensure data are properly 8-byte aligned, and
-// that data are returned correctly according to Mac OS X ABI specs.
-
-inline int64_t OSAtomicCompareAndSwap64(
-    int64_t oldValue, int64_t newValue, int64_t *theValue) {
-  __asm__ __volatile__(
-      "_OSAtomicCompareAndSwap64_not_supported_for_32_bit_ppc\n\t");
-  return 0;
-}
-
-inline int64_t OSAtomicAdd64(int64_t theAmount, int64_t *theValue) {
-  __asm__ __volatile__(
-      "_OSAtomicAdd64_not_supported_for_32_bit_ppc\n\t");
-  return 0;
-}
-
-inline int64_t OSAtomicCompareAndSwap64Barrier(
-    int64_t oldValue, int64_t newValue, int64_t *theValue) {
-  int64_t prev = OSAtomicCompareAndSwap64(oldValue, newValue, theValue);
-  OSMemoryBarrier();
-  return prev;
-}
-
-inline int64_t OSAtomicAdd64Barrier(
-    int64_t theAmount, int64_t *theValue) {
-  int64_t new_val = OSAtomicAdd64(theAmount, theValue);
-  OSMemoryBarrier();
-  return new_val;
-}
-#endif
-
-
-namespace base {
-namespace subtle {
-
-typedef int64_t Atomic64;
-
-inline void MemoryBarrier() {
-  OSMemoryBarrier();
-}
-
-// 32-bit Versions.
-
-inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32 *ptr,
-                                         Atomic32 old_value,
-                                         Atomic32 new_value) {
-  Atomic32 prev_value;
-  do {
-    if (OSAtomicCompareAndSwap32(old_value, new_value,
-                                 const_cast<Atomic32*>(ptr))) {
-      return old_value;
-    }
-    prev_value = *ptr;
-  } while (prev_value == old_value);
-  return prev_value;
-}
-
-inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32 *ptr,
-                                         Atomic32 new_value) {
-  Atomic32 old_value;
-  do {
-    old_value = *ptr;
-  } while (!OSAtomicCompareAndSwap32(old_value, new_value,
-                                     const_cast<Atomic32*>(ptr)));
-  return old_value;
-}
-
-inline Atomic32 Acquire_AtomicExchange(volatile Atomic32 *ptr,
-                                       Atomic32 new_value) {
-  Atomic32 old_value;
-  do {
-    old_value = *ptr;
-  } while (!OSAtomicCompareAndSwap32Barrier(old_value, new_value,
-                                            const_cast<Atomic32*>(ptr)));
-  return old_value;
-}
-
-inline Atomic32 Release_AtomicExchange(volatile Atomic32 *ptr,
-                                       Atomic32 new_value) {
-  return Acquire_AtomicExchange(ptr, new_value);
-}
-
-inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr,
-                                          Atomic32 increment) {
-  return OSAtomicAdd32(increment, const_cast<Atomic32*>(ptr));
-}
-
-inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr,
-                                          Atomic32 increment) {
-  return OSAtomicAdd32Barrier(increment, const_cast<Atomic32*>(ptr));
-}
-
-inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr,
-                                       Atomic32 old_value,
-                                       Atomic32 new_value) {
-  Atomic32 prev_value;
-  do {
-    if (OSAtomicCompareAndSwap32Barrier(old_value, new_value,
-                                        const_cast<Atomic32*>(ptr))) {
-      return old_value;
-    }
-    prev_value = *ptr;
-  } while (prev_value == old_value);
-  return prev_value;
-}
-
-inline Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr,
-                                       Atomic32 old_value,
-                                       Atomic32 new_value) {
-  return Acquire_CompareAndSwap(ptr, old_value, new_value);
-}
-
-inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
-  *ptr = value;
-}
-
-inline void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value) {
-  *ptr = value;
-  MemoryBarrier();
-}
-
-inline void Release_Store(volatile Atomic32 *ptr, Atomic32 value) {
-  MemoryBarrier();
-  *ptr = value;
-}
-
-inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
-  return *ptr;
-}
-
-inline Atomic32 Acquire_Load(volatile const Atomic32 *ptr) {
-  Atomic32 value = *ptr;
-  MemoryBarrier();
-  return value;
-}
-
-inline Atomic32 Release_Load(volatile const Atomic32 *ptr) {
-  MemoryBarrier();
-  return *ptr;
-}
-
-// 64-bit version
-
-inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64 *ptr,
-                                         Atomic64 old_value,
-                                         Atomic64 new_value) {
-  Atomic64 prev_value;
-  do {
-    if (OSAtomicCompareAndSwap64(old_value, new_value,
-                                 const_cast<Atomic64*>(ptr))) {
-      return old_value;
-    }
-    prev_value = *ptr;
-  } while (prev_value == old_value);
-  return prev_value;
-}
-
-inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64 *ptr,
-                                         Atomic64 new_value) {
-  Atomic64 old_value;
-  do {
-    old_value = *ptr;
-  } while (!OSAtomicCompareAndSwap64(old_value, new_value,
-                                     const_cast<Atomic64*>(ptr)));
-  return old_value;
-}
-
-inline Atomic64 Acquire_AtomicExchange(volatile Atomic64 *ptr,
-                                       Atomic64 new_value) {
-  Atomic64 old_value;
-  do {
-    old_value = *ptr;
-  } while (!OSAtomicCompareAndSwap64Barrier(old_value, new_value,
-                                            const_cast<Atomic64*>(ptr)));
-  return old_value;
-}
-
-inline Atomic64 Release_AtomicExchange(volatile Atomic64 *ptr,
-                                       Atomic64 new_value) {
-  return Acquire_AtomicExchange(ptr, new_value);
-}
-
-inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64 *ptr,
-                                          Atomic64 increment) {
-  return OSAtomicAdd64(increment, const_cast<Atomic64*>(ptr));
-}
-
-inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64 *ptr,
-                                        Atomic64 increment) {
-  return OSAtomicAdd64Barrier(increment, const_cast<Atomic64*>(ptr));
-}
-
-inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64 *ptr,
-                                       Atomic64 old_value,
-                                       Atomic64 new_value) {
-  Atomic64 prev_value;
-  do {
-    if (OSAtomicCompareAndSwap64Barrier(old_value, new_value,
-                                        const_cast<Atomic64*>(ptr))) {
-      return old_value;
-    }
-    prev_value = *ptr;
-  } while (prev_value == old_value);
-  return prev_value;
-}
-
-inline Atomic64 Release_CompareAndSwap(volatile Atomic64 *ptr,
-                                       Atomic64 old_value,
-                                       Atomic64 new_value) {
-  // The lib kern interface does not distinguish between
-  // Acquire and Release memory barriers; they are equivalent.
-  return Acquire_CompareAndSwap(ptr, old_value, new_value);
-}
-
-#ifdef __LP64__
-
-// 64-bit implementation on 64-bit platform
-
-inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
-  *ptr = value;
-}
-
-inline void Acquire_Store(volatile Atomic64 *ptr, Atomic64 value) {
-  *ptr = value;
-  MemoryBarrier();
-}
-
-inline void Release_Store(volatile Atomic64 *ptr, Atomic64 value) {
-  MemoryBarrier();
-  *ptr = value;
-}
-
-inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
-  return *ptr;
-}
-
-inline Atomic64 Acquire_Load(volatile const Atomic64 *ptr) {
-  Atomic64 value = *ptr;
-  MemoryBarrier();
-  return value;
-}
-
-inline Atomic64 Release_Load(volatile const Atomic64 *ptr) {
-  MemoryBarrier();
-  return *ptr;
-}
-
-#else
-
-// 64-bit implementation on 32-bit platform
-
-#if defined(__ppc__)
-
-inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
-   __asm__ __volatile__(
-       "_NoBarrier_Store_not_supported_for_32_bit_ppc\n\t");
-}
-
-inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
-   __asm__ __volatile__(
-       "_NoBarrier_Load_not_supported_for_32_bit_ppc\n\t");
-   return 0;
-}
-
-#elif defined(__i386__)
-
-inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
-  __asm__ __volatile__("movq %1, %%mm0\n\t"    // Use mmx reg for 64-bit atomic
-                       "movq %%mm0, %0\n\t"  // moves (ptr could be read-only)
-                       "emms\n\t"              // Reset FP registers
-                       : "=m" (*ptr)
-                       : "m" (value)
-                       : // mark the FP stack and mmx registers as clobbered
-                         "st", "st(1)", "st(2)", "st(3)", "st(4)",
-                         "st(5)", "st(6)", "st(7)", "mm0", "mm1",
-                         "mm2", "mm3", "mm4", "mm5", "mm6", "mm7");
-
-}
-
-inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
-  Atomic64 value;
-  __asm__ __volatile__("movq %1, %%mm0\n\t"  // Use mmx reg for 64-bit atomic
-                       "movq %%mm0, %0\n\t"  // moves (ptr could be read-only)
-                       "emms\n\t"            // Reset FP registers
-                       : "=m" (value)
-                       : "m" (*ptr)
-                       : // mark the FP stack and mmx registers as clobbered
-                         "st", "st(1)", "st(2)", "st(3)", "st(4)",
-                         "st(5)", "st(6)", "st(7)", "mm0", "mm1",
-                         "mm2", "mm3", "mm4", "mm5", "mm6", "mm7");
-
-  return value;
-}
-
-#elif defined(__arm__)
-
-inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
-  int store_failed;
-  Atomic64 dummy;
-  __asm__ __volatile__(
-      "1:\n"
-      // Dummy load to lock cache line.
-      "ldrexd  %1, [%3]\n"
-      "strexd  %0, %2, [%3]\n"
-      "teq     %0, #0\n"
-      "bne     1b"
-      : "=&r" (store_failed), "=&r"(dummy)
-      : "r"(value), "r" (ptr)
-      : "cc", "memory");
-}
-
-inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
-  Atomic64 res;
-  __asm__ __volatile__(
-      "ldrexd   %0, [%1]\n"
-      "clrex\n"
-      : "=r" (res)
-      : "r"(ptr), "Q"(*ptr));
-  return res;
-}
-
-#endif
-
-
-inline void Acquire_Store(volatile Atomic64 *ptr, Atomic64 value) {
-  NoBarrier_Store(ptr, value);
-  MemoryBarrier();
-}
-
-inline void Release_Store(volatile Atomic64 *ptr, Atomic64 value) {
-  MemoryBarrier();
-  NoBarrier_Store(ptr, value);
-}
-
-inline Atomic64 Acquire_Load(volatile const Atomic64 *ptr) {
-  Atomic64 value = NoBarrier_Load(ptr);
-  MemoryBarrier();
-  return value;
-}
-
-inline Atomic64 Release_Load(volatile const Atomic64 *ptr) {
-  MemoryBarrier();
-  return NoBarrier_Load(ptr);
-}
-#endif  // __LP64__
-
-}   // namespace base::subtle
-}   // namespace base
-
-// NOTE(user): The following is also deprecated.  New callers should use
-// the base::subtle namespace.
-inline void MemoryBarrier() {
-  base::subtle::MemoryBarrier();
-}
-#endif  // BASE_AUXILIARY_ATOMICOPS_INTERNALS_MACOSX_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/auxiliary/atomicops-internals-windows.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/auxiliary/atomicops-internals-windows.h b/be/src/gutil/auxiliary/atomicops-internals-windows.h
index 11d7d9d..96674dc 100644
--- a/be/src/gutil/auxiliary/atomicops-internals-windows.h
+++ b/be/src/gutil/auxiliary/atomicops-internals-windows.h
@@ -11,7 +11,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include "gutil/basictypes.h"  // For COMPILE_ASSERT
+#include "kudu/gutil/basictypes.h"  // For COMPILE_ASSERT
 
 typedef int32 Atomic32;
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/basictypes.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/basictypes.h b/be/src/gutil/basictypes.h
index 2f21d03..1c095ca 100644
--- a/be/src/gutil/basictypes.h
+++ b/be/src/gutil/basictypes.h
@@ -5,8 +5,8 @@
 #ifndef BASE_BASICTYPES_H_
 #define BASE_BASICTYPES_H_
 
-#include "gutil/integral_types.h"
-#include "gutil/macros.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/macros.h"
 
 // Argument type used in interfaces that can optionally take ownership
 // of a passed in argument.  If TAKE_OWNERSHIP is passed, the called


[03/14] incubator-impala git commit: Fix missing declaration of std::max in hdfs-avro-scanner-test

Posted by he...@apache.org.
Fix missing declaration of std::max in hdfs-avro-scanner-test

Change-Id: Id41c14e98163bcbb03675969e0a53754e92a4c14
Reviewed-on: http://gerrit.cloudera.org:8080/6497
Reviewed-by: Sailesh Mukil <sa...@cloudera.com>
Tested-by: Henry Robinson <he...@cloudera.com>


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

Branch: refs/heads/master
Commit: ff095f1894979a3899a9367b44d8dd7a6bfe0726
Parents: 296df3c
Author: Henry Robinson <he...@cloudera.com>
Authored: Mon Mar 27 17:55:55 2017 -0700
Committer: Henry Robinson <he...@cloudera.com>
Committed: Wed Mar 29 02:51:18 2017 +0000

----------------------------------------------------------------------
 be/src/exec/hdfs-avro-scanner-test.cc | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/ff095f18/be/src/exec/hdfs-avro-scanner-test.cc
----------------------------------------------------------------------
diff --git a/be/src/exec/hdfs-avro-scanner-test.cc b/be/src/exec/hdfs-avro-scanner-test.cc
index b031d6c..3567d5c 100644
--- a/be/src/exec/hdfs-avro-scanner-test.cc
+++ b/be/src/exec/hdfs-avro-scanner-test.cc
@@ -17,6 +17,7 @@
 
 #include "exec/hdfs-avro-scanner.h"
 
+#include <algorithm>
 #include <limits.h>
 
 #include "exec/read-write-util.h"
@@ -25,6 +26,8 @@
 #include "runtime/string-value.inline.h"
 #include "testutil/gtest-util.h"
 
+#include "common/names.h"
+
 // TODO: IMPALA-3658: complete CHAR unit tests.
 // TODO: IMPALA-3658: complete VARCHAR unit tests.
 


[06/14] incubator-impala git commit: IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

Posted by he...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/sparsetable.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/sparsetable.h b/be/src/gutil/sparsetable.h
deleted file mode 100644
index 007f76b..0000000
--- a/be/src/gutil/sparsetable.h
+++ /dev/null
@@ -1,1838 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-//
-//
-// A sparsetable is a random container that implements a sparse array,
-// that is, an array that uses very little memory to store unassigned
-// indices (in this case, between 1-2 bits per unassigned index).  For
-// instance, if you allocate an array of size 5 and assign a[2] = <big
-// struct>, then a[2] will take up a lot of memory but a[0], a[1],
-// a[3], and a[4] will not.  Array elements that have a value are
-// called "assigned".  Array elements that have no value yet, or have
-// had their value cleared using erase() or clear(), are called
-// "unassigned".
-//
-// Unassigned values seem to have the default value of T (see below).
-// Nevertheless, there is a difference between an unassigned index and
-// one explicitly assigned the value of T().  The latter is considered
-// assigned.
-//
-// Access to an array element is constant time, as is insertion and
-// deletion.  Insertion and deletion may be fairly slow, however:
-// because of this container's memory economy, each insert and delete
-// causes a memory reallocation.
-//
-// NOTE: You should not test(), get(), or set() any index that is
-// greater than sparsetable.size().  If you need to do that, call
-// resize() first.
-//
-// --- Template parameters
-// PARAMETER   DESCRIPTION                           DEFAULT
-// T           The value of the array: the type of   --
-//             object that is stored in the array.
-//
-// GROUP_SIZE  How large each "group" in the table   48
-//             is (see below).  Larger values use
-//             a little less memory but cause most
-//             operations to be a little slower
-//
-// Alloc:      Allocator to use to allocate memory.  libc_allocator_with_realloc
-//
-// --- Model of
-// Random Access Container
-//
-// --- Type requirements
-// T must be Copy Constructible. It need not be Assignable.
-//
-// --- Public base classes
-// None.
-//
-// --- Members
-// Type members
-//
-// MEMBER           WHERE DEFINED DESCRIPTION
-// value_type       container     The type of object, T, stored in the array
-// allocator_type   container     Allocator to use
-// pointer          container     Pointer to p
-// const_pointer    container     Const pointer to p
-// reference        container     Reference to t
-// const_reference  container     Const reference to t
-// size_type        container     An unsigned integral type
-// difference_type  container     A signed integral type
-// iterator [*]     container     Iterator used to iterate over a sparsetable
-// const_iterator   container     Const iterator used to iterate over a table
-// reverse_iterator reversible    Iterator used to iterate backwards over
-//                  container     a sparsetable
-// const_reverse_iterator   reversible container   Guess
-// nonempty_iterator [+]           sparsetable     Iterates over assigned
-//                                                 array elements only
-// const_nonempty_iterator         sparsetable     Iterates over assigned
-//                                                 array elements only
-// reverse_nonempty_iterator       sparsetable     Iterates backwards over
-//                                                 assigned array elements only
-// const_reverse_nonempty_iterator sparsetable     Iterates backwards over
-//                                                 assigned array elements only
-//
-// [*] All iterators are const in a sparsetable (though nonempty_iterators
-//     may not be).  Use get() and set() to assign values, not iterators.
-//
-// [+] iterators are random-access iterators.  nonempty_iterators are
-//     bidirectional iterators.
-
-// Iterator members
-// MEMBER              WHERE DEFINED  DESCRIPTION
-//
-// iterator begin()    container      An iterator to the beginning of the table
-// iterator end()      container      An iterator to the end of the table
-// const_iterator      container      A const_iterator pointing to the
-//   begin() const                    beginning of a sparsetable
-// const_iterator      container      A const_iterator pointing to the
-//   end() const                      end of a sparsetable
-//
-// reverse_iterator          reversable     Points to beginning of a reversed
-//   rbegin()                container      sparsetable
-// reverse_iterator          reversable     Points to end of a reversed table
-//   rend()                  container
-// const_reverse_iterator    reversable     Points to beginning of a
-//   rbegin() const          container      reversed sparsetable
-// const_reverse_iterator    reversable     Points to end of a reversed table
-//   rend() const            container
-//
-// nonempty_iterator         sparsetable    Points to first assigned element
-//    begin()                               of a sparsetable
-// nonempty_iterator         sparsetable    Points past last assigned element
-//    end()                                 of a sparsetable
-// const_nonempty_iterator   sparsetable    Points to first assigned element
-//    begin() const                         of a sparsetable
-// const_nonempty_iterator   sparsetable    Points past last assigned element
-//    end() const                           of a sparsetable
-//
-// reverse_nonempty_iterator sparsetable    Points to first assigned element
-//    begin()                               of a reversed sparsetable
-// reverse_nonempty_iterator sparsetable    Points past last assigned element
-//    end()                                 of a reversed sparsetable
-// const_reverse_nonempty_iterator sparsetable    Points to first assigned
-//    begin() const                               elt of a reversed sparsetable
-// const_reverse_nonempty_iterator sparsetable    Points past last assigned
-//    end() const                                 elt of a reversed sparsetable
-//
-//
-// Other members
-// MEMBER                      WHERE DEFINED  DESCRIPTION
-// sparsetable()               sparsetable    A table of size 0; must resize()
-//                                            before using.
-// sparsetable(size_type size) sparsetable    A table of size size.  All
-//                                            indices are unassigned.
-// sparsetable(
-//    const sparsetable &tbl)  sparsetable    Copy constructor
-// ~sparsetable()              sparsetable    The destructor
-// sparsetable &operator=(     sparsetable    The assignment operator
-//    const sparsetable &tbl)
-//
-// void resize(size_type size) sparsetable    Grow or shrink a table to
-//                                            have size indices [*]
-//
-// void swap(sparsetable &x)   sparsetable    Swap two sparsetables
-// void swap(sparsetable &x,   sparsetable    Swap two sparsetables
-//           sparsetable &y)                  (global, not member, function)
-//
-// size_type size() const      sparsetable    Number of "buckets" in the table
-// size_type max_size() const  sparsetable    Max allowed size of a sparsetable
-// bool empty() const          sparsetable    true if size() == 0
-// size_type num_nonempty() const  sparsetable  Number of assigned "buckets"
-//
-// const_reference get(        sparsetable    Value at index i, or default
-//    size_type i) const                      value if i is unassigned
-// const_reference operator[]( sparsetable    Identical to get(i) [+]
-//    difference_type i) const
-// reference set(size_type i,  sparsetable    Set element at index i to
-//    const_reference val)                    be a copy of val
-// bool test(size_type i)      sparsetable    True if element at index i
-//    const                                   has been assigned to
-// bool test(iterator pos)     sparsetable    True if element pointed to
-//    const                                   by pos has been assigned to
-// void erase(iterator pos)    sparsetable    Set element pointed to by
-//                                            pos to be unassigned [!]
-// void erase(size_type i)     sparsetable    Set element i to be unassigned
-// void erase(iterator start,  sparsetable    Erases all elements between
-//            iterator end)                   start and end
-// void clear()                sparsetable    Erases all elements in the table
-//
-// I/O versions exist for both FILE* and for File* (Google2-style files):
-// bool write_metadata(FILE *fp) sparsetable  Writes a sparsetable to the
-// bool write_metadata(File *fp)              given file.  true if write
-//                                            completes successfully
-// bool read_metadata(FILE *fp) sparsetable   Replaces sparsetable with
-// bool read_metadata(File *fp)               version read from fp.  true
-//                                            if read completes sucessfully
-// bool write_nopointer_data(FILE *fp)        Read/write the data stored in
-// bool read_nopointer_data(FILE*fp)          the table, if it's simple
-//
-// bool operator==(            forward        Tests two tables for equality.
-//    const sparsetable &t1,   container      This is a global function,
-//    const sparsetable &t2)                  not a member function.
-// bool operator<(             forward        Lexicographical comparison.
-//    const sparsetable &t1,   container      This is a global function,
-//    const sparsetable &t2)                  not a member function.
-//
-// [*] If you shrink a sparsetable using resize(), assigned elements
-// past the end of the table are removed using erase().  If you grow
-// a sparsetable, new unassigned indices are created.
-//
-// [+] Note that operator[] returns a const reference.  You must use
-// set() to change the value of a table element.
-//
-// [!] Unassignment also calls the destructor.
-//
-// Iterators are invalidated whenever an item is inserted or
-// deleted (ie set() or erase() is used) or when the size of
-// the table changes (ie resize() or clear() is used).
-//
-// See doc/sparsetable.html for more information about how to use this class.
-
-// Note: this uses STL style for naming, rather than Google naming.
-// That's because this is an STL-y container
-
-#ifndef UTIL_GTL_SPARSETABLE_H_
-#define UTIL_GTL_SPARSETABLE_H_
-
-#include <assert.h>             // for bounds checking
-#include <stdio.h>              // to read/write tables
-#include <stdlib.h>             // for malloc/free
-#include <string.h>             // for memcpy
-#include <sys/types.h>          // to get u_int16_t (ISO naming madness)
-#include <algorithm>
-using std::copy;
-using std::max;
-using std::min;
-using std::reverse;
-using std::sort;
-using std::swap;            // equal, lexicographical_compare, swap,...
-#include <iterator>
-using std::back_insert_iterator;
-using std::iterator_traits;             // to define reverse_iterator for me
-#include <memory>               // uninitialized_copy, uninitialized_fill
-#include <vector>
-using std::vector;               // a sparsetable is a vector of groups
-
-#include "gutil/type_traits.h"
-#include "gutil/libc_allocator_with_realloc.h"
-
-// A lot of work to get a type that's guaranteed to be 16 bits...
-#ifndef HAVE_U_INT16_T
-# if defined HAVE_UINT16_T
-    typedef uint16_t u_int16_t;    // true on solaris, possibly other C99 libc's
-# elif defined HAVE___UINT16
-    typedef __int16 int16_t;       // true on vc++7
-    typedef unsigned __int16 u_int16_t;
-# else
-    // Cannot find a 16-bit integer type.  Hoping for the best with "short"...
-    typedef short int int16_t;
-    typedef unsigned short int u_int16_t;
-# endif
-#endif
-
-namespace base {
-
-namespace base {   // just to make google->opensource transition easier
-using base::true_type;
-using base::false_type;
-using base::integral_constant;
-using base::has_trivial_copy;
-using base::has_trivial_destructor;
-using base::is_same;
-}
-
-
-// The smaller this is, the faster lookup is (because the group bitmap is
-// smaller) and the faster insert is, because there's less to move.
-// On the other hand, there are more groups.  Since group::size_type is
-// a short, this number should be of the form 32*x + 16 to avoid waste.
-static const u_int16_t DEFAULT_SPARSEGROUP_SIZE = 48;   // fits in 1.5 words
-
-
-// Our iterator as simple as iterators can be: basically it's just
-// the index into our table.  Dereference, the only complicated
-// thing, we punt to the table class.  This just goes to show how
-// much machinery STL requires to do even the most trivial tasks.
-//
-// A NOTE ON ASSIGNING:
-// A sparse table does not actually allocate memory for entries
-// that are not filled.  Because of this, it becomes complicated
-// to have a non-const iterator: we don't know, if the iterator points
-// to a not-filled bucket, whether you plan to fill it with something
-// or whether you plan to read its value (in which case you'll get
-// the default bucket value).  Therefore, while we can define const
-// operations in a pretty 'normal' way, for non-const operations, we
-// define something that returns a helper object with operator= and
-// operator& that allocate a bucket lazily.  We use this for table[]
-// and also for regular table iterators.
-
-template <class tabletype>
-class table_element_adaptor {
- public:
-  typedef typename tabletype::value_type value_type;
-  typedef typename tabletype::size_type size_type;
-  typedef typename tabletype::reference reference;
-  typedef typename tabletype::pointer pointer;
-
-  table_element_adaptor(tabletype *tbl, size_type p)
-    : table(tbl), pos(p) { }
-  table_element_adaptor& operator= (const value_type &val) {
-    table->set(pos, val);
-    return *this;
-  }
-  operator value_type() { return table->get(pos); }   // we look like a value
-  pointer operator& () { return &table->mutating_get(pos); }
-
- private:
-  tabletype* table;
-  size_type pos;
-};
-
-// Our iterator as simple as iterators can be: basically it's just
-// the index into our table.  Dereference, the only complicated
-// thing, we punt to the table class.  This just goes to show how
-// much machinery STL requires to do even the most trivial tasks.
-//
-// By templatizing over tabletype, we have one iterator type which
-// we can use for both sparsetables and sparsebins.  In fact it
-// works on any class that allows size() and operator[] (eg vector),
-// as long as it does the standard STL typedefs too (eg value_type).
-
-template <class tabletype>
-class table_iterator {
- public:
-  typedef table_iterator iterator;
-
-  typedef std::random_access_iterator_tag iterator_category;
-  typedef typename tabletype::value_type value_type;
-  typedef typename tabletype::difference_type difference_type;
-  typedef typename tabletype::size_type size_type;
-  typedef table_element_adaptor<tabletype> reference;
-  typedef table_element_adaptor<tabletype>* pointer;
-
-  // The "real" constructor
-  table_iterator(tabletype *tbl, size_type p)
-    : table(tbl), pos(p) { }
-  // The default constructor, used when I define vars of type table::iterator
-  table_iterator() : table(NULL), pos(0) { }
-  // The copy constructor, for when I say table::iterator foo = tbl.begin()
-  // The default destructor is fine; we don't define one
-  // The default operator= is fine; we don't define one
-
-  // The main thing our iterator does is dereference.  If the table entry
-  // we point to is empty, we return the default value type.
-  // This is the big different function from the const iterator.
-  reference operator*()              {
-    return table_element_adaptor<tabletype>(table, pos);
-  }
-  pointer operator->()               { return &(operator*()); }
-
-  // Helper function to assert things are ok; eg pos is still in range
-  void check() const {
-    assert(table);
-    assert(pos <= table->size());
-  }
-
-  // Arithmetic: we just do arithmetic on pos.  We don't even need to
-  // do bounds checking, since STL doesn't consider that its job.  :-)
-  iterator& operator+=(size_type t) { pos += t; check(); return *this; }
-  iterator& operator-=(size_type t) { pos -= t; check(); return *this; }
-  iterator& operator++()            { ++pos; check(); return *this; }
-  iterator& operator--()            { --pos; check(); return *this; }
-  iterator operator++(int)          { iterator tmp(*this);     // for x++
-                                      ++pos; check(); return tmp; }
-  iterator operator--(int)          { iterator tmp(*this);     // for x--
-                                      --pos; check(); return tmp; }
-  iterator operator+(difference_type i) const  { iterator tmp(*this);
-                                                 tmp += i; return tmp; }
-  iterator operator-(difference_type i) const  { iterator tmp(*this);
-                                                 tmp -= i; return tmp; }
-  difference_type operator-(iterator it) const {      // for "x = it2 - it"
-    assert(table == it.table);
-    return pos - it.pos;
-  }
-  reference operator[](difference_type n) const {
-    return *(*this + n);            // simple though not totally efficient
-  }
-
-  // Comparisons.
-  bool operator==(const iterator& it) const {
-    return table == it.table && pos == it.pos;
-  }
-  bool operator<(const iterator& it) const {
-    assert(table == it.table);              // life is bad bad bad otherwise
-    return pos < it.pos;
-  }
-  bool operator!=(const iterator& it) const { return !(*this == it); }
-  bool operator<=(const iterator& it) const { return !(it < *this); }
-  bool operator>(const iterator& it) const { return it < *this; }
-  bool operator>=(const iterator& it) const { return !(*this < it); }
-
-  // Here's the info we actually need to be an iterator
-  tabletype *table;              // so we can dereference and bounds-check
-  size_type pos;                 // index into the table
-};
-
-// support for "3 + iterator" has to be defined outside the class, alas
-template<class T>
-table_iterator<T> operator+(typename table_iterator<T>::difference_type i,
-                            table_iterator<T> it) {
-  return it + i;               // so people can say it2 = 3 + it
-}
-
-template <class tabletype>
-class const_table_iterator {
- public:
-  typedef table_iterator<tabletype> iterator;
-  typedef const_table_iterator const_iterator;
-
-  typedef std::random_access_iterator_tag iterator_category;
-  typedef typename tabletype::value_type value_type;
-  typedef typename tabletype::difference_type difference_type;
-  typedef typename tabletype::size_type size_type;
-  typedef typename tabletype::const_reference reference;  // we're const-only
-  typedef typename tabletype::const_pointer pointer;
-
-  // The "real" constructor
-  const_table_iterator(const tabletype *tbl, size_type p)
-    : table(tbl), pos(p) { }
-  // The default constructor, used when I define vars of type table::iterator
-  const_table_iterator() : table(NULL), pos(0) { }
-  // The copy constructor, for when I say table::iterator foo = tbl.begin()
-  // Also converts normal iterators to const iterators
-  const_table_iterator(const iterator &from)
-    : table(from.table), pos(from.pos) { }
-  // The default destructor is fine; we don't define one
-  // The default operator= is fine; we don't define one
-
-  // The main thing our iterator does is dereference.  If the table entry
-  // we point to is empty, we return the default value type.
-  reference operator*() const       { return (*table)[pos]; }
-  pointer operator->() const        { return &(operator*()); }
-
-  // Helper function to assert things are ok; eg pos is still in range
-  void check() const {
-    assert(table);
-    assert(pos <= table->size());
-  }
-
-  // Arithmetic: we just do arithmetic on pos.  We don't even need to
-  // do bounds checking, since STL doesn't consider that its job.  :-)
-  const_iterator& operator+=(size_type t) { pos += t; check(); return *this; }
-  const_iterator& operator-=(size_type t) { pos -= t; check(); return *this; }
-  const_iterator& operator++()            { ++pos; check(); return *this; }
-  const_iterator& operator--()            { --pos; check(); return *this; }
-  const_iterator operator++(int) { const_iterator tmp(*this);  // for x++
-                                   ++pos; check(); return tmp; }
-  const_iterator operator--(int) { const_iterator tmp(*this);  // for x--
-                                   --pos; check(); return tmp; }
-  const_iterator operator+(difference_type i) const { const_iterator tmp(*this);
-                                                       tmp += i; return tmp; }
-  const_iterator operator-(difference_type i) const { const_iterator tmp(*this);
-                                                       tmp -= i; return tmp; }
-  difference_type operator-(const_iterator it) const {   // for "x = it2 - it"
-    assert(table == it.table);
-    return pos - it.pos;
-  }
-  reference operator[](difference_type n) const {
-    return *(*this + n);            // simple though not totally efficient
-  }
-
-  // Comparisons.
-  bool operator==(const const_iterator& it) const {
-    return table == it.table && pos == it.pos;
-  }
-  bool operator<(const const_iterator& it) const {
-    assert(table == it.table);              // life is bad bad bad otherwise
-    return pos < it.pos;
-  }
-  bool operator!=(const const_iterator& it) const { return !(*this == it); }
-  bool operator<=(const const_iterator& it) const { return !(it < *this); }
-  bool operator>(const const_iterator& it) const { return it < *this; }
-  bool operator>=(const const_iterator& it) const { return !(*this < it); }
-
-  // Here's the info we actually need to be an iterator
-  const tabletype *table;        // so we can dereference and bounds-check
-  size_type pos;                 // index into the table
-};
-
-// support for "3 + iterator" has to be defined outside the class, alas
-template<class T>
-const_table_iterator<T> operator+(typename
-                                  const_table_iterator<T>::difference_type i,
-                                  const_table_iterator<T> it) {
-  return it + i;               // so people can say it2 = 3 + it
-}
-
-
-// ---------------------------------------------------------------------------
-
-
-/*
-// This is a 2-D iterator.  You specify a begin and end over a list
-// of *containers*.  We iterate over each container by iterating over
-// it.  It's actually simple:
-// VECTOR.begin() VECTOR[0].begin()  --------> VECTOR[0].end() ---,
-//     |          ________________________________________________/
-//     |          \_> VECTOR[1].begin()  -------->  VECTOR[1].end() -,
-//     |          ___________________________________________________/
-//     v          \_> ......
-// VECTOR.end()
-//
-// It's impossible to do random access on one of these things in constant
-// time, so it's just a bidirectional iterator.
-//
-// Unfortunately, because we need to use this for a non-empty iterator,
-// we use nonempty_begin() and nonempty_end() instead of begin() and end()
-// (though only going across, not down).
-*/
-
-#define TWOD_BEGIN_      nonempty_begin
-#define TWOD_END_        nonempty_end
-#define TWOD_ITER_       nonempty_iterator
-#define TWOD_CONST_ITER_ const_nonempty_iterator
-
-template <class containertype>
-class two_d_iterator {
- public:
-  typedef two_d_iterator iterator;
-
-  typedef std::bidirectional_iterator_tag iterator_category;
-  // apparently some versions of VC++ have trouble with two ::'s in a typename
-  typedef typename containertype::value_type _tmp_vt;
-  typedef typename _tmp_vt::value_type value_type;
-  typedef typename _tmp_vt::difference_type difference_type;
-  typedef typename _tmp_vt::reference reference;
-  typedef typename _tmp_vt::pointer pointer;
-
-  // The "real" constructor.  begin and end specify how many rows we have
-  // (in the diagram above); we always iterate over each row completely.
-  two_d_iterator(typename containertype::iterator begin,
-                 typename containertype::iterator end,
-                 typename containertype::iterator curr)
-    : row_begin(begin), row_end(end), row_current(curr), col_current() {
-    if ( row_current != row_end ) {
-      col_current = row_current->TWOD_BEGIN_();
-      advance_past_end();                 // in case cur->begin() == cur->end()
-    }
-  }
-  // If you want to start at an arbitrary place, you can, I guess
-  two_d_iterator(typename containertype::iterator begin,
-                 typename containertype::iterator end,
-                 typename containertype::iterator curr,
-                 typename containertype::value_type::TWOD_ITER_ col)
-    : row_begin(begin), row_end(end), row_current(curr), col_current(col) {
-    advance_past_end();                 // in case cur->begin() == cur->end()
-  }
-  // The default constructor, used when I define vars of type table::iterator
-  two_d_iterator() : row_begin(), row_end(), row_current(), col_current() { }
-  // The default destructor is fine; we don't define one
-  // The default operator= is fine; we don't define one
-
-  // Happy dereferencer
-  reference operator*() const    { return *col_current; }
-  pointer operator->() const     { return &(operator*()); }
-
-  // Arithmetic: we just do arithmetic on pos.  We don't even need to
-  // do bounds checking, since STL doesn't consider that its job.  :-)
-  // NOTE: this is not amortized constant time!  What do we do about it?
-  void advance_past_end() {          // used when col_current points to end()
-    while ( col_current == row_current->TWOD_END_() ) {  // end of current row
-      ++row_current;                                // go to beginning of next
-      if ( row_current != row_end )                 // col is irrelevant at end
-        col_current = row_current->TWOD_BEGIN_();
-      else
-        break;                                      // don't go past row_end
-    }
-  }
-
-  iterator& operator++() {
-    assert(row_current != row_end);                 // how to ++ from there?
-    ++col_current;
-    advance_past_end();                 // in case col_current is at end()
-    return *this;
-  }
-  iterator& operator--() {
-    while ( row_current == row_end ||
-            col_current == row_current->TWOD_BEGIN_() ) {
-      assert(row_current != row_begin);
-      --row_current;
-      col_current = row_current->TWOD_END_();             // this is 1 too far
-    }
-    --col_current;
-    return *this;
-  }
-  iterator operator++(int)       { iterator tmp(*this); ++*this; return tmp; }
-  iterator operator--(int)       { iterator tmp(*this); --*this; return tmp; }
-
-
-  // Comparisons.
-  bool operator==(const iterator& it) const {
-    return ( row_begin == it.row_begin &&
-             row_end == it.row_end &&
-             row_current == it.row_current &&
-             (row_current == row_end || col_current == it.col_current) );
-  }
-  bool operator!=(const iterator& it) const { return !(*this == it); }
-
-
-  // Here's the info we actually need to be an iterator
-  // These need to be public so we convert from iterator to const_iterator
-  typename containertype::iterator row_begin, row_end, row_current;
-  typename containertype::value_type::TWOD_ITER_ col_current;
-};
-
-// The same thing again, but this time const.  :-(
-template <class containertype>
-class const_two_d_iterator {
- public:
-  typedef const_two_d_iterator iterator;
-
-  typedef std::bidirectional_iterator_tag iterator_category;
-  // apparently some versions of VC++ have trouble with two ::'s in a typename
-  typedef typename containertype::value_type _tmp_vt;
-  typedef typename _tmp_vt::value_type value_type;
-  typedef typename _tmp_vt::difference_type difference_type;
-  typedef typename _tmp_vt::const_reference reference;
-  typedef typename _tmp_vt::const_pointer pointer;
-
-  const_two_d_iterator(typename containertype::const_iterator begin,
-                       typename containertype::const_iterator end,
-                       typename containertype::const_iterator curr)
-    : row_begin(begin), row_end(end), row_current(curr), col_current() {
-    if ( curr != end ) {
-      col_current = curr->TWOD_BEGIN_();
-      advance_past_end();                 // in case cur->begin() == cur->end()
-    }
-  }
-  const_two_d_iterator(typename containertype::const_iterator begin,
-                       typename containertype::const_iterator end,
-                       typename containertype::const_iterator curr,
-                       typename containertype::value_type::TWOD_CONST_ITER_ col)
-    : row_begin(begin), row_end(end), row_current(curr), col_current(col) {
-    advance_past_end();                 // in case cur->begin() == cur->end()
-  }
-  const_two_d_iterator()
-    : row_begin(), row_end(), row_current(), col_current() {
-  }
-  // Need this explicitly so we can convert normal iterators to const iterators
-  // TODO(user): explicit?
-  const_two_d_iterator(const two_d_iterator<containertype>& it) :
-    row_begin(it.row_begin), row_end(it.row_end), row_current(it.row_current),
-    col_current(it.col_current) { }
-
-  typename containertype::const_iterator row_begin, row_end, row_current;
-  typename containertype::value_type::TWOD_CONST_ITER_ col_current;
-
-
-  // EVERYTHING FROM HERE DOWN IS THE SAME AS THE NON-CONST ITERATOR
-  reference operator*() const    { return *col_current; }
-  pointer operator->() const     { return &(operator*()); }
-
-  void advance_past_end() {          // used when col_current points to end()
-    while ( col_current == row_current->TWOD_END_() ) {  // end of current row
-      ++row_current;                                // go to beginning of next
-      if ( row_current != row_end )                 // col is irrelevant at end
-        col_current = row_current->TWOD_BEGIN_();
-      else
-        break;                                      // don't go past row_end
-    }
-  }
-  iterator& operator++() {
-    assert(row_current != row_end);                 // how to ++ from there?
-    ++col_current;
-    advance_past_end();                 // in case col_current is at end()
-    return *this;
-  }
-  iterator& operator--() {
-    while ( row_current == row_end ||
-            col_current == row_current->TWOD_BEGIN_() ) {
-      assert(row_current != row_begin);
-      --row_current;
-      col_current = row_current->TWOD_END_();             // this is 1 too far
-    }
-    --col_current;
-    return *this;
-  }
-  iterator operator++(int)       { iterator tmp(*this); ++*this; return tmp; }
-  iterator operator--(int)       { iterator tmp(*this); --*this; return tmp; }
-
-  bool operator==(const iterator& it) const {
-    return ( row_begin == it.row_begin &&
-             row_end == it.row_end &&
-             row_current == it.row_current &&
-             (row_current == row_end || col_current == it.col_current) );
-  }
-  bool operator!=(const iterator& it) const { return !(*this == it); }
-};
-
-// We provide yet another version, to be as frugal with memory as
-// possible.  This one frees each block of memory as it finishes
-// iterating over it.  By the end, the entire table is freed.
-// For understandable reasons, you can only iterate over it once,
-// which is why it's an input iterator
-template <class containertype>
-class destructive_two_d_iterator {
- public:
-  typedef destructive_two_d_iterator iterator;
-
-  typedef std::input_iterator_tag iterator_category;
-  // apparently some versions of VC++ have trouble with two ::'s in a typename
-  typedef typename containertype::value_type _tmp_vt;
-  typedef typename _tmp_vt::value_type value_type;
-  typedef typename _tmp_vt::difference_type difference_type;
-  typedef typename _tmp_vt::reference reference;
-  typedef typename _tmp_vt::pointer pointer;
-
-  destructive_two_d_iterator(typename containertype::iterator begin,
-                             typename containertype::iterator end,
-                             typename containertype::iterator curr)
-    : row_begin(begin), row_end(end), row_current(curr), col_current() {
-    if ( curr != end ) {
-      col_current = curr->TWOD_BEGIN_();
-      advance_past_end();                 // in case cur->begin() == cur->end()
-    }
-  }
-  destructive_two_d_iterator(typename containertype::iterator begin,
-                             typename containertype::iterator end,
-                             typename containertype::iterator curr,
-                             typename containertype::value_type::TWOD_ITER_ col)
-    : row_begin(begin), row_end(end), row_current(curr), col_current(col) {
-    advance_past_end();                 // in case cur->begin() == cur->end()
-  }
-  destructive_two_d_iterator()
-    : row_begin(), row_end(), row_current(), col_current() {
-  }
-
-  typename containertype::iterator row_begin, row_end, row_current;
-  typename containertype::value_type::TWOD_ITER_ col_current;
-
-  // This is the part that destroys
-  void advance_past_end() {          // used when col_current points to end()
-    while ( col_current == row_current->TWOD_END_() ) {  // end of current row
-      row_current->clear();                         // the destructive part
-      // It would be nice if we could decrement sparsetable->num_buckets here
-      ++row_current;                                // go to beginning of next
-      if ( row_current != row_end )                 // col is irrelevant at end
-        col_current = row_current->TWOD_BEGIN_();
-      else
-        break;                                      // don't go past row_end
-    }
-  }
-
-  // EVERYTHING FROM HERE DOWN IS THE SAME AS THE REGULAR ITERATOR
-  reference operator*() const    { return *col_current; }
-  pointer operator->() const     { return &(operator*()); }
-
-  iterator& operator++() {
-    assert(row_current != row_end);                 // how to ++ from there?
-    ++col_current;
-    advance_past_end();                 // in case col_current is at end()
-    return *this;
-  }
-  iterator operator++(int)       { iterator tmp(*this); ++*this; return tmp; }
-
-  bool operator==(const iterator& it) const {
-    return ( row_begin == it.row_begin &&
-             row_end == it.row_end &&
-             row_current == it.row_current &&
-             (row_current == row_end || col_current == it.col_current) );
-  }
-  bool operator!=(const iterator& it) const { return !(*this == it); }
-};
-
-#undef TWOD_BEGIN_
-#undef TWOD_END_
-#undef TWOD_ITER_
-#undef TWOD_CONST_ITER_
-
-
-
-
-// SPARSE-TABLE
-// ------------
-// The idea is that a table with (logically) t buckets is divided
-// into t/M *groups* of M buckets each.  (M is a constant set in
-// GROUP_SIZE for efficiency.)  Each group is stored sparsely.
-// Thus, inserting into the table causes some array to grow, which is
-// slow but still constant time.  Lookup involves doing a
-// logical-position-to-sparse-position lookup, which is also slow but
-// constant time.  The larger M is, the slower these operations are
-// but the less overhead (slightly).
-//
-// To store the sparse array, we store a bitmap B, where B[i] = 1 iff
-// bucket i is non-empty.  Then to look up bucket i we really look up
-// array[# of 1s before i in B].  This is constant time for fixed M.
-//
-// Terminology: the position of an item in the overall table (from
-// 1 .. t) is called its "location."  The logical position in a group
-// (from 1 .. M ) is called its "position."  The actual location in
-// the array (from 1 .. # of non-empty buckets in the group) is
-// called its "offset."
-
-// The weird mod in the offset is entirely to quiet compiler warnings
-// as is the cast to int after doing the "x mod 256"
-#define PUT_(take_from, offset)  do {                                          \
-  if (putc(static_cast<int>(((take_from) >> ((offset) % (sizeof(take_from)*8)))\
-                             % 256), fp)                                       \
-      == EOF)                                                                  \
-    return false;                                                              \
-} while (0)
-
-#define GET_(add_to, offset)  do {                                            \
-  if ((x=getc(fp)) == EOF)                                                    \
-    return false;                                                             \
-  else                                                                        \
-    add_to |= (static_cast<size_type>(x) << ((offset) % (sizeof(add_to)*8))); \
-} while (0)
-
-template <class T, u_int16_t GROUP_SIZE, class Alloc>
-class sparsegroup {
- private:
-  typedef typename Alloc::template rebind<T>::other value_alloc_type;
-
- public:
-  // Basic types
-  typedef T value_type;
-  typedef Alloc allocator_type;
-  typedef typename value_alloc_type::reference reference;
-  typedef typename value_alloc_type::const_reference const_reference;
-  typedef typename value_alloc_type::pointer pointer;
-  typedef typename value_alloc_type::const_pointer const_pointer;
-
-  typedef table_iterator<sparsegroup<T, GROUP_SIZE, Alloc> > iterator;
-  typedef const_table_iterator<sparsegroup<T, GROUP_SIZE, Alloc> >
-      const_iterator;
-  typedef table_element_adaptor<sparsegroup<T, GROUP_SIZE, Alloc> >
-      element_adaptor;
-  typedef u_int16_t size_type;                  // max # of buckets
-  typedef int16_t difference_type;
-  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
-  typedef std::reverse_iterator<iterator> reverse_iterator;   // from iterator.h
-
-  // These are our special iterators, that go over non-empty buckets in a
-  // group.  These aren't const-only because you can change non-empty bcks.
-  typedef pointer nonempty_iterator;
-  typedef const_pointer const_nonempty_iterator;
-  typedef std::reverse_iterator<nonempty_iterator> reverse_nonempty_iterator;
-  typedef std::reverse_iterator<const_nonempty_iterator>
-      const_reverse_nonempty_iterator;
-
-  // Iterator functions
-  iterator begin()                      { return iterator(this, 0); }
-  const_iterator begin() const          { return const_iterator(this, 0); }
-  iterator end()                        { return iterator(this, size()); }
-  const_iterator end() const            { return const_iterator(this, size()); }
-  reverse_iterator rbegin()             { return reverse_iterator(end()); }
-  const_reverse_iterator rbegin() const {
-    return const_reverse_iterator(end());
-  }
-  reverse_iterator rend()               { return reverse_iterator(begin()); }
-  const_reverse_iterator rend() const {
-    return const_reverse_iterator(begin());
-  }
-
-  // We'll have versions for our special non-empty iterator too
-  nonempty_iterator nonempty_begin()             { return group; }
-  const_nonempty_iterator nonempty_begin() const { return group; }
-  nonempty_iterator nonempty_end() {
-    return group + settings.num_buckets;
-  }
-  const_nonempty_iterator nonempty_end() const {
-    return group + settings.num_buckets;
-  }
-  reverse_nonempty_iterator nonempty_rbegin() {
-    return reverse_nonempty_iterator(nonempty_end());
-  }
-  const_reverse_nonempty_iterator nonempty_rbegin() const {
-    return const_reverse_nonempty_iterator(nonempty_end());
-  }
-  reverse_nonempty_iterator nonempty_rend() {
-    return reverse_nonempty_iterator(nonempty_begin());
-  }
-  const_reverse_nonempty_iterator nonempty_rend() const {
-    return const_reverse_nonempty_iterator(nonempty_begin());
-  }
-
-
-  // This gives us the "default" value to return for an empty bucket.
-  // We just use the default constructor on T, the template type
-  const_reference default_value() const {
-    static value_type defaultval = value_type();
-    return defaultval;
-  }
-
-
- private:
-  // We need to do all this bit manipulation, of course.  ick
-  static size_type charbit(size_type i)  { return i >> 3; }
-  static size_type modbit(size_type i)   { return 1 << (i&7); }
-  int bmtest(size_type i) const    { return bitmap[charbit(i)] & modbit(i); }
-  void bmset(size_type i)          { bitmap[charbit(i)] |= modbit(i); }
-  void bmclear(size_type i)        { bitmap[charbit(i)] &= ~modbit(i); }
-
-  pointer allocate_group(size_type n) {
-    pointer retval = settings.allocate(n);
-    if (retval == NULL) {
-      // We really should use PRIuS here, but I don't want to have to add
-      // a whole new configure option, with concomitant macro namespace
-      // pollution, just to print this (unlikely) error message.  So I cast.
-      fprintf(stderr, "sparsehash FATAL ERROR: failed to allocate %lu groups\n",
-              static_cast<unsigned long>(n));
-      exit(1);
-    }
-    return retval;
-  }
-
-  void free_group() {
-    if (!group)  return;
-    pointer end_it = group + settings.num_buckets;
-    for (pointer p = group; p != end_it; ++p)
-      p->~value_type();
-    settings.deallocate(group, settings.num_buckets);
-    group = NULL;
-  }
-
-  static size_type bits_in_char(unsigned char c) {
-    // We could make these ints.  The tradeoff is size (eg does it overwhelm
-    // the cache?) vs efficiency in referencing sub-word-sized array elements.
-    static const char bits_in[256] = {
-      0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
-      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-      1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
-      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-      2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
-      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-      3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
-      4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
-    };
-    return bits_in[c];
-  }
-
- public:                         // get_iter() in sparsetable needs it
-  // We need a small function that tells us how many set bits there are
-  // in positions 0..i-1 of the bitmap.  It uses a big table.
-  // We make it static so templates don't allocate lots of these tables.
-  // There are lots of ways to do this calculation (called 'popcount').
-  // The 8-bit table lookup is one of the fastest, though this
-  // implementation suffers from not doing any loop unrolling.  See, eg,
-  //   http://www.dalkescientific.com/writings/diary/archive/2008/07/03/hakmem_and_other_popcounts.html
-  //   http://gurmeetsingh.wordpress.com/2008/08/05/fast-bit-counting-routines/
-  static size_type pos_to_offset(const unsigned char *bm, size_type pos) {
-    size_type retval = 0;
-
-    // [Note: condition pos > 8 is an optimization; convince yourself we
-    // give exactly the same result as if we had pos >= 8 here instead.]
-    for ( ; pos > 8; pos -= 8 )                   // bm[0..pos/8-1]
-      retval += bits_in_char(*bm++);              // chars we want *all* bits in
-    return retval + bits_in_char(*bm & ((1 << pos)-1));    // char including pos
-  }
-
-  size_type pos_to_offset(size_type pos) const {  // not static but still const
-    return pos_to_offset(bitmap, pos);
-  }
-
-  // Returns the (logical) position in the bm[] array, i, such that
-  // bm[i] is the offset-th set bit in the array.  It is the inverse
-  // of pos_to_offset.  get_pos() uses this function to find the index
-  // of an nonempty_iterator in the table.  Bit-twiddling from
-  // http://hackersdelight.org/basics.pdf
-  static size_type offset_to_pos(const unsigned char *bm, size_type offset) {
-    size_type retval = 0;
-    // This is sizeof(this->bitmap).
-    const size_type group_size = (GROUP_SIZE-1) / 8 + 1;
-    for (size_type i = 0; i < group_size; i++) {   // forward scan
-      unsigned char pop_count = bits_in_char(*bm);
-      if (pop_count > offset) {
-        unsigned char last_bm = *bm;
-        for (; offset > 0; offset--) {
-          last_bm &= (last_bm-1);  // remove right-most set bit
-        }
-        // Clear all bits to the left of the rightmost bit (the &),
-        // and then clear the rightmost bit but set all bits to the
-        // right of it (the -1).
-        last_bm = (last_bm & -last_bm) - 1;
-        retval += bits_in_char(last_bm);
-        return retval;
-      }
-      offset -= pop_count;
-      retval += 8;
-      bm++;
-    }
-    return retval;
-  }
-
-  size_type offset_to_pos(size_type offset) const {
-    return offset_to_pos(bitmap, offset);
-  }
-
-
- public:
-  // Constructors -- default and copy -- and destructor
-  explicit sparsegroup(allocator_type& a) :
-      group(0), settings(alloc_impl<value_alloc_type>(a)) {
-    memset(bitmap, 0, sizeof(bitmap));
-  }
-  sparsegroup(const sparsegroup& x) : group(0), settings(x.settings) {
-    if ( settings.num_buckets ) {
-      group = allocate_group(x.settings.num_buckets);
-      std::uninitialized_copy(x.group, x.group + x.settings.num_buckets, group);
-    }
-    memcpy(bitmap, x.bitmap, sizeof(bitmap));
-  }
-  ~sparsegroup() { free_group(); }
-
-  // Operator= is just like the copy constructor, I guess
-  // TODO(user): Make this exception safe. Handle exceptions in value_type's
-  // copy constructor.
-  sparsegroup &operator=(const sparsegroup& x) {
-    if ( &x == this ) return *this;                    // x = x
-    if ( x.settings.num_buckets == 0 ) {
-      free_group();
-    } else {
-      pointer p = allocate_group(x.settings.num_buckets);
-      std::uninitialized_copy(x.group, x.group + x.settings.num_buckets, p);
-      free_group();
-      group = p;
-    }
-    memcpy(bitmap, x.bitmap, sizeof(bitmap));
-    settings.num_buckets = x.settings.num_buckets;
-    return *this;
-  }
-
-  // Many STL algorithms use swap instead of copy constructors
-  void swap(sparsegroup& x) {
-    std::swap(group, x.group);                // defined in <algorithm>
-    for ( int i = 0; i < sizeof(bitmap) / sizeof(*bitmap); ++i )
-      std::swap(bitmap[i], x.bitmap[i]);      // swap not defined on arrays
-    std::swap(settings.num_buckets, x.settings.num_buckets);
-    // we purposefully don't swap the allocator, which may not be swap-able
-  }
-
-  // It's always nice to be able to clear a table without deallocating it
-  void clear() {
-    free_group();
-    memset(bitmap, 0, sizeof(bitmap));
-    settings.num_buckets = 0;
-  }
-
-  // Functions that tell you about size.  Alas, these aren't so useful
-  // because our table is always fixed size.
-  size_type size() const           { return GROUP_SIZE; }
-  size_type max_size() const       { return GROUP_SIZE; }
-  bool empty() const               { return false; }
-  // We also may want to know how many *used* buckets there are
-  size_type num_nonempty() const   { return settings.num_buckets; }
-
-
-  // get()/set() are explicitly const/non-const.  You can use [] if
-  // you want something that can be either (potentially more expensive).
-  const_reference get(size_type i) const {
-    if ( bmtest(i) )           // bucket i is occupied
-      return group[pos_to_offset(bitmap, i)];
-    else
-      return default_value();  // return the default reference
-  }
-
-  // TODO(user): make protected + friend
-  // This is used by sparse_hashtable to get an element from the table
-  // when we know it exists.
-  const_reference unsafe_get(size_type i) const {
-    assert(bmtest(i));
-    return group[pos_to_offset(bitmap, i)];
-  }
-
-  // TODO(user): make protected + friend
-  reference mutating_get(size_type i) {    // fills bucket i before getting
-    if ( !bmtest(i) )
-      set(i, default_value());
-    return group[pos_to_offset(bitmap, i)];
-  }
-
-  // Syntactic sugar.  It's easy to return a const reference.  To
-  // return a non-const reference, we need to use the assigner adaptor.
-  const_reference operator[](size_type i) const {
-    return get(i);
-  }
-
-  element_adaptor operator[](size_type i) {
-    return element_adaptor(this, i);
-  }
-
- private:
-  // Create space at group[offset], assuming value_type has trivial
-  // copy constructor and destructor, and the allocator_type is
-  // the default libc_allocator_with_alloc.  (Really, we want it to have
-  // "trivial move", because that's what realloc and memmove both do.
-  // But there's no way to capture that using type_traits, so we
-  // pretend that move(x, y) is equivalent to "x.~T(); new(x) T(y);"
-  // which is pretty much correct, if a bit conservative.)
-  void set_aux(size_type offset, base::true_type) {
-    group = settings.realloc_or_die(group, settings.num_buckets+1);
-    // This is equivalent to memmove(), but faster on my Intel P4,
-    // at least with gcc4.1 -O2 / glibc 2.3.6.
-    for (size_type i = settings.num_buckets; i > offset; --i)
-      memcpy(group + i, group + i-1, sizeof(*group));
-  }
-
-  // Create space at group[offset], without special assumptions about value_type
-  // and allocator_type.
-  void set_aux(size_type offset, base::false_type) {
-    // This is valid because 0 <= offset <= num_buckets
-    pointer p = allocate_group(settings.num_buckets + 1);
-    std::uninitialized_copy(group, group + offset, p);
-    std::uninitialized_copy(group + offset, group + settings.num_buckets,
-                            p + offset + 1);
-    free_group();
-    group = p;
-  }
-
- public:
-  // This returns a reference to the inserted item (which is a copy of val).
-  // TODO(user): Make this exception safe: handle exceptions from
-  // value_type's copy constructor.
-  reference set(size_type i, const_reference val) {
-    size_type offset =
-        pos_to_offset(bitmap, i);  // where we'll find (or insert)
-    if ( bmtest(i) ) {
-      // Delete the old value, which we're replacing with the new one
-      group[offset].~value_type();
-    } else {
-      typedef base::integral_constant<bool,
-          (base::has_trivial_copy<value_type>::value &&
-           base::has_trivial_destructor<value_type>::value &&
-           base::is_same<
-               allocator_type,
-               libc_allocator_with_realloc<value_type> >::value)>
-          realloc_and_memmove_ok; // we pretend mv(x,y) == "x.~T(); new(x) T(y)"
-      set_aux(offset, realloc_and_memmove_ok());
-      ++settings.num_buckets;
-      bmset(i);
-    }
-    // This does the actual inserting.  Since we made the array using
-    // malloc, we use "placement new" to just call the constructor.
-    new(&group[offset]) value_type(val);
-    return group[offset];
-  }
-
-  // We let you see if a bucket is non-empty without retrieving it
-  bool test(size_type i) const {
-    return bmtest(i) != 0;
-  }
-  bool test(iterator pos) const {
-    return bmtest(pos.pos) != 0;
-  }
-
- private:
-  // Shrink the array, assuming value_type has trivial copy
-  // constructor and destructor, and the allocator_type is the default
-  // libc_allocator_with_alloc.  (Really, we want it to have "trivial
-  // move", because that's what realloc and memmove both do.  But
-  // there's no way to capture that using type_traits, so we pretend
-  // that move(x, y) is equivalent to ""x.~T(); new(x) T(y);"
-  // which is pretty much correct, if a bit conservative.)
-  void erase_aux(size_type offset, base::true_type) {
-    // This isn't technically necessary, since we know we have a
-    // trivial destructor, but is a cheap way to get a bit more safety.
-    group[offset].~value_type();
-    // This is equivalent to memmove(), but faster on my Intel P4,
-    // at lesat with gcc4.1 -O2 / glibc 2.3.6.
-    assert(settings.num_buckets > 0);
-    for (size_type i = offset; i < settings.num_buckets-1; ++i)
-      memcpy(group + i, group + i+1, sizeof(*group));  // hopefully inlined!
-    group = settings.realloc_or_die(group, settings.num_buckets-1);
-  }
-
-  // Shrink the array, without any special assumptions about value_type and
-  // allocator_type.
-  void erase_aux(size_type offset, base::false_type) {
-    // This is valid because 0 <= offset < num_buckets. Note the inequality.
-    pointer p = allocate_group(settings.num_buckets - 1);
-    std::uninitialized_copy(group, group + offset, p);
-    std::uninitialized_copy(group + offset + 1, group + settings.num_buckets,
-                            p + offset);
-    free_group();
-    group = p;
-  }
-
- public:
-  // This takes the specified elements out of the group.  This is
-  // "undefining", rather than "clearing".
-  // TODO(user): Make this exception safe: handle exceptions from
-  // value_type's copy constructor.
-  void erase(size_type i) {
-    if ( bmtest(i) ) {                         // trivial to erase empty bucket
-      size_type offset =
-          pos_to_offset(bitmap, i);  // where we'll find (or insert)
-      if ( settings.num_buckets == 1 ) {
-        free_group();
-        group = NULL;
-      } else {
-        typedef base::integral_constant<bool,
-            (base::has_trivial_copy<value_type>::value &&
-             base::has_trivial_destructor<value_type>::value &&
-             base::is_same<
-                 allocator_type,
-                 libc_allocator_with_realloc<value_type> >::value)>
-            realloc_and_memmove_ok;  // pretend mv(x,y) == "x.~T(); new(x) T(y)"
-        erase_aux(offset, realloc_and_memmove_ok());
-      }
-      --settings.num_buckets;
-      bmclear(i);
-    }
-  }
-
-  void erase(iterator pos) {
-    erase(pos.pos);
-  }
-
-  void erase(iterator start_it, iterator end_it) {
-    // This could be more efficient, but to do so we'd need to make
-    // bmclear() clear a range of indices.  Doesn't seem worth it.
-    for ( ; start_it != end_it; ++start_it )
-      erase(start_it);
-  }
-
-
-  // I/O
-  // We support reading and writing groups to disk.  We don't store
-  // the actual array contents (which we don't know how to store),
-  // just the bitmap and size.  Meant to be used with table I/O.
-
-  // Returns true if all was ok.
-  bool write_metadata(FILE *fp) const {
-    // we explicitly set to u_int16_t
-    assert(sizeof(settings.num_buckets) == 2);
-    PUT_(settings.num_buckets, 8);
-    PUT_(settings.num_buckets, 0);
-    if ( !fwrite(bitmap, sizeof(bitmap), 1, fp) )
-      return false;
-    return true;
-  }
-
-  // Reading destroys the old group contents!  Returns true if all was ok.
-  bool read_metadata(FILE *fp) {
-    clear();
-
-    int x;          // the GET_ macro requires an 'int x' to be defined
-    GET_(settings.num_buckets, 8);
-    GET_(settings.num_buckets, 0);
-
-    if ( !fread(bitmap, sizeof(bitmap), 1, fp) )  return false;
-
-    // We'll allocate the space, but we won't fill it: it will be
-    // left as uninitialized raw memory.
-    group = allocate_group(settings.num_buckets);
-    return true;
-  }
-
-  // If your keys and values are simple enough, we can write them
-  // to disk for you.  "simple enough" means POD and no pointers.
-  // However, we don't try to normalize endianness.
-  bool write_nopointer_data(FILE *fp) const {
-    for ( const_nonempty_iterator it = nonempty_begin();
-          it != nonempty_end(); ++it ) {
-      if ( !fwrite(&*it, sizeof(*it), 1, fp) )  return false;
-    }
-    return true;
-  }
-
-  // When reading, we have to override the potential const-ness of *it.
-  // Again, only meaningful if value_type is a POD.
-  bool read_nopointer_data(FILE *fp) {
-    for ( nonempty_iterator it = nonempty_begin();
-          it != nonempty_end(); ++it ) {
-      if ( !fread(reinterpret_cast<void*>(&(*it)), sizeof(*it), 1, fp) )
-        return false;
-    }
-    return true;
-  }
-
-
-  // Comparisons.  We only need to define == and < -- we get
-  // != > <= >= via relops.h (which we happily included above).
-  // Note the comparisons are pretty arbitrary: we compare
-  // values of the first index that isn't equal (using default
-  // value for empty buckets).
-  bool operator==(const sparsegroup& x) const {
-    return ( settings.num_buckets == x.settings.num_buckets &&
-             memcmp(bitmap, x.bitmap, sizeof(bitmap)) == 0 &&
-             std::equal(begin(), end(), x.begin()) );    // from <algorithm>
-  }
-
-  bool operator<(const sparsegroup& x) const {      // also from <algorithm>
-    return std::lexicographical_compare(begin(), end(), x.begin(), x.end());
-  }
-  bool operator!=(const sparsegroup& x) const { return !(*this == x); }
-  bool operator<=(const sparsegroup& x) const { return !(x < *this); }
-  bool operator>(const sparsegroup& x) const { return x < *this; }
-  bool operator>=(const sparsegroup& x) const { return !(*this < x); }
-
- private:
-  template <class A>
-  class alloc_impl : public A {
-   public:
-    typedef typename A::pointer pointer;
-    typedef typename A::size_type size_type;
-
-    // Convert a normal allocator to one that has realloc_or_die()
-    alloc_impl(const A& a) : A(a) {}  // TODO(user): explicit?
-
-    // realloc_or_die should only be used when using the default
-    // allocator (libc_allocator_with_realloc).
-    pointer realloc_or_die(pointer /*ptr*/, size_type /*n*/) {
-      fprintf(stderr, "realloc_or_die is only supported for "
-                      "libc_allocator_with_realloc\n");
-      exit(1);
-      return NULL;
-    }
-  };
-
-  // A template specialization of alloc_impl for
-  // libc_allocator_with_realloc that can handle realloc_or_die.
-  template <class A>
-  class alloc_impl<libc_allocator_with_realloc<A> >
-      : public libc_allocator_with_realloc<A> {
-   public:
-    typedef typename libc_allocator_with_realloc<A>::pointer pointer;
-    typedef typename libc_allocator_with_realloc<A>::size_type size_type;
-
-    alloc_impl(const libc_allocator_with_realloc<A>& a)
-        : libc_allocator_with_realloc<A>(a) { }
-
-    pointer realloc_or_die(pointer ptr, size_type n) {
-      pointer retval = this->reallocate(ptr, n);
-      if (retval == NULL) {
-        fprintf(stderr, "sparsehash: FATAL ERROR: failed to reallocate "
-                "%lu elements for ptr %p", static_cast<unsigned long>(n), ptr);
-        exit(1);
-      }
-      return retval;
-    }
-  };
-
-  // Package allocator with num_buckets to eliminate memory needed for the
-  // zero-size allocator.
-  // If new fields are added to this class, we should add them to
-  // operator= and swap.
-  class Settings : public alloc_impl<value_alloc_type> {
-   public:
-    Settings(const alloc_impl<value_alloc_type>& a, u_int16_t n = 0)
-        : alloc_impl<value_alloc_type>(a), num_buckets(n) { }
-    Settings(const Settings& s)
-        : alloc_impl<value_alloc_type>(s), num_buckets(s.num_buckets) { }
-
-    u_int16_t num_buckets;                    // limits GROUP_SIZE to 64K
-  };
-
-  // The actual data
-  pointer group;                              // (small) array of T's
-  Settings settings;                          // allocator and num_buckets
-  unsigned char bitmap[(GROUP_SIZE-1)/8 + 1];  // fancy math is so we round up
-};
-
-// We need a global swap as well
-template <class T, u_int16_t GROUP_SIZE, class Alloc>
-inline void swap(sparsegroup<T, GROUP_SIZE, Alloc> &x,
-                 sparsegroup<T, GROUP_SIZE, Alloc> &y) {
-  x.swap(y);
-}
-
-// ---------------------------------------------------------------------------
-
-
-template <class T, u_int16_t GROUP_SIZE = DEFAULT_SPARSEGROUP_SIZE,
-          class Alloc = libc_allocator_with_realloc<T> >
-class sparsetable {
- private:
-  typedef typename Alloc::template rebind<T>::other value_alloc_type;
-  typedef typename Alloc::template rebind<
-      sparsegroup<T, GROUP_SIZE, value_alloc_type> >::other vector_alloc;
-
- public:
-  // Basic types
-  typedef T value_type;                        // stolen from stl_vector.h
-  typedef Alloc allocator_type;
-  typedef typename value_alloc_type::size_type size_type;
-  typedef typename value_alloc_type::difference_type difference_type;
-  typedef typename value_alloc_type::reference reference;
-  typedef typename value_alloc_type::const_reference const_reference;
-  typedef typename value_alloc_type::pointer pointer;
-  typedef typename value_alloc_type::const_pointer const_pointer;
-  typedef table_iterator<sparsetable<T, GROUP_SIZE, Alloc> > iterator;
-  typedef const_table_iterator<sparsetable<T, GROUP_SIZE, Alloc> >
-      const_iterator;
-  typedef table_element_adaptor<sparsetable<T, GROUP_SIZE, Alloc> >
-      element_adaptor;
-  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
-  typedef std::reverse_iterator<iterator> reverse_iterator;   // from iterator.h
-
-  // These are our special iterators, that go over non-empty buckets in a
-  // table.  These aren't const only because you can change non-empty bcks.
-  typedef two_d_iterator<
-      std::vector< sparsegroup<value_type, GROUP_SIZE, value_alloc_type>,
-                   vector_alloc> >
-     nonempty_iterator;
-  typedef const_two_d_iterator<
-      std::vector< sparsegroup<value_type, GROUP_SIZE, value_alloc_type>,
-                   vector_alloc> >
-      const_nonempty_iterator;
-  typedef std::reverse_iterator<nonempty_iterator> reverse_nonempty_iterator;
-  typedef std::reverse_iterator<const_nonempty_iterator>
-      const_reverse_nonempty_iterator;
-  // Another special iterator: it frees memory as it iterates (used to resize)
-  typedef destructive_two_d_iterator<
-      std::vector< sparsegroup<value_type, GROUP_SIZE, value_alloc_type >,
-                   vector_alloc> >
-      destructive_iterator;
-
-  // Iterator functions
-  iterator begin()                      { return iterator(this, 0); }
-  const_iterator begin() const          { return const_iterator(this, 0); }
-  iterator end()                        { return iterator(this, size()); }
-  const_iterator end() const            { return const_iterator(this, size()); }
-  reverse_iterator rbegin()             { return reverse_iterator(end()); }
-  const_reverse_iterator rbegin() const {
-    return const_reverse_iterator(end());
-  }
-  reverse_iterator rend()               { return reverse_iterator(begin()); }
-  const_reverse_iterator rend() const {
-    return const_reverse_iterator(begin());
-  }
-
-  // Versions for our special non-empty iterator
-  nonempty_iterator nonempty_begin()             {
-    return nonempty_iterator(groups.begin(), groups.end(), groups.begin());
-  }
-  const_nonempty_iterator nonempty_begin() const {
-    return
-        const_nonempty_iterator(groups.begin(), groups.end(), groups.begin());
-  }
-  nonempty_iterator nonempty_end() {
-    return nonempty_iterator(groups.begin(), groups.end(), groups.end());
-  }
-  const_nonempty_iterator nonempty_end() const {
-    return const_nonempty_iterator(groups.begin(), groups.end(), groups.end());
-  }
-  reverse_nonempty_iterator nonempty_rbegin() {
-    return reverse_nonempty_iterator(nonempty_end());
-  }
-  const_reverse_nonempty_iterator nonempty_rbegin() const {
-    return const_reverse_nonempty_iterator(nonempty_end());
-  }
-  reverse_nonempty_iterator nonempty_rend() {
-    return reverse_nonempty_iterator(nonempty_begin());
-  }
-  const_reverse_nonempty_iterator nonempty_rend() const {
-    return const_reverse_nonempty_iterator(nonempty_begin());
-  }
-  destructive_iterator destructive_begin() {
-    return destructive_iterator(groups.begin(), groups.end(), groups.begin());
-  }
-  destructive_iterator destructive_end() {
-    return destructive_iterator(groups.begin(), groups.end(), groups.end());
-  }
-
-  typedef sparsegroup<value_type, GROUP_SIZE, allocator_type> group_type;
-  typedef std::vector<group_type, vector_alloc > group_vector_type;
-
-  typedef typename group_vector_type::reference GroupsReference;
-  typedef typename group_vector_type::const_reference GroupsConstReference;
-  typedef typename group_vector_type::iterator GroupsIterator;
-  typedef typename group_vector_type::const_iterator GroupsConstIterator;
-
-  // How to deal with the proper group
-  static size_type num_groups(size_type num) {   // how many to hold num buckets
-    return num == 0 ? 0 : ((num-1) / GROUP_SIZE) + 1;
-  }
-
-  u_int16_t pos_in_group(size_type i) const {
-    return static_cast<u_int16_t>(i % GROUP_SIZE);
-  }
-  size_type group_num(size_type i) const {
-    return i / GROUP_SIZE;
-  }
-  GroupsReference which_group(size_type i) {
-    return groups[group_num(i)];
-  }
-  GroupsConstReference which_group(size_type i) const {
-    return groups[group_num(i)];
-  }
-
- public:
-  // Constructors -- default, normal (when you specify size), and copy
-  explicit sparsetable(size_type sz = 0, Alloc alloc = Alloc())
-      : groups(vector_alloc(alloc)), settings(alloc, sz) {
-    groups.resize(num_groups(sz), group_type(settings));
-  }
-  // We can get away with using the default copy constructor,
-  // and default destructor, and hence the default operator=.  Huzzah!
-
-  // Many STL algorithms use swap instead of copy constructors
-  void swap(sparsetable& x) {
-    std::swap(groups, x.groups);              // defined in stl_algobase.h
-    std::swap(settings.table_size, x.settings.table_size);
-    std::swap(settings.num_buckets, x.settings.num_buckets);
-  }
-
-  // It's always nice to be able to clear a table without deallocating it
-  void clear() {
-    GroupsIterator group;
-    for ( group = groups.begin(); group != groups.end(); ++group ) {
-      group->clear();
-    }
-    settings.num_buckets = 0;
-  }
-
-  // ACCESSOR FUNCTIONS for the things we templatize on, basically
-  allocator_type get_allocator() const {
-    return allocator_type(settings);
-  }
-
-
-  // Functions that tell you about size.
-  // NOTE: empty() is non-intuitive!  It does not tell you the number
-  // of not-empty buckets (use num_nonempty() for that).  Instead
-  // it says whether you've allocated any buckets or not.
-  size_type size() const           { return settings.table_size; }
-  size_type max_size() const       { return settings.max_size(); }
-  bool empty() const               { return settings.table_size == 0; }
-  // We also may want to know how many *used* buckets there are
-  size_type num_nonempty() const   { return settings.num_buckets; }
-
-  // OK, we'll let you resize one of these puppies
-  void resize(size_type new_size) {
-    groups.resize(num_groups(new_size), group_type(settings));
-    if ( new_size < settings.table_size ) {
-      // lower num_buckets, clear last group
-      if ( pos_in_group(new_size) > 0 )     // need to clear inside last group
-        groups.back().erase(groups.back().begin() + pos_in_group(new_size),
-                            groups.back().end());
-      settings.num_buckets = 0;                   // refigure # of used buckets
-      GroupsConstIterator group;
-      for ( group = groups.begin(); group != groups.end(); ++group )
-        settings.num_buckets += group->num_nonempty();
-    }
-    settings.table_size = new_size;
-  }
-
-
-  // We let you see if a bucket is non-empty without retrieving it
-  bool test(size_type i) const {
-    assert(i < settings.table_size);
-    return which_group(i).test(pos_in_group(i));
-  }
-  bool test(iterator pos) const {
-    return which_group(pos.pos).test(pos_in_group(pos.pos));
-  }
-  bool test(const_iterator pos) const {
-    return which_group(pos.pos).test(pos_in_group(pos.pos));
-  }
-
-  // We only return const_references because it's really hard to
-  // return something settable for empty buckets.  Use set() instead.
-  const_reference get(size_type i) const {
-    assert(i < settings.table_size);
-    return which_group(i).get(pos_in_group(i));
-  }
-
-  // TODO(user): make protected + friend
-  // This is used by sparse_hashtable to get an element from the table
-  // when we know it exists (because the caller has called test(i)).
-  const_reference unsafe_get(size_type i) const {
-    assert(i < settings.table_size);
-    assert(test(i));
-    return which_group(i).unsafe_get(pos_in_group(i));
-  }
-
-  // TODO(user): make protected + friend element_adaptor
-  reference mutating_get(size_type i) {    // fills bucket i before getting
-    assert(i < settings.table_size);
-    size_type old_numbuckets = which_group(i).num_nonempty();
-    reference retval = which_group(i).mutating_get(pos_in_group(i));
-    settings.num_buckets += which_group(i).num_nonempty() - old_numbuckets;
-    return retval;
-  }
-
-  // Syntactic sugar.  As in sparsegroup, the non-const version is harder
-  const_reference operator[](size_type i) const {
-    return get(i);
-  }
-
-  element_adaptor operator[](size_type i) {
-    return element_adaptor(this, i);
-  }
-
-  // Needed for hashtables, gets as a nonempty_iterator.  Crashes for empty bcks
-  const_nonempty_iterator get_iter(size_type i) const {
-    assert(test(i));    // how can a nonempty_iterator point to an empty bucket?
-    return const_nonempty_iterator(
-      groups.begin(), groups.end(),
-      groups.begin() + group_num(i),
-      (groups[group_num(i)].nonempty_begin() +
-       groups[group_num(i)].pos_to_offset(pos_in_group(i))));
-  }
-  // For nonempty we can return a non-const version
-  nonempty_iterator get_iter(size_type i) {
-    assert(test(i));    // how can a nonempty_iterator point to an empty bucket?
-    return nonempty_iterator(
-      groups.begin(), groups.end(),
-      groups.begin() + group_num(i),
-      (groups[group_num(i)].nonempty_begin() +
-       groups[group_num(i)].pos_to_offset(pos_in_group(i))));
-  }
-
-  // And the reverse transformation.
-  size_type get_pos(const const_nonempty_iterator it) const {
-    difference_type current_row = it.row_current - it.row_begin;
-    difference_type current_col = (it.col_current -
-                                   groups[current_row].nonempty_begin());
-    return ((current_row * GROUP_SIZE) +
-            groups[current_row].offset_to_pos(current_col));
-  }
-
-
-  // This returns a reference to the inserted item (which is a copy of val)
-  // The trick is to figure out whether we're replacing or inserting anew
-  reference set(size_type i, const_reference val) {
-    assert(i < settings.table_size);
-    size_type old_numbuckets = which_group(i).num_nonempty();
-    reference retval = which_group(i).set(pos_in_group(i), val);
-    settings.num_buckets += which_group(i).num_nonempty() - old_numbuckets;
-    return retval;
-  }
-
-  // This takes the specified elements out of the table.  This is
-  // "undefining", rather than "clearing".
-  void erase(size_type i) {
-    assert(i < settings.table_size);
-    size_type old_numbuckets = which_group(i).num_nonempty();
-    which_group(i).erase(pos_in_group(i));
-    settings.num_buckets += which_group(i).num_nonempty() - old_numbuckets;
-  }
-
-  void erase(iterator pos) {
-    erase(pos.pos);
-  }
-
-  void erase(iterator start_it, iterator end_it) {
-    // This could be more efficient, but then we'd need to figure
-    // out if we spanned groups or not.  Doesn't seem worth it.
-    for ( ; start_it != end_it; ++start_it )
-      erase(start_it);
-  }
-
-
-  // We support reading and writing tables to disk.  We don't store
-  // the actual array contents (which we don't know how to store),
-  // just the groups and sizes.  Returns true if all went ok.
-
- private:
-  // Every time the disk format changes, this should probably change too
-  typedef unsigned long MagicNumberType;
-  static const MagicNumberType MAGIC_NUMBER = 0x24687531;
-
-  // Old versions of this code write all data in 32 bits.  We need to
-  // support these files as well as having support for 64-bit systems.
-  // So we use the following encoding scheme: for values < 2^32-1, we
-  // store in 4 bytes in big-endian order.  For values > 2^32, we
-  // store 0xFFFFFFF followed by 8 bytes in big-endian order.  This
-  // causes us to mis-read old-version code that stores exactly
-  // 0xFFFFFFF, but I don't think that is likely to have happened for
-  // these particular values.
-  template <typename IntType>
-  static bool write_32_or_64(FILE* fp, IntType value) {
-    if ( value < 0xFFFFFFFFULL ) {        // fits in 4 bytes
-      PUT_(value, 24);
-      PUT_(value, 16);
-      PUT_(value, 8);
-      PUT_(value, 0);
-    } else if ( value == 0xFFFFFFFFUL ) {   // special case in 32bit systems
-      PUT_(0xFF, 0); PUT_(0xFF, 0); PUT_(0xFF, 0); PUT_(0xFF, 0);  // marker
-      PUT_(0, 0); PUT_(0, 0); PUT_(0, 0); PUT_(0, 0);
-      PUT_(0xFF, 0); PUT_(0xFF, 0); PUT_(0xFF, 0); PUT_(0xFF, 0);
-    } else {
-      PUT_(0xFF, 0); PUT_(0xFF, 0); PUT_(0xFF, 0); PUT_(0xFF, 0);  // marker
-      PUT_(value, 56);
-      PUT_(value, 48);
-      PUT_(value, 40);
-      PUT_(value, 32);
-      PUT_(value, 24);
-      PUT_(value, 16);
-      PUT_(value, 8);
-      PUT_(value, 0);
-    }
-    return true;
-  }
-
-  template <typename IntType>
-  static bool read_32_or_64(FILE* fp, IntType *value) {  // reads into value
-    size_type first4 = 0;
-    int x;
-    GET_(first4, 24);
-    GET_(first4, 16);
-    GET_(first4, 8);
-    GET_(first4, 0);
-    if ( first4 < 0xFFFFFFFFULL ) {
-      *value = first4;
-    } else {
-      GET_(*value, 56);
-      GET_(*value, 48);
-      GET_(*value, 40);
-      GET_(*value, 32);
-      GET_(*value, 24);
-      GET_(*value, 16);
-      GET_(*value, 8);
-      GET_(*value, 0);
-    }
-    return true;
-  }
-
- public:
-  bool write_metadata(FILE *fp) const {
-    if ( !write_32_or_64(fp, MAGIC_NUMBER) )  return false;
-    if ( !write_32_or_64(fp, settings.table_size) )  return false;
-    if ( !write_32_or_64(fp, settings.num_buckets) )  return false;
-
-    GroupsConstIterator group;
-    for ( group = groups.begin(); group != groups.end(); ++group )
-      if ( group->write_metadata(fp) == false )  return false;
-    return true;
-  }
-
-  // Reading destroys the old table contents!  Returns true if read ok.
-  bool read_metadata(FILE *fp) {
-    size_type magic_read = 0;
-    if ( !read_32_or_64(fp, &magic_read) )  return false;
-    if ( magic_read != MAGIC_NUMBER ) {
-      clear();                        // just to be consistent
-      return false;
-    }
-
-    if ( !read_32_or_64(fp, &settings.table_size) )  return false;
-    if ( !read_32_or_64(fp, &settings.num_buckets) )  return false;
-
-    resize(settings.table_size);                    // so the vector's sized ok
-    GroupsIterator group;
-    for ( group = groups.begin(); group != groups.end(); ++group )
-      if ( group->read_metadata(fp) == false )  return false;
-    return true;
-  }
-
-  // This code is identical to that for SparseGroup
-  // If your keys and values are simple enough, we can write them
-  // to disk for you.  "simple enough" means no pointers.
-  // However, we don't try to normalize endianness
-  bool write_nopointer_data(FILE *fp) const {
-    for ( const_nonempty_iterator it = nonempty_begin();
-          it != nonempty_end(); ++it ) {
-      if ( !fwrite(&*it, sizeof(*it), 1, fp) )  return false;
-    }
-    return true;
-  }
-
-  // When reading, we have to override the potential const-ness of *it
-  bool read_nopointer_data(FILE *fp) {
-    for ( nonempty_iterator it = nonempty_begin();
-          it != nonempty_end(); ++it ) {
-      if ( !fread(reinterpret_cast<void*>(&(*it)), sizeof(*it), 1, fp) )
-        return false;
-    }
-    return true;
-  }
-
-
-  // Comparisons.  Note the comparisons are pretty arbitrary: we
-  // compare values of the first index that isn't equal (using default
-  // value for empty buckets).
-  bool operator==(const sparsetable& x) const {
-    return settings.table_size == x.settings.table_size &&
-           settings.num_buckets == x.settings.num_buckets &&
-           groups == x.groups;
-  }
-
-  bool operator<(const sparsetable& x) const {
-    return std::lexicographical_compare(begin(), end(), x.begin(), x.end());
-  }
-  bool operator!=(const sparsetable& x) const { return !(*this == x); }
-  bool operator<=(const sparsetable& x) const { return !(x < *this); }
-  bool operator>(const sparsetable& x) const { return x < *this; }
-  bool operator>=(const sparsetable& x) const { return !(*this < x); }
-
-
- private:
-  // Package allocator with table_size and num_buckets to eliminate memory
-  // needed for the zero-size allocator.
-  // If new fields are added to this class, we should add them to
-  // operator= and swap.
-  class Settings : public allocator_type {
-   public:
-    typedef typename allocator_type::size_type size_type;
-
-    Settings(const allocator_type& a, size_type sz = 0, size_type n = 0)
-        : allocator_type(a), table_size(sz), num_buckets(n) { }
-
-    Settings(const Settings& s)
-        : allocator_type(s),
-          table_size(s.table_size), num_buckets(s.num_buckets) { }
-
-    size_type table_size;          // how many buckets they want
-    size_type num_buckets;         // number of non-empty buckets
-  };
-
-  // The actual data
-  group_vector_type groups;        // our list of groups
-  Settings settings;               // allocator, table size, buckets
-};
-
-// We need a global swap as well
-template <class T, u_int16_t GROUP_SIZE, class Alloc>
-inline void swap(sparsetable<T, GROUP_SIZE, Alloc> &x,
-                 sparsetable<T, GROUP_SIZE, Alloc> &y) {
-  x.swap(y);
-}
-
-#undef GET_
-#undef PUT_
-
-}
-
-#endif  // UTIL_GTL_SPARSETABLE_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/spinlock.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock.cc b/be/src/gutil/spinlock.cc
index a5ca7c6..8a02c95 100644
--- a/be/src/gutil/spinlock.cc
+++ b/be/src/gutil/spinlock.cc
@@ -32,11 +32,11 @@
  * Author: Sanjay Ghemawat
  */
 
-#include "gutil/spinlock.h"
-#include "gutil/synchronization_profiling.h"
-#include "gutil/spinlock_internal.h"
-#include "gutil/walltime.h"
-#include "gutil/sysinfo.h"   /* for NumCPUs() */
+#include "kudu/gutil/spinlock.h"
+#include "kudu/gutil/synchronization_profiling.h"
+#include "kudu/gutil/spinlock_internal.h"
+#include "kudu/gutil/walltime.h"
+#include "kudu/gutil/sysinfo.h"   /* for NumCPUs() */
 
 namespace base {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/spinlock.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock.h b/be/src/gutil/spinlock.h
index 3cf7d3e..fcd6287 100644
--- a/be/src/gutil/spinlock.h
+++ b/be/src/gutil/spinlock.h
@@ -39,10 +39,10 @@
 #ifndef BASE_SPINLOCK_H_
 #define BASE_SPINLOCK_H_
 
-#include "gutil/atomicops.h"
-#include "gutil/basictypes.h"
-#include "gutil/dynamic_annotations.h"
-#include "gutil/thread_annotations.h"
+#include "kudu/gutil/atomicops.h"
+#include "kudu/gutil/basictypes.h"
+#include "kudu/gutil/dynamic_annotations.h"
+#include "kudu/gutil/thread_annotations.h"
 
 // This isn't originally in the base:: namespace in tcmalloc,
 // but tcmalloc inadvertently exports these symbols. So, if we

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/spinlock_internal.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock_internal.cc b/be/src/gutil/spinlock_internal.cc
index 0850cf1..151b0dd 100644
--- a/be/src/gutil/spinlock_internal.cc
+++ b/be/src/gutil/spinlock_internal.cc
@@ -41,17 +41,17 @@
 // In all cases, it must return in bounded time even if SpinlockWake() is not
 // called.
 
-#include "gutil/spinlock_internal.h"
+#include "kudu/gutil/spinlock_internal.h"
 
 // forward declaration for use by spinlock_*-inl.h
 namespace base { namespace internal { static int SuggestedDelayNS(int loop); }}
 
 #if defined(_WIN32)
-#include "gutil/spinlock_win32-inl.h"
+#include "kudu/gutil/spinlock_win32-inl.h"
 #elif defined(__linux__)
-#include "gutil/spinlock_linux-inl.h"
+#include "kudu/gutil/spinlock_linux-inl.h"
 #else
-#include "gutil/spinlock_posix-inl.h"
+#include "kudu/gutil/spinlock_posix-inl.h"
 #endif
 
 namespace base {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/spinlock_internal.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock_internal.h b/be/src/gutil/spinlock_internal.h
index a7f5150..c235893 100644
--- a/be/src/gutil/spinlock_internal.h
+++ b/be/src/gutil/spinlock_internal.h
@@ -36,8 +36,8 @@
 #ifndef BASE_SPINLOCK_INTERNAL_H_
 #define BASE_SPINLOCK_INTERNAL_H_
 
-#include "gutil/basictypes.h"
-#include "gutil/atomicops.h"
+#include "kudu/gutil/basictypes.h"
+#include "kudu/gutil/atomicops.h"
 
 namespace base {
 namespace internal {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/spinlock_linux-inl.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock_linux-inl.h b/be/src/gutil/spinlock_linux-inl.h
index c9838e4..41ef03a 100644
--- a/be/src/gutil/spinlock_linux-inl.h
+++ b/be/src/gutil/spinlock_linux-inl.h
@@ -36,7 +36,7 @@
 #include <sched.h>
 #include <time.h>
 #include <limits.h>
-#include "gutil/linux_syscall_support.h"
+#include "kudu/gutil/linux_syscall_support.h"
 
 #define FUTEX_WAIT 0
 #define FUTEX_WAKE 1

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/spinlock_win32-inl.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/spinlock_win32-inl.h b/be/src/gutil/spinlock_win32-inl.h
index ed636b4..956b965 100644
--- a/be/src/gutil/spinlock_win32-inl.h
+++ b/be/src/gutil/spinlock_win32-inl.h
@@ -1,37 +1,54 @@
-// Copyright 2009 Google, Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-// All rights reserved.
+// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
+/* Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ---
+ * This file is a Win32-specific part of spinlock_internal.cc
+ */
 
-// This file is a Win32-specific part of spinlock_wait.cc
 
 #include <windows.h>
 
 namespace base {
-namespace subtle {
+namespace internal {
 
 void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop) {
   if (loop == 0) {
   } else if (loop == 1) {
     Sleep(0);
   } else {
-    Sleep(base::subtle::SuggestedDelayNS(loop) / 1000000);
+    Sleep(base::internal::SuggestedDelayNS(loop) / 1000000);
   }
 }
 
 void SpinLockWake(volatile Atomic32 *w, bool all) {
 }
 
-} // namespace subtle
+} // namespace internal
 } // namespace base


[13/14] incubator-impala git commit: IMPALA-4758: (2/2) Impala-side changes to build with latest gutil

Posted by he...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/strip.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/strip.cc b/be/src/gutil/strings/strip.cc
index 1a6a547..ff7449b 100644
--- a/be/src/gutil/strings/strip.cc
+++ b/be/src/gutil/strings/strip.cc
@@ -4,7 +4,7 @@
 // This file contains functions that remove a defined part from the string,
 // i.e., strip the string.
 
-#include "kudu/gutil/strings/strip.h"
+#include "gutil/strings/strip.h"
 
 #include <assert.h>
 #include <string.h>
@@ -18,8 +18,8 @@ using std::swap;
 #include <string>
 using std::string;
 
-#include "kudu/gutil/strings/ascii_ctype.h"
-#include "kudu/gutil/strings/stringpiece.h"
+#include "gutil/strings/ascii_ctype.h"
+#include "gutil/strings/stringpiece.h"
 
 string StripPrefixString(StringPiece str, const StringPiece& prefix) {
   if (str.starts_with(prefix))

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/strip.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/strip.h b/be/src/gutil/strings/strip.h
index 8104b76..cdde845 100644
--- a/be/src/gutil/strings/strip.h
+++ b/be/src/gutil/strings/strip.h
@@ -11,8 +11,8 @@
 #include <string>
 using std::string;
 
-#include "kudu/gutil/strings/ascii_ctype.h"
-#include "kudu/gutil/strings/stringpiece.h"
+#include "gutil/strings/ascii_ctype.h"
+#include "gutil/strings/stringpiece.h"
 
 // Given a string and a putative prefix, returns the string minus the
 // prefix string if the prefix matches, otherwise the original

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/substitute.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/substitute.cc b/be/src/gutil/strings/substitute.cc
index 245894b..76ca151 100644
--- a/be/src/gutil/strings/substitute.cc
+++ b/be/src/gutil/strings/substitute.cc
@@ -1,13 +1,13 @@
 // Copyright 2008 Google Inc.  All rights reserved.
 
-#include "kudu/gutil/strings/substitute.h"
+#include "gutil/strings/substitute.h"
 
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/strings/ascii_ctype.h"
-#include "kudu/gutil/strings/escaping.h"
-#include "kudu/gutil/stl_util.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/macros.h"
+#include "gutil/strings/ascii_ctype.h"
+#include "gutil/strings/escaping.h"
+#include "gutil/stl_util.h"
 
 namespace strings {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/substitute.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/substitute.h b/be/src/gutil/strings/substitute.h
index 0812c3f..84d362a 100644
--- a/be/src/gutil/strings/substitute.h
+++ b/be/src/gutil/strings/substitute.h
@@ -4,9 +4,9 @@
 #include <string>
 using std::string;
 
-#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/strings/numbers.h"
-#include "kudu/gutil/strings/stringpiece.h"
+#include "gutil/basictypes.h"
+#include "gutil/strings/numbers.h"
+#include "gutil/strings/stringpiece.h"
 
 
 #ifndef STRINGS_SUBSTITUTE_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/util.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/util.cc b/be/src/gutil/strings/util.cc
index c16d9b2..a5e29c4 100644
--- a/be/src/gutil/strings/util.cc
+++ b/be/src/gutil/strings/util.cc
@@ -5,7 +5,7 @@
 // TODO(user): visit each const_cast.  Some of them are no longer necessary
 // because last Single Unix Spec and grte v2 are more const-y.
 
-#include "kudu/gutil/strings/util.h"
+#include "gutil/strings/util.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -24,13 +24,13 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include <glog/logging.h>
-#include "kudu/gutil/logging-inl.h"
-#include "kudu/gutil/strings/ascii_ctype.h"
-#include "kudu/gutil/strings/numbers.h"
-#include "kudu/gutil/strings/stringpiece.h"
-#include "kudu/gutil/stl_util.h"  // for string_as_array, STLAppendToString
-#include "kudu/gutil/utf/utf.h"
+#include <common/logging.h>
+#include "gutil/logging-inl.h"
+#include "gutil/strings/ascii_ctype.h"
+#include "gutil/strings/numbers.h"
+#include "gutil/strings/stringpiece.h"
+#include "gutil/stl_util.h"  // for string_as_array, STLAppendToString
+#include "gutil/utf/utf.h"
 
 #ifdef OS_WINDOWS
 #ifdef min  // windows.h defines this to something silly

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strings/util.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/util.h b/be/src/gutil/strings/util.h
index 59db97d..2090e0f 100644
--- a/be/src/gutil/strings/util.h
+++ b/be/src/gutil/strings/util.h
@@ -42,9 +42,9 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/strings/stringpiece.h"
+#include "gutil/integral_types.h"
+#include "gutil/port.h"
+#include "gutil/strings/stringpiece.h"
 
 // Newer functions.
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strtoint.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strtoint.cc b/be/src/gutil/strtoint.cc
index bb96a57..9df29a3 100644
--- a/be/src/gutil/strtoint.cc
+++ b/be/src/gutil/strtoint.cc
@@ -5,8 +5,8 @@
 //
 
 #include <errno.h>
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/strtoint.h"
+#include "gutil/port.h"
+#include "gutil/strtoint.h"
 
 // Replacement strto[u]l functions that have identical overflow and underflow
 // characteristics for both ILP-32 and LP-64 platforms, including errno

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/strtoint.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strtoint.h b/be/src/gutil/strtoint.h
index b581385..581ebf9 100644
--- a/be/src/gutil/strtoint.h
+++ b/be/src/gutil/strtoint.h
@@ -33,9 +33,9 @@
 #include <stdlib.h> // For strtol* functions.
 #include <string>
 using std::string;
-#include "kudu/gutil/integral_types.h"
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/port.h"
+#include "gutil/integral_types.h"
+#include "gutil/macros.h"
+#include "gutil/port.h"
 
 // Adapter functions for handling overflow and errno.
 int32 strto32_adapter(const char *nptr, char **endptr, int base);

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/synchronization_profiling.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/synchronization_profiling.h b/be/src/gutil/synchronization_profiling.h
index f008871..3292787 100644
--- a/be/src/gutil/synchronization_profiling.h
+++ b/be/src/gutil/synchronization_profiling.h
@@ -35,7 +35,7 @@
 #ifndef BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
 #define BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
 
-#include "kudu/gutil/basictypes.h"
+#include "gutil/basictypes.h"
 
 namespace gutil {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/sysinfo.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/sysinfo.cc b/be/src/gutil/sysinfo.cc
index 6006b6d..a2b6077 100644
--- a/be/src/gutil/sysinfo.cc
+++ b/be/src/gutil/sysinfo.cc
@@ -53,11 +53,11 @@
 #include <shlwapi.h>          // for SHGetValueA()
 #include <tlhelp32.h>         // for Module32First()
 #endif
-#include "kudu/gutil/dynamic_annotations.h"   // for RunningOnValgrind
-#include "kudu/gutil/macros.h"
-#include "kudu/gutil/sysinfo.h"
-#include "kudu/gutil/walltime.h"
-#include <glog/logging.h>
+#include "gutil/dynamic_annotations.h"   // for RunningOnValgrind
+#include "gutil/macros.h"
+#include "gutil/sysinfo.h"
+#include "gutil/walltime.h"
+#include <common/logging.h>
 
 // This isn't in the 'base' namespace in tcmallc. But, tcmalloc
 // exports these functions, so we need to namespace them to avoid

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/threading/thread_collision_warner.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/threading/thread_collision_warner.cc b/be/src/gutil/threading/thread_collision_warner.cc
index 89270d8..2fa4415 100644
--- a/be/src/gutil/threading/thread_collision_warner.cc
+++ b/be/src/gutil/threading/thread_collision_warner.cc
@@ -2,11 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "kudu/gutil/threading/thread_collision_warner.h"
+#include "gutil/threading/thread_collision_warner.h"
 
-#include <glog/logging.h>
+#include <common/logging.h>
 
-#include "kudu/gutil/linux_syscall_support.h"
+#include "gutil/linux_syscall_support.h"
 
 namespace base {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/threading/thread_collision_warner.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/threading/thread_collision_warner.h b/be/src/gutil/threading/thread_collision_warner.h
index d59ea67..92d3e5c 100644
--- a/be/src/gutil/threading/thread_collision_warner.h
+++ b/be/src/gutil/threading/thread_collision_warner.h
@@ -7,9 +7,9 @@
 
 #include <memory>
 
-#include "kudu/gutil/atomicops.h"
-#include "kudu/gutil/port.h"
-#include "kudu/gutil/macros.h"
+#include "gutil/atomicops.h"
+#include "gutil/port.h"
+#include "gutil/macros.h"
  
 #ifndef BASE_EXPORT
 #define BASE_EXPORT

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/type_traits.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/type_traits.h b/be/src/gutil/type_traits.h
index a4e874f..db03e54 100644
--- a/be/src/gutil/type_traits.h
+++ b/be/src/gutil/type_traits.h
@@ -63,7 +63,7 @@
 using std::make_pair;
 using std::pair;                  // For pair
 
-#include "kudu/gutil/template_util.h"     // For true_type and false_type
+#include "gutil/template_util.h"     // For true_type and false_type
 
 namespace base {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/walltime.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/walltime.cc b/be/src/gutil/walltime.cc
index 89a805e..8f19f97 100644
--- a/be/src/gutil/walltime.cc
+++ b/be/src/gutil/walltime.cc
@@ -24,7 +24,7 @@
 #define _GNU_SOURCE   // Linux wants that for strptime in time.h
 #endif
 
-#include "kudu/gutil/walltime.h"
+#include "gutil/walltime.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -183,6 +183,7 @@ WallTime WallTime_Now() {
 #endif  // defined(__APPLE__)
 }
 
+
 void StringAppendStrftime(string* dst,
                           const char* format,
                           time_t when,

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/gutil/walltime.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/walltime.h b/be/src/gutil/walltime.h
index e6a1294..e16e5ca 100644
--- a/be/src/gutil/walltime.h
+++ b/be/src/gutil/walltime.h
@@ -21,7 +21,7 @@
 
 #include <sys/time.h>
 
-#include <glog/logging.h>
+#include <common/logging.h>
 #include <string>
 using std::string;
 
@@ -30,10 +30,16 @@ using std::string;
 #include <mach/mach.h>
 #include <mach/mach_time.h>
 
-#include "kudu/gutil/once.h"
+#include "gutil/once.h"
 #endif  // defined(__APPLE__)
 
-#include "kudu/gutil/integral_types.h"
+#include "gutil/integral_types.h"
+
+#define NANOS_PER_SEC  1000000000ll
+#define NANOS_PER_MICRO      1000ll
+#define MICROS_PER_SEC    1000000ll
+#define MICROS_PER_MILLI     1000ll
+#define MILLIS_PER_SEC       1000ll
 
 typedef double WallTime;
 
@@ -80,7 +86,7 @@ inline void GetCurrentTime(mach_timespec_t* ts) {
 inline MicrosecondsInt64 GetCurrentTimeMicros() {
   mach_timespec_t ts;
   GetCurrentTime(&ts);
-  return ts.tv_sec * 1e6 + ts.tv_nsec / 1e3;
+  return ts.tv_sec * MICROS_PER_SEC + ts.tv_nsec / NANOS_PER_MICRO;
 }
 
 inline int64_t GetMonoTimeNanos() {
@@ -95,7 +101,7 @@ inline int64_t GetMonoTimeNanos() {
 }
 
 inline MicrosecondsInt64 GetMonoTimeMicros() {
-  return GetMonoTimeNanos() / 1e3;
+  return GetMonoTimeNanos() / NANOS_PER_MICRO;
 }
 
 inline MicrosecondsInt64 GetThreadCpuTimeMicros() {
@@ -121,7 +127,8 @@ inline MicrosecondsInt64 GetThreadCpuTimeMicros() {
     return 0;
   }
 
-  return thread_info_data.user_time.seconds * 1e6 + thread_info_data.user_time.microseconds;
+  return thread_info_data.user_time.seconds * MICROS_PER_SEC +
+      thread_info_data.user_time.microseconds;
 }
 
 #else
@@ -129,7 +136,7 @@ inline MicrosecondsInt64 GetThreadCpuTimeMicros() {
 inline MicrosecondsInt64 GetClockTimeMicros(clockid_t clock) {
   timespec ts;
   clock_gettime(clock, &ts);
-  return ts.tv_sec * 1e6 + ts.tv_nsec / 1e3;
+  return ts.tv_sec * MICROS_PER_SEC + ts.tv_nsec / NANOS_PER_MICRO;
 }
 
 #endif // defined(__APPLE__)
@@ -175,5 +182,5 @@ class CycleClock {
   CycleClock();
 };
 
-#include "kudu/gutil/cycleclock-inl.h"  // inline method bodies
+#include "gutil/cycleclock-inl.h"  // inline method bodies
 #endif  // GUTIL_WALLTIME_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/runtime/buffered-tuple-stream-test.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/buffered-tuple-stream-test.cc b/be/src/runtime/buffered-tuple-stream-test.cc
index 7793767..3c50ec5 100644
--- a/be/src/runtime/buffered-tuple-stream-test.cc
+++ b/be/src/runtime/buffered-tuple-stream-test.cc
@@ -43,7 +43,7 @@
 
 #include "common/names.h"
 
-using base::FreeDeleter;
+using kudu::FreeDeleter;
 
 static const int BATCH_SIZE = 250;
 static const int IO_BLOCK_SIZE = 8 * 1024 * 1024;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/runtime/buffered-tuple-stream-v2-test.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/buffered-tuple-stream-v2-test.cc b/be/src/runtime/buffered-tuple-stream-v2-test.cc
index 5ff6471..da75212 100644
--- a/be/src/runtime/buffered-tuple-stream-v2-test.cc
+++ b/be/src/runtime/buffered-tuple-stream-v2-test.cc
@@ -44,7 +44,7 @@
 
 #include "common/names.h"
 
-using base::FreeDeleter;
+using kudu::FreeDeleter;
 using std::numeric_limits;
 
 static const int BATCH_SIZE = 250;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/runtime/bufferpool/suballocator.cc
----------------------------------------------------------------------
diff --git a/be/src/runtime/bufferpool/suballocator.cc b/be/src/runtime/bufferpool/suballocator.cc
index a6ab1ff..1d74d86 100644
--- a/be/src/runtime/bufferpool/suballocator.cc
+++ b/be/src/runtime/bufferpool/suballocator.cc
@@ -19,7 +19,6 @@
 
 #include <new>
 
-#include "gutil/bits.h"
 #include "runtime/bufferpool/reservation-tracker.h"
 #include "util/bit-util.h"
 
@@ -83,7 +82,7 @@ Status Suballocator::Allocate(int64_t bytes, unique_ptr<Suballocation>* result)
 }
 
 int Suballocator::ComputeListIndex(int64_t bytes) const {
-  return Bits::Log2CeilingNonZero64(bytes) - LOG_MIN_ALLOCATION_BYTES;
+  return BitUtil::Log2CeilingNonZero64(bytes) - LOG_MIN_ALLOCATION_BYTES;
 }
 
 Status Suballocator::AllocateBuffer(int64_t bytes, unique_ptr<Suballocation>* result) {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/runtime/collection-value-builder.h
----------------------------------------------------------------------
diff --git a/be/src/runtime/collection-value-builder.h b/be/src/runtime/collection-value-builder.h
index 701b22b..1811a9a 100644
--- a/be/src/runtime/collection-value-builder.h
+++ b/be/src/runtime/collection-value-builder.h
@@ -60,7 +60,8 @@ class CollectionValueBuilder {
       DCHECK_GE(buffer_size_, bytes_written);
       if (buffer_size_ == bytes_written) {
         // Double tuple buffer
-        int64_t new_buffer_size = max<int64_t>(buffer_size_ * 2, tuple_desc_.byte_size());
+        int64_t new_buffer_size =
+            std::max<int64_t>(buffer_size_ * 2, tuple_desc_.byte_size());
         uint8_t* new_buf = pool_->TryAllocate(new_buffer_size);
         if (UNLIKELY(new_buf == NULL)) {
           *tuple_mem = NULL;
@@ -113,4 +114,3 @@ class CollectionValueBuilder {
 }
 
 #endif
-

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/util/bit-util-test.cc
----------------------------------------------------------------------
diff --git a/be/src/util/bit-util-test.cc b/be/src/util/bit-util-test.cc
index 2559d18..948e5cf 100644
--- a/be/src/util/bit-util-test.cc
+++ b/be/src/util/bit-util-test.cc
@@ -247,16 +247,14 @@ TEST(BitUtil, ByteSwap) {
 }
 
 TEST(BitUtil, Log2) {
-  // We use gutil's implementation in place of an older custom implementation in BitUtil.
-  // We leave this test here to ensure no test coverage is lost.
-  EXPECT_EQ(Bits::Log2CeilingNonZero64(1), 0);
-  EXPECT_EQ(Bits::Log2CeilingNonZero64(2), 1);
-  EXPECT_EQ(Bits::Log2CeilingNonZero64(3), 2);
-  EXPECT_EQ(Bits::Log2CeilingNonZero64(4), 2);
-  EXPECT_EQ(Bits::Log2CeilingNonZero64(5), 3);
-  EXPECT_EQ(Bits::Log2CeilingNonZero64(INT_MAX), 31);
-  EXPECT_EQ(Bits::Log2CeilingNonZero64(UINT_MAX), 32);
-  EXPECT_EQ(Bits::Log2CeilingNonZero64(ULLONG_MAX), 64);
+  EXPECT_EQ(BitUtil::Log2CeilingNonZero64(1), 0);
+  EXPECT_EQ(BitUtil::Log2CeilingNonZero64(2), 1);
+  EXPECT_EQ(BitUtil::Log2CeilingNonZero64(3), 2);
+  EXPECT_EQ(BitUtil::Log2CeilingNonZero64(4), 2);
+  EXPECT_EQ(BitUtil::Log2CeilingNonZero64(5), 3);
+  EXPECT_EQ(BitUtil::Log2CeilingNonZero64(INT_MAX), 31);
+  EXPECT_EQ(BitUtil::Log2CeilingNonZero64(UINT_MAX), 32);
+  EXPECT_EQ(BitUtil::Log2CeilingNonZero64(ULLONG_MAX), 64);
 }
 
 TEST(BitUtil, RoundUpToPowerOf2) {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/util/bit-util.h
----------------------------------------------------------------------
diff --git a/be/src/util/bit-util.h b/be/src/util/bit-util.h
index 571f1ae..25a8c96 100644
--- a/be/src/util/bit-util.h
+++ b/be/src/util/bit-util.h
@@ -32,6 +32,7 @@
 #include <boost/type_traits/make_unsigned.hpp>
 
 #include "common/compiler-util.h"
+#include "gutil/bits.h"
 #include "util/cpu-info.h"
 #include "util/sse-util.h"
 
@@ -285,6 +286,40 @@ class BitUtil {
     if (UNLIKELY(v == 0)) return otherwise;
     return __builtin_ctzll(v);
   }
+
+  /// More efficient version of similar functions found in gutil/
+  static inline int Log2Ceiling(uint32 n) {
+    int floor = Bits::Log2Floor(n);
+    // Check if zero or a power of two. This pattern is recognised by gcc and optimised
+    // into branch-free code.
+    if (0 == (n & (n - 1))) {
+      return floor;
+    } else {
+      return floor + 1;
+    }
+  }
+
+  static inline int Log2Ceiling64(uint64 n) {
+    int floor = Bits::Log2Floor64(n);
+    // Check if zero or a power of two. This pattern is recognised by gcc and optimised
+    // into branch-free code.
+    if (0 == (n & (n - 1))) {
+      return floor;
+    } else {
+      return floor + 1;
+    }
+  }
+
+  static inline int Log2CeilingNonZero64(uint64 n) {
+    int floor = Bits::Log2FloorNonZero64(n);
+    // Check if zero or a power of two. This pattern is recognised by gcc and optimised
+    // into branch-free code.
+    if (0 == (n & (n - 1))) {
+      return floor;
+    } else {
+      return floor + 1;
+    }
+  }
 };
 
 /// An encapsulation class of SIMD byteswap functions

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/util/error-util.h
----------------------------------------------------------------------
diff --git a/be/src/util/error-util.h b/be/src/util/error-util.h
index 25fa0ff..06441cb 100644
--- a/be/src/util/error-util.h
+++ b/be/src/util/error-util.h
@@ -22,9 +22,10 @@
 #include <string>
 #include <vector>
 
+#include "common/logging.h"
 #include "gen-cpp/CatalogObjects_types.h"
-#include "gen-cpp/ErrorCodes_types.h"
 #include "gen-cpp/ErrorCodes_constants.h"
+#include "gen-cpp/ErrorCodes_types.h"
 #include "gen-cpp/ImpalaInternalService_types.h"
 #include "gutil/strings/substitute.h"
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/be/src/util/time.h
----------------------------------------------------------------------
diff --git a/be/src/util/time.h b/be/src/util/time.h
index efe6a3b..3ec009a 100644
--- a/be/src/util/time.h
+++ b/be/src/util/time.h
@@ -31,7 +31,9 @@ namespace impala {
 /// time. Typically the value corresponds to elapsed time since the system booted. See
 /// UnixMillis() below if you need to send a time to a different host.
 inline int64_t MonotonicNanos() {
-  return GetMonoTimeNanos();
+  timespec ts;
+  clock_gettime(CLOCK_MONOTONIC, &ts);
+  return ts.tv_sec * NANOS_PER_SEC + ts.tv_nsec;
 }
 
 inline int64_t MonotonicMicros() {  // 63 bits ~= 5K years uptime

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/23100102/cmake_modules/kudu_cmake_fns.txt
----------------------------------------------------------------------
diff --git a/cmake_modules/kudu_cmake_fns.txt b/cmake_modules/kudu_cmake_fns.txt
index 8cd2cbc..ebbf114 100644
--- a/cmake_modules/kudu_cmake_fns.txt
+++ b/cmake_modules/kudu_cmake_fns.txt
@@ -55,8 +55,12 @@ function(ADD_EXPORTABLE_LIBRARY LIB_NAME)
   set(EXECUTABLE_OUTPUT_PATH "${BUILD_OUTPUT_ROOT_DIRECTORY}/${LIB_NAME}")
 
   add_library(${LIB_NAME} ${ARG_SRCS})
+  if(ARG_COMPILE_FLAGS)
+    set_target_properties(${LIB_NAME}
+      PROPERTIES COMPILE_FLAGS ${ARG_COMPILE_FLAGS})
+  endif()
   if (ARG_DEPS)
-    add_dependencies(${LIB_NAME} ${ARG_DEPS})
+    target_link_libraries(${LIB_NAME} ${ARG_DEPS})
   endif()
 endfunction()
 


[09/14] incubator-impala git commit: IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

Posted by he...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/bind_internal.h.pump
----------------------------------------------------------------------
diff --git a/be/src/gutil/bind_internal.h.pump b/be/src/gutil/bind_internal.h.pump
new file mode 100644
index 0000000..1c8ad61
--- /dev/null
+++ b/be/src/gutil/bind_internal.h.pump
@@ -0,0 +1,464 @@
+$$ This is a pump file for generating file templates.  Pump is a python
+$$ script that is part of the Google Test suite of utilities.  Description
+$$ can be found here:
+$$
+$$ http://code.google.com/p/googletest/wiki/PumpManual
+$$
+
+$$ See comment for MAX_ARITY in gutil/bind.h.pump.
+$var MAX_ARITY = 7
+$range ARITY 0..MAX_ARITY
+
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GUTIL_BIND_INTERNAL_H_
+#define GUTIL_BIND_INTERNAL_H_
+
+#include "gutil/bind_helpers.h"
+#include "gutil/callback_internal.h"
+#include "gutil/raw_scoped_refptr_mismatch_checker.h"
+#include "gutil/template_util.h"
+
+#if defined(OS_WIN)
+#include "gutil/bind_internal_win.h"
+#endif
+
+// During Chromium import, WeakPtr-related code was removed.
+
+namespace kudu {
+namespace internal {
+
+// See gutil/callback.h for user documentation.
+//
+//
+// CONCEPTS:
+//  Runnable -- A type (really a type class) that has a single Run() method
+//              and a RunType typedef that corresponds to the type of Run().
+//              A Runnable can declare that it should treated like a method
+//              call by including a typedef named IsMethod.  The value of
+//              this typedef is NOT inspected, only the existence.  When a
+//              Runnable declares itself a method, Bind() will enforce special
+//              refcounting + WeakPtr handling semantics for the first
+//              parameter which is expected to be an object.
+//  Functor -- A copyable type representing something that should be called.
+//             All function pointers, Callback<>, and Runnables are functors
+//             even if the invocation syntax differs.
+//  RunType -- A function type (as opposed to function _pointer_ type) for
+//             a Run() function.  Usually just a convenience typedef.
+//  (Bound)ArgsType -- A function type that is being (ab)used to store the
+//                     types of set of arguments.  The "return" type is always
+//                     void here.  We use this hack so that we do not need
+//                     a new type name for each arity of type. (eg.,
+//                     BindState1, BindState2).  This makes forward
+//                     declarations and friending much much easier.
+//
+// Types:
+//  RunnableAdapter<> -- Wraps the various "function" pointer types into an
+//                       object that adheres to the Runnable interface.
+//                       There are |3*ARITY| RunnableAdapter types.
+//  FunctionTraits<> -- Type traits that unwrap a function signature into a
+//                      a set of easier to use typedefs.  Used mainly for
+//                      compile time asserts.
+//                      There are |ARITY| FunctionTraits types.
+//  ForceVoidReturn<> -- Helper class for translating function signatures to
+//                       equivalent forms with a "void" return type.
+//                    There are |ARITY| ForceVoidReturn types.
+//  FunctorTraits<> -- Type traits used determine the correct RunType and
+//                     RunnableType for a Functor.  This is where function
+//                     signature adapters are applied.
+//                    There are |ARITY| ForceVoidReturn types.
+//  MakeRunnable<> -- Takes a Functor and returns an object in the Runnable
+//                    type class that represents the underlying Functor.
+//                    There are |O(1)| MakeRunnable types.
+//  InvokeHelper<> -- Take a Runnable + arguments and actully invokes it.
+//                    Handle the differing syntaxes needed for WeakPtr<> support,
+//                    and for ignoring return values.  This is separate from
+//                    Invoker to avoid creating multiple version of Invoker<>
+//                    which grows at O(n^2) with the arity.
+//                    There are |k*ARITY| InvokeHelper types.
+//  Invoker<> -- Unwraps the curried parameters and executes the Runnable.
+//               There are |(ARITY^2 + ARITY)/2| Invoketypes.
+//  BindState<> -- Stores the curried parameters, and is the main entry point
+//                 into the Bind() system, doing most of the type resolution.
+//                 There are ARITY BindState types.
+
+// RunnableAdapter<>
+//
+// The RunnableAdapter<> templates provide a uniform interface for invoking
+// a function pointer, method pointer, or const method pointer. The adapter
+// exposes a Run() method with an appropriate signature. Using this wrapper
+// allows for writing code that supports all three pointer types without
+// undue repetition.  Without it, a lot of code would need to be repeated 3
+// times.
+//
+// For method pointers and const method pointers the first argument to Run()
+// is considered to be the received of the method.  This is similar to STL's
+// mem_fun().
+//
+// This class also exposes a RunType typedef that is the function type of the
+// Run() function.
+//
+// If and only if the wrapper contains a method or const method pointer, an
+// IsMethod typedef is exposed.  The existence of this typedef (NOT the value)
+// marks that the wrapper should be considered a method wrapper.
+
+template <typename Functor>
+class RunnableAdapter;
+
+$for ARITY [[
+$range ARG 1..ARITY
+
+// Function: Arity $(ARITY).
+template <typename R[[]]
+$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
+class RunnableAdapter<R(*)($for ARG , [[A$(ARG)]])> {
+ public:
+  typedef R (RunType)($for ARG , [[A$(ARG)]]);
+
+  explicit RunnableAdapter(R(*function)($for ARG , [[A$(ARG)]]))
+      : function_(function) {
+  }
+
+  R Run($for ARG , [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
+    return function_($for ARG , [[CallbackForward(a$(ARG))]]);
+  }
+
+ private:
+  R (*function_)($for ARG , [[A$(ARG)]]);
+};
+
+// Method: Arity $(ARITY).
+template <typename R, typename T[[]]
+$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
+class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]])> {
+ public:
+  typedef R (RunType)(T*[[]]
+$if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]]))
+      : method_(method) {
+  }
+
+  R Run(T* object[[]]
+$if ARITY > 0[[, ]]  $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
+    return (object->*method_)($for ARG , [[CallbackForward(a$(ARG))]]);
+  }
+
+ private:
+  R (T::*method_)($for ARG , [[A$(ARG)]]);
+};
+
+// Const Method: Arity $(ARITY).
+template <typename R, typename T[[]]
+$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
+class RunnableAdapter<R(T::*)($for ARG , [[A$(ARG)]]) const> {
+ public:
+  typedef R (RunType)(const T*[[]]
+$if ARITY > 0[[, ]] $for ARG , [[A$(ARG)]]);
+  typedef base::true_type IsMethod;
+
+  explicit RunnableAdapter(R(T::*method)($for ARG , [[A$(ARG)]]) const)
+      : method_(method) {
+  }
+
+  R Run(const T* object[[]]
+$if ARITY > 0[[, ]]  $for ARG, [[typename CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) {
+    return (object->*method_)($for ARG , [[CallbackForward(a$(ARG))]]);
+  }
+
+ private:
+  R (T::*method_)($for ARG , [[A$(ARG)]]) const;
+};
+
+]]  $$ for ARITY
+
+
+// FunctionTraits<>
+//
+// Breaks a function signature apart into typedefs for easier introspection.
+template <typename Sig>
+struct FunctionTraits;
+
+$for ARITY [[
+$range ARG 1..ARITY
+
+template <typename R[[]]
+$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
+struct FunctionTraits<R($for ARG , [[A$(ARG)]])> {
+  typedef R ReturnType;
+$for ARG [[
+
+  typedef A$(ARG) A$(ARG)Type;
+]]
+
+};
+
+]]
+
+
+// ForceVoidReturn<>
+//
+// Set of templates that support forcing the function return type to void.
+template <typename Sig>
+struct ForceVoidReturn;
+
+$for ARITY [[
+$range ARG 1..ARITY
+
+template <typename R[[]]
+$if ARITY > 0[[, ]] $for ARG , [[typename A$(ARG)]]>
+struct ForceVoidReturn<R($for ARG , [[A$(ARG)]])> {
+  typedef void(RunType)($for ARG , [[A$(ARG)]]);
+};
+
+]]  $$ for ARITY
+
+
+// FunctorTraits<>
+//
+// See description at top of file.
+template <typename T>
+struct FunctorTraits {
+  typedef RunnableAdapter<T> RunnableType;
+  typedef typename RunnableType::RunType RunType;
+};
+
+template <typename T>
+struct FunctorTraits<IgnoreResultHelper<T> > {
+  typedef typename FunctorTraits<T>::RunnableType RunnableType;
+  typedef typename ForceVoidReturn<
+      typename RunnableType::RunType>::RunType RunType;
+};
+
+template <typename T>
+struct FunctorTraits<Callback<T> > {
+  typedef Callback<T> RunnableType;
+  typedef typename Callback<T>::RunType RunType;
+};
+
+
+// MakeRunnable<>
+//
+// Converts a passed in functor to a RunnableType using type inference.
+
+template <typename T>
+typename FunctorTraits<T>::RunnableType MakeRunnable(const T& t) {
+  return RunnableAdapter<T>(t);
+}
+
+template <typename T>
+typename FunctorTraits<T>::RunnableType
+MakeRunnable(const IgnoreResultHelper<T>& t) {
+  return MakeRunnable(t.functor_);
+}
+
+template <typename T>
+const typename FunctorTraits<Callback<T> >::RunnableType&
+MakeRunnable(const Callback<T>& t) {
+  DCHECK(!t.is_null());
+  return t;
+}
+
+
+// InvokeHelper<>
+//
+// There are 3 logical InvokeHelper<> specializations: normal, void-return,
+// WeakCalls.
+//
+// The normal type just calls the underlying runnable.
+//
+// We need a InvokeHelper to handle void return types in order to support
+// IgnoreResult().  Normally, if the Runnable's RunType had a void return,
+// the template system would just accept "return functor.Run()" ignoring
+// the fact that a void function is being used with return. This piece of
+// sugar breaks though when the Runnable's RunType is not void.  Thus, we
+// need a partial specialization to change the syntax to drop the "return"
+// from the invocation call.
+//
+// WeakCalls similarly need special syntax that is applied to the first
+// argument to check if they should no-op themselves.
+template <bool IsWeakCall, typename ReturnType, typename Runnable,
+          typename ArgsType>
+struct InvokeHelper;
+
+$for ARITY [[
+$range ARG 1..ARITY
+$range WEAKCALL_ARG 2..ARITY
+
+template <typename ReturnType, typename Runnable[[]]
+$if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]>
+struct InvokeHelper<false, ReturnType, Runnable,
+    void($for ARG , [[A$(ARG)]])>  {
+  static ReturnType MakeItSo(Runnable runnable[[]]
+$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) {
+    return runnable.Run($for ARG , [[CallbackForward(a$(ARG))]]);
+  }
+};
+
+template <typename Runnable[[]]
+$if ARITY > 0 [[,]] $for ARG , [[typename A$(ARG)]]>
+struct InvokeHelper<false, void, Runnable,
+    void($for ARG , [[A$(ARG)]])>  {
+  static void MakeItSo(Runnable runnable[[]]
+$if ARITY > 0[[, ]] $for ARG , [[A$(ARG) a$(ARG)]]) {
+    runnable.Run($for ARG , [[CallbackForward(a$(ARG))]]);
+  }
+};
+
+]] $$ for ARITY
+
+// Invoker<>
+//
+// See description at the top of the file.
+template <int NumBound, typename Storage, typename RunType>
+struct Invoker;
+
+$for ARITY [[
+
+$$ Number of bound arguments.
+$range BOUND 0..ARITY
+$for BOUND [[
+
+$var UNBOUND = ARITY - BOUND
+$range ARG 1..ARITY
+$range BOUND_ARG 1..BOUND
+$range UNBOUND_ARG (ARITY - UNBOUND + 1)..ARITY
+
+// Arity $(ARITY) -> $(UNBOUND).
+template <typename StorageType, typename R[[]]
+$if ARITY > 0 [[,]][[]]
+$for ARG , [[typename X$(ARG)]]>
+struct Invoker<$(BOUND), StorageType, R($for ARG , [[X$(ARG)]])> {
+  typedef R(RunType)(BindStateBase*[[]]
+$if UNBOUND != 0 [[, ]]
+$for UNBOUND_ARG , [[typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType]]);
+
+  typedef R(UnboundRunType)($for UNBOUND_ARG , [[X$(UNBOUND_ARG)]]);
+
+  static R Run(BindStateBase* base[[]]
+$if UNBOUND != 0 [[, ]][[]]
+$for UNBOUND_ARG , [[
+typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG)
+]][[]]
+) {
+    StorageType* storage = static_cast<StorageType*>(base);
+
+    // Local references to make debugger stepping easier. If in a debugger,
+    // you really want to warp ahead and step through the
+    // InvokeHelper<>::MakeItSo() call below.
+$for BOUND_ARG
+[[
+
+    typedef typename StorageType::Bound$(BOUND_ARG)UnwrapTraits Bound$(BOUND_ARG)UnwrapTraits;
+]]
+
+
+$for BOUND_ARG
+[[
+
+    typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType x$(BOUND_ARG) =
+        Bound$(BOUND_ARG)UnwrapTraits::Unwrap(storage->p$(BOUND_ARG)_);
+]]
+
+    return InvokeHelper<StorageType::IsWeakCall::value, R,
+           typename StorageType::RunnableType,
+           void(
+$for BOUND_ARG , [[
+typename Bound$(BOUND_ARG)UnwrapTraits::ForwardType
+]]
+
+$if UNBOUND > 0 [[$if BOUND > 0 [[, ]]]][[]]
+
+$for UNBOUND_ARG , [[
+typename CallbackParamTraits<X$(UNBOUND_ARG)>::ForwardType x$(UNBOUND_ARG)
+]]
+)>
+               ::MakeItSo(storage->runnable_
+$if ARITY > 0[[, ]] $for ARG , [[CallbackForward(x$(ARG))]]);
+  }
+};
+
+]] $$ for BOUND
+]] $$ for ARITY
+
+
+// BindState<>
+//
+// This stores all the state passed into Bind() and is also where most
+// of the template resolution magic occurs.
+//
+// Runnable is the functor we are binding arguments to.
+// RunType is type of the Run() function that the Invoker<> should use.
+// Normally, this is the same as the RunType of the Runnable, but it can
+// be different if an adapter like IgnoreResult() has been used.
+//
+// BoundArgsType contains the storage type for all the bound arguments by
+// (ab)using a function type.
+template <typename Runnable, typename RunType, typename BoundArgsType>
+struct BindState;
+
+$for ARITY [[
+$range ARG 1..ARITY
+
+template <typename Runnable, typename RunType[[]]
+$if ARITY > 0[[, ]] $for ARG , [[typename P$(ARG)]]>
+struct BindState<Runnable, RunType, void($for ARG , [[P$(ARG)]])> : public BindStateBase {
+  typedef Runnable RunnableType;
+
+  typedef base::false_type IsWeakCall;
+
+  typedef Invoker<$(ARITY), BindState, RunType> InvokerType;
+  typedef typename InvokerType::UnboundRunType UnboundRunType;
+
+$if ARITY > 0 [[
+
+  // Convenience typedefs for bound argument types.
+
+$for ARG [[
+  typedef UnwrapTraits<P$(ARG)> Bound$(ARG)UnwrapTraits;
+
+]]  $$ for ARG
+
+
+]]  $$ if ARITY > 0
+
+$$ The extra [[ ]] is needed to massage spacing. Silly pump.py.
+[[  ]]$if ARITY == 0 [[explicit ]]BindState(const Runnable& runnable
+$if ARITY > 0 [[, ]] $for ARG , [[const P$(ARG)& p$(ARG)]])
+      : runnable_(runnable)[[]]
+$if ARITY == 0 [[
+ {
+
+]] $else [[
+, $for ARG , [[
+
+        p$(ARG)_(p$(ARG))
+]] {
+    MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::AddRef(p1_);
+
+]]
+  }
+
+  virtual ~BindState() {
+$if ARITY > 0 [[
+    MaybeRefcount<HasIsMethodTag<Runnable>::value, P1>::Release(p1_);
+]]
+  }
+
+  RunnableType runnable_;
+
+$for ARG [[
+  P$(ARG) p$(ARG)_;
+
+]]
+};
+
+]] $$ for ARITY
+
+}  // namespace internal
+}  // namespace kudu
+
+#endif  // GUTIL_BIND_INTERNAL_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/bits.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/bits.cc b/be/src/gutil/bits.cc
index dec6f51..333e464 100644
--- a/be/src/gutil/bits.cc
+++ b/be/src/gutil/bits.cc
@@ -2,7 +2,7 @@
 //
 // Derived from code by Moses Charikar
 
-#include "gutil/bits.h"
+#include "kudu/gutil/bits.h"
 
 #include <assert.h>
 
@@ -71,6 +71,22 @@ int Bits::Log2Floor_Portable(uint32 n) {
   return log;
 }
 
+int Bits::Log2Ceiling(uint32 n) {
+  int floor = Log2Floor(n);
+  if (n == (n &~ (n - 1)))              // zero or a power of two
+    return floor;
+  else
+    return floor + 1;
+}
+
+int Bits::Log2Ceiling64(uint64 n) {
+  int floor = Log2Floor64(n);
+  if (n == (n &~ (n - 1)))              // zero or a power of two
+    return floor;
+  else
+    return floor + 1;
+}
+
 int Bits::FindLSBSetNonZero_Portable(uint32 n) {
   int rc = 31;
   for (int i = 4, shift = 1 << 4; i >= 0; --i) {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/bits.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/bits.h b/be/src/gutil/bits.h
index bce7f69..639186e 100644
--- a/be/src/gutil/bits.h
+++ b/be/src/gutil/bits.h
@@ -2,8 +2,12 @@
 //
 // A collection of useful (static) bit-twiddling functions.
 
-#include "gutil/basictypes.h"
-#include "gutil/integral_types.h"
+#include <glog/logging.h>
+
+#include "kudu/gutil/basictypes.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/macros.h"
 
 #ifndef _BITS_H_
 #define _BITS_H_
@@ -76,10 +80,6 @@ class Bits {
   static int Log2Ceiling(uint32 n);
   static int Log2Ceiling64(uint64 n);
 
-  // Potentially faster version of Log2Ceiling() that returns an
-  // undefined value if n == 0
-  static int Log2CeilingNonZero64(uint64 n);
-
   // Return the first set least / most significant bit, 0-indexed.  Returns an
   // undefined value if n == 0.  FindLSBSetNonZero() is similar to ffs() except
   // that it's 0-indexed, while FindMSBSetNonZero() is the same as
@@ -140,36 +140,6 @@ inline int Bits::Log2FloorNonZero(uint32 n) {
   return 31 ^ __builtin_clz(n);
 }
 
-inline int Bits::Log2Ceiling(uint32 n) {
-  int floor = Log2Floor(n);
-  // Check if zero or a power of two. This pattern is recognised by gcc and optimised
-  // into branch-free code.
-  if (0 == (n & (n - 1)))
-    return floor;
-  else
-    return floor + 1;
-}
-
-inline int Bits::Log2Ceiling64(uint64 n) {
-  int floor = Log2Floor64(n);
-  // Check if zero or a power of two. This pattern is recognised by gcc and optimised
-  // into branch-free code.
-  if (0 == (n & (n - 1)))
-    return floor;
-  else
-    return floor + 1;
-}
-
-inline int Bits::Log2CeilingNonZero64(uint64 n) {
-  int floor = Log2FloorNonZero64(n);
-  // Check if zero or a power of two. This pattern is recognised by gcc and optimised
-  // into branch-free code.
-  if (0 == (n & (n - 1)))
-    return floor;
-  else
-    return floor + 1;
-}
-
 inline int Bits::FindLSBSetNonZero(uint32 n) {
   return __builtin_ctz(n);
 }
@@ -186,9 +156,9 @@ inline int Bits::FindLSBSetNonZero64(uint64 n) {
   return __builtin_ctzll(n);
 }
 #elif defined(_MSC_VER)
-#include "gutil/bits-internal-windows.h"
+#include "kudu/gutil/bits-internal-windows.h"
 #else
-#include "gutil/bits-internal-unknown.h"
+#include "kudu/gutil/bits-internal-unknown.h"
 #endif
 
 inline int Bits::CountOnesInByte(unsigned char n) {

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/callback.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/callback.h b/be/src/gutil/callback.h
new file mode 100644
index 0000000..1a41622
--- /dev/null
+++ b/be/src/gutil/callback.h
@@ -0,0 +1,765 @@
+// This file was GENERATED by command:
+//     pump.py callback.h.pump
+// DO NOT EDIT BY HAND!!!
+
+
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef KUDU_GUTIL_CALLBACK_H_
+#define KUDU_GUTIL_CALLBACK_H_
+
+#include "kudu/gutil/callback_forward.h"
+#include "kudu/gutil/callback_internal.h"
+#include "kudu/gutil/template_util.h"
+
+// NOTE: Header files that do not require the full definition of Callback or
+// Closure should #include "kudu/gutil/callback_forward.h" instead of this file.
+
+// -----------------------------------------------------------------------------
+// Introduction
+// -----------------------------------------------------------------------------
+//
+// The templated Callback class is a generalized function object. Together
+// with the Bind() function in bind.h, they provide a type-safe method for
+// performing partial application of functions.
+//
+// Partial application (or "currying") is the process of binding a subset of
+// a function's arguments to produce another function that takes fewer
+// arguments. This can be used to pass around a unit of delayed execution,
+// much like lexical closures are used in other languages. For example, it
+// is used in Chromium code to schedule tasks on different MessageLoops.
+//
+// A callback with no unbound input parameters (kudu::Callback<void(void)>)
+// is called a kudu::Closure. Note that this is NOT the same as what other
+// languages refer to as a closure -- it does not retain a reference to its
+// enclosing environment.
+//
+// MEMORY MANAGEMENT AND PASSING
+//
+// The Callback objects themselves should be passed by const-reference, and
+// stored by copy. They internally store their state via a refcounted class
+// and thus do not need to be deleted.
+//
+// The reason to pass via a const-reference is to avoid unnecessary
+// AddRef/Release pairs to the internal state.
+//
+//
+// -----------------------------------------------------------------------------
+// Quick reference for basic stuff
+// -----------------------------------------------------------------------------
+//
+// BINDING A BARE FUNCTION
+//
+//   int Return5() { return 5; }
+//   kudu::Callback<int(void)> func_cb = kudu::Bind(&Return5);
+//   LOG(INFO) << func_cb.Run();  // Prints 5.
+//
+// BINDING A CLASS METHOD
+//
+//   The first argument to bind is the member function to call, the second is
+//   the object on which to call it.
+//
+//   class Ref : public kudu::RefCountedThreadSafe<Ref> {
+//    public:
+//     int Foo() { return 3; }
+//     void PrintBye() { LOG(INFO) << "bye."; }
+//   };
+//   scoped_refptr<Ref> ref = new Ref();
+//   kudu::Callback<void(void)> ref_cb = kudu::Bind(&Ref::Foo, ref);
+//   LOG(INFO) << ref_cb.Run();  // Prints out 3.
+//
+//   By default the object must support RefCounted or you will get a compiler
+//   error. If you're passing between threads, be sure it's
+//   RefCountedThreadSafe! See "Advanced binding of member functions" below if
+//   you don't want to use reference counting.
+//
+// RUNNING A CALLBACK
+//
+//   Callbacks can be run with their "Run" method, which has the same
+//   signature as the template argument to the callback.
+//
+//   void DoSomething(const kudu::Callback<void(int, std::string)>& callback) {
+//     callback.Run(5, "hello");
+//   }
+//
+//   Callbacks can be run more than once (they don't get deleted or marked when
+//   run). However, this precludes using kudu::Passed (see below).
+//
+//   void DoSomething(const kudu::Callback<double(double)>& callback) {
+//     double myresult = callback.Run(3.14159);
+//     myresult += callback.Run(2.71828);
+//   }
+//
+// PASSING UNBOUND INPUT PARAMETERS
+//
+//   Unbound parameters are specified at the time a callback is Run(). They are
+//   specified in the Callback template type:
+//
+//   void MyFunc(int i, const std::string& str) {}
+//   kudu::Callback<void(int, const std::string&)> cb = kudu::Bind(&MyFunc);
+//   cb.Run(23, "hello, world");
+//
+// PASSING BOUND INPUT PARAMETERS
+//
+//   Bound parameters are specified when you create the callback as arguments
+//   to Bind(). They will be passed to the function and the Run()ner of the
+//   callback doesn't see those values or even know that the function it's
+//   calling.
+//
+//   void MyFunc(int i, const std::string& str) {}
+//   kudu::Callback<void(void)> cb = kudu::Bind(&MyFunc, 23, "hello world");
+//   cb.Run();
+//
+//   A callback with no unbound input parameters (kudu::Callback<void(void)>)
+//   is called a kudu::Closure. So we could have also written:
+//
+//   kudu::Closure cb = kudu::Bind(&MyFunc, 23, "hello world");
+//
+//   When calling member functions, bound parameters just go after the object
+//   pointer.
+//
+//   kudu::Closure cb = kudu::Bind(&MyClass::MyFunc, this, 23, "hello world");
+//
+// PARTIAL BINDING OF PARAMETERS
+//
+//   You can specify some parameters when you create the callback, and specify
+//   the rest when you execute the callback.
+//
+//   void MyFunc(int i, const std::string& str) {}
+//   kudu::Callback<void(const std::string&)> cb = kudu::Bind(&MyFunc, 23);
+//   cb.Run("hello world");
+//
+//   When calling a function bound parameters are first, followed by unbound
+//   parameters.
+//
+//
+// -----------------------------------------------------------------------------
+// Quick reference for advanced binding
+// -----------------------------------------------------------------------------
+//
+// BINDING A CLASS METHOD WITH WEAK POINTERS
+//
+//   kudu::Bind(&MyClass::Foo, GetWeakPtr());
+//
+//   The callback will not be issued if the object is destroyed at the time
+//   it's issued. DANGER: weak pointers are not threadsafe, so don't use this
+//   when passing between threads!
+//
+// BINDING A CLASS METHOD WITH MANUAL LIFETIME MANAGEMENT
+//
+//   kudu::Bind(&MyClass::Foo, kudu::Unretained(this));
+//
+//   This disables all lifetime management on the object. You're responsible
+//   for making sure the object is alive at the time of the call. You break it,
+//   you own it!
+//
+// BINDING A CLASS METHOD AND HAVING THE CALLBACK OWN THE CLASS
+//
+//   MyClass* myclass = new MyClass;
+//   kudu::Bind(&MyClass::Foo, kudu::Owned(myclass));
+//
+//   The object will be deleted when the callback is destroyed, even if it's
+//   not run (like if you post a task during shutdown). Potentially useful for
+//   "fire and forget" cases.
+//
+// IGNORING RETURN VALUES
+//
+//   Sometimes you want to call a function that returns a value in a callback
+//   that doesn't expect a return value.
+//
+//   int DoSomething(int arg) { cout << arg << endl; }
+//   kudu::Callback<void<int>) cb =
+//       kudu::Bind(kudu::IgnoreResult(&DoSomething));
+//
+//
+// -----------------------------------------------------------------------------
+// Quick reference for binding parameters to Bind()
+// -----------------------------------------------------------------------------
+//
+// Bound parameters are specified as arguments to Bind() and are passed to the
+// function. A callback with no parameters or no unbound parameters is called a
+// Closure (kudu::Callback<void(void)> and kudu::Closure are the same thing).
+//
+// PASSING PARAMETERS OWNED BY THE CALLBACK
+//
+//   void Foo(int* arg) { cout << *arg << endl; }
+//   int* pn = new int(1);
+//   kudu::Closure foo_callback = kudu::Bind(&foo, kudu::Owned(pn));
+//
+//   The parameter will be deleted when the callback is destroyed, even if it's
+//   not run (like if you post a task during shutdown).
+//
+// PASSING PARAMETERS AS A scoped_ptr
+//
+//   void TakesOwnership(scoped_ptr<Foo> arg) {}
+//   scoped_ptr<Foo> f(new Foo);
+//   // f becomes null during the following call.
+//   kudu::Closure cb = kudu::Bind(&TakesOwnership, kudu::Passed(&f));
+//
+//   Ownership of the parameter will be with the callback until the it is run,
+//   when ownership is passed to the callback function. This means the callback
+//   can only be run once. If the callback is never run, it will delete the
+//   object when it's destroyed.
+//
+// PASSING PARAMETERS AS A scoped_refptr
+//
+//   void TakesOneRef(scoped_refptr<Foo> arg) {}
+//   scoped_refptr<Foo> f(new Foo)
+//   kudu::Closure cb = kudu::Bind(&TakesOneRef, f);
+//
+//   This should "just work." The closure will take a reference as long as it
+//   is alive, and another reference will be taken for the called function.
+//
+// PASSING PARAMETERS BY REFERENCE
+//
+//   void foo(int arg) { cout << arg << endl }
+//   int n = 1;
+//   kudu::Closure has_ref = kudu::Bind(&foo, kudu::ConstRef(n));
+//   n = 2;
+//   has_ref.Run();  // Prints "2"
+//
+//   Normally parameters are copied in the closure. DANGER: ConstRef stores a
+//   const reference instead, referencing the original parameter. This means
+//   that you must ensure the object outlives the callback!
+//
+//
+// -----------------------------------------------------------------------------
+// Implementation notes
+// -----------------------------------------------------------------------------
+//
+// WHERE IS THIS DESIGN FROM:
+//
+// The design Callback and Bind is heavily influenced by C++'s
+// tr1::function/tr1::bind, and by the "Google Callback" system used inside
+// Google.
+//
+//
+// HOW THE IMPLEMENTATION WORKS:
+//
+// There are three main components to the system:
+//   1) The Callback classes.
+//   2) The Bind() functions.
+//   3) The arguments wrappers (e.g., Unretained() and ConstRef()).
+//
+// The Callback classes represent a generic function pointer. Internally,
+// it stores a refcounted piece of state that represents the target function
+// and all its bound parameters.  Each Callback specialization has a templated
+// constructor that takes an BindState<>*.  In the context of the constructor,
+// the static type of this BindState<> pointer uniquely identifies the
+// function it is representing, all its bound parameters, and a Run() method
+// that is capable of invoking the target.
+//
+// Callback's constructor takes the BindState<>* that has the full static type
+// and erases the target function type as well as the types of the bound
+// parameters.  It does this by storing a pointer to the specific Run()
+// function, and upcasting the state of BindState<>* to a
+// BindStateBase*. This is safe as long as this BindStateBase pointer
+// is only used with the stored Run() pointer.
+//
+// To BindState<> objects are created inside the Bind() functions.
+// These functions, along with a set of internal templates, are responsible for
+//
+//  - Unwrapping the function signature into return type, and parameters
+//  - Determining the number of parameters that are bound
+//  - Creating the BindState storing the bound parameters
+//  - Performing compile-time asserts to avoid error-prone behavior
+//  - Returning an Callback<> with an arity matching the number of unbound
+//    parameters and that knows the correct refcounting semantics for the
+//    target object if we are binding a method.
+//
+// The Bind functions do the above using type-inference, and template
+// specializations.
+//
+// By default Bind() will store copies of all bound parameters, and attempt
+// to refcount a target object if the function being bound is a class method.
+// These copies are created even if the function takes parameters as const
+// references. (Binding to non-const references is forbidden, see bind.h.)
+//
+// To change this behavior, we introduce a set of argument wrappers
+// (e.g., Unretained(), and ConstRef()).  These are simple container templates
+// that are passed by value, and wrap a pointer to argument.  See the
+// file-level comment in kudu/gutil/bind_helpers.h for more info.
+//
+// These types are passed to the Unwrap() functions, and the MaybeRefcount()
+// functions respectively to modify the behavior of Bind().  The Unwrap()
+// and MaybeRefcount() functions change behavior by doing partial
+// specialization based on whether or not a parameter is a wrapper type.
+//
+// ConstRef() is similar to tr1::cref.  Unretained() is specific to Chromium.
+//
+//
+// WHY NOT TR1 FUNCTION/BIND?
+//
+// Direct use of tr1::function and tr1::bind was considered, but ultimately
+// rejected because of the number of copy constructors invocations involved
+// in the binding of arguments during construction, and the forwarding of
+// arguments during invocation.  These copies will no longer be an issue in
+// C++0x because C++0x will support rvalue reference allowing for the compiler
+// to avoid these copies.  However, waiting for C++0x is not an option.
+//
+// Measured with valgrind on gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5), the
+// tr1::bind call itself will invoke a non-trivial copy constructor three times
+// for each bound parameter.  Also, each when passing a tr1::function, each
+// bound argument will be copied again.
+//
+// In addition to the copies taken at binding and invocation, copying a
+// tr1::function causes a copy to be made of all the bound parameters and
+// state.
+//
+// Furthermore, in Chromium, it is desirable for the Callback to take a
+// reference on a target object when representing a class method call.  This
+// is not supported by tr1.
+//
+// Lastly, tr1::function and tr1::bind has a more general and flexible API.
+// This includes things like argument reordering by use of
+// tr1::bind::placeholder, support for non-const reference parameters, and some
+// limited amount of subtyping of the tr1::function object (e.g.,
+// tr1::function<int(int)> is convertible to tr1::function<void(int)>).
+//
+// These are not features that are required in Chromium. Some of them, such as
+// allowing for reference parameters, and subtyping of functions, may actually
+// become a source of errors. Removing support for these features actually
+// allows for a simpler implementation, and a terser Currying API.
+//
+//
+// WHY NOT GOOGLE CALLBACKS?
+//
+// The Google callback system also does not support refcounting.  Furthermore,
+// its implementation has a number of strange edge cases with respect to type
+// conversion of its arguments.  In particular, the argument's constness must
+// at times match exactly the function signature, or the type-inference might
+// break.  Given the above, writing a custom solution was easier.
+//
+//
+// MISSING FUNCTIONALITY
+//  - Invoking the return of Bind.  Bind(&foo).Run() does not work;
+//  - Binding arrays to functions that take a non-const pointer.
+//    Example:
+//      void Foo(const char* ptr);
+//      void Bar(char* ptr);
+//      Bind(&Foo, "test");
+//      Bind(&Bar, "test");  // This fails because ptr is not const.
+
+namespace kudu {
+
+// First, we forward declare the Callback class template. This informs the
+// compiler that the template only has 1 type parameter which is the function
+// signature that the Callback is representing.
+//
+// After this, create template specializations for 0-7 parameters. Note that
+// even though the template typelist grows, the specialization still
+// only has one type: the function signature.
+//
+// If you are thinking of forward declaring Callback in your own header file,
+// please include "base/callback_forward.h" instead.
+template <typename Sig>
+class Callback;
+
+namespace internal {
+template <typename Runnable, typename RunType, typename BoundArgsType>
+struct BindState;
+}  // namespace internal
+
+template <typename R>
+class Callback<R(void)> : public internal::CallbackBase {
+ public:
+  typedef R(RunType)();
+
+  Callback() : CallbackBase(NULL) { }
+
+  // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+  // return the exact Callback<> type.  See base/bind.h for details.
+  template <typename Runnable, typename BindRunType, typename BoundArgsType>
+  Callback(internal::BindState<Runnable, BindRunType,
+           BoundArgsType>* bind_state)
+      : CallbackBase(bind_state) {
+
+    // Force the assignment to a local variable of PolymorphicInvoke
+    // so the compiler will typecheck that the passed in Run() method has
+    // the correct type.
+    PolymorphicInvoke invoke_func =
+        &internal::BindState<Runnable, BindRunType, BoundArgsType>
+            ::InvokerType::Run;
+    polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+  }
+
+  bool Equals(const Callback& other) const {
+    return CallbackBase::Equals(other);
+  }
+
+  R Run() const {
+    PolymorphicInvoke f =
+        reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+    return f(bind_state_.get());
+  }
+
+ private:
+  typedef R(*PolymorphicInvoke)(
+      internal::BindStateBase*);
+
+};
+
+template <typename R, typename A1>
+class Callback<R(A1)> : public internal::CallbackBase {
+ public:
+  typedef R(RunType)(A1);
+
+  Callback() : CallbackBase(NULL) { }
+
+  // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+  // return the exact Callback<> type.  See base/bind.h for details.
+  template <typename Runnable, typename BindRunType, typename BoundArgsType>
+  Callback(internal::BindState<Runnable, BindRunType,
+           BoundArgsType>* bind_state)
+      : CallbackBase(bind_state) {
+
+    // Force the assignment to a local variable of PolymorphicInvoke
+    // so the compiler will typecheck that the passed in Run() method has
+    // the correct type.
+    PolymorphicInvoke invoke_func =
+        &internal::BindState<Runnable, BindRunType, BoundArgsType>
+            ::InvokerType::Run;
+    polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+  }
+
+  bool Equals(const Callback& other) const {
+    return CallbackBase::Equals(other);
+  }
+
+  R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1) const {
+    PolymorphicInvoke f =
+        reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+    return f(bind_state_.get(), internal::CallbackForward(a1));
+  }
+
+ private:
+  typedef R(*PolymorphicInvoke)(
+      internal::BindStateBase*,
+          typename internal::CallbackParamTraits<A1>::ForwardType);
+
+};
+
+template <typename R, typename A1, typename A2>
+class Callback<R(A1, A2)> : public internal::CallbackBase {
+ public:
+  typedef R(RunType)(A1, A2);
+
+  Callback() : CallbackBase(NULL) { }
+
+  // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+  // return the exact Callback<> type.  See base/bind.h for details.
+  template <typename Runnable, typename BindRunType, typename BoundArgsType>
+  Callback(internal::BindState<Runnable, BindRunType,
+           BoundArgsType>* bind_state)
+      : CallbackBase(bind_state) {
+
+    // Force the assignment to a local variable of PolymorphicInvoke
+    // so the compiler will typecheck that the passed in Run() method has
+    // the correct type.
+    PolymorphicInvoke invoke_func =
+        &internal::BindState<Runnable, BindRunType, BoundArgsType>
+            ::InvokerType::Run;
+    polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+  }
+
+  bool Equals(const Callback& other) const {
+    return CallbackBase::Equals(other);
+  }
+
+  R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1,
+        typename internal::CallbackParamTraits<A2>::ForwardType a2) const {
+    PolymorphicInvoke f =
+        reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+    return f(bind_state_.get(), internal::CallbackForward(a1),
+             internal::CallbackForward(a2));
+  }
+
+ private:
+  typedef R(*PolymorphicInvoke)(
+      internal::BindStateBase*,
+          typename internal::CallbackParamTraits<A1>::ForwardType,
+          typename internal::CallbackParamTraits<A2>::ForwardType);
+
+};
+
+template <typename R, typename A1, typename A2, typename A3>
+class Callback<R(A1, A2, A3)> : public internal::CallbackBase {
+ public:
+  typedef R(RunType)(A1, A2, A3);
+
+  Callback() : CallbackBase(NULL) { }
+
+  // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+  // return the exact Callback<> type.  See base/bind.h for details.
+  template <typename Runnable, typename BindRunType, typename BoundArgsType>
+  Callback(internal::BindState<Runnable, BindRunType,
+           BoundArgsType>* bind_state)
+      : CallbackBase(bind_state) {
+
+    // Force the assignment to a local variable of PolymorphicInvoke
+    // so the compiler will typecheck that the passed in Run() method has
+    // the correct type.
+    PolymorphicInvoke invoke_func =
+        &internal::BindState<Runnable, BindRunType, BoundArgsType>
+            ::InvokerType::Run;
+    polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+  }
+
+  bool Equals(const Callback& other) const {
+    return CallbackBase::Equals(other);
+  }
+
+  R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1,
+        typename internal::CallbackParamTraits<A2>::ForwardType a2,
+        typename internal::CallbackParamTraits<A3>::ForwardType a3) const {
+    PolymorphicInvoke f =
+        reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+    return f(bind_state_.get(), internal::CallbackForward(a1),
+             internal::CallbackForward(a2),
+             internal::CallbackForward(a3));
+  }
+
+ private:
+  typedef R(*PolymorphicInvoke)(
+      internal::BindStateBase*,
+          typename internal::CallbackParamTraits<A1>::ForwardType,
+          typename internal::CallbackParamTraits<A2>::ForwardType,
+          typename internal::CallbackParamTraits<A3>::ForwardType);
+
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4>
+class Callback<R(A1, A2, A3, A4)> : public internal::CallbackBase {
+ public:
+  typedef R(RunType)(A1, A2, A3, A4);
+
+  Callback() : CallbackBase(NULL) { }
+
+  // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+  // return the exact Callback<> type.  See base/bind.h for details.
+  template <typename Runnable, typename BindRunType, typename BoundArgsType>
+  Callback(internal::BindState<Runnable, BindRunType,
+           BoundArgsType>* bind_state)
+      : CallbackBase(bind_state) {
+
+    // Force the assignment to a local variable of PolymorphicInvoke
+    // so the compiler will typecheck that the passed in Run() method has
+    // the correct type.
+    PolymorphicInvoke invoke_func =
+        &internal::BindState<Runnable, BindRunType, BoundArgsType>
+            ::InvokerType::Run;
+    polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+  }
+
+  bool Equals(const Callback& other) const {
+    return CallbackBase::Equals(other);
+  }
+
+  R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1,
+        typename internal::CallbackParamTraits<A2>::ForwardType a2,
+        typename internal::CallbackParamTraits<A3>::ForwardType a3,
+        typename internal::CallbackParamTraits<A4>::ForwardType a4) const {
+    PolymorphicInvoke f =
+        reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+    return f(bind_state_.get(), internal::CallbackForward(a1),
+             internal::CallbackForward(a2),
+             internal::CallbackForward(a3),
+             internal::CallbackForward(a4));
+  }
+
+ private:
+  typedef R(*PolymorphicInvoke)(
+      internal::BindStateBase*,
+          typename internal::CallbackParamTraits<A1>::ForwardType,
+          typename internal::CallbackParamTraits<A2>::ForwardType,
+          typename internal::CallbackParamTraits<A3>::ForwardType,
+          typename internal::CallbackParamTraits<A4>::ForwardType);
+
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5>
+class Callback<R(A1, A2, A3, A4, A5)> : public internal::CallbackBase {
+ public:
+  typedef R(RunType)(A1, A2, A3, A4, A5);
+
+  Callback() : CallbackBase(NULL) { }
+
+  // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+  // return the exact Callback<> type.  See base/bind.h for details.
+  template <typename Runnable, typename BindRunType, typename BoundArgsType>
+  Callback(internal::BindState<Runnable, BindRunType,
+           BoundArgsType>* bind_state)
+      : CallbackBase(bind_state) {
+
+    // Force the assignment to a local variable of PolymorphicInvoke
+    // so the compiler will typecheck that the passed in Run() method has
+    // the correct type.
+    PolymorphicInvoke invoke_func =
+        &internal::BindState<Runnable, BindRunType, BoundArgsType>
+            ::InvokerType::Run;
+    polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+  }
+
+  bool Equals(const Callback& other) const {
+    return CallbackBase::Equals(other);
+  }
+
+  R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1,
+        typename internal::CallbackParamTraits<A2>::ForwardType a2,
+        typename internal::CallbackParamTraits<A3>::ForwardType a3,
+        typename internal::CallbackParamTraits<A4>::ForwardType a4,
+        typename internal::CallbackParamTraits<A5>::ForwardType a5) const {
+    PolymorphicInvoke f =
+        reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+    return f(bind_state_.get(), internal::CallbackForward(a1),
+             internal::CallbackForward(a2),
+             internal::CallbackForward(a3),
+             internal::CallbackForward(a4),
+             internal::CallbackForward(a5));
+  }
+
+ private:
+  typedef R(*PolymorphicInvoke)(
+      internal::BindStateBase*,
+          typename internal::CallbackParamTraits<A1>::ForwardType,
+          typename internal::CallbackParamTraits<A2>::ForwardType,
+          typename internal::CallbackParamTraits<A3>::ForwardType,
+          typename internal::CallbackParamTraits<A4>::ForwardType,
+          typename internal::CallbackParamTraits<A5>::ForwardType);
+
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6>
+class Callback<R(A1, A2, A3, A4, A5, A6)> : public internal::CallbackBase {
+ public:
+  typedef R(RunType)(A1, A2, A3, A4, A5, A6);
+
+  Callback() : CallbackBase(NULL) { }
+
+  // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+  // return the exact Callback<> type.  See base/bind.h for details.
+  template <typename Runnable, typename BindRunType, typename BoundArgsType>
+  Callback(internal::BindState<Runnable, BindRunType,
+           BoundArgsType>* bind_state)
+      : CallbackBase(bind_state) {
+
+    // Force the assignment to a local variable of PolymorphicInvoke
+    // so the compiler will typecheck that the passed in Run() method has
+    // the correct type.
+    PolymorphicInvoke invoke_func =
+        &internal::BindState<Runnable, BindRunType, BoundArgsType>
+            ::InvokerType::Run;
+    polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+  }
+
+  bool Equals(const Callback& other) const {
+    return CallbackBase::Equals(other);
+  }
+
+  R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1,
+        typename internal::CallbackParamTraits<A2>::ForwardType a2,
+        typename internal::CallbackParamTraits<A3>::ForwardType a3,
+        typename internal::CallbackParamTraits<A4>::ForwardType a4,
+        typename internal::CallbackParamTraits<A5>::ForwardType a5,
+        typename internal::CallbackParamTraits<A6>::ForwardType a6) const {
+    PolymorphicInvoke f =
+        reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+    return f(bind_state_.get(), internal::CallbackForward(a1),
+             internal::CallbackForward(a2),
+             internal::CallbackForward(a3),
+             internal::CallbackForward(a4),
+             internal::CallbackForward(a5),
+             internal::CallbackForward(a6));
+  }
+
+ private:
+  typedef R(*PolymorphicInvoke)(
+      internal::BindStateBase*,
+          typename internal::CallbackParamTraits<A1>::ForwardType,
+          typename internal::CallbackParamTraits<A2>::ForwardType,
+          typename internal::CallbackParamTraits<A3>::ForwardType,
+          typename internal::CallbackParamTraits<A4>::ForwardType,
+          typename internal::CallbackParamTraits<A5>::ForwardType,
+          typename internal::CallbackParamTraits<A6>::ForwardType);
+
+};
+
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+    typename A5, typename A6, typename A7>
+class Callback<R(A1, A2, A3, A4, A5, A6, A7)> : public internal::CallbackBase {
+ public:
+  typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7);
+
+  Callback() : CallbackBase(NULL) { }
+
+  // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+  // return the exact Callback<> type.  See base/bind.h for details.
+  template <typename Runnable, typename BindRunType, typename BoundArgsType>
+  Callback(internal::BindState<Runnable, BindRunType,
+           BoundArgsType>* bind_state)
+      : CallbackBase(bind_state) {
+
+    // Force the assignment to a local variable of PolymorphicInvoke
+    // so the compiler will typecheck that the passed in Run() method has
+    // the correct type.
+    PolymorphicInvoke invoke_func =
+        &internal::BindState<Runnable, BindRunType, BoundArgsType>
+            ::InvokerType::Run;
+    polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+  }
+
+  bool Equals(const Callback& other) const {
+    return CallbackBase::Equals(other);
+  }
+
+  R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1,
+        typename internal::CallbackParamTraits<A2>::ForwardType a2,
+        typename internal::CallbackParamTraits<A3>::ForwardType a3,
+        typename internal::CallbackParamTraits<A4>::ForwardType a4,
+        typename internal::CallbackParamTraits<A5>::ForwardType a5,
+        typename internal::CallbackParamTraits<A6>::ForwardType a6,
+        typename internal::CallbackParamTraits<A7>::ForwardType a7) const {
+    PolymorphicInvoke f =
+        reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+    return f(bind_state_.get(), internal::CallbackForward(a1),
+             internal::CallbackForward(a2),
+             internal::CallbackForward(a3),
+             internal::CallbackForward(a4),
+             internal::CallbackForward(a5),
+             internal::CallbackForward(a6),
+             internal::CallbackForward(a7));
+  }
+
+ private:
+  typedef R(*PolymorphicInvoke)(
+      internal::BindStateBase*,
+          typename internal::CallbackParamTraits<A1>::ForwardType,
+          typename internal::CallbackParamTraits<A2>::ForwardType,
+          typename internal::CallbackParamTraits<A3>::ForwardType,
+          typename internal::CallbackParamTraits<A4>::ForwardType,
+          typename internal::CallbackParamTraits<A5>::ForwardType,
+          typename internal::CallbackParamTraits<A6>::ForwardType,
+          typename internal::CallbackParamTraits<A7>::ForwardType);
+
+};
+
+
+// Syntactic sugar to make Callbacks<void(void)> easier to declare since it
+// will be used in a lot of APIs with delayed execution.
+typedef Callback<void(void)> Closure;
+
+}  // namespace kudu
+
+#endif  // KUDU_GUTIL_CALLBACK_H

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/callback.h.pump
----------------------------------------------------------------------
diff --git a/be/src/gutil/callback.h.pump b/be/src/gutil/callback.h.pump
new file mode 100644
index 0000000..b96c6c9
--- /dev/null
+++ b/be/src/gutil/callback.h.pump
@@ -0,0 +1,436 @@
+$$ This is a pump file for generating file templates.  Pump is a python
+$$ script that is part of the Google Test suite of utilities.  Description
+$$ can be found here:
+$$
+$$ http://code.google.com/p/googletest/wiki/PumpManual
+$$
+
+$$ See comment for MAX_ARITY in gutil/bind.h.pump.
+$var MAX_ARITY = 7
+
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GUTIL_CALLBACK_H_
+#define GUTIL_CALLBACK_H_
+
+#include "gutil/callback_forward.h"
+#include "gutil/callback_internal.h"
+#include "gutil/template_util.h"
+
+// NOTE: Header files that do not require the full definition of Callback or
+// Closure should #include "gutil/callback_forward.h" instead of this file.
+
+// -----------------------------------------------------------------------------
+// Introduction
+// -----------------------------------------------------------------------------
+//
+// The templated Callback class is a generalized function object. Together
+// with the Bind() function in bind.h, they provide a type-safe method for
+// performing partial application of functions.
+//
+// Partial application (or "currying") is the process of binding a subset of
+// a function's arguments to produce another function that takes fewer
+// arguments. This can be used to pass around a unit of delayed execution,
+// much like lexical closures are used in other languages. For example, it
+// is used in Chromium code to schedule tasks on different MessageLoops.
+//
+// A callback with no unbound input parameters (kudu::Callback<void(void)>)
+// is called a kudu::Closure. Note that this is NOT the same as what other
+// languages refer to as a closure -- it does not retain a reference to its
+// enclosing environment.
+//
+// MEMORY MANAGEMENT AND PASSING
+//
+// The Callback objects themselves should be passed by const-reference, and
+// stored by copy. They internally store their state via a refcounted class
+// and thus do not need to be deleted.
+//
+// The reason to pass via a const-reference is to avoid unnecessary
+// AddRef/Release pairs to the internal state.
+//
+//
+// -----------------------------------------------------------------------------
+// Quick reference for basic stuff
+// -----------------------------------------------------------------------------
+//
+// BINDING A BARE FUNCTION
+//
+//   int Return5() { return 5; }
+//   kudu::Callback<int(void)> func_cb = kudu::Bind(&Return5);
+//   LOG(INFO) << func_cb.Run();  // Prints 5.
+//
+// BINDING A CLASS METHOD
+//
+//   The first argument to bind is the member function to call, the second is
+//   the object on which to call it.
+//
+//   class Ref : public kudu::RefCountedThreadSafe<Ref> {
+//    public:
+//     int Foo() { return 3; }
+//     void PrintBye() { LOG(INFO) << "bye."; }
+//   };
+//   scoped_refptr<Ref> ref = new Ref();
+//   kudu::Callback<void(void)> ref_cb = kudu::Bind(&Ref::Foo, ref);
+//   LOG(INFO) << ref_cb.Run();  // Prints out 3.
+//
+//   By default the object must support RefCounted or you will get a compiler
+//   error. If you're passing between threads, be sure it's
+//   RefCountedThreadSafe! See "Advanced binding of member functions" below if
+//   you don't want to use reference counting.
+//
+// RUNNING A CALLBACK
+//
+//   Callbacks can be run with their "Run" method, which has the same
+//   signature as the template argument to the callback.
+//
+//   void DoSomething(const kudu::Callback<void(int, std::string)>& callback) {
+//     callback.Run(5, "hello");
+//   }
+//
+//   Callbacks can be run more than once (they don't get deleted or marked when
+//   run). However, this precludes using kudu::Passed (see below).
+//
+//   void DoSomething(const kudu::Callback<double(double)>& callback) {
+//     double myresult = callback.Run(3.14159);
+//     myresult += callback.Run(2.71828);
+//   }
+//
+// PASSING UNBOUND INPUT PARAMETERS
+//
+//   Unbound parameters are specified at the time a callback is Run(). They are
+//   specified in the Callback template type:
+//
+//   void MyFunc(int i, const std::string& str) {}
+//   kudu::Callback<void(int, const std::string&)> cb = kudu::Bind(&MyFunc);
+//   cb.Run(23, "hello, world");
+//
+// PASSING BOUND INPUT PARAMETERS
+//
+//   Bound parameters are specified when you create the callback as arguments
+//   to Bind(). They will be passed to the function and the Run()ner of the
+//   callback doesn't see those values or even know that the function it's
+//   calling.
+//
+//   void MyFunc(int i, const std::string& str) {}
+//   kudu::Callback<void(void)> cb = kudu::Bind(&MyFunc, 23, "hello world");
+//   cb.Run();
+//
+//   A callback with no unbound input parameters (kudu::Callback<void(void)>)
+//   is called a kudu::Closure. So we could have also written:
+//
+//   kudu::Closure cb = kudu::Bind(&MyFunc, 23, "hello world");
+//
+//   When calling member functions, bound parameters just go after the object
+//   pointer.
+//
+//   kudu::Closure cb = kudu::Bind(&MyClass::MyFunc, this, 23, "hello world");
+//
+// PARTIAL BINDING OF PARAMETERS
+//
+//   You can specify some parameters when you create the callback, and specify
+//   the rest when you execute the callback.
+//
+//   void MyFunc(int i, const std::string& str) {}
+//   kudu::Callback<void(const std::string&)> cb = kudu::Bind(&MyFunc, 23);
+//   cb.Run("hello world");
+//
+//   When calling a function bound parameters are first, followed by unbound
+//   parameters.
+//
+//
+// -----------------------------------------------------------------------------
+// Quick reference for advanced binding
+// -----------------------------------------------------------------------------
+//
+// BINDING A CLASS METHOD WITH WEAK POINTERS
+//
+//   kudu::Bind(&MyClass::Foo, GetWeakPtr());
+//
+//   The callback will not be issued if the object is destroyed at the time
+//   it's issued. DANGER: weak pointers are not threadsafe, so don't use this
+//   when passing between threads!
+//
+// BINDING A CLASS METHOD WITH MANUAL LIFETIME MANAGEMENT
+//
+//   kudu::Bind(&MyClass::Foo, kudu::Unretained(this));
+//
+//   This disables all lifetime management on the object. You're responsible
+//   for making sure the object is alive at the time of the call. You break it,
+//   you own it!
+//
+// BINDING A CLASS METHOD AND HAVING THE CALLBACK OWN THE CLASS
+//
+//   MyClass* myclass = new MyClass;
+//   kudu::Bind(&MyClass::Foo, kudu::Owned(myclass));
+//
+//   The object will be deleted when the callback is destroyed, even if it's
+//   not run (like if you post a task during shutdown). Potentially useful for
+//   "fire and forget" cases.
+//
+// IGNORING RETURN VALUES
+//
+//   Sometimes you want to call a function that returns a value in a callback
+//   that doesn't expect a return value.
+//
+//   int DoSomething(int arg) { cout << arg << endl; }
+//   kudu::Callback<void<int>) cb =
+//       kudu::Bind(kudu::IgnoreResult(&DoSomething));
+//
+//
+// -----------------------------------------------------------------------------
+// Quick reference for binding parameters to Bind()
+// -----------------------------------------------------------------------------
+//
+// Bound parameters are specified as arguments to Bind() and are passed to the
+// function. A callback with no parameters or no unbound parameters is called a
+// Closure (kudu::Callback<void(void)> and kudu::Closure are the same thing).
+//
+// PASSING PARAMETERS OWNED BY THE CALLBACK
+//
+//   void Foo(int* arg) { cout << *arg << endl; }
+//   int* pn = new int(1);
+//   kudu::Closure foo_callback = kudu::Bind(&foo, kudu::Owned(pn));
+//
+//   The parameter will be deleted when the callback is destroyed, even if it's
+//   not run (like if you post a task during shutdown).
+//
+// PASSING PARAMETERS AS A scoped_ptr
+//
+//   void TakesOwnership(scoped_ptr<Foo> arg) {}
+//   scoped_ptr<Foo> f(new Foo);
+//   // f becomes null during the following call.
+//   kudu::Closure cb = kudu::Bind(&TakesOwnership, kudu::Passed(&f));
+//
+//   Ownership of the parameter will be with the callback until the it is run,
+//   when ownership is passed to the callback function. This means the callback
+//   can only be run once. If the callback is never run, it will delete the
+//   object when it's destroyed.
+//
+// PASSING PARAMETERS AS A scoped_refptr
+//
+//   void TakesOneRef(scoped_refptr<Foo> arg) {}
+//   scoped_refptr<Foo> f(new Foo)
+//   kudu::Closure cb = kudu::Bind(&TakesOneRef, f);
+//
+//   This should "just work." The closure will take a reference as long as it
+//   is alive, and another reference will be taken for the called function.
+//
+// PASSING PARAMETERS BY REFERENCE
+//
+//   void foo(int arg) { cout << arg << endl }
+//   int n = 1;
+//   kudu::Closure has_ref = kudu::Bind(&foo, kudu::ConstRef(n));
+//   n = 2;
+//   has_ref.Run();  // Prints "2"
+//
+//   Normally parameters are copied in the closure. DANGER: ConstRef stores a
+//   const reference instead, referencing the original parameter. This means
+//   that you must ensure the object outlives the callback!
+//
+//
+// -----------------------------------------------------------------------------
+// Implementation notes
+// -----------------------------------------------------------------------------
+//
+// WHERE IS THIS DESIGN FROM:
+//
+// The design Callback and Bind is heavily influenced by C++'s
+// tr1::function/tr1::bind, and by the "Google Callback" system used inside
+// Google.
+//
+//
+// HOW THE IMPLEMENTATION WORKS:
+//
+// There are three main components to the system:
+//   1) The Callback classes.
+//   2) The Bind() functions.
+//   3) The arguments wrappers (e.g., Unretained() and ConstRef()).
+//
+// The Callback classes represent a generic function pointer. Internally,
+// it stores a refcounted piece of state that represents the target function
+// and all its bound parameters.  Each Callback specialization has a templated
+// constructor that takes an BindState<>*.  In the context of the constructor,
+// the static type of this BindState<> pointer uniquely identifies the
+// function it is representing, all its bound parameters, and a Run() method
+// that is capable of invoking the target.
+//
+// Callback's constructor takes the BindState<>* that has the full static type
+// and erases the target function type as well as the types of the bound
+// parameters.  It does this by storing a pointer to the specific Run()
+// function, and upcasting the state of BindState<>* to a
+// BindStateBase*. This is safe as long as this BindStateBase pointer
+// is only used with the stored Run() pointer.
+//
+// To BindState<> objects are created inside the Bind() functions.
+// These functions, along with a set of internal templates, are responsible for
+//
+//  - Unwrapping the function signature into return type, and parameters
+//  - Determining the number of parameters that are bound
+//  - Creating the BindState storing the bound parameters
+//  - Performing compile-time asserts to avoid error-prone behavior
+//  - Returning an Callback<> with an arity matching the number of unbound
+//    parameters and that knows the correct refcounting semantics for the
+//    target object if we are binding a method.
+//
+// The Bind functions do the above using type-inference, and template
+// specializations.
+//
+// By default Bind() will store copies of all bound parameters, and attempt
+// to refcount a target object if the function being bound is a class method.
+// These copies are created even if the function takes parameters as const
+// references. (Binding to non-const references is forbidden, see bind.h.)
+//
+// To change this behavior, we introduce a set of argument wrappers
+// (e.g., Unretained(), and ConstRef()).  These are simple container templates
+// that are passed by value, and wrap a pointer to argument.  See the
+// file-level comment in gutil/bind_helpers.h for more info.
+//
+// These types are passed to the Unwrap() functions, and the MaybeRefcount()
+// functions respectively to modify the behavior of Bind().  The Unwrap()
+// and MaybeRefcount() functions change behavior by doing partial
+// specialization based on whether or not a parameter is a wrapper type.
+//
+// ConstRef() is similar to tr1::cref.  Unretained() is specific to Chromium.
+//
+//
+// WHY NOT TR1 FUNCTION/BIND?
+//
+// Direct use of tr1::function and tr1::bind was considered, but ultimately
+// rejected because of the number of copy constructors invocations involved
+// in the binding of arguments during construction, and the forwarding of
+// arguments during invocation.  These copies will no longer be an issue in
+// C++0x because C++0x will support rvalue reference allowing for the compiler
+// to avoid these copies.  However, waiting for C++0x is not an option.
+//
+// Measured with valgrind on gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5), the
+// tr1::bind call itself will invoke a non-trivial copy constructor three times
+// for each bound parameter.  Also, each when passing a tr1::function, each
+// bound argument will be copied again.
+//
+// In addition to the copies taken at binding and invocation, copying a
+// tr1::function causes a copy to be made of all the bound parameters and
+// state.
+//
+// Furthermore, in Chromium, it is desirable for the Callback to take a
+// reference on a target object when representing a class method call.  This
+// is not supported by tr1.
+//
+// Lastly, tr1::function and tr1::bind has a more general and flexible API.
+// This includes things like argument reordering by use of
+// tr1::bind::placeholder, support for non-const reference parameters, and some
+// limited amount of subtyping of the tr1::function object (e.g.,
+// tr1::function<int(int)> is convertible to tr1::function<void(int)>).
+//
+// These are not features that are required in Chromium. Some of them, such as
+// allowing for reference parameters, and subtyping of functions, may actually
+// become a source of errors. Removing support for these features actually
+// allows for a simpler implementation, and a terser Currying API.
+//
+//
+// WHY NOT GOOGLE CALLBACKS?
+//
+// The Google callback system also does not support refcounting.  Furthermore,
+// its implementation has a number of strange edge cases with respect to type
+// conversion of its arguments.  In particular, the argument's constness must
+// at times match exactly the function signature, or the type-inference might
+// break.  Given the above, writing a custom solution was easier.
+//
+//
+// MISSING FUNCTIONALITY
+//  - Invoking the return of Bind.  Bind(&foo).Run() does not work;
+//  - Binding arrays to functions that take a non-const pointer.
+//    Example:
+//      void Foo(const char* ptr);
+//      void Bar(char* ptr);
+//      Bind(&Foo, "test");
+//      Bind(&Bar, "test");  // This fails because ptr is not const.
+
+namespace kudu {
+
+// First, we forward declare the Callback class template. This informs the
+// compiler that the template only has 1 type parameter which is the function
+// signature that the Callback is representing.
+//
+// After this, create template specializations for 0-$(MAX_ARITY) parameters. Note that
+// even though the template typelist grows, the specialization still
+// only has one type: the function signature.
+//
+// If you are thinking of forward declaring Callback in your own header file,
+// please include "base/callback_forward.h" instead.
+template <typename Sig>
+class Callback;
+
+namespace internal {
+template <typename Runnable, typename RunType, typename BoundArgsType>
+struct BindState;
+}  // namespace internal
+
+
+$range ARITY 0..MAX_ARITY
+$for ARITY [[
+$range ARG 1..ARITY
+
+$if ARITY == 0 [[
+template <typename R>
+class Callback<R(void)> : public internal::CallbackBase {
+]] $else [[
+template <typename R, $for ARG , [[typename A$(ARG)]]>
+class Callback<R($for ARG , [[A$(ARG)]])> : public internal::CallbackBase {
+]]
+
+ public:
+  typedef R(RunType)($for ARG , [[A$(ARG)]]);
+
+  Callback() : CallbackBase(NULL) { }
+
+  // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+  // return the exact Callback<> type.  See base/bind.h for details.
+  template <typename Runnable, typename BindRunType, typename BoundArgsType>
+  Callback(internal::BindState<Runnable, BindRunType,
+           BoundArgsType>* bind_state)
+      : CallbackBase(bind_state) {
+
+    // Force the assignment to a local variable of PolymorphicInvoke
+    // so the compiler will typecheck that the passed in Run() method has
+    // the correct type.
+    PolymorphicInvoke invoke_func =
+        &internal::BindState<Runnable, BindRunType, BoundArgsType>
+            ::InvokerType::Run;
+    polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+  }
+
+  bool Equals(const Callback& other) const {
+    return CallbackBase::Equals(other);
+  }
+
+  R Run($for ARG ,
+        [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const {
+    PolymorphicInvoke f =
+        reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+    return f(bind_state_.get()[[]]
+$if ARITY != 0 [[, ]]
+$for ARG ,
+             [[internal::CallbackForward(a$(ARG))]]);
+  }
+
+ private:
+  typedef R(*PolymorphicInvoke)(
+      internal::BindStateBase*[[]]
+$if ARITY != 0 [[, ]]
+$for ARG , [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType]]);
+
+};
+
+
+]]  $$ for ARITY
+
+// Syntactic sugar to make Callbacks<void(void)> easier to declare since it
+// will be used in a lot of APIs with delayed execution.
+typedef Callback<void(void)> Closure;
+
+}  // namespace kudu
+
+#endif  // GUTIL_CALLBACK_H

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/callback_forward.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/callback_forward.h b/be/src/gutil/callback_forward.h
new file mode 100644
index 0000000..956ff73
--- /dev/null
+++ b/be/src/gutil/callback_forward.h
@@ -0,0 +1,17 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef KUDU_GUTIL_CALLBACK_FORWARD_H_
+#define KUDU_GUTIL_CALLBACK_FORWARD_H_
+
+namespace kudu {
+
+template <typename Sig>
+class Callback;
+
+typedef Callback<void(void)> Closure;
+
+}  // namespace kudu
+
+#endif  // KUDU_GUTIL_CALLBACK_FORWARD_H

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/callback_internal.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/callback_internal.cc b/be/src/gutil/callback_internal.cc
new file mode 100644
index 0000000..05b9e8f
--- /dev/null
+++ b/be/src/gutil/callback_internal.cc
@@ -0,0 +1,36 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "kudu/gutil/callback_internal.h"
+
+namespace kudu {
+namespace internal {
+
+bool CallbackBase::is_null() const {
+  return bind_state_.get() == nullptr;
+}
+
+void CallbackBase::Reset() {
+  polymorphic_invoke_ = nullptr;
+  // NULL the bind_state_ last, since it may be holding the last ref to whatever
+  // object owns us, and we may be deleted after that.
+  bind_state_ = nullptr;
+}
+
+bool CallbackBase::Equals(const CallbackBase& other) const {
+  return bind_state_.get() == other.bind_state_.get() &&
+         polymorphic_invoke_ == other.polymorphic_invoke_;
+}
+
+CallbackBase::CallbackBase(BindStateBase* bind_state)
+    : bind_state_(bind_state),
+      polymorphic_invoke_(nullptr) {
+  DCHECK(!bind_state_.get() || bind_state_->HasOneRef());
+}
+
+CallbackBase::~CallbackBase() {
+}
+
+}  // namespace internal
+}  // namespace kudu

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/callback_internal.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/callback_internal.h b/be/src/gutil/callback_internal.h
new file mode 100644
index 0000000..47b5655
--- /dev/null
+++ b/be/src/gutil/callback_internal.h
@@ -0,0 +1,177 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file contains utility functions and classes that help the
+// implementation, and management of the Callback objects.
+
+#ifndef KUDU_GUTIL_CALLBACK_INTERNAL_H_
+#define KUDU_GUTIL_CALLBACK_INTERNAL_H_
+
+#include <stddef.h>
+
+#include "kudu/gutil/gscoped_ptr.h"
+#include "kudu/gutil/ref_counted.h"
+
+template <typename T>
+class ScopedVector;
+
+namespace kudu {
+namespace internal {
+
+// BindStateBase is used to provide an opaque handle that the Callback
+// class can use to represent a function object with bound arguments.  It
+// behaves as an existential type that is used by a corresponding
+// DoInvoke function to perform the function execution.  This allows
+// us to shield the Callback class from the types of the bound argument via
+// "type erasure."
+class BindStateBase : public RefCountedThreadSafe<BindStateBase> {
+ protected:
+  friend class RefCountedThreadSafe<BindStateBase>;
+  virtual ~BindStateBase() {}
+};
+
+// Holds the Callback methods that don't require specialization to reduce
+// template bloat.
+class CallbackBase {
+ public:
+  // Returns true if Callback is null (doesn't refer to anything).
+  bool is_null() const;
+
+  // Returns the Callback into an uninitialized state.
+  void Reset();
+
+ protected:
+  // In C++, it is safe to cast function pointers to function pointers of
+  // another type. It is not okay to use void*. We create a InvokeFuncStorage
+  // that that can store our function pointer, and then cast it back to
+  // the original type on usage.
+  typedef void(*InvokeFuncStorage)(void);
+
+  // Returns true if this callback equals |other|. |other| may be null.
+  bool Equals(const CallbackBase& other) const;
+
+  // Allow initializing of |bind_state_| via the constructor to avoid default
+  // initialization of the scoped_refptr.  We do not also initialize
+  // |polymorphic_invoke_| here because doing a normal assignment in the
+  // derived Callback templates makes for much nicer compiler errors.
+  explicit CallbackBase(BindStateBase* bind_state);
+
+  // Force the destructor to be instantiated inside this translation unit so
+  // that our subclasses will not get inlined versions.  Avoids more template
+  // bloat.
+  ~CallbackBase();
+
+  scoped_refptr<BindStateBase> bind_state_;
+  InvokeFuncStorage polymorphic_invoke_;
+};
+
+// A helper template to determine if given type is non-const move-only-type,
+// i.e. if a value of the given type should be passed via .Pass() in a
+// destructive way.
+template <typename T> struct IsMoveOnlyType {
+  template <typename U>
+  static base::YesType Test(const typename U::MoveOnlyTypeForCPP03*);
+
+  template <typename U>
+  static base::NoType Test(...);
+
+  static const bool value = sizeof(Test<T>(0)) == sizeof(base::YesType) &&
+                            !base::is_const<T>::value;
+};
+
+// This is a typetraits object that's used to take an argument type, and
+// extract a suitable type for storing and forwarding arguments.
+//
+// In particular, it strips off references, and converts arrays to
+// pointers for storage; and it avoids accidentally trying to create a
+// "reference of a reference" if the argument is a reference type.
+//
+// This array type becomes an issue for storage because we are passing bound
+// parameters by const reference. In this case, we end up passing an actual
+// array type in the initializer list which C++ does not allow.  This will
+// break passing of C-string literals.
+template <typename T, bool is_move_only = IsMoveOnlyType<T>::value>
+struct CallbackParamTraits {
+  typedef const T& ForwardType;
+  typedef T StorageType;
+};
+
+// The Storage should almost be impossible to trigger unless someone manually
+// specifies type of the bind parameters.  However, in case they do,
+// this will guard against us accidentally storing a reference parameter.
+//
+// The ForwardType should only be used for unbound arguments.
+template <typename T>
+struct CallbackParamTraits<T&, false> {
+  typedef T& ForwardType;
+  typedef T StorageType;
+};
+
+// Note that for array types, we implicitly add a const in the conversion. This
+// means that it is not possible to bind array arguments to functions that take
+// a non-const pointer. Trying to specialize the template based on a "const
+// T[n]" does not seem to match correctly, so we are stuck with this
+// restriction.
+template <typename T, size_t n>
+struct CallbackParamTraits<T[n], false> {
+  typedef const T* ForwardType;
+  typedef const T* StorageType;
+};
+
+// See comment for CallbackParamTraits<T[n]>.
+template <typename T>
+struct CallbackParamTraits<T[], false> {
+  typedef const T* ForwardType;
+  typedef const T* StorageType;
+};
+
+// Parameter traits for movable-but-not-copyable scopers.
+//
+// Callback<>/Bind() understands movable-but-not-copyable semantics where
+// the type cannot be copied but can still have its state destructively
+// transferred (aka. moved) to another instance of the same type by calling a
+// helper function.  When used with Bind(), this signifies transferal of the
+// object's state to the target function.
+//
+// For these types, the ForwardType must not be a const reference, or a
+// reference.  A const reference is inappropriate, and would break const
+// correctness, because we are implementing a destructive move.  A non-const
+// reference cannot be used with temporaries which means the result of a
+// function or a cast would not be usable with Callback<> or Bind().
+template <typename T>
+struct CallbackParamTraits<T, true> {
+  typedef T ForwardType;
+  typedef T StorageType;
+};
+
+// CallbackForward() is a very limited simulation of C++11's std::forward()
+// used by the Callback/Bind system for a set of movable-but-not-copyable
+// types.  It is needed because forwarding a movable-but-not-copyable
+// argument to another function requires us to invoke the proper move
+// operator to create a rvalue version of the type.  The supported types are
+// whitelisted below as overloads of the CallbackForward() function. The
+// default template compiles out to be a no-op.
+//
+// In C++11, std::forward would replace all uses of this function.  However, it
+// is impossible to implement a general std::forward with C++11 due to a lack
+// of rvalue references.
+//
+// In addition to Callback/Bind, this is used by PostTaskAndReplyWithResult to
+// simulate std::forward() and forward the result of one Callback as a
+// parameter to another callback. This is to support Callbacks that return
+// the movable-but-not-copyable types whitelisted above.
+template <typename T>
+typename base::enable_if<!IsMoveOnlyType<T>::value, T>::type& CallbackForward(T& t) {
+  return t;
+}
+
+template <typename T>
+typename base::enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward(T& t) {
+  return t.Pass();
+}
+
+}  // namespace internal
+}  // namespace kudu
+
+#endif  // KUDU_GUTIL_CALLBACK_INTERNAL_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/casts.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/casts.h b/be/src/gutil/casts.h
index fe3d7b4..474e083 100644
--- a/be/src/gutil/casts.h
+++ b/be/src/gutil/casts.h
@@ -14,9 +14,11 @@
 #include <string.h>         // for memcpy
 #include <limits.h>         // for enumeration casts and tests
 
-#include "gutil/macros.h"
-#include "gutil/template_util.h"
-#include "gutil/type_traits.h"
+#include <glog/logging.h>
+
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/template_util.h"
+#include "kudu/gutil/type_traits.h"
 
 // Use implicit_cast as a safe version of static_cast or const_cast
 // for implicit conversions. For example:
@@ -164,7 +166,7 @@ template <class Dest, class Source>
 inline Dest bit_cast(const Source& source) {
   // Compile time assertion: sizeof(Dest) == sizeof(Source)
   // A compile error here means your Dest and Source have different sizes.
-  typedef char VerifySizesAreEqual [sizeof(Dest) == sizeof(Source) ? 1 : -1];
+  COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), VerifySizesAreEqual);
 
   Dest dest;
   memcpy(&dest, &source, sizeof(dest));
@@ -361,14 +363,12 @@ inline bool tight_enum_test_cast(int e_val, Enum* e_var) {
   }
 }
 
-// The plain casts require logging, and we get header recursion if
-// it is done directly.  So, we do it indirectly.
-// The following function is defined in logging.cc.
-
 namespace base {
 namespace internal {
 
-void WarnEnumCastError(int value_of_int);
+inline void WarnEnumCastError(int value_of_int) {
+  LOG(DFATAL) << "Bad enum value " << value_of_int;
+}
 
 }  // namespace internal
 }  // namespace base

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/charmap.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/charmap.h b/be/src/gutil/charmap.h
index b3a75c9..2698bbe 100644
--- a/be/src/gutil/charmap.h
+++ b/be/src/gutil/charmap.h
@@ -18,9 +18,9 @@
 
 #include <string.h>
 
-#include "gutil/basictypes.h"
-#include "gutil/integral_types.h"
-#include "gutil/type_traits.h"
+#include "kudu/gutil/basictypes.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/type_traits.h"
 
 class Charmap {
  public:
@@ -64,8 +64,8 @@ class Charmap {
   }
 
   bool IsZero() const {
-    for (int i = 0; i < 8; ++i) {
-      if (m_[i] != 0)
+    for (uint32 c : m_) {
+      if (c != 0)
         return false;
     }
     return true;


[04/14] incubator-impala git commit: IMPALA-4758: (1/2) Update gutil/ from Kudu@a1bfd7b

Posted by he...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/util.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/util.cc b/be/src/gutil/strings/util.cc
index 8447662..c16d9b2 100644
--- a/be/src/gutil/strings/util.cc
+++ b/be/src/gutil/strings/util.cc
@@ -5,7 +5,7 @@
 // TODO(user): visit each const_cast.  Some of them are no longer necessary
 // because last Single Unix Spec and grte v2 are more const-y.
 
-#include "gutil/strings/util.h"
+#include "kudu/gutil/strings/util.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -25,11 +25,12 @@ using std::string;
 using std::vector;
 
 #include <glog/logging.h>
-#include "gutil/logging-inl.h"
-#include "gutil/strings/ascii_ctype.h"
-#include "gutil/strings/numbers.h"
-#include "gutil/strings/stringpiece.h"
-#include "gutil/stl_util.h"  // for string_as_array, STLAppendToString
+#include "kudu/gutil/logging-inl.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
+#include "kudu/gutil/strings/numbers.h"
+#include "kudu/gutil/strings/stringpiece.h"
+#include "kudu/gutil/stl_util.h"  // for string_as_array, STLAppendToString
+#include "kudu/gutil/utf/utf.h"
 
 #ifdef OS_WINDOWS
 #ifdef min  // windows.h defines this to something silly
@@ -55,9 +56,9 @@ char* strnstr(const char* haystack, const char* needle,
   }
   size_t needle_len = strlen(needle);
   char* where;
-  while ((where = strnchr(haystack, *needle, haystack_len)) != NULL) {
+  while ((where = strnchr(haystack, *needle, haystack_len)) != nullptr) {
     if (where - haystack + needle_len > haystack_len) {
-      return NULL;
+      return nullptr;
     }
     if (strncmp(where, needle, needle_len) == 0) {
       return where;
@@ -65,18 +66,18 @@ char* strnstr(const char* haystack, const char* needle,
     haystack_len -= where + 1 - haystack;
     haystack = where + 1;
   }
-  return NULL;
+  return nullptr;
 }
 
 const char* strnprefix(const char* haystack, int haystack_size,
                               const char* needle, int needle_size) {
   if (needle_size > haystack_size) {
-    return NULL;
+    return nullptr;
   } else {
     if (strncmp(haystack, needle, needle_size) == 0) {
       return haystack + needle_size;
     } else {
-      return NULL;
+      return nullptr;
     }
   }
 }
@@ -84,12 +85,12 @@ const char* strnprefix(const char* haystack, int haystack_size,
 const char* strncaseprefix(const char* haystack, int haystack_size,
                                   const char* needle, int needle_size) {
   if (needle_size > haystack_size) {
-    return NULL;
+    return nullptr;
   } else {
     if (strncasecmp(haystack, needle, needle_size) == 0) {
       return haystack + needle_size;
     } else {
-      return NULL;
+      return nullptr;
     }
   }
 }
@@ -102,20 +103,20 @@ char* strcasesuffix(char* str, const char* suffix) {
   if (lenstr >= lensuffix && 0 == strcasecmp(strbeginningoftheend, suffix)) {
     return (strbeginningoftheend);
   } else {
-    return (NULL);
+    return (nullptr);
   }
 }
 
 const char* strnsuffix(const char* haystack, int haystack_size,
                               const char* needle, int needle_size) {
   if (needle_size > haystack_size) {
-    return NULL;
+    return nullptr;
   } else {
     const char* start = haystack + haystack_size - needle_size;
     if (strncmp(start, needle, needle_size) == 0) {
       return start;
     } else {
-      return NULL;
+      return nullptr;
     }
   }
 }
@@ -123,20 +124,20 @@ const char* strnsuffix(const char* haystack, int haystack_size,
 const char* strncasesuffix(const char* haystack, int haystack_size,
                            const char* needle, int needle_size) {
   if (needle_size > haystack_size) {
-    return NULL;
+    return nullptr;
   } else {
     const char* start = haystack + haystack_size - needle_size;
     if (strncasecmp(start, needle, needle_size) == 0) {
       return start;
     } else {
-      return NULL;
+      return nullptr;
     }
   }
 }
 
 char* strchrnth(const char* str, const char& c, int n) {
-  if (str == NULL)
-    return NULL;
+  if (str == nullptr)
+    return nullptr;
   if (n <= 0)
     return const_cast<char*>(str);
   const char* sp;
@@ -148,18 +149,18 @@ char* strchrnth(const char* str, const char& c, int n) {
         break;
     }
   }
-  return (k < n) ? NULL : const_cast<char*>(sp);
+  return (k < n) ? nullptr : const_cast<char*>(sp);
 }
 
 char* AdjustedLastPos(const char* str, char separator, int n) {
-  if ( str == NULL )
-    return NULL;
-  const char* pos = NULL;
+  if ( str == nullptr )
+    return nullptr;
+  const char* pos = nullptr;
   if ( n > 0 )
     pos = strchrnth(str, separator, n);
 
   // if n <= 0 or separator appears fewer than n times, get the last occurrence
-  if ( pos == NULL)
+  if ( pos == nullptr)
     pos = strrchr(str, separator);
   return const_cast<char*>(pos);
 }
@@ -237,7 +238,7 @@ void StringReplace(const StringPiece& s, const StringPiece& oldsub,
 int GlobalReplaceSubstring(const StringPiece& substring,
                            const StringPiece& replacement,
                            string* s) {
-  CHECK(s != NULL);
+  CHECK(s != nullptr);
   if (s->empty() || substring.empty())
     return 0;
   string tmp;
@@ -305,7 +306,7 @@ char *gstrcasestr(const char* haystack, const char* needle) {
     do {
       do {
         if ((sc = *haystack++) == 0)
-          return NULL;
+          return nullptr;
       } while (ascii_tolower(sc) != c);
     } while (strncasecmp(haystack, needle, len) != 0);
     haystack--;
@@ -332,7 +333,7 @@ const char *gstrncasestr(const char* haystack, const char* needle, size_t len) {
       do {
         if (len-- <= needle_len
             || 0 == (sc = *haystack++))
-          return NULL;
+          return nullptr;
       } while (ascii_tolower(sc) != c);
     } while (strncasecmp(haystack, needle, needle_len) != 0);
     haystack--;
@@ -360,22 +361,22 @@ char *gstrncasestr_split(const char* str,
                          const char* prefix, char non_alpha,
                          const char* suffix,
                          size_t n) {
-  int prelen = prefix == NULL ? 0 : strlen(prefix);
-  int suflen = suffix == NULL ? 0 : strlen(suffix);
+  int prelen = prefix == nullptr ? 0 : strlen(prefix);
+  int suflen = suffix == nullptr ? 0 : strlen(suffix);
 
   // adjust the string and its length to avoid unnessary searching.
   // an added benefit is to avoid unnecessary range checks in the if
   // statement in the inner loop.
-  if (suflen + prelen >= n)  return NULL;
+  if (suflen + prelen >= n)  return nullptr;
   str += prelen;
   n -= prelen;
   n -= suflen;
 
-  const char* where = NULL;
+  const char* where = nullptr;
 
   // for every occurance of non_alpha in the string ...
   while ((where = static_cast<const char*>(
-            memchr(str, non_alpha, n))) != NULL) {
+            memchr(str, non_alpha, n))) != nullptr) {
     // ... test whether it is followed by suffix and preceded by prefix
     if ((!suflen || strncasecmp(where + 1, suffix, suflen) == 0) &&
         (!prelen || strncasecmp(where - prelen, prefix, prelen) == 0)) {
@@ -386,7 +387,7 @@ char *gstrncasestr_split(const char* str,
     str = where + 1;
   }
 
-  return NULL;
+  return nullptr;
 }
 
 // ----------------------------------------------------------------------
@@ -413,7 +414,7 @@ char *strcasestr_alnum(const char *haystack, const char *needle) {
   // Skip non-alnums at beginning
   while ( !ascii_isalnum(*haystack) )
     if ( *haystack++ == '\0' )
-      return NULL;
+      return nullptr;
   haystack_ptr = haystack;
 
   while ( *needle_ptr != '\0' ) {
@@ -424,7 +425,7 @@ char *strcasestr_alnum(const char *haystack, const char *needle) {
 
     while ( !ascii_isalnum(*haystack_ptr) )
       if ( *haystack_ptr++ == '\0' )
-        return NULL;
+        return nullptr;
 
     if ( ascii_tolower(*needle_ptr) == ascii_tolower(*haystack_ptr) ) {
       // Case-insensitive match - advance
@@ -435,7 +436,7 @@ char *strcasestr_alnum(const char *haystack, const char *needle) {
       haystack++;
       while ( !ascii_isalnum(*haystack) )
         if ( *haystack++ == '\0' )
-          return NULL;
+          return nullptr;
       haystack_ptr = haystack;
       needle_ptr = needle;
     }
@@ -476,7 +477,7 @@ int CountSubstring(StringPiece text, StringPiece substring) {
 const char* strstr_delimited(const char* haystack,
                              const char* needle,
                              char delim) {
-  if (!needle || !haystack) return NULL;
+  if (!needle || !haystack) return nullptr;
   if (*needle == '\0') return haystack;
 
   int needle_len = strlen(needle);
@@ -503,12 +504,12 @@ const char* strstr_delimited(const char* haystack,
 
     // No match. Consume non-delimiter characters until we run out of them.
     while (*haystack != delim) {
-      if (*haystack == '\0') return NULL;
+      if (*haystack == '\0') return nullptr;
       ++haystack;
     }
   }
   LOG(FATAL) << "Unreachable statement";
-  return NULL;
+  return nullptr;
 }
 
 
@@ -522,8 +523,8 @@ char* gstrsep(char** stringp, const char* delim) {
   int c, sc;
   char *tok;
 
-  if ((s = *stringp) == NULL)
-    return NULL;
+  if ((s = *stringp) == nullptr)
+    return nullptr;
 
   tok = s;
   while (true) {
@@ -532,7 +533,7 @@ char* gstrsep(char** stringp, const char* delim) {
     do {
       if ((sc = *spanp++) == c) {
         if (c == 0)
-          s = NULL;
+          s = nullptr;
         else
           s[-1] = 0;
         *stringp = s;
@@ -541,7 +542,7 @@ char* gstrsep(char** stringp, const char* delim) {
     } while (sc != 0);
   }
 
-  return NULL; /* should not happen */
+  return nullptr; /* should not happen */
 }
 
 void FastStringAppend(string* s, const char* data, int len) {
@@ -592,7 +593,7 @@ char* FastTimeToBuffer(time_t s, char* buffer) {
   }
 
   struct tm tm;
-  if (PortableSafeGmtime(&s, &tm) == NULL) {
+  if (PortableSafeGmtime(&s, &tm) == nullptr) {
     // Error message must fit in 30-char buffer.
     memcpy(buffer, "Invalid:", sizeof("Invalid:"));
     FastInt64ToBufferLeft(s, buffer+strlen(buffer));
@@ -677,17 +678,17 @@ char* FastTimeToBuffer(time_t s, char* buffer) {
 //    and didn't want to (or cannot) modify the string
 // ----------------------------------------------------------------------
 char* strdup_with_new(const char* the_string) {
-  if (the_string == NULL)
-    return NULL;
+  if (the_string == nullptr)
+    return nullptr;
   else
     return strndup_with_new(the_string, strlen(the_string));
 }
 
 char* strndup_with_new(const char* the_string, int max_length) {
-  if (the_string == NULL)
-    return NULL;
+  if (the_string == nullptr)
+    return nullptr;
 
-  char* result = new char[max_length + 1];
+  auto result = new char[max_length + 1];
   result[max_length] = '\0';  // terminate the string because strncpy might not
   return strncpy(result, the_string, max_length);
 }
@@ -709,17 +710,17 @@ char* strndup_with_new(const char* the_string, int max_length) {
 //    Precondition: (end_ptr != NULL)
 // ----------------------------------------------------------------------
 const char* ScanForFirstWord(const char* the_string, const char** end_ptr) {
-  CHECK(end_ptr != NULL) << ": precondition violated";
+  CHECK(end_ptr != nullptr) << ": precondition violated";
 
-  if (the_string == NULL)  // empty string
-    return NULL;
+  if (the_string == nullptr)  // empty string
+    return nullptr;
 
   const char* curr = the_string;
   while ((*curr != '\0') && ascii_isspace(*curr))  // skip initial spaces
     ++curr;
 
   if (*curr == '\0')  // no valid word found
-    return NULL;
+    return nullptr;
 
   // else has a valid word
   const char* first_word = curr;
@@ -744,7 +745,7 @@ const char *AdvanceIdentifier(const char *str) {
   // We could have used ascii_isalpha and ascii_isalnum.
   char ch = *str++;
   if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_'))
-    return NULL;
+    return nullptr;
   while (true) {
     ch = *str;
     if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
@@ -766,6 +767,146 @@ bool IsIdentifier(const char *str) {
   return end && *end == '\0';
 }
 
+static bool IsWildcard(Rune character) {
+  return character == '*' || character == '?';
+}
+
+// Move the strings pointers to the point where they start to differ.
+template <typename CHAR, typename NEXT>
+static void EatSameChars(const CHAR** pattern, const CHAR* pattern_end,
+                         const CHAR** string, const CHAR* string_end,
+                         NEXT next) {
+  const CHAR* escape = nullptr;
+  while (*pattern != pattern_end && *string != string_end) {
+    if (!escape && IsWildcard(**pattern)) {
+      // We don't want to match wildcard here, except if it's escaped.
+      return;
+    }
+
+    // Check if the escapement char is found. If so, skip it and move to the
+    // next character.
+    if (!escape && **pattern == '\\') {
+      escape = *pattern;
+      next(pattern, pattern_end);
+      continue;
+    }
+
+    // Check if the chars match, if so, increment the ptrs.
+    const CHAR* pattern_next = *pattern;
+    const CHAR* string_next = *string;
+    Rune pattern_char = next(&pattern_next, pattern_end);
+    if (pattern_char == next(&string_next, string_end) &&
+        pattern_char != Runeerror &&
+        pattern_char <= Runemax) {
+      *pattern = pattern_next;
+      *string = string_next;
+    } else {
+      // Uh ho, it did not match, we are done. If the last char was an
+      // escapement, that means that it was an error to advance the ptr here,
+      // let's put it back where it was. This also mean that the MatchPattern
+      // function will return false because if we can't match an escape char
+      // here, then no one will.
+      if (escape) {
+        *pattern = escape;
+      }
+      return;
+    }
+
+    escape = nullptr;
+  }
+}
+
+template <typename CHAR, typename NEXT>
+static void EatWildcard(const CHAR** pattern, const CHAR* end, NEXT next) {
+  while (*pattern != end) {
+    if (!IsWildcard(**pattern))
+      return;
+    next(pattern, end);
+  }
+}
+
+template <typename CHAR, typename NEXT>
+static bool MatchPatternT(const CHAR* eval, const CHAR* eval_end,
+                          const CHAR* pattern, const CHAR* pattern_end,
+                          int depth,
+                          NEXT next) {
+  const int kMaxDepth = 16;
+  if (depth > kMaxDepth)
+    return false;
+
+  // Eat all the matching chars.
+  EatSameChars(&pattern, pattern_end, &eval, eval_end, next);
+
+  // If the string is empty, then the pattern must be empty too, or contains
+  // only wildcards.
+  if (eval == eval_end) {
+    EatWildcard(&pattern, pattern_end, next);
+    return pattern == pattern_end;
+  }
+
+  // Pattern is empty but not string, this is not a match.
+  if (pattern == pattern_end)
+    return false;
+
+  // If this is a question mark, then we need to compare the rest with
+  // the current string or the string with one character eaten.
+  const CHAR* next_pattern = pattern;
+  next(&next_pattern, pattern_end);
+  if (pattern[0] == '?') {
+    if (MatchPatternT(eval, eval_end, next_pattern, pattern_end,
+                      depth + 1, next))
+      return true;
+    const CHAR* next_eval = eval;
+    next(&next_eval, eval_end);
+    if (MatchPatternT(next_eval, eval_end, next_pattern, pattern_end,
+                      depth + 1, next))
+      return true;
+  }
+
+  // This is a *, try to match all the possible substrings with the remainder
+  // of the pattern.
+  if (pattern[0] == '*') {
+    // Collapse duplicate wild cards (********** into *) so that the
+    // method does not recurse unnecessarily. http://crbug.com/52839
+    EatWildcard(&next_pattern, pattern_end, next);
+
+    while (eval != eval_end) {
+      if (MatchPatternT(eval, eval_end, next_pattern, pattern_end,
+                        depth + 1, next))
+        return true;
+      eval++;
+    }
+
+    // We reached the end of the string, let see if the pattern contains only
+    // wildcards.
+    if (eval == eval_end) {
+      EatWildcard(&pattern, pattern_end, next);
+      if (pattern != pattern_end)
+        return false;
+      return true;
+    }
+  }
+
+  return false;
+}
+
+struct NextCharUTF8 {
+  Rune operator()(const char** p, const char* end) {
+    Rune c;
+    int offset = charntorune(&c, *p, static_cast<int>(end - *p));
+    *p += offset;
+    return c;
+  }
+};
+
+bool MatchPattern(const StringPiece& eval,
+                  const StringPiece& pattern) {
+  return MatchPatternT(eval.data(), eval.data() + eval.size(),
+                       pattern.data(), pattern.data() + pattern.size(),
+                       0, NextCharUTF8());
+}
+
+
 
 // ----------------------------------------------------------------------
 // FindTagValuePair
@@ -783,7 +924,7 @@ bool FindTagValuePair(const char* arg_str, char tag_value_separator,
                       char **tag, int *tag_len,
                       char **value, int *value_len) {
   char* in_str = const_cast<char*>(arg_str);  // For msvc8.
-  if (in_str == NULL)
+  if (in_str == nullptr)
     return false;
   char tv_sep_or_term[3] = {tag_value_separator, string_terminal, '\0'};
   char attr_sep_or_term[3] = {attribute_separator, string_terminal, '\0'};
@@ -791,20 +932,20 @@ bool FindTagValuePair(const char* arg_str, char tag_value_separator,
   // Look for beginning of tag
   *tag = strpbrk(in_str, attr_sep_or_term);
   // If string_terminal is '\0', strpbrk won't find it but return null.
-  if (*tag == NULL || **tag == string_terminal)
+  if (*tag == nullptr || **tag == string_terminal)
     *tag = in_str;
   else
     (*tag)++;   // Move past separator
   // Now look for value...
   char *tv_sep_pos = strpbrk(*tag, tv_sep_or_term);
-  if (tv_sep_pos == NULL || *tv_sep_pos == string_terminal)
+  if (tv_sep_pos == nullptr || *tv_sep_pos == string_terminal)
     return false;
   // ...and end of value
   char *attr_sep_pos = strpbrk(tv_sep_pos, attr_sep_or_term);
 
   *tag_len = tv_sep_pos - *tag;
   *value = tv_sep_pos + 1;
-  if (attr_sep_pos != NULL)
+  if (attr_sep_pos != nullptr)
     *value_len = attr_sep_pos - *value;
   else
     *value_len = strlen(*value);
@@ -858,7 +999,7 @@ void InsertString(string *const s,
   tmp.reserve(s_len + separator_len * num_indices);
 
   vector<uint32>::const_iterator const ind_end(indices.end());
-  vector<uint32>::const_iterator ind_pos(indices.begin());
+  auto ind_pos(indices.begin());
 
   uint32 last_pos(0);
   while (ind_pos != ind_end) {
@@ -951,8 +1092,8 @@ StringPiece FindEol(StringPiece s) {
 //  return true if string s contains only whitespace characters
 //------------------------------------------------------------------------
 bool OnlyWhitespace(const StringPiece& s) {
-  for ( int i = 0; i < s.size(); ++i ) {
-    if ( !ascii_isspace(s[i]) ) return false;
+  for (const auto& c : s) {
+    if ( !ascii_isspace(c) ) return false;
   }
   return true;
 }
@@ -1051,3 +1192,27 @@ bool GetlineFromStdioFile(FILE* file, string* str, char delim) {
     str->push_back(c);
   }
 }
+
+namespace {
+
+template <typename CHAR>
+size_t lcpyT(CHAR* dst, const CHAR* src, size_t dst_size) {
+  for (size_t i = 0; i < dst_size; ++i) {
+    if ((dst[i] = src[i]) == 0)  // We hit and copied the terminating NULL.
+      return i;
+  }
+
+  // We were left off at dst_size.  We over copied 1 byte.  Null terminate.
+  if (dst_size != 0)
+    dst[dst_size - 1] = 0;
+
+  // Count the rest of the |src|, and return it's length in characters.
+  while (src[dst_size]) ++dst_size;
+  return dst_size;
+}
+
+}  // namespace
+
+size_t strings::strlcpy(char* dst, const char* src, size_t dst_size) {
+  return lcpyT<char>(dst, src, dst_size);
+}

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strings/util.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strings/util.h b/be/src/gutil/strings/util.h
index 562e497..59db97d 100644
--- a/be/src/gutil/strings/util.h
+++ b/be/src/gutil/strings/util.h
@@ -42,9 +42,9 @@ using std::string;
 #include <vector>
 using std::vector;
 
-#include "gutil/integral_types.h"
-#include "gutil/port.h"
-#include "gutil/strings/stringpiece.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/strings/stringpiece.h"
 
 // Newer functions.
 
@@ -179,6 +179,14 @@ inline bool HasSuffixString(const StringPiece& str,
   return str.ends_with(suffix);
 }
 
+// Returns true if the string passed in matches the pattern. The pattern
+// string can contain wildcards like * and ?
+// The backslash character (\) is an escape character for * and ?
+// We limit the patterns to having a max of 16 * or ? characters.
+// ? matches 0 or 1 character, while * matches 0 or more characters.
+bool MatchPattern(const StringPiece& string,
+                  const StringPiece& pattern);
+
 // Returns where suffix begins in str, or NULL if str doesn't end with suffix.
 inline char* strsuffix(char* str, const char* suffix) {
   const int lenstr = strlen(str);
@@ -337,6 +345,18 @@ inline char* safestrncpy(char* dest, const char* src, size_t n) {
   return dest;
 }
 
+namespace strings {
+
+// BSD-style safe and consistent string copy functions.
+// Copies |src| to |dst|, where |dst_size| is the total allocated size of |dst|.
+// Copies at most |dst_size|-1 characters, and always NULL terminates |dst|, as
+// long as |dst_size| is not 0.  Returns the length of |src| in characters.
+// If the return value is >= dst_size, then the output was truncated.
+// NOTE: All sizes are in number of characters, NOT in bytes.
+size_t strlcpy(char* dst, const char* src, size_t dst_size);
+
+} // namespace strings
+
 // Replaces the first occurrence (if replace_all is false) or all occurrences
 // (if replace_all is true) of oldsub in s with newsub. In the second version,
 // *res must be distinct from all the other arguments.

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strtoint.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/strtoint.cc b/be/src/gutil/strtoint.cc
index 9df29a3..bb96a57 100644
--- a/be/src/gutil/strtoint.cc
+++ b/be/src/gutil/strtoint.cc
@@ -5,8 +5,8 @@
 //
 
 #include <errno.h>
-#include "gutil/port.h"
-#include "gutil/strtoint.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/strtoint.h"
 
 // Replacement strto[u]l functions that have identical overflow and underflow
 // characteristics for both ILP-32 and LP-64 platforms, including errno

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/strtoint.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/strtoint.h b/be/src/gutil/strtoint.h
index 581ebf9..b581385 100644
--- a/be/src/gutil/strtoint.h
+++ b/be/src/gutil/strtoint.h
@@ -33,9 +33,9 @@
 #include <stdlib.h> // For strtol* functions.
 #include <string>
 using std::string;
-#include "gutil/integral_types.h"
-#include "gutil/macros.h"
-#include "gutil/port.h"
+#include "kudu/gutil/integral_types.h"
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/port.h"
 
 // Adapter functions for handling overflow and errno.
 int32 strto32_adapter(const char *nptr, char **endptr, int base);

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/synchronization_profiling.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/synchronization_profiling.h b/be/src/gutil/synchronization_profiling.h
index 3292787..f008871 100644
--- a/be/src/gutil/synchronization_profiling.h
+++ b/be/src/gutil/synchronization_profiling.h
@@ -35,7 +35,7 @@
 #ifndef BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
 #define BASE_AUXILIARY_SYNCHRONIZATION_PROFILING_H_
 
-#include "gutil/basictypes.h"
+#include "kudu/gutil/basictypes.h"
 
 namespace gutil {
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/sysinfo.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/sysinfo.cc b/be/src/gutil/sysinfo.cc
index f9232d1..6006b6d 100644
--- a/be/src/gutil/sysinfo.cc
+++ b/be/src/gutil/sysinfo.cc
@@ -53,10 +53,10 @@
 #include <shlwapi.h>          // for SHGetValueA()
 #include <tlhelp32.h>         // for Module32First()
 #endif
-#include "gutil/dynamic_annotations.h"   // for RunningOnValgrind
-#include "gutil/macros.h"
-#include "gutil/sysinfo.h"
-#include "gutil/walltime.h"
+#include "kudu/gutil/dynamic_annotations.h"   // for RunningOnValgrind
+#include "kudu/gutil/macros.h"
+#include "kudu/gutil/sysinfo.h"
+#include "kudu/gutil/walltime.h"
 #include <glog/logging.h>
 
 // This isn't in the 'base' namespace in tcmallc. But, tcmalloc
@@ -74,6 +74,7 @@ namespace base {
 
 static double cpuinfo_cycles_per_second = 1.0;  // 0.0 might be dangerous
 static int cpuinfo_num_cpus = 1;  // Conservative guess
+static int cpuinfo_max_cpu_index = -1;
 
 void SleepForNanoseconds(int64_t nanoseconds) {
   // Sleep for nanosecond duration
@@ -144,6 +145,25 @@ static bool ReadIntFromFile(const char *file, int *value) {
   return false;
 }
 
+static int ReadMaxCPUIndex() {
+  char buf[1024];
+  CHECK(SlurpSmallTextFile("/sys/devices/system/cpu/present", buf, arraysize(buf)));
+
+  // On a single-core machine, 'buf' will contain the string '0' with a newline.
+  if (strcmp(buf, "0\n") == 0) {
+    return 0;
+  }
+
+  // On multi-core, it will have a CPU range like '0-7'.
+  CHECK_EQ(0, memcmp(buf, "0-", 2)) << "bad list of possible CPUs: " << buf;
+
+  char* max_cpu_str = &buf[2];
+  char* err;
+  int val = strtol(max_cpu_str, &err, 10);
+  CHECK(*err == '\n' || *err == '\0') << "unable to parse max CPU index from: " << buf;
+  return val;
+}
+
 #endif
 
 // WARNING: logging calls back to InitializeSystemInfo() so it must
@@ -286,6 +306,7 @@ static void InitializeSystemInfo() {
   if (num_cpus > 0) {
     cpuinfo_num_cpus = num_cpus;
   }
+  cpuinfo_max_cpu_index = ReadMaxCPUIndex();
 
 #elif defined __FreeBSD__
   // For this sysctl to work, the machine must be configured without
@@ -364,6 +385,13 @@ static void InitializeSystemInfo() {
   // Generic cycles per second counter
   cpuinfo_cycles_per_second = EstimateCyclesPerSecond(1000);
 #endif
+
+  // On platforms where we can't determine the max CPU index, just use the
+  // number of CPUs. This might break if CPUs are taken offline, but
+  // better than a wild guess.
+  if (cpuinfo_max_cpu_index < 0) {
+    cpuinfo_max_cpu_index = cpuinfo_num_cpus - 1;
+  }
 }
 
 double CyclesPerSecond(void) {
@@ -376,4 +404,9 @@ int NumCPUs(void) {
   return cpuinfo_num_cpus;
 }
 
+int MaxCPUIndex(void) {
+  InitializeSystemInfo();
+  return cpuinfo_max_cpu_index;
+}
+
 } // namespace base

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/sysinfo.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/sysinfo.h b/be/src/gutil/sysinfo.h
index 1ce95d0..ec3abe7 100644
--- a/be/src/gutil/sysinfo.h
+++ b/be/src/gutil/sysinfo.h
@@ -41,6 +41,10 @@ namespace base {
 // value of sched_getcpu().
 extern int NumCPUs();
 
+// Return the maximum CPU index that may be returned by sched_getcpu(). For example, on
+// an 8-core machine, this will return '7' even if some of the CPUs have been disabled.
+extern int MaxCPUIndex();
+
 void SleepForNanoseconds(int64_t nanoseconds);
 void SleepForMilliseconds(int64_t milliseconds);
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/template_util.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/template_util.h b/be/src/gutil/template_util.h
index 35b1fa0..aebfa16 100644
--- a/be/src/gutil/template_util.h
+++ b/be/src/gutil/template_util.h
@@ -59,6 +59,11 @@ struct big_ {
   char dummy[2];
 };
 
+// Types YesType and NoType are guaranteed such that sizeof(YesType) <
+// sizeof(NoType).
+typedef small_ YesType;
+typedef big_ NoType;
+
 // Identity metafunction.
 template <class T>
 struct identity_ {
@@ -88,6 +93,16 @@ typedef integral_constant<bool, false> false_type;
 typedef true_type  true_;
 typedef false_type false_;
 
+template <class T> struct is_non_const_reference : false_type {};
+template <class T> struct is_non_const_reference<T&> : true_type {};
+template <class T> struct is_non_const_reference<const T&> : false_type {};
+
+template <class T> struct is_const : false_type {};
+template <class T> struct is_const<const T> : true_type {};
+
+template <class T> struct is_void : false_type {};
+template <> struct is_void<void> : true_type {};
+
 // if_ is a templatized conditional statement.
 // if_<cond, A, B> is a compile time evaluation of cond.
 // if_<>::type contains A if cond is true, B otherwise.
@@ -127,6 +142,22 @@ template<typename A, typename B>
 struct or_ : public integral_constant<bool, (A::value || B::value)> {
 };
 
+// Used to determine if a type is a struct/union/class. Inspired by Boost's
+// is_class type_trait implementation.
+struct IsClassHelper {
+  template <typename C>
+  static YesType Test(void(C::*)(void));
+
+  template <typename C>
+  static NoType Test(...);
+};
+
+template <typename T>
+struct is_class
+    : integral_constant<bool,
+                        sizeof(IsClassHelper::Test<T>(0)) ==
+                            sizeof(YesType)> {
+};
 
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/threading/thread_collision_warner.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/threading/thread_collision_warner.cc b/be/src/gutil/threading/thread_collision_warner.cc
new file mode 100644
index 0000000..89270d8
--- /dev/null
+++ b/be/src/gutil/threading/thread_collision_warner.cc
@@ -0,0 +1,82 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "kudu/gutil/threading/thread_collision_warner.h"
+
+#include <glog/logging.h>
+
+#include "kudu/gutil/linux_syscall_support.h"
+
+namespace base {
+
+void DCheckAsserter::warn() {
+  LOG(FATAL) << "Thread Collision";
+}
+
+#if 0
+// Original source from Chromium -- we didn't import their threading library
+// into Cloudera source as of yet
+
+static subtle::Atomic32 CurrentThread() {
+  const PlatformThreadId current_thread_id = PlatformThread::CurrentId();
+  // We need to get the thread id into an atomic data type. This might be a
+  // truncating conversion, but any loss-of-information just increases the
+  // chance of a fault negative, not a false positive.
+  const subtle::Atomic32 atomic_thread_id =
+      static_cast<subtle::Atomic32>(current_thread_id);
+
+  return atomic_thread_id;
+}
+#else
+
+static subtle::Atomic64 CurrentThread() {
+#if defined(__APPLE__)
+  uint64_t tid;
+  CHECK_EQ(0, pthread_threadid_np(NULL, &tid));
+  return tid;
+#elif defined(__linux__)
+  return syscall(__NR_gettid);
+#endif
+}
+
+#endif
+
+void ThreadCollisionWarner::EnterSelf() {
+  // If the active thread is 0 then I'll write the current thread ID
+  // if two or more threads arrive here only one will succeed to
+  // write on valid_thread_id_ the current thread ID.
+  subtle::Atomic64 current_thread_id = CurrentThread();
+
+  int64_t previous_value = subtle::NoBarrier_CompareAndSwap(&valid_thread_id_,
+                                                            0,
+                                                            current_thread_id);
+  if (previous_value != 0 && previous_value != current_thread_id) {
+    // gotcha! a thread is trying to use the same class and that is
+    // not current thread.
+    asserter_->warn();
+  }
+
+  subtle::NoBarrier_AtomicIncrement(&counter_, 1);
+}
+
+void ThreadCollisionWarner::Enter() {
+  subtle::Atomic64 current_thread_id = CurrentThread();
+
+  if (subtle::NoBarrier_CompareAndSwap(&valid_thread_id_,
+                                       0,
+                                       current_thread_id) != 0) {
+    // gotcha! another thread is trying to use the same class.
+    asserter_->warn();
+  }
+
+  subtle::NoBarrier_AtomicIncrement(&counter_, 1);
+}
+
+void ThreadCollisionWarner::Leave() {
+  if (subtle::Barrier_AtomicIncrement(&counter_, -1) == 0) {
+    subtle::NoBarrier_Store(&valid_thread_id_, 0);
+  }
+}
+
+}  // namespace base

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/threading/thread_collision_warner.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/threading/thread_collision_warner.h b/be/src/gutil/threading/thread_collision_warner.h
new file mode 100644
index 0000000..d59ea67
--- /dev/null
+++ b/be/src/gutil/threading/thread_collision_warner.h
@@ -0,0 +1,248 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_THREADING_THREAD_COLLISION_WARNER_H_
+#define BASE_THREADING_THREAD_COLLISION_WARNER_H_
+
+#include <memory>
+
+#include "kudu/gutil/atomicops.h"
+#include "kudu/gutil/port.h"
+#include "kudu/gutil/macros.h"
+ 
+#ifndef BASE_EXPORT
+#define BASE_EXPORT
+#endif
+
+// A helper class alongside macros to be used to verify assumptions about thread
+// safety of a class.
+//
+// Example: Queue implementation non thread-safe but still usable if clients
+//          are synchronized somehow.
+//
+//          In this case the macro DFAKE_SCOPED_LOCK has to be
+//          used, it checks that if a thread is inside the push/pop then
+//          noone else is still inside the pop/push
+//
+// class NonThreadSafeQueue {
+//  public:
+//   ...
+//   void push(int) { DFAKE_SCOPED_LOCK(push_pop_); ... }
+//   int pop() { DFAKE_SCOPED_LOCK(push_pop_); ... }
+//   ...
+//  private:
+//   DFAKE_MUTEX(push_pop_);
+// };
+//
+//
+// Example: Queue implementation non thread-safe but still usable if clients
+//          are synchronized somehow, it calls a method to "protect" from
+//          a "protected" method
+//
+//          In this case the macro DFAKE_SCOPED_RECURSIVE_LOCK
+//          has to be used, it checks that if a thread is inside the push/pop
+//          then noone else is still inside the pop/push
+//
+// class NonThreadSafeQueue {
+//  public:
+//   void push(int) {
+//     DFAKE_SCOPED_LOCK(push_pop_);
+//     ...
+//   }
+//   int pop() {
+//     DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_);
+//     bar();
+//     ...
+//   }
+//   void bar() { DFAKE_SCOPED_RECURSIVE_LOCK(push_pop_); ... }
+//   ...
+//  private:
+//   DFAKE_MUTEX(push_pop_);
+// };
+//
+//
+// Example: Queue implementation not usable even if clients are synchronized,
+//          so only one thread in the class life cycle can use the two members
+//          push/pop.
+//
+//          In this case the macro DFAKE_SCOPED_LOCK_THREAD_LOCKED pins the
+//          specified
+//          critical section the first time a thread enters push or pop, from
+//          that time on only that thread is allowed to execute push or pop.
+//
+// class NonThreadSafeQueue {
+//  public:
+//   ...
+//   void push(int) { DFAKE_SCOPED_LOCK_THREAD_LOCKED(push_pop_); ... }
+//   int pop() { DFAKE_SCOPED_LOCK_THREAD_LOCKED(push_pop_); ... }
+//   ...
+//  private:
+//   DFAKE_MUTEX(push_pop_);
+// };
+//
+//
+// Example: Class that has to be contructed/destroyed on same thread, it has
+//          a "shareable" method (with external synchronization) and a not
+//          shareable method (even with external synchronization).
+//
+//          In this case 3 Critical sections have to be defined
+//
+// class ExoticClass {
+//  public:
+//   ExoticClass() { DFAKE_SCOPED_LOCK_THREAD_LOCKED(ctor_dtor_); ... }
+//   ~ExoticClass() { DFAKE_SCOPED_LOCK_THREAD_LOCKED(ctor_dtor_); ... }
+//
+//   void Shareable() { DFAKE_SCOPED_LOCK(shareable_section_); ... }
+//   void NotShareable() { DFAKE_SCOPED_LOCK_THREAD_LOCKED(ctor_dtor_); ... }
+//   ...
+//  private:
+//   DFAKE_MUTEX(ctor_dtor_);
+//   DFAKE_MUTEX(shareable_section_);
+// };
+
+
+#if !defined(NDEBUG)
+
+// Defines a class member that acts like a mutex. It is used only as a
+// verification tool.
+#define DFAKE_MUTEX(obj) \
+     mutable base::ThreadCollisionWarner obj
+// Asserts the call is never called simultaneously in two threads. Used at
+// member function scope.
+#define DFAKE_SCOPED_LOCK(obj) \
+     base::ThreadCollisionWarner::ScopedCheck s_check_##obj(&obj)
+// Asserts the call is never called simultaneously in two threads. Used at
+// member function scope. Same as DFAKE_SCOPED_LOCK but allows recursive locks.
+#define DFAKE_SCOPED_RECURSIVE_LOCK(obj) \
+     base::ThreadCollisionWarner::ScopedRecursiveCheck sr_check_##obj(&obj)
+// Asserts the code is always executed in the same thread.
+#define DFAKE_SCOPED_LOCK_THREAD_LOCKED(obj) \
+     base::ThreadCollisionWarner::Check check_##obj(&obj)
+
+#else
+
+#define DFAKE_MUTEX(obj) typedef void InternalFakeMutexType##obj
+#define DFAKE_SCOPED_LOCK(obj) ((void)0)
+#define DFAKE_SCOPED_RECURSIVE_LOCK(obj) ((void)0)
+#define DFAKE_SCOPED_LOCK_THREAD_LOCKED(obj) ((void)0)
+
+#endif
+
+namespace base {
+
+// The class ThreadCollisionWarner uses an Asserter to notify the collision
+// AsserterBase is the interfaces and DCheckAsserter is the default asserter
+// used. During the unit tests is used another class that doesn't "DCHECK"
+// in case of collision (check thread_collision_warner_unittests.cc)
+struct BASE_EXPORT AsserterBase {
+  virtual ~AsserterBase() {}
+  virtual void warn() = 0;
+};
+
+struct BASE_EXPORT DCheckAsserter : public AsserterBase {
+  virtual ~DCheckAsserter() {}
+  virtual void warn() OVERRIDE;
+};
+
+class BASE_EXPORT ThreadCollisionWarner {
+ public:
+  // The parameter asserter is there only for test purpose
+  explicit ThreadCollisionWarner(AsserterBase* asserter = new DCheckAsserter())
+      : valid_thread_id_(0),
+        counter_(0),
+        asserter_(asserter) {}
+
+  ~ThreadCollisionWarner() {
+    delete asserter_;
+  }
+
+  // This class is meant to be used through the macro
+  // DFAKE_SCOPED_LOCK_THREAD_LOCKED
+  // it doesn't leave the critical section, as opposed to ScopedCheck,
+  // because the critical section being pinned is allowed to be used only
+  // from one thread
+  class BASE_EXPORT Check {
+   public:
+    explicit Check(ThreadCollisionWarner* warner)
+        : warner_(warner) {
+      warner_->EnterSelf();
+    }
+
+    ~Check() {}
+
+   private:
+    ThreadCollisionWarner* warner_;
+
+    DISALLOW_COPY_AND_ASSIGN(Check);
+  };
+
+  // This class is meant to be used through the macro
+  // DFAKE_SCOPED_LOCK
+  class BASE_EXPORT ScopedCheck {
+   public:
+    explicit ScopedCheck(ThreadCollisionWarner* warner)
+        : warner_(warner) {
+      warner_->Enter();
+    }
+
+    ~ScopedCheck() {
+      warner_->Leave();
+    }
+
+   private:
+    ThreadCollisionWarner* warner_;
+
+    DISALLOW_COPY_AND_ASSIGN(ScopedCheck);
+  };
+
+  // This class is meant to be used through the macro
+  // DFAKE_SCOPED_RECURSIVE_LOCK
+  class BASE_EXPORT ScopedRecursiveCheck {
+   public:
+    explicit ScopedRecursiveCheck(ThreadCollisionWarner* warner)
+        : warner_(warner) {
+      warner_->EnterSelf();
+    }
+
+    ~ScopedRecursiveCheck() {
+      warner_->Leave();
+    }
+
+   private:
+    ThreadCollisionWarner* warner_;
+
+    DISALLOW_COPY_AND_ASSIGN(ScopedRecursiveCheck);
+  };
+
+ private:
+  // This method stores the current thread identifier and does a DCHECK
+  // if a another thread has already done it, it is safe if same thread
+  // calls this multiple time (recursion allowed).
+  void EnterSelf();
+
+  // Same as EnterSelf but recursion is not allowed.
+  void Enter();
+
+  // Removes the thread_id stored in order to allow other threads to
+  // call EnterSelf or Enter.
+  void Leave();
+
+  // This stores the thread id that is inside the critical section, if the
+  // value is 0 then no thread is inside.
+  volatile subtle::Atomic64 valid_thread_id_;
+
+  // Counter to trace how many time a critical section was "pinned"
+  // (when allowed) in order to unpin it when counter_ reaches 0.
+  volatile subtle::Atomic64 counter_;
+
+  // Here only for class unit tests purpose, during the test I need to not
+  // DCHECK but notify the collision with something else.
+  AsserterBase* asserter_;
+
+  DISALLOW_COPY_AND_ASSIGN(ThreadCollisionWarner);
+};
+
+}  // namespace base
+
+#endif  // BASE_THREADING_THREAD_COLLISION_WARNER_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/type_traits.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/type_traits.h b/be/src/gutil/type_traits.h
index e408fd0..a4e874f 100644
--- a/be/src/gutil/type_traits.h
+++ b/be/src/gutil/type_traits.h
@@ -63,7 +63,7 @@
 using std::make_pair;
 using std::pair;                  // For pair
 
-#include "gutil/template_util.h"     // For true_type and false_type
+#include "kudu/gutil/template_util.h"     // For true_type and false_type
 
 namespace base {
 
@@ -116,6 +116,10 @@ template<> struct is_integral<__wchar_t> : true_type { };
 #else
 template<> struct is_integral<wchar_t> : true_type { };
 #endif
+#if defined(__APPLE__)
+template<> struct is_integral<int64_t> : true_type { };
+template<> struct is_integral<uint64_t> : true_type { };
+#endif
 template<> struct is_integral<short> : true_type { };
 template<> struct is_integral<unsigned short> : true_type { };
 template<> struct is_integral<int> : true_type { };
@@ -350,10 +354,10 @@ struct is_convertible
 // these types are PODs, for human use.  They may be made more contentful
 // later.  The typedef is just to make it legal to put a semicolon after
 // these macros.
-#define DECLARE_POD(TypeName) typedef int Dummy_Type_For_DECLARE_POD
+#define DECLARE_POD(TypeName) typedef int Dummy_Type_For_DECLARE_POD ATTRIBUTE_UNUSED
 #define DECLARE_NESTED_POD(TypeName) DECLARE_POD(TypeName)
 #define PROPAGATE_POD_FROM_TEMPLATE_ARGUMENT(TemplateName)             \
-    typedef int Dummy_Type_For_PROPAGATE_POD_FROM_TEMPLATE_ARGUMENT
-#define ENFORCE_POD(TypeName) typedef int Dummy_Type_For_ENFORCE_POD
+    typedef int Dummy_Type_For_PROPAGATE_POD_FROM_TEMPLATE_ARGUMENT ATTRIBUTE_UNUSED
+#define ENFORCE_POD(TypeName) typedef int Dummy_Type_For_ENFORCE_POD ATTRIBUTE_UNUSED
 
 #endif  // BASE_TYPE_TRAITS_H_

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/utf/rune.c
----------------------------------------------------------------------
diff --git a/be/src/gutil/utf/rune.c b/be/src/gutil/utf/rune.c
new file mode 100644
index 0000000..1e7299c
--- /dev/null
+++ b/be/src/gutil/utf/rune.c
@@ -0,0 +1,350 @@
+/*
+ * The authors of this software are Rob Pike and Ken Thompson.
+ *              Copyright (c) 2002 by Lucent Technologies.
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose without fee is hereby granted, provided that this entire notice
+ * is included in all copies of any software which is or includes a copy
+ * or modification of this software and in all copies of the supporting
+ * documentation for such software.
+ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
+ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
+ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+ */
+#include <stdarg.h>
+#include <string.h>
+#include "gutil/utf/utf.h"
+#include "gutil/utf/utfdef.h"
+
+enum
+{
+	Bit1	= 7,
+	Bitx	= 6,
+	Bit2	= 5,
+	Bit3	= 4,
+	Bit4	= 3,
+	Bit5	= 2, 
+
+	T1	= ((1<<(Bit1+1))-1) ^ 0xFF,	/* 0000 0000 */
+	Tx	= ((1<<(Bitx+1))-1) ^ 0xFF,	/* 1000 0000 */
+	T2	= ((1<<(Bit2+1))-1) ^ 0xFF,	/* 1100 0000 */
+	T3	= ((1<<(Bit3+1))-1) ^ 0xFF,	/* 1110 0000 */
+	T4	= ((1<<(Bit4+1))-1) ^ 0xFF,	/* 1111 0000 */
+	T5	= ((1<<(Bit5+1))-1) ^ 0xFF,	/* 1111 1000 */
+
+	Rune1	= (1<<(Bit1+0*Bitx))-1,		/* 0000 0000 0111 1111 */
+	Rune2	= (1<<(Bit2+1*Bitx))-1,		/* 0000 0111 1111 1111 */
+	Rune3	= (1<<(Bit3+2*Bitx))-1,		/* 1111 1111 1111 1111 */
+	Rune4	= (1<<(Bit4+3*Bitx))-1,
+                                        /* 0001 1111 1111 1111 1111 1111 */
+
+	Maskx	= (1<<Bitx)-1,			/* 0011 1111 */
+	Testx	= Maskx ^ 0xFF,			/* 1100 0000 */
+
+	Bad	= Runeerror,
+};
+
+/*
+ * Modified by Wei-Hwa Huang, Google Inc., on 2004-09-24
+ * This is a slower but "safe" version of the old chartorune 
+ * that works on strings that are not necessarily null-terminated.
+ * 
+ * If you know for sure that your string is null-terminated,
+ * chartorune will be a bit faster.
+ *
+ * It is guaranteed not to attempt to access "length"
+ * past the incoming pointer.  This is to avoid
+ * possible access violations.  If the string appears to be
+ * well-formed but incomplete (i.e., to get the whole Rune
+ * we'd need to read past str+length) then we'll set the Rune
+ * to Bad and return 0.
+ *
+ * Note that if we have decoding problems for other
+ * reasons, we return 1 instead of 0.
+ */
+int
+charntorune(Rune *rune, const char *str, int length)
+{
+	int c, c1, c2, c3;
+	long l;
+
+	/* When we're not allowed to read anything */
+	if(length <= 0) {
+		goto badlen;
+	}
+
+	/*
+	 * one character sequence (7-bit value)
+	 *	00000-0007F => T1
+	 */
+	c = *(uchar*)str;
+	if(c < Tx) {
+		*rune = c;
+		return 1;
+	}
+
+	// If we can't read more than one character we must stop
+	if(length <= 1) {
+		goto badlen;
+	}
+
+	/*
+	 * two character sequence (11-bit value)
+	 *	0080-07FF => T2 Tx
+	 */
+	c1 = *(uchar*)(str+1) ^ Tx;
+	if(c1 & Testx)
+		goto bad;
+	if(c < T3) {
+		if(c < T2)
+			goto bad;
+		l = ((c << Bitx) | c1) & Rune2;
+		if(l <= Rune1)
+			goto bad;
+		*rune = l;
+		return 2;
+	}
+
+	// If we can't read more than two characters we must stop
+	if(length <= 2) {
+		goto badlen;
+	}
+
+	/*
+	 * three character sequence (16-bit value)
+	 *	0800-FFFF => T3 Tx Tx
+	 */
+	c2 = *(uchar*)(str+2) ^ Tx;
+	if(c2 & Testx)
+		goto bad;
+	if(c < T4) {
+		l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
+		if(l <= Rune2)
+			goto bad;
+		*rune = l;
+		return 3;
+	}
+
+	if (length <= 3)
+		goto badlen;
+
+	/*
+	 * four character sequence (21-bit value)
+	 *	10000-1FFFFF => T4 Tx Tx Tx
+	 */
+	c3 = *(uchar*)(str+3) ^ Tx;
+	if (c3 & Testx)
+		goto bad;
+	if (c < T5) {
+		l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
+		if (l <= Rune3)
+			goto bad;
+		*rune = l;
+		return 4;
+	}
+
+	// Support for 5-byte or longer UTF-8 would go here, but
+	// since we don't have that, we'll just fall through to bad.
+
+	/*
+	 * bad decoding
+	 */
+bad:
+	*rune = Bad;
+	return 1;
+badlen:
+	*rune = Bad;
+	return 0;
+
+}
+
+
+/*
+ * This is the older "unsafe" version, which works fine on 
+ * null-terminated strings.
+ */
+int
+chartorune(Rune *rune, const char *str)
+{
+	int c, c1, c2, c3;
+	long l;
+
+	/*
+	 * one character sequence
+	 *	00000-0007F => T1
+	 */
+	c = *(uchar*)str;
+	if(c < Tx) {
+		*rune = c;
+		return 1;
+	}
+
+	/*
+	 * two character sequence
+	 *	0080-07FF => T2 Tx
+	 */
+	c1 = *(uchar*)(str+1) ^ Tx;
+	if(c1 & Testx)
+		goto bad;
+	if(c < T3) {
+		if(c < T2)
+			goto bad;
+		l = ((c << Bitx) | c1) & Rune2;
+		if(l <= Rune1)
+			goto bad;
+		*rune = l;
+		return 2;
+	}
+
+	/*
+	 * three character sequence
+	 *	0800-FFFF => T3 Tx Tx
+	 */
+	c2 = *(uchar*)(str+2) ^ Tx;
+	if(c2 & Testx)
+		goto bad;
+	if(c < T4) {
+		l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
+		if(l <= Rune2)
+			goto bad;
+		*rune = l;
+		return 3;
+	}
+
+	/*
+	 * four character sequence (21-bit value)
+	 *	10000-1FFFFF => T4 Tx Tx Tx
+	 */
+	c3 = *(uchar*)(str+3) ^ Tx;
+	if (c3 & Testx)
+		goto bad;
+	if (c < T5) {
+		l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
+		if (l <= Rune3)
+			goto bad;
+		*rune = l;
+		return 4;
+	}
+
+	/*
+	 * Support for 5-byte or longer UTF-8 would go here, but
+	 * since we don't have that, we'll just fall through to bad.
+	 */
+
+	/*
+	 * bad decoding
+	 */
+bad:
+	*rune = Bad;
+	return 1;
+}
+
+int
+isvalidcharntorune(const char* str, int length, Rune* rune, int* consumed) {
+	*consumed = charntorune(rune, str, length);
+	return *rune != Runeerror || *consumed == 3;
+}
+    
+int
+runetochar(char *str, const Rune *rune)
+{
+	/* Runes are signed, so convert to unsigned for range check. */
+	unsigned long c;
+
+	/*
+	 * one character sequence
+	 *	00000-0007F => 00-7F
+	 */
+	c = *rune;
+	if(c <= Rune1) {
+		str[0] = c;
+		return 1;
+	}
+
+	/*
+	 * two character sequence
+	 *	0080-07FF => T2 Tx
+	 */
+	if(c <= Rune2) {
+		str[0] = T2 | (c >> 1*Bitx);
+		str[1] = Tx | (c & Maskx);
+		return 2;
+	}
+
+	/*
+	 * If the Rune is out of range, convert it to the error rune.
+	 * Do this test here because the error rune encodes to three bytes.
+	 * Doing it earlier would duplicate work, since an out of range
+	 * Rune wouldn't have fit in one or two bytes.
+	 */
+	if (c > Runemax)
+		c = Runeerror;
+
+	/*
+	 * three character sequence
+	 *	0800-FFFF => T3 Tx Tx
+	 */
+	if (c <= Rune3) {
+		str[0] = T3 |  (c >> 2*Bitx);
+		str[1] = Tx | ((c >> 1*Bitx) & Maskx);
+		str[2] = Tx |  (c & Maskx);
+		return 3;
+	}
+
+	/*
+	 * four character sequence (21-bit value)
+	 *     10000-1FFFFF => T4 Tx Tx Tx
+	 */
+	str[0] = T4 | (c >> 3*Bitx);
+	str[1] = Tx | ((c >> 2*Bitx) & Maskx);
+	str[2] = Tx | ((c >> 1*Bitx) & Maskx);
+	str[3] = Tx | (c & Maskx);
+	return 4;
+}
+
+int
+runelen(Rune rune)
+{
+	char str[10];
+
+	return runetochar(str, &rune);
+}
+
+int
+runenlen(const Rune *r, int nrune)
+{
+	int nb, c;
+
+	nb = 0;
+	while(nrune--) {
+		c = *r++;
+		if (c <= Rune1)
+			nb++;
+		else if (c <= Rune2)
+			nb += 2;
+		else if (c <= Rune3)
+			nb += 3;
+		else /* assert(c <= Rune4) */ 
+			nb += 4;
+	}
+	return nb;
+}
+
+int
+fullrune(const char *str, int n)
+{
+	if (n > 0) {
+		int c = *(uchar*)str;
+		if (c < Tx)
+			return 1;
+		if (n > 1) {
+			if (c < T3)
+				return 1;
+			if (n > 2) {
+				if (c < T4 || n > 3)
+					return 1;
+			}
+		}
+	}
+	return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/utf/rune.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/utf/rune.cc b/be/src/gutil/utf/rune.cc
deleted file mode 100644
index 908a9e0..0000000
--- a/be/src/gutil/utf/rune.cc
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * The authors of this software are Rob Pike and Ken Thompson.
- *              Copyright (c) 2002 by Lucent Technologies.
- * Permission to use, copy, modify, and distribute this software for any
- * purpose without fee is hereby granted, provided that this entire notice
- * is included in all copies of any software which is or includes a copy
- * or modification of this software and in all copies of the supporting
- * documentation for such software.
- * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTY.  IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
- * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
- * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
- */
-#include <stdarg.h>
-#include <string.h>
-#include "gutil/utf/utf.h"
-#include "gutil/utf/utfdef.h"
-
-extern "C" {
-
-enum
-{
-	Bit1	= 7,
-	Bitx	= 6,
-	Bit2	= 5,
-	Bit3	= 4,
-	Bit4	= 3,
-	Bit5	= 2,
-
-	T1	= ((1<<(Bit1+1))-1) ^ 0xFF,	/* 0000 0000 */
-	Tx	= ((1<<(Bitx+1))-1) ^ 0xFF,	/* 1000 0000 */
-	T2	= ((1<<(Bit2+1))-1) ^ 0xFF,	/* 1100 0000 */
-	T3	= ((1<<(Bit3+1))-1) ^ 0xFF,	/* 1110 0000 */
-	T4	= ((1<<(Bit4+1))-1) ^ 0xFF,	/* 1111 0000 */
-	T5	= ((1<<(Bit5+1))-1) ^ 0xFF,	/* 1111 1000 */
-
-	Rune1	= (1<<(Bit1+0*Bitx))-1,		/* 0000 0000 0111 1111 */
-	Rune2	= (1<<(Bit2+1*Bitx))-1,		/* 0000 0111 1111 1111 */
-	Rune3	= (1<<(Bit3+2*Bitx))-1,		/* 1111 1111 1111 1111 */
-	Rune4	= (1<<(Bit4+3*Bitx))-1,
-                                        /* 0001 1111 1111 1111 1111 1111 */
-
-	Maskx	= (1<<Bitx)-1,			/* 0011 1111 */
-	Testx	= Maskx ^ 0xFF,			/* 1100 0000 */
-
-	Bad	= Runeerror,
-};
-
-/*
- * Modified by Wei-Hwa Huang, Google Inc., on 2004-09-24
- * This is a slower but "safe" version of the old chartorune
- * that works on strings that are not necessarily null-terminated.
- *
- * If you know for sure that your string is null-terminated,
- * chartorune will be a bit faster.
- *
- * It is guaranteed not to attempt to access "length"
- * past the incoming pointer.  This is to avoid
- * possible access violations.  If the string appears to be
- * well-formed but incomplete (i.e., to get the whole Rune
- * we'd need to read past str+length) then we'll set the Rune
- * to Bad and return 0.
- *
- * Note that if we have decoding problems for other
- * reasons, we return 1 instead of 0.
- */
-int
-charntorune(Rune *rune, const char *str, int length)
-{
-	int c, c1, c2, c3;
-	long l;
-
-	/* When we're not allowed to read anything */
-	if(length <= 0) {
-		goto badlen;
-	}
-
-	/*
-	 * one character sequence (7-bit value)
-	 *	00000-0007F => T1
-	 */
-	c = *(uchar*)str;
-	if(c < Tx) {
-		*rune = c;
-		return 1;
-	}
-
-	// If we can't read more than one character we must stop
-	if(length <= 1) {
-		goto badlen;
-	}
-
-	/*
-	 * two character sequence (11-bit value)
-	 *	0080-07FF => T2 Tx
-	 */
-	c1 = *(uchar*)(str+1) ^ Tx;
-	if(c1 & Testx)
-		goto bad;
-	if(c < T3) {
-		if(c < T2)
-			goto bad;
-		l = ((c << Bitx) | c1) & Rune2;
-		if(l <= Rune1)
-			goto bad;
-		*rune = l;
-		return 2;
-	}
-
-	// If we can't read more than two characters we must stop
-	if(length <= 2) {
-		goto badlen;
-	}
-
-	/*
-	 * three character sequence (16-bit value)
-	 *	0800-FFFF => T3 Tx Tx
-	 */
-	c2 = *(uchar*)(str+2) ^ Tx;
-	if(c2 & Testx)
-		goto bad;
-	if(c < T4) {
-		l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
-		if(l <= Rune2)
-			goto bad;
-		*rune = l;
-		return 3;
-	}
-
-	if (length <= 3)
-		goto badlen;
-
-	/*
-	 * four character sequence (21-bit value)
-	 *	10000-1FFFFF => T4 Tx Tx Tx
-	 */
-	c3 = *(uchar*)(str+3) ^ Tx;
-	if (c3 & Testx)
-		goto bad;
-	if (c < T5) {
-		l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
-		if (l <= Rune3)
-			goto bad;
-		*rune = l;
-		return 4;
-	}
-
-	// Support for 5-byte or longer UTF-8 would go here, but
-	// since we don't have that, we'll just fall through to bad.
-
-	/*
-	 * bad decoding
-	 */
-bad:
-	*rune = Bad;
-	return 1;
-badlen:
-	*rune = Bad;
-	return 0;
-
-}
-
-
-/*
- * This is the older "unsafe" version, which works fine on
- * null-terminated strings.
- */
-int
-chartorune(Rune *rune, const char *str)
-{
-	int c, c1, c2, c3;
-	long l;
-
-	/*
-	 * one character sequence
-	 *	00000-0007F => T1
-	 */
-	c = *(uchar*)str;
-	if(c < Tx) {
-		*rune = c;
-		return 1;
-	}
-
-	/*
-	 * two character sequence
-	 *	0080-07FF => T2 Tx
-	 */
-	c1 = *(uchar*)(str+1) ^ Tx;
-	if(c1 & Testx)
-		goto bad;
-	if(c < T3) {
-		if(c < T2)
-			goto bad;
-		l = ((c << Bitx) | c1) & Rune2;
-		if(l <= Rune1)
-			goto bad;
-		*rune = l;
-		return 2;
-	}
-
-	/*
-	 * three character sequence
-	 *	0800-FFFF => T3 Tx Tx
-	 */
-	c2 = *(uchar*)(str+2) ^ Tx;
-	if(c2 & Testx)
-		goto bad;
-	if(c < T4) {
-		l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
-		if(l <= Rune2)
-			goto bad;
-		*rune = l;
-		return 3;
-	}
-
-	/*
-	 * four character sequence (21-bit value)
-	 *	10000-1FFFFF => T4 Tx Tx Tx
-	 */
-	c3 = *(uchar*)(str+3) ^ Tx;
-	if (c3 & Testx)
-		goto bad;
-	if (c < T5) {
-		l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
-		if (l <= Rune3)
-			goto bad;
-		*rune = l;
-		return 4;
-	}
-
-	/*
-	 * Support for 5-byte or longer UTF-8 would go here, but
-	 * since we don't have that, we'll just fall through to bad.
-	 */
-
-	/*
-	 * bad decoding
-	 */
-bad:
-	*rune = Bad;
-	return 1;
-}
-
-int
-isvalidcharntorune(const char* str, int length, Rune* rune, int* consumed) {
-	*consumed = charntorune(rune, str, length);
-	return *rune != Runeerror || *consumed == 3;
-}
-
-int
-runetochar(char *str, const Rune *rune)
-{
-	/* Runes are signed, so convert to unsigned for range check. */
-	unsigned long c;
-
-	/*
-	 * one character sequence
-	 *	00000-0007F => 00-7F
-	 */
-	c = *rune;
-	if(c <= Rune1) {
-		str[0] = c;
-		return 1;
-	}
-
-	/*
-	 * two character sequence
-	 *	0080-07FF => T2 Tx
-	 */
-	if(c <= Rune2) {
-		str[0] = T2 | (c >> 1*Bitx);
-		str[1] = Tx | (c & Maskx);
-		return 2;
-	}
-
-	/*
-	 * If the Rune is out of range, convert it to the error rune.
-	 * Do this test here because the error rune encodes to three bytes.
-	 * Doing it earlier would duplicate work, since an out of range
-	 * Rune wouldn't have fit in one or two bytes.
-	 */
-	if (c > Runemax)
-		c = Runeerror;
-
-	/*
-	 * three character sequence
-	 *	0800-FFFF => T3 Tx Tx
-	 */
-	if (c <= Rune3) {
-		str[0] = T3 |  (c >> 2*Bitx);
-		str[1] = Tx | ((c >> 1*Bitx) & Maskx);
-		str[2] = Tx |  (c & Maskx);
-		return 3;
-	}
-
-	/*
-	 * four character sequence (21-bit value)
-	 *     10000-1FFFFF => T4 Tx Tx Tx
-	 */
-	str[0] = T4 | (c >> 3*Bitx);
-	str[1] = Tx | ((c >> 2*Bitx) & Maskx);
-	str[2] = Tx | ((c >> 1*Bitx) & Maskx);
-	str[3] = Tx | (c & Maskx);
-	return 4;
-}
-
-int
-runelen(Rune rune)
-{
-	char str[10];
-
-	return runetochar(str, &rune);
-}
-
-int
-runenlen(const Rune *r, int nrune)
-{
-	int nb, c;
-
-	nb = 0;
-	while(nrune--) {
-		c = *r++;
-		if (c <= Rune1)
-			nb++;
-		else if (c <= Rune2)
-			nb += 2;
-		else if (c <= Rune3)
-			nb += 3;
-		else /* assert(c <= Rune4) */
-			nb += 4;
-	}
-	return nb;
-}
-
-int
-fullrune(const char *str, int n)
-{
-	if (n > 0) {
-		int c = *(uchar*)str;
-		if (c < Tx)
-			return 1;
-		if (n > 1) {
-			if (c < T3)
-				return 1;
-			if (n > 2) {
-				if (c < T4 || n > 3)
-					return 1;
-			}
-		}
-	}
-	return 0;
-}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/walltime.cc
----------------------------------------------------------------------
diff --git a/be/src/gutil/walltime.cc b/be/src/gutil/walltime.cc
index 04d7f4b..89a805e 100644
--- a/be/src/gutil/walltime.cc
+++ b/be/src/gutil/walltime.cc
@@ -1,16 +1,21 @@
 // Copyright 2012 Google Inc. All Rights Reserved.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 //
 // Author: tkaftal@google.com (Tomasz Kaftal)
 //
@@ -19,7 +24,7 @@
 #define _GNU_SOURCE   // Linux wants that for strptime in time.h
 #endif
 
-#include "gutil/walltime.h"
+#include "kudu/gutil/walltime.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -68,7 +73,7 @@ static void StringAppendStrftime(string* dst,
   int length = sizeof(space);
   for (int sanity = 0; sanity < 5; ++sanity) {
     length *= 2;
-    char* buf = new char[length];
+    auto buf = new char[length];
 
     result = strftime(buf, length, format, tm);
     if ((result >= 0) && (result < length)) {
@@ -136,7 +141,7 @@ bool WallTime_Parse_Timezone(const char* time_spec,
      memset(&split_time, 0, sizeof(split_time));
   }
   const char* parsed = strptime(time_spec, format, &split_time);
-  if (parsed == NULL) return false;
+  if (parsed == nullptr) return false;
 
   // If format ends with "%S", match fractional seconds
   double fraction = 0.0;
@@ -166,6 +171,18 @@ bool WallTime_Parse_Timezone(const char* time_spec,
   return true;
 }
 
+WallTime WallTime_Now() {
+#if defined(__APPLE__)
+  mach_timespec_t ts;
+  walltime_internal::GetCurrentTime(&ts);
+  return ts.tv_sec + ts.tv_nsec / static_cast<double>(1e9);
+#else
+  timespec ts;
+  clock_gettime(CLOCK_REALTIME, &ts);
+  return ts.tv_sec + ts.tv_nsec / static_cast<double>(1e9);
+#endif  // defined(__APPLE__)
+}
+
 void StringAppendStrftime(string* dst,
                           const char* format,
                           time_t when,
@@ -173,9 +190,9 @@ void StringAppendStrftime(string* dst,
   struct tm tm;
   bool conversion_error;
   if (local) {
-    conversion_error = (localtime_r(&when, &tm) == NULL);
+    conversion_error = (localtime_r(&when, &tm) == nullptr);
   } else {
-    conversion_error = (gmtime_r(&when, &tm) == NULL);
+    conversion_error = (gmtime_r(&when, &tm) == nullptr);
   }
   if (conversion_error) {
     // If we couldn't convert the time, don't append anything.
@@ -186,6 +203,6 @@ void StringAppendStrftime(string* dst,
 
 string LocalTimeAsString() {
   string ret;
-  StringAppendStrftime(&ret, "%Y-%m-%d %H:%M:%S %Z", time(NULL), true);
+  StringAppendStrftime(&ret, "%Y-%m-%d %H:%M:%S %Z", time(nullptr), true);
   return ret;
 }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/02f3e3fc/be/src/gutil/walltime.h
----------------------------------------------------------------------
diff --git a/be/src/gutil/walltime.h b/be/src/gutil/walltime.h
index 2f04ebe..e6a1294 100644
--- a/be/src/gutil/walltime.h
+++ b/be/src/gutil/walltime.h
@@ -1,21 +1,27 @@
 // Copyright 2012 Google Inc. All Rights Reserved.
 //
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+//   http://www.apache.org/licenses/LICENSE-2.0
 //
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
 #ifndef GUTIL_WALLTIME_H_
 #define GUTIL_WALLTIME_H_
 
 #include <sys/time.h>
 
+#include <glog/logging.h>
 #include <string>
 using std::string;
 
@@ -24,17 +30,10 @@ using std::string;
 #include <mach/mach.h>
 #include <mach/mach_time.h>
 
-#include "gutil/once.h"
+#include "kudu/gutil/once.h"
 #endif  // defined(__APPLE__)
 
-#include "common/logging.h"
-#include "gutil/integral_types.h"
-
-#define NANOS_PER_SEC  1000000000ll
-#define NANOS_PER_MICRO      1000ll
-#define MICROS_PER_SEC    1000000ll
-#define MICROS_PER_MILLI     1000ll
-#define MILLIS_PER_SEC       1000ll
+#include "kudu/gutil/integral_types.h"
 
 typedef double WallTime;
 
@@ -58,8 +57,10 @@ bool WallTime_Parse_Timezone(const char* time_spec,
                                     bool local,
                                     WallTime* result);
 
+// Return current time in seconds as a WallTime.
+WallTime WallTime_Now();
+
 typedef int64 MicrosecondsInt64;
-typedef int64 NanosecondsInt64;
 
 namespace walltime_internal {
 
@@ -79,7 +80,7 @@ inline void GetCurrentTime(mach_timespec_t* ts) {
 inline MicrosecondsInt64 GetCurrentTimeMicros() {
   mach_timespec_t ts;
   GetCurrentTime(&ts);
-  return ts.tv_sec * MICROS_PER_SEC + ts.tv_nsec / NANOS_PER_MICRO;
+  return ts.tv_sec * 1e6 + ts.tv_nsec / 1e3;
 }
 
 inline int64_t GetMonoTimeNanos() {
@@ -94,7 +95,7 @@ inline int64_t GetMonoTimeNanos() {
 }
 
 inline MicrosecondsInt64 GetMonoTimeMicros() {
-  return GetMonoTimeNanos() / NANOS_PER_MICRO;
+  return GetMonoTimeNanos() / 1e3;
 }
 
 inline MicrosecondsInt64 GetThreadCpuTimeMicros() {
@@ -120,8 +121,7 @@ inline MicrosecondsInt64 GetThreadCpuTimeMicros() {
     return 0;
   }
 
-  return thread_info_data.user_time.seconds * MICROS_PER_SEC +
-      thread_info_data.user_time.microseconds;
+  return thread_info_data.user_time.seconds * 1e6 + thread_info_data.user_time.microseconds;
 }
 
 #else
@@ -129,20 +129,13 @@ inline MicrosecondsInt64 GetThreadCpuTimeMicros() {
 inline MicrosecondsInt64 GetClockTimeMicros(clockid_t clock) {
   timespec ts;
   clock_gettime(clock, &ts);
-  return ts.tv_sec * MICROS_PER_SEC + ts.tv_nsec / NANOS_PER_MICRO;
-}
-
-inline NanosecondsInt64 GetClockTimeNanos(clockid_t clock) {
-  timespec ts;
-  clock_gettime(clock, &ts);
-  return ts.tv_sec * NANOS_PER_SEC + ts.tv_nsec;
+  return ts.tv_sec * 1e6 + ts.tv_nsec / 1e3;
 }
 
 #endif // defined(__APPLE__)
 
 } // namespace walltime_internal
 
-
 // Returns the time since the Epoch measured in microseconds.
 inline MicrosecondsInt64 GetCurrentTimeMicros() {
 #if defined(__APPLE__)
@@ -152,15 +145,6 @@ inline MicrosecondsInt64 GetCurrentTimeMicros() {
 #endif  // defined(__APPLE__)
 }
 
-// Returns the time since the Epoch measured in microseconds.
-inline NanosecondsInt64 GetMonoTimeNanos() {
-#if defined(__APPLE__)
-  return walltime_internal::GetMonoTimeNanos();
-#else
-  return walltime_internal::GetClockTimeNanos(CLOCK_MONOTONIC);
-#endif  // defined(__APPLE__)
-}
-
 // Returns the time since some arbitrary reference point, measured in microseconds.
 // Guaranteed to be monotonic (and therefore useful for measuring intervals)
 inline MicrosecondsInt64 GetMonoTimeMicros() {
@@ -191,5 +175,5 @@ class CycleClock {
   CycleClock();
 };
 
-#include "gutil/cycleclock-inl.h"  // inline method bodies
+#include "kudu/gutil/cycleclock-inl.h"  // inline method bodies
 #endif  // GUTIL_WALLTIME_H_