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 079bf1d71a39134b9abb4e1c250ce7988230797e
Author: Zoltan Martonka <[email protected]>
AuthorDate: Wed Jun 26 09:20:39 2024 +0000

    Fix cache cleaning in dense_node-itest
    
    Running dense_node-itest with --measure_startup_drop_caches (as
    src/kudu/scripts/benchmarks.sh does) fails on Ubuntu 22.04. We try to
    open the /proc/sys/vm/drop_caches file with O_RDWR mode to write "3"
    into it. On Ubuntu 18.04, the file seems to have read permissions too,
    but on 22.04 it is properly set to --w-------, so we fail to do so.
    
    Change-Id: I1f36f5a97d9a032aeb495989b4dc05191bf66425
    Reviewed-on: http://gerrit.cloudera.org:8080/21509
    Reviewed-by: Zoltan Chovan <[email protected]>
    Reviewed-by: Wang Xixu <[email protected]>
    Tested-by: Marton Greber <[email protected]>
    Reviewed-by: Marton Greber <[email protected]>
---
 src/kudu/integration-tests/dense_node-itest.cc |  5 ++---
 src/kudu/util/env.h                            |  3 +++
 src/kudu/util/env_posix.cc                     | 21 +++++++++++++++++++++
 src/kudu/util/os-util.cc                       | 15 +++++----------
 src/kudu/util/os-util.h                        |  2 ++
 5 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/src/kudu/integration-tests/dense_node-itest.cc 
b/src/kudu/integration-tests/dense_node-itest.cc
index afd849e6a..212181eac 100644
--- a/src/kudu/integration-tests/dense_node-itest.cc
+++ b/src/kudu/integration-tests/dense_node-itest.cc
@@ -42,6 +42,7 @@
 #include "kudu/util/env.h"
 #include "kudu/util/metrics.h"
 #include "kudu/util/monotime.h"
+#include "kudu/util/os-util.h"
 #include "kudu/util/status.h"
 #include "kudu/util/stopwatch.h"
 #include "kudu/util/test_macros.h"
@@ -247,9 +248,7 @@ TEST_P(DenseNodeTest, RunTest) {
       unique_ptr<WritableFile> f;
       WritableFileOptions opts;
       opts.mode = Env::MUST_EXIST;
-      ASSERT_OK(env_->NewWritableFile(opts, "/proc/sys/vm/drop_caches", &f));
-      ASSERT_OK(f->Append("3\n"));
-      ASSERT_OK(f->Close());
+      ASSERT_OK(FreeSlabObjectsAndPagecache());
     }
   }
 
diff --git a/src/kudu/util/env.h b/src/kudu/util/env.h
index 9f941b3f7..a69281970 100644
--- a/src/kudu/util/env.h
+++ b/src/kudu/util/env.h
@@ -396,6 +396,9 @@ class Env {
   // Set the raw server encryption key. The key size is in bits.
   virtual void SetEncryptionKey(const uint8_t* key, size_t key_size) = 0;
 
+  // Used for manipulating the proc filesystem
+  virtual Status EchoToFile(const char* file_path, const char* data_ptr, int 
data_size) = 0;
+
  private:
   DISALLOW_COPY_AND_ASSIGN(Env);
 };
diff --git a/src/kudu/util/env_posix.cc b/src/kudu/util/env_posix.cc
index 360df4f25..1b0ddd635 100644
--- a/src/kudu/util/env_posix.cc
+++ b/src/kudu/util/env_posix.cc
@@ -2464,6 +2464,27 @@ class PosixEnv : public Env {
     return Status::OK();
   }
 
+  Status EchoToFile(const char* file_path, const char* data_ptr, int 
data_size) override {
+    int f;
+    RETRY_ON_EINTR(f, open(file_path, O_WRONLY));
+    if (f == -1)
+      return IOError(file_path, errno);
+    ssize_t write_ret;
+    RETRY_ON_EINTR(write_ret, write(f, data_ptr, data_size));
+    if (write_ret == -1) {
+      // Try to close it anyway, but return the error during write().
+      int saved_errno = errno;
+      int dont_care;
+      RETRY_ON_EINTR(dont_care, close(f));
+      return IOError(file_path, saved_errno);
+    }
+    int close_ret;
+    RETRY_ON_EINTR(close_ret, close(f));
+    if (close_ret == -1)
+      return IOError(file_path, errno);
+    return Status::OK();
+  }
+
   std::optional<EncryptionHeader> encryption_key_;
 };
 
diff --git a/src/kudu/util/os-util.cc b/src/kudu/util/os-util.cc
index 85ceb9f4b..bedfcd0fb 100644
--- a/src/kudu/util/os-util.cc
+++ b/src/kudu/util/os-util.cc
@@ -24,7 +24,6 @@
 
 #include "kudu/util/os-util.h"
 
-#include <fcntl.h>
 #include <sys/resource.h>
 #include <unistd.h>
 
@@ -36,7 +35,6 @@
 
 #include <glog/logging.h>
 
-#include "kudu/gutil/macros.h"
 #include "kudu/gutil/strings/numbers.h"
 #include "kudu/gutil/strings/split.h"
 #include "kudu/gutil/strings/stringpiece.h"
@@ -133,14 +131,11 @@ void DisableCoreDumps() {
   // is set to a pipe rather than a file, it's not sufficient. Setting
   // this pattern results in piping a very minimal dump into the core
   // processor (eg abrtd), thus speeding up the crash.
-  int f;
-  RETRY_ON_EINTR(f, open("/proc/self/coredump_filter", O_WRONLY));
-  if (f >= 0) {
-    ssize_t ret;
-    RETRY_ON_EINTR(ret, write(f, "00000000", 8));
-    int close_ret;
-    RETRY_ON_EINTR(close_ret, close(f));
-  }
+  (void)Env::Default()->EchoToFile("/proc/self/coredump_filter", "00000000", 
8);
+}
+
+Status FreeSlabObjectsAndPagecache() {
+  return Env::Default()->EchoToFile("/proc/sys/vm/drop_caches", "3", 1);
 }
 
 bool IsBeingDebugged() {
diff --git a/src/kudu/util/os-util.h b/src/kudu/util/os-util.h
index 7e1bbb64f..5619a007e 100644
--- a/src/kudu/util/os-util.h
+++ b/src/kudu/util/os-util.h
@@ -62,6 +62,8 @@ Status GetThreadStats(int64_t tid, ThreadStats* stats);
 // want to generate a core dump from an "expected" crash.
 void DisableCoreDumps();
 
+Status FreeSlabObjectsAndPagecache();
+
 // Return true if this process appears to be running under a debugger or 
strace.
 //
 // This may return false on unsupported (non-Linux) platforms.

Reply via email to