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 2025/02/20 06:28:53 UTC

(kudu) branch master updated (08756b17a -> 8f136bb21)

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 08756b17a [cbtree] modernize code in CBTree
     new 57fb36a72 [consensus] address warning on released replicates
     new 8f136bb21 [util] add 'nodiscard' attribute for Status

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:
 src/kudu/consensus/log.cc |  4 +++-
 src/kudu/util/status.h    | 20 +++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)


(kudu) 02/02: [util] add 'nodiscard' attribute for Status

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 8f136bb21c71de13f643a19d9308140a1b76d0d2
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Wed Feb 19 13:47:05 2025 -0800

    [util] add 'nodiscard' attribute for Status
    
    This patch helps to spot sloppy error handling and catch related
    mistakes and bugs at compile time once Status class is marked with the
    'nodiscard' attribute [1].  It has a potential of saving us time doing
    debugging and troubleshooting, at least I know a few occasions where
    it should have helped :)
    
    With this patch, a non-handled result Status produces a compiler's
    warning when compiling with CLANG or GCC13 and newer.  People developing
    on macOS and Ubuntu 24.04 can see that with this patch, and our ASAN and
    TSAN pre-commit builds should produce corresponding warnings as well.
    A follow-up changelist [2] turns warnings into errors.  Once the
    sloppiness in error handling is addressed throughout the existing code,
    [2] should be added to guard against sloppy error handling
    in newly added code.
    
    [1] https://en.cppreference.com/w/cpp/language/attributes/nodiscard
    [2] https://gerrit.cloudera.org/#/c/22489/
    
    Change-Id: I1ec324e3bb5d10bc35f34ed2614e239a4a150446
    Reviewed-on: http://gerrit.cloudera.org:8080/22504
    Reviewed-by: Abhishek Chennaka <ac...@cloudera.com>
    Tested-by: Alexey Serbin <al...@apache.org>
---
 src/kudu/util/status.h | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/kudu/util/status.h b/src/kudu/util/status.h
index 5acf59045..107516bc5 100644
--- a/src/kudu/util/status.h
+++ b/src/kudu/util/status.h
@@ -126,6 +126,24 @@
     } \
   } while (0)
 
+// Introduce [[nodiscard]] attribute if compiling with the C++17 or newer.
+#if __cplusplus >= 201703L
+  // This works as intended with KUDU_EXPORT and other attributes for LLVM/CLANG
+  // (at least starting version 11.0.0 that's current version in thirdparty),
+  // but GCC prior to version 13.0 is touchy if mixing attributes of different
+  // types/styles, see [1] for details. So, enable this only if compiling with
+  // CLANG or GCC version 13 and newer.
+  //
+  // [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69585 for details).
+  #if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 13)
+    #define KUDU_ATTR_NODISCARD [[nodiscard]] // NOLINT(whitespace/braces)
+  #else
+    #define KUDU_ATTR_NODISCARD
+  #endif
+#else   // #if __cplusplus >= 201703L ...
+  #define KUDU_ATTR_NODISCARD
+#endif  // #if __cplusplus >= 201703L ... #else ...
+
 /// @file status.h
 ///
 /// This header is used in both the Kudu build as well as in builds of
@@ -162,7 +180,7 @@
 namespace kudu {
 
 /// @brief A representation of an operation's outcome.
-class KUDU_EXPORT Status {
+class KUDU_EXPORT KUDU_ATTR_NODISCARD Status {
  public:
   /// Create an object representing success status.
   Status() : state_(NULL) { }


(kudu) 01/02: [consensus] address warning on released replicates

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 57fb36a72261e1369dd9e5bc222676a0b860525e
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Wed Feb 19 15:01:14 2025 -0800

    [consensus] address warning on released replicates
    
    This patch addresses a warning that appeared after upgrading protobuf
    to version 3.21.9.  Since the new protobuf marks some of the
    auto-generated methods with the [[nodiscard]] attribute, there was an
    extra warning that might have pointed to a possible memory leak.
    It wasn't the case because of the Log::AsyncAppendReplicates() method's
    semantics, but it's worth addressing it anyway.
    
    Change-Id: Ia756597b920622baef8c55b5040d6c051814db63
    Reviewed-on: http://gerrit.cloudera.org:8080/22505
    Tested-by: Alexey Serbin <al...@apache.org>
    Reviewed-by: Abhishek Chennaka <ac...@cloudera.com>
---
 src/kudu/consensus/log.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/kudu/consensus/log.cc b/src/kudu/consensus/log.cc
index 81d6f279a..422e6e771 100644
--- a/src/kudu/consensus/log.cc
+++ b/src/kudu/consensus/log.cc
@@ -872,7 +872,9 @@ Status Log::AsyncAppendReplicates(vector<ReplicateRefPtr> replicates,
       CreateBatchFromPB(REPLICATE, batch_pb, std::move(callback));
 
   for (LogEntryPB& entry : *batch_pb.mutable_entry()) {
-    entry.release_replicate();
+    // Release the ownership of ReplicateMsg in every entry since it's managed
+    // at the upper level where the 'replicates' parameter is passed from.
+    entry.unsafe_arena_release_replicate();
   }
 
   return AsyncAppend(std::move(batch));