You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2023/09/03 14:37:06 UTC

[kudu] branch master updated (ecb51af80 -> 86bdc679f)

This is an automated email from the ASF dual-hosted git repository.

alexey pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


    from ecb51af80 KUDU-3508 increase Ranger start timeout to 120 seconds
     new 63ca4b5b4 [client] fix doxygen warnings
     new 86bdc679f [util] deprecate {MonoTime,MonoDelta}::Equals() methods

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 docs/support/doxygen/client_api.doxy.in          |  13 +++
 src/kudu/client/client.h                         |  22 ++--
 src/kudu/client/write_op.h                       |   2 +
 src/kudu/consensus/time_manager-test.cc          |   3 +-
 src/kudu/integration-tests/master-stress-test.cc |   6 +-
 src/kudu/rpc/exactly_once_rpc-test.cc            |  13 +--
 src/kudu/rpc/result_tracker.cc                   |  11 +-
 src/kudu/util/monotime-test.cc                   |  19 ++--
 src/kudu/util/monotime.cc                        | 122 +++++++++++------------
 src/kudu/util/monotime.h                         |  72 ++++++++-----
 src/kudu/util/threadpool.cc                      |   6 +-
 11 files changed, 166 insertions(+), 123 deletions(-)


[kudu] 02/02: [util] deprecate {MonoTime,MonoDelta}::Equals() methods

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 86bdc679f6a5435c649d2ac0f6557daab632b953
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Thu Aug 10 15:11:53 2023 -0700

    [util] deprecate {MonoTime,MonoDelta}::Equals() methods
    
    All these Equals(), LessThan(), MoreThan(), Earliest(), AddDelta(), etc.
    methods look a bit funny in the C++ code.  Also, the API already exposes
    more expressive means to do the same: the corresponding operators.
    To prevent spreading the harder-to-read and funny looking code, this
    patch declares those operators obsolete to promote using the better
    option.  Of course, due to the compatibility reasons, those methods are
    still kept in the public API as they used to be, but now the compiler
    will emit a warning when trying to use those deprecated methods.
    
    I also took the liberty of updating the related code to be more
    style-compliant and making other minor improvements.
    
    Change-Id: I716955dcc7359f920d0b5bedf9035a42edeb6e92
    Reviewed-on: http://gerrit.cloudera.org:8080/20442
    Reviewed-by: Mahesh Reddy <mr...@cloudera.com>
    Reviewed-by: Abhishek Chennaka <ac...@cloudera.com>
    Tested-by: Alexey Serbin <al...@apache.org>
---
 src/kudu/consensus/time_manager-test.cc          |   3 +-
 src/kudu/integration-tests/master-stress-test.cc |   6 +-
 src/kudu/rpc/exactly_once_rpc-test.cc            |  13 +--
 src/kudu/rpc/result_tracker.cc                   |  11 +-
 src/kudu/util/monotime-test.cc                   |  19 ++--
 src/kudu/util/monotime.cc                        | 122 +++++++++++------------
 src/kudu/util/monotime.h                         |  72 ++++++++-----
 src/kudu/util/threadpool.cc                      |   6 +-
 8 files changed, 136 insertions(+), 116 deletions(-)

diff --git a/src/kudu/consensus/time_manager-test.cc b/src/kudu/consensus/time_manager-test.cc
index 32608db25..da37c83c2 100644
--- a/src/kudu/consensus/time_manager-test.cc
+++ b/src/kudu/consensus/time_manager-test.cc
@@ -203,8 +203,7 @@ TEST_F(TimeManagerTest, TestTimeManagerLeaderMode) {
   // safe time shouldn't move anymore ...
   ASSERT_EQ(time_manager_->GetSafeTime(), safe_after);
   now = clock_.Now();
-  MonoTime after_small = MonoTime::Now();
-  after_small.AddDelta(MonoDelta::FromMilliseconds(100));
+  const auto after_small = MonoTime::Now() + MonoDelta::FromMilliseconds(100);
   ASSERT_TRUE(time_manager_->WaitUntilSafe(now, after_small).IsTimedOut());
 
   // ... unless we get a message from the leader.
diff --git a/src/kudu/integration-tests/master-stress-test.cc b/src/kudu/integration-tests/master-stress-test.cc
index 1889ff4a5..dd07243ec 100644
--- a/src/kudu/integration-tests/master-stress-test.cc
+++ b/src/kudu/integration-tests/master-stress-test.cc
@@ -23,6 +23,7 @@
 #include <string>
 #include <thread>
 #include <tuple>
+#include <type_traits>
 #include <unordered_map>
 #include <utility>
 #include <vector>
@@ -49,7 +50,6 @@
 #include "kudu/master/master.proxy.h"
 #include "kudu/mini-cluster/external_mini_cluster.h"
 #include "kudu/rpc/messenger.h"
-#include "kudu/rpc/response_callback.h"
 #include "kudu/rpc/rpc_controller.h"
 #include "kudu/tablet/tablet.pb.h"
 #include "kudu/thrift/client.h"
@@ -436,8 +436,8 @@ class MasterStressTest : public ExternalMiniClusterITestBase,
     MessengerBuilder bld("RestartMasterMessenger");
     CHECK_OK(bld.Build(&messenger));
 
-    MonoTime deadline(MonoTime::Now());
-    deadline.AddDelta(MonoDelta::FromSeconds(FLAGS_num_seconds_to_run));
+    const auto deadline = MonoTime::Now() +
+        MonoDelta::FromSeconds(FLAGS_num_seconds_to_run);
 
     MonoTime now(MonoTime::Now());
     while (now < deadline) {
diff --git a/src/kudu/rpc/exactly_once_rpc-test.cc b/src/kudu/rpc/exactly_once_rpc-test.cc
index 31f474489..8308b66bb 100644
--- a/src/kudu/rpc/exactly_once_rpc-test.cc
+++ b/src/kudu/rpc/exactly_once_rpc-test.cc
@@ -25,6 +25,7 @@
 #include <ostream>
 #include <string>
 #include <thread>
+#include <type_traits>
 #include <utility>
 #include <vector>
 
@@ -44,7 +45,6 @@
 #include "kudu/rpc/rtest.pb.h"
 #include "kudu/rpc/rtest.proxy.h"
 #include "kudu/util/countdown_latch.h"
-#include "kudu/util/mem_tracker.h"
 #include "kudu/util/monotime.h"
 #include "kudu/util/net/sockaddr.h"
 #include "kudu/util/pb_util.h"
@@ -220,11 +220,10 @@ class ExactlyOnceRpcTest : public RpcTestBase {
                      shared_ptr<Messenger> messenger,
                      int value,
                      int server_sleep = 0) : latch(1) {
-      MonoTime now = MonoTime::Now();
-      now.AddDelta(MonoDelta::FromMilliseconds(10000));
+      const auto deadline = MonoTime::Now() + MonoDelta::FromSeconds(10);
       rpc = new CalculatorServiceRpc(server_picker,
                                      request_tracker,
-                                     now,
+                                     deadline,
                                      std::move(messenger),
                                      value,
                                      &latch,
@@ -298,8 +297,7 @@ class ExactlyOnceRpcTest : public RpcTestBase {
   // This continuously issues calls to the server, that often last longer than
   // 'remember_responses_ttl_ms', making sure that we don't get errors back.
   void DoLongWritesThread(MonoDelta run_for) {
-    MonoTime run_until = MonoTime::Now();
-    run_until.AddDelta(run_for);
+    const auto run_until = MonoTime::Now() + run_for;
     int counter = 0;
     while (MonoTime::Now() < run_until) {
       unique_ptr<RetriableRpcExactlyOnceAdder> adder(new RetriableRpcExactlyOnceAdder(
@@ -327,8 +325,7 @@ class ExactlyOnceRpcTest : public RpcTestBase {
   // client should be GCed.
   void StubbornlyWriteTheSameRequestThread(ResultTracker::SequenceNumber sequence_number,
                                            MonoDelta run_for) {
-    MonoTime run_until = MonoTime::Now();
-    run_until.AddDelta(run_for);
+    const auto run_until = MonoTime::Now() + run_for;
     // Make an initial request, so that we get a response to compare to.
     ExactlyOnceResponsePB original_response;
     CHECK_OK(MakeAddCall(sequence_number, 0, &original_response));
diff --git a/src/kudu/rpc/result_tracker.cc b/src/kudu/rpc/result_tracker.cc
index d5a376c2b..7d2c3fe3c 100644
--- a/src/kudu/rpc/result_tracker.cc
+++ b/src/kudu/rpc/result_tracker.cc
@@ -20,6 +20,7 @@
 #include <algorithm>
 #include <mutex>
 #include <ostream>
+#include <type_traits>
 
 #include <gflags/gflags.h>
 #include <glog/logging.h>
@@ -474,12 +475,10 @@ void ResultTracker::GCResults() {
   lock_guard<simple_spinlock> l(lock_);
   MonoTime now = MonoTime::Now();
   // Calculate the instants before which we'll start GCing ClientStates and CompletionRecords.
-  MonoTime time_to_gc_clients_from = now;
-  time_to_gc_clients_from.AddDelta(
-      MonoDelta::FromMilliseconds(-FLAGS_remember_clients_ttl_ms));
-  MonoTime time_to_gc_responses_from = now;
-  time_to_gc_responses_from.AddDelta(
-      MonoDelta::FromMilliseconds(-FLAGS_remember_responses_ttl_ms));
+  const auto time_to_gc_clients_from = now -
+      MonoDelta::FromMilliseconds(FLAGS_remember_clients_ttl_ms);
+  const auto time_to_gc_responses_from = now -
+      MonoDelta::FromMilliseconds(FLAGS_remember_responses_ttl_ms);
 
   // Now go through the ClientStates. If we haven't heard from a client in a while
   // GC it and all its completion records (making sure there isn't actually one in progress first).
diff --git a/src/kudu/util/monotime-test.cc b/src/kudu/util/monotime-test.cc
index a75d6fa70..7404b7b24 100644
--- a/src/kudu/util/monotime-test.cc
+++ b/src/kudu/util/monotime-test.cc
@@ -23,12 +23,19 @@
 #include <cstdint>
 #include <ctime>
 #include <ostream>
+#include <string>
 
 #include <glog/logging.h>
 #include <gtest/gtest.h>
 
 #include "kudu/util/test_util.h"
 
+// Many original scenarios in this test suite use the deprecated
+// MonoTime/MonoDelta API, so let's add a blanket pragma to quell the warnings
+// about using the deprecated methods.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
 namespace kudu {
 
 TEST(TestMonoTime, TestMonotonicity) {
@@ -38,16 +45,14 @@ TEST(TestMonoTime, TestMonotonicity) {
 
   do {
     next = MonoTime::Now();
-    //LOG(INFO) << " next = " << next.ToString();
-  } while (!prev.ComesBefore(next));
-  ASSERT_FALSE(next.ComesBefore(prev));
+  } while (prev >= next);
+  ASSERT_LE(prev, next);
   alarm(0);
 }
 
 TEST(TestMonoTime, TestComparison) {
-  MonoTime now(MonoTime::Now());
-  MonoTime future(now);
-  future.AddDelta(MonoDelta::FromNanoseconds(1L));
+  const MonoTime now(MonoTime::Now());
+  const MonoTime future(now + MonoDelta::FromNanoseconds(1L));
 
   ASSERT_GT((future - now).ToNanoseconds(), 0);
   ASSERT_LT((now - future).ToNanoseconds(), 0);
@@ -508,3 +513,5 @@ TEST(TestMonoTimePerf, TestMonoTimePerf) {
 }
 
 } // namespace kudu
+
+#pragma GCC diagnostic pop
diff --git a/src/kudu/util/monotime.cc b/src/kudu/util/monotime.cc
index da7a6c55a..1a44f74bb 100644
--- a/src/kudu/util/monotime.cc
+++ b/src/kudu/util/monotime.cc
@@ -19,6 +19,7 @@
 
 #include <sys/time.h>
 
+#include <cstdint>
 #include <ctime>
 #include <limits>
 #include <ostream>
@@ -47,8 +48,7 @@ namespace kudu {
 const int64_t MonoDelta::kUninitialized = kint64min;
 
 MonoDelta MonoDelta::FromSeconds(double seconds) {
-  int64_t delta = seconds * MonoTime::kNanosecondsPerSecond;
-  return MonoDelta(delta);
+  return MonoDelta(seconds * MonoTime::kNanosecondsPerSecond);
 }
 
 MonoDelta MonoDelta::FromMilliseconds(int64_t ms) {
@@ -71,22 +71,16 @@ bool MonoDelta::Initialized() const {
   return nano_delta_ != kUninitialized;
 }
 
-bool MonoDelta::LessThan(const MonoDelta &rhs) const {
-  DCHECK(Initialized());
-  DCHECK(rhs.Initialized());
-  return nano_delta_ < rhs.nano_delta_;
+bool MonoDelta::LessThan(const MonoDelta& rhs) const {
+  return *this < rhs;
 }
 
-bool MonoDelta::MoreThan(const MonoDelta &rhs) const {
-  DCHECK(Initialized());
-  DCHECK(rhs.Initialized());
-  return nano_delta_ > rhs.nano_delta_;
+bool MonoDelta::MoreThan(const MonoDelta& rhs) const {
+  return *this > rhs;
 }
 
-bool MonoDelta::Equals(const MonoDelta &rhs) const {
-  DCHECK(Initialized());
-  DCHECK(rhs.Initialized());
-  return nano_delta_ == rhs.nano_delta_;
+bool MonoDelta::Equals(const MonoDelta& rhs) const {
+  return *this == rhs;
 }
 
 std::string MonoDelta::ToString() const {
@@ -94,14 +88,12 @@ std::string MonoDelta::ToString() const {
 }
 
 MonoDelta::MonoDelta(int64_t delta)
-  : nano_delta_(delta) {
+    : nano_delta_(delta) {
 }
 
 double MonoDelta::ToSeconds() const {
   DCHECK(Initialized());
-  double d(nano_delta_);
-  d /= MonoTime::kNanosecondsPerSecond;
-  return d;
+  return static_cast<double>(nano_delta_) / MonoTime::kNanosecondsPerSecond;
 }
 
 int64_t MonoDelta::ToNanoseconds() const {
@@ -111,7 +103,7 @@ int64_t MonoDelta::ToNanoseconds() const {
 
 int64_t MonoDelta::ToMicroseconds() const {
   DCHECK(Initialized());
- return nano_delta_ / MonoTime::kNanosecondsPerMicrosecond;
+  return nano_delta_ / MonoTime::kNanosecondsPerMicrosecond;
 }
 
 int64_t MonoDelta::ToMilliseconds() const {
@@ -119,7 +111,7 @@ int64_t MonoDelta::ToMilliseconds() const {
   return nano_delta_ / MonoTime::kNanosecondsPerMillisecond;
 }
 
-void MonoDelta::ToTimeVal(struct timeval *tv) const {
+void MonoDelta::ToTimeVal(struct timeval* tv) const {
   DCHECK(Initialized());
   tv->tv_sec = nano_delta_ / MonoTime::kNanosecondsPerSecond;
   tv->tv_usec = (nano_delta_ - (tv->tv_sec * MonoTime::kNanosecondsPerSecond))
@@ -210,20 +202,16 @@ bool MonoTime::Initialized() const {
   return nanos_ != 0;
 }
 
-MonoDelta MonoTime::GetDeltaSince(const MonoTime &rhs) const {
+MonoDelta MonoTime::GetDeltaSince(const MonoTime& rhs) const {
   return rhs - *this;
 }
 
-void MonoTime::AddDelta(const MonoDelta &delta) {
-  DCHECK(Initialized());
-  DCHECK(delta.Initialized());
-  nanos_ += delta.nano_delta_;
+void MonoTime::AddDelta(const MonoDelta& delta) {
+  this->operator+=(delta);
 }
 
-bool MonoTime::ComesBefore(const MonoTime &rhs) const {
-  DCHECK(Initialized());
-  DCHECK(rhs.Initialized());
-  return nanos_ < rhs.nanos_;
+bool MonoTime::ComesBefore(const MonoTime& rhs) const {
+  return *this < rhs;
 }
 
 std::string MonoTime::ToString() const {
@@ -236,16 +224,20 @@ void MonoTime::ToTimeSpec(struct timespec* ts) const {
 }
 
 bool MonoTime::Equals(const MonoTime& other) const {
-  return nanos_ == other.nanos_;
+  return *this == other;
 }
 
 MonoTime& MonoTime::operator+=(const MonoDelta& delta) {
-  this->AddDelta(delta);
+  DCHECK(Initialized());
+  DCHECK(delta.Initialized());
+  nanos_ += delta.nano_delta_;
   return *this;
 }
 
 MonoTime& MonoTime::operator-=(const MonoDelta& delta) {
-  this->AddDelta(MonoDelta(-1 * delta.nano_delta_));
+  DCHECK(Initialized());
+  DCHECK(delta.Initialized());
+  nanos_ -= delta.nano_delta_;
   return *this;
 }
 
@@ -264,9 +256,7 @@ MonoTime::MonoTime(int64_t nanos) KUDU_MONOTIME_NOEXCEPT
 }
 
 double MonoTime::ToSeconds() const {
-  double d(nanos_);
-  d /= MonoTime::kNanosecondsPerSecond;
-  return d;
+  return static_cast<double>(nanos_) / MonoTime::kNanosecondsPerSecond;
 }
 
 void SleepFor(const MonoDelta& delta) {
@@ -274,80 +264,84 @@ void SleepFor(const MonoDelta& delta) {
   base::SleepForNanoseconds(delta.ToNanoseconds());
 }
 
-bool operator==(const MonoDelta &lhs, const MonoDelta &rhs) {
-  return lhs.Equals(rhs);
+bool operator==(const MonoDelta& lhs, const MonoDelta& rhs) {
+  DCHECK(lhs.Initialized());
+  DCHECK(rhs.Initialized());
+  return lhs.nano_delta_ == rhs.nano_delta_;
 }
 
-bool operator!=(const MonoDelta &lhs, const MonoDelta &rhs) {
-  return !lhs.Equals(rhs);
+bool operator!=(const MonoDelta& lhs, const MonoDelta& rhs) {
+  return !(lhs == rhs);
 }
 
-bool operator<(const MonoDelta &lhs, const MonoDelta &rhs) {
-  return lhs.LessThan(rhs);
+bool operator<(const MonoDelta& lhs, const MonoDelta& rhs) {
+  DCHECK(lhs.Initialized());
+  DCHECK(rhs.Initialized());
+  return lhs.nano_delta_ < rhs.nano_delta_;
 }
 
-bool operator<=(const MonoDelta &lhs, const MonoDelta &rhs) {
-  return lhs.LessThan(rhs) || lhs.Equals(rhs);
+bool operator<=(const MonoDelta& lhs, const MonoDelta& rhs) {
+  return !(lhs > rhs);
 }
 
-bool operator>(const MonoDelta &lhs, const MonoDelta &rhs) {
-  return lhs.MoreThan(rhs);
+bool operator>(const MonoDelta& lhs, const MonoDelta& rhs) {
+  return rhs < lhs;
 }
 
-bool operator>=(const MonoDelta &lhs, const MonoDelta &rhs) {
-  return lhs.MoreThan(rhs) || lhs.Equals(rhs);
+bool operator>=(const MonoDelta& lhs, const MonoDelta& rhs) {
+  return !(lhs < rhs);
 }
 
-MonoDelta operator-(const MonoDelta &lhs, const MonoDelta &rhs) {
+MonoDelta operator-(const MonoDelta& lhs, const MonoDelta& rhs) {
   return MonoDelta(lhs.nano_delta_ - rhs.nano_delta_);
 }
 
-MonoDelta operator+(const MonoDelta &lhs, const MonoDelta &rhs) {
+MonoDelta operator+(const MonoDelta& lhs, const MonoDelta& rhs) {
   return MonoDelta(lhs.nano_delta_ + rhs.nano_delta_);
 }
 
 bool operator==(const MonoTime& lhs, const MonoTime& rhs) {
-  return lhs.Equals(rhs);
+  return lhs.nanos_ == rhs.nanos_;
 }
 
 bool operator!=(const MonoTime& lhs, const MonoTime& rhs) {
-  return !lhs.Equals(rhs);
+  return !(lhs == rhs);
 }
 
 bool operator<(const MonoTime& lhs, const MonoTime& rhs) {
-  return lhs.ComesBefore(rhs);
+  DCHECK(lhs.Initialized());
+  DCHECK(rhs.Initialized());
+  return lhs.nanos_ < rhs.nanos_;
 }
 
 bool operator<=(const MonoTime& lhs, const MonoTime& rhs) {
-  return lhs.ComesBefore(rhs) || lhs.Equals(rhs);
+  return !(lhs > rhs);
 }
 
 bool operator>(const MonoTime& lhs, const MonoTime& rhs) {
-  return rhs.ComesBefore(lhs);
+  return rhs < lhs;
 }
 
 bool operator>=(const MonoTime& lhs, const MonoTime& rhs) {
-  return rhs.ComesBefore(lhs) || rhs.Equals(lhs);
+  return !(lhs < rhs);
 }
 
 MonoTime operator+(const MonoTime& t, const MonoDelta& delta) {
-  MonoTime tmp(t);
-  tmp.AddDelta(delta);
-  return tmp;
+  DCHECK(t.Initialized());
+  DCHECK(delta.Initialized());
+  return MonoTime(t.nanos_ + delta.nano_delta_);
 }
 
 MonoTime operator-(const MonoTime& t, const MonoDelta& delta) {
-  MonoTime tmp(t);
-  tmp.AddDelta(MonoDelta::FromNanoseconds(-delta.ToNanoseconds()));
-  return tmp;
+  DCHECK(t.Initialized());
+  DCHECK(delta.Initialized());
+  return MonoTime(t.nanos_ - delta.nano_delta_);
 }
 
 MonoDelta operator-(const MonoTime& t_end, const MonoTime& t_beg) {
   DCHECK(t_beg.Initialized());
   DCHECK(t_end.Initialized());
-  int64_t delta(t_end.nanos_);
-  delta -= t_beg.nanos_;
-  return MonoDelta(delta);
+  return MonoDelta(t_end.nanos_ - t_beg.nanos_);
 }
 
 std::ostream& operator<<(std::ostream& os, const kudu::MonoTime& time) {
diff --git a/src/kudu/util/monotime.h b/src/kudu/util/monotime.h
index 474dde1ee..583a1de01 100644
--- a/src/kudu/util/monotime.h
+++ b/src/kudu/util/monotime.h
@@ -94,30 +94,39 @@ class KUDU_EXPORT MonoDelta {
   /// @return @c true iff this object is initialized.
   bool Initialized() const;
 
+  /// @deprecated Use operator<(const MonoDelta&, const MonoDelta&) instead.
+  ///
   /// Check whether this time interval is shorter than the specified one.
   ///
   /// @param [in] rhs
   ///   A time interval for comparison.
   /// @return @c true iff this time interval is strictly shorter
   ///   than the specified one.
-  bool LessThan(const MonoDelta &rhs) const;
+  bool LessThan(const MonoDelta& rhs) const
+      ATTRIBUTE_DEPRECATED("use operator<(const MonoDelta&, const MonoDelta&) instead");
 
+  /// @deprecated Use operator>(const MonoDelta&, const MonoDelta&) instead.
+  ///
   /// Check whether this time interval is longer than the specified one.
   ///
   /// @param [in] rhs
   ///   A time interval for comparison.
   /// @return @c true iff this time interval is strictly longer
   ///   than the specified one.
-  bool MoreThan(const MonoDelta &rhs) const;
+  bool MoreThan(const MonoDelta& rhs) const
+      ATTRIBUTE_DEPRECATED("use operator>(const MonoDelta&, const MonoDelta&) instead");
 
+  /// @deprecated Use operator==(const MonoDelta&, const MonoDelta&) instead.
+  ///
   /// Check whether this time interval has the same duration
-  ///  as the specified one.
+  /// as the specified one.
   ///
   /// @param [in] rhs
   ///   A time interval for comparison.
   /// @return @c true iff this time interval has the same duration as the
   ///   the specified one.
-  bool Equals(const MonoDelta &rhs) const;
+  bool Equals(const MonoDelta& rhs) const ATTRIBUTE_DEPRECATED(
+      "use operator==(const MonoDelta&, const MonoDelta&) instead");
 
   /// @return String representation of this interval's duration (in seconds).
   std::string ToString() const;
@@ -137,7 +146,7 @@ class KUDU_EXPORT MonoDelta {
   ///
   /// @param [out] tv
   ///   Placeholder for the result value.
-  void ToTimeVal(struct timeval *tv) const;
+  void ToTimeVal(struct timeval* tv) const;
 
   /// Represent this time interval as a timespec structure, with nanosecond
   /// accuracy.
@@ -180,6 +189,11 @@ class KUDU_EXPORT MonoDelta {
   friend MonoDelta operator-(const class MonoTime&, const class MonoTime&);
   friend MonoDelta operator-(const MonoDelta&, const MonoDelta&);
   friend MonoDelta operator+(const MonoDelta&, const MonoDelta&);
+  friend class MonoTime operator-(const class MonoTime&, const class MonoDelta&);
+  friend class MonoTime operator+(const class MonoTime&, const class MonoDelta&);
+  friend bool operator==(const MonoDelta&, const MonoDelta&);
+  friend bool operator<(const MonoDelta&, const MonoDelta&);
+  friend bool operator>(const MonoDelta&, const MonoDelta&);
 
   FRIEND_TEST(TestMonoTime, TestDeltaConversions);
 
@@ -223,9 +237,9 @@ class KUDU_EXPORT MonoTime {
   /// @return MonoTime equal to farthest possible time into the past.
   static MonoTime Min();
 
-  /// Select the earliest between the specified time points.
+  /// @deprecated Use std::min() instead.
   ///
-  /// @deprecated Use @c use std::min() instead.
+  /// Select the earliest between the specified time points.
   ///
   /// @param [in] a
   ///   The first MonoTime object to select from.
@@ -242,25 +256,30 @@ class KUDU_EXPORT MonoTime {
   /// @return @c true iff the object is initialized.
   bool Initialized() const;
 
-  /// Compute time interval between the point in time specified by this
-  /// and the specified object.
-  ///
   /// @deprecated Use @c kudu::operator-(const MonoTime&, const MonoTime&)
   ///   instead.
   ///
+  /// Compute time interval between the point in time specified by this
+  /// and the specified object.
+  ///
   /// @param [in] rhs
   ///   The object that corresponds to the left boundary of the time interval,
   ///   where this object corresponds to the right boundary of the interval.
   /// @return The resulting time interval represented as a MonoDelta object.
-  MonoDelta GetDeltaSince(const MonoTime &rhs) const ATTRIBUTE_DEPRECATED(
+  MonoDelta GetDeltaSince(const MonoTime& rhs) const ATTRIBUTE_DEPRECATED(
       "use kudu::operator-(const MonoTime&, const MonoTime&) instead");
 
+  /// @deprecated Use @c operator+=(const MonoDelta&) instead.
+  ///
   /// Advance this object's time specification by the specified interval.
   ///
   /// @param [in] delta
   ///   The time interval to add.
-  void AddDelta(const MonoDelta &delta);
+  void AddDelta(const MonoDelta& delta) ATTRIBUTE_DEPRECATED(
+      "use operator+=(const MonoDelta&) instead");
 
+  /// @deprecated Use @c operator<(const MonoTime&, const MonoTime&) instead.
+  ///
   /// Check whether the point in time specified by this object is earlier
   /// than the specified one.
   ///
@@ -268,7 +287,8 @@ class KUDU_EXPORT MonoTime {
   ///   The other MonoTime object to compare with.
   /// @return @c true iff the point in time represented by this MonoTime object
   ///   is earlier then the point in time represented by the parameter.
-  bool ComesBefore(const MonoTime &rhs) const;
+  bool ComesBefore(const MonoTime& rhs) const ATTRIBUTE_DEPRECATED(
+      "use operator<(const MonoTime&, const MonoTime&) instead");
 
   /// @return String representation of the object (in seconds).
   std::string ToString() const;
@@ -280,16 +300,16 @@ class KUDU_EXPORT MonoTime {
   ///   Placeholder for the result value.
   void ToTimeSpec(struct timespec* ts) const;
 
+  /// @deprecated Use operator==(const MonoTime&, const MonoTime&) instead.
+  ///
   /// Check whether this object represents the same point in time as the other.
   ///
   /// @param [in] other
   ///   The other MonoTime object to compare.
   /// @return @c true iff the point in time represented by this MonoTime object
   ///   is the same as the one represented by the other.
-  bool Equals(const MonoTime& other) const;
-
-  /// @name Syntactic sugar: increment/decrement operators for MonoTime.
-  ///@{
+  bool Equals(const MonoTime& other) const ATTRIBUTE_DEPRECATED(
+      "use operator==(const MonoTime&, const MonoTime&) instead");
 
   /// Add a delta to the point in time represented by the object.
   ///
@@ -304,11 +324,15 @@ class KUDU_EXPORT MonoTime {
   ///   The delta to substract.
   /// @return Reference to the modified object.
   MonoTime& operator-=(const MonoDelta& delta);
-  ///@}
 
  private:
   friend class MonoDelta;
   friend MonoDelta operator-(const MonoTime&, const MonoTime&);
+  friend MonoTime operator-(const MonoTime&, const MonoDelta&);
+  friend MonoTime operator+(const MonoTime&, const MonoDelta&);
+  friend bool operator==(const MonoTime&, const MonoTime&);
+  friend bool operator<(const MonoTime&, const MonoTime&);
+
   FRIEND_TEST(TestMonoTime, TestTimeSpec);
   FRIEND_TEST(TestMonoTime, TestDeltaConversions);
 
@@ -339,7 +363,7 @@ void KUDU_EXPORT SleepFor(const MonoDelta& delta);
 ///   A time interval for comparison: the right-hand operand.
 /// @return @c true iff the time interval represented by @c lhs is equal
 ///   to the time interval represented by @c rhs.
-bool KUDU_EXPORT operator==(const MonoDelta &lhs, const MonoDelta &rhs);
+bool KUDU_EXPORT operator==(const MonoDelta& lhs, const MonoDelta& rhs);
 
 /// @param [in] lhs
 ///   A time interval for comparison: the left-hand operand.
@@ -347,7 +371,7 @@ bool KUDU_EXPORT operator==(const MonoDelta &lhs, const MonoDelta &rhs);
 ///   A time interval for comparison: the right-hand operand.
 /// @return @c true iff the time interval represented by @c lhs is not equal
 ///   to the time interval represented by @c rhs.
-bool KUDU_EXPORT operator!=(const MonoDelta &lhs, const MonoDelta &rhs);
+bool KUDU_EXPORT operator!=(const MonoDelta& lhs, const MonoDelta& rhs);
 
 /// @param [in] lhs
 ///   A time interval for comparison: the left-hand operand.
@@ -355,7 +379,7 @@ bool KUDU_EXPORT operator!=(const MonoDelta &lhs, const MonoDelta &rhs);
 ///   A time interval for comparison: the right-hand operand.
 /// @return @c true iff the time interval represented by @c lhs is shorter
 ///   than the time interval represented by @c rhs.
-bool KUDU_EXPORT operator<(const MonoDelta &lhs, const MonoDelta &rhs);
+bool KUDU_EXPORT operator<(const MonoDelta& lhs, const MonoDelta& rhs);
 
 /// @param [in] lhs
 ///   A time interval for comparison: the left-hand operand.
@@ -363,7 +387,7 @@ bool KUDU_EXPORT operator<(const MonoDelta &lhs, const MonoDelta &rhs);
 ///   A time interval for comparison: the right-hand operand.
 /// @return @c true iff the time interval represented by @c lhs is shorter
 ///   than or equal to the time interval represented by @c rhs.
-bool KUDU_EXPORT operator<=(const MonoDelta &lhs, const MonoDelta &rhs);
+bool KUDU_EXPORT operator<=(const MonoDelta& lhs, const MonoDelta& rhs);
 
 /// @param [in] lhs
 ///   A time interval for comparison: the left-hand operand.
@@ -371,7 +395,7 @@ bool KUDU_EXPORT operator<=(const MonoDelta &lhs, const MonoDelta &rhs);
 ///   A time interval for comparison: the right-hand operand.
 /// @return @c true iff the time interval represented by @c lhs is longer
 ///   than the time interval represented by @c rhs.
-bool KUDU_EXPORT operator>(const MonoDelta &lhs, const MonoDelta &rhs);
+bool KUDU_EXPORT operator>(const MonoDelta& lhs, const MonoDelta& rhs);
 
 /// @param [in] lhs
 ///   A time interval for comparison: the left-hand operand.
@@ -379,7 +403,7 @@ bool KUDU_EXPORT operator>(const MonoDelta &lhs, const MonoDelta &rhs);
 ///   A time interval for comparison: the right-hand operand.
 /// @return @c true iff the time interval represented by @c lhs is longer
 ///   than or equal to the time interval represented by @c rhs.
-bool KUDU_EXPORT operator>=(const MonoDelta &lhs, const MonoDelta &rhs);
+bool KUDU_EXPORT operator>=(const MonoDelta& lhs, const MonoDelta& rhs);
 
 /// @param [in] lhs
 ///   A time interval for substraction: the left-hand operand.
diff --git a/src/kudu/util/threadpool.cc b/src/kudu/util/threadpool.cc
index f8a10758d..4454ca04f 100644
--- a/src/kudu/util/threadpool.cc
+++ b/src/kudu/util/threadpool.cc
@@ -260,9 +260,9 @@ void ThreadPoolToken::Shutdown() {
 // Submit a task, running after delay_ms delay some time
 Status ThreadPoolToken::Schedule(std::function<void()> f, int64_t delay_ms) {
   CHECK(mode() == ThreadPool::ExecutionMode::SERIAL);
-  MonoTime execute_time = MonoTime::Now();
-  execute_time.AddDelta(MonoDelta::FromMilliseconds(delay_ms));
-  return pool_->Schedule(this, std::move(f), execute_time);
+  return pool_->Schedule(this,
+                         std::move(f),
+                         MonoTime::Now() + MonoDelta::FromMilliseconds(delay_ms));
 }
 
 void ThreadPoolToken::Wait() {


[kudu] 01/02: [client] fix doxygen warnings

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 63ca4b5b43e8552f5408efbe43e7915b2f375b70
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Wed Aug 30 15:02:19 2023 -0700

    [client] fix doxygen warnings
    
    This patch should help at least with follow-up Kudu releases while
    building doxygen documentation for the C++ client.
    
    This patch doesn't contain any functional modifications.
    
    Change-Id: I440d4f79ccd1b7e4f852cdf423727245e84e8d56
    Reviewed-on: http://gerrit.cloudera.org:8080/20441
    Tested-by: Kudu Jenkins
    Reviewed-by: Mahesh Reddy <mr...@cloudera.com>
    Reviewed-by: Abhishek Chennaka <ac...@cloudera.com>
---
 docs/support/doxygen/client_api.doxy.in | 13 +++++++++++++
 src/kudu/client/client.h                | 22 +++++++++++++++-------
 src/kudu/client/write_op.h              |  2 ++
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/docs/support/doxygen/client_api.doxy.in b/docs/support/doxygen/client_api.doxy.in
index c438bf591..df783a3ba 100644
--- a/docs/support/doxygen/client_api.doxy.in
+++ b/docs/support/doxygen/client_api.doxy.in
@@ -43,6 +43,19 @@ RECURSIVE              = YES
 # in those anyway.
 EXCLUDE                = @DOXY_CLIENT_API_EXCLUDE@
 
+# Enable pre-processing and macro expansion in doxygen (both are turned off
+# by default otherwise), but expand only macros that specified by the
+# PREDEFINED configuration parameter below. As of now, that's to simplify the
+# signatures of the documented methods that otherwise might be interpreted
+# in a wrong way by doxygen. This recipe is documented at least at
+# https://www.doxygen.nl/manual/preprocessing.html
+ENABLE_PREPROCESSING   = YES
+MACRO_EXPANSION        = YES
+EXPAND_ONLY_PREDEF     = YES
+
+# Below is the list of macros to be expanded by a custom way by doxygen.
+PREDEFINED             = ATTRIBUTE_DEPRECATED(x):=
+
 # We add information about the Kudu version the documentation is generated for.
 # NOTE: this tag requires GENERATE_HTML enabled.
 HTML_FOOTER            = @DOXY_CLIENT_API_FOOTER@
diff --git a/src/kudu/client/client.h b/src/kudu/client/client.h
index 8de0dc8da..ceb888e45 100644
--- a/src/kudu/client/client.h
+++ b/src/kudu/client/client.h
@@ -334,8 +334,9 @@ class KUDU_EXPORT KuduClientBuilder {
 
   /// Add a trusted root CA certificate into the client's TLS certificate bundle.
   ///
-  /// @param [in] cert_pem_str
+  /// @param [in] cert_pem
   ///   The trusted certificate to add, in PEM format.
+  /// @return Reference to the updated object.
   KuduClientBuilder& trusted_certificate(const std::string& cert_pem);
 
   /// @brief Set the number of reactors for the RPC messenger.
@@ -713,7 +714,7 @@ class KUDU_EXPORT KuduClient : public sp::enable_shared_from_this<KuduClient> {
   /// The delete operation or drop operation means that the service will directly
   /// delete the table after receiving the instruction. Which means that once we
   /// delete the table by mistake, we have no way to recall the deleted data.
-  /// We have added a new API @SoftDeleteTable to allow the deleted data to be
+  /// We have added a new SoftDeleteTable API to allow the deleted data to be
   /// reserved for a period of time, which means that the wrongly deleted data may
   /// be recalled. In order to be compatible with the previous versions, this interface
   /// will continue to directly delete tables without reserving the table.
@@ -3411,6 +3412,18 @@ class KUDU_EXPORT KuduScanTokenBuilder {
   /// @return Operation result status.
   Status SetQueryId(const std::string& query_id);
 
+  /// Set approximate data size (in bytes) for each key range that a single scan
+  /// token is built for.
+  ///
+  /// @param [in] split_size_bytes
+  ///   The approximate target size of the data to be retrieved per scan token.
+  ///   If set to @c 0 (and that's the default, unless explicitly set by calling
+  ///   this method), the key ranges of the scan tokens to be produced
+  ///   are determined by the table's partition schema, so a single token
+  ///   is built per single tablet. Also see @c KuduScanToken#setSplitSizeBytes
+  ///   in the Java client.
+  void SetSplitSizeBytes(uint64_t split_size_bytes);
+
   /// Build the set of scan tokens.
   ///
   /// The builder may be reused after this call.
@@ -3421,11 +3434,6 @@ class KUDU_EXPORT KuduScanTokenBuilder {
   /// @return Operation result status.
   Status Build(std::vector<KuduScanToken*>* tokens) WARN_UNUSED_RESULT;
 
-  /// Set the size of the data in each key range.
-  /// The default value is 0 without set and tokens build by meta cache.
-  /// It's corresponding to 'setSplitSizeBytes' in Java client.
-  void SetSplitSizeBytes(uint64_t split_size_bytes);
-
  private:
   class KUDU_NO_EXPORT Data;
 
diff --git a/src/kudu/client/write_op.h b/src/kudu/client/write_op.h
index 32cfa5b55..5a96a7a3f 100644
--- a/src/kudu/client/write_op.h
+++ b/src/kudu/client/write_op.h
@@ -95,6 +95,8 @@ class KUDU_EXPORT KuduWriteOperation {
   ///   caller must handle redaction themselves, if necessary.
   virtual std::string ToString() const = 0;
 
+  /// @return Raw pointer to KuduTable object representing the table
+  ///   that the write is targeted for.
   const KuduTable* table() const { return table_.get(); }
 
  protected: