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

laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b44580c4 fix(ut): fix the dsn.meta.test using a directorty may has 
not permission (#2019)
9b44580c4 is described below

commit 9b44580c40b9ed87c4fcd1e78068e80186b90175
Author: Yingchun Lai <[email protected]>
AuthorDate: Thu May 23 19:33:16 2024 +0800

    fix(ut): fix the dsn.meta.test using a directorty may has not permission 
(#2019)
    
    Use the current working directory rather than the fixed '/home/work/' 
directory.
---
 src/common/fs_manager.cpp   |  3 +++
 src/meta/test/misc/misc.cpp | 28 +++++++++++++---------------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/common/fs_manager.cpp b/src/common/fs_manager.cpp
index 1b633b1d2..4544c0098 100644
--- a/src/common/fs_manager.cpp
+++ b/src/common/fs_manager.cpp
@@ -298,6 +298,7 @@ dir_node *fs_manager::find_best_dir_for_new_replica(const 
gpid &pid) const
         for (const auto &dn : _dir_nodes) {
             // Do not allocate new replica on dir_node which is not NORMAL.
             if (dn->status != disk_status::NORMAL) {
+                LOG_INFO("skip the {} state dir_node({})", 
enum_to_string(dn->status), dn->tag);
                 continue;
             }
             CHECK(!dn->has(pid), "gpid({}) already exists in dir_node({})", 
pid, dn->tag);
@@ -440,6 +441,7 @@ dir_node *fs_manager::find_replica_dir(absl::string_view 
app_type, gpid pid)
         for (const auto &dn : _dir_nodes) {
             // Skip IO error dir_node.
             if (dn->status == disk_status::IO_ERROR) {
+                LOG_INFO("skip the {} state dir_node({})", 
enum_to_string(dn->status), dn->tag);
                 continue;
             }
             const auto dir = dn->replica_dir(app_type, pid);
@@ -498,6 +500,7 @@ dir_node 
*fs_manager::create_child_replica_dir(absl::string_view app_type,
         for (const auto &dn : _dir_nodes) {
             // Skip non-available dir_node.
             if (dn->status != disk_status::NORMAL) {
+                LOG_INFO("skip the {} state dir_node({})", 
enum_to_string(dn->status), dn->tag);
                 continue;
             }
             child_dir = dn->replica_dir(app_type, child_pid);
diff --git a/src/meta/test/misc/misc.cpp b/src/meta/test/misc/misc.cpp
index 149f0735e..ef85d7e99 100644
--- a/src/meta/test/misc/misc.cpp
+++ b/src/meta/test/misc/misc.cpp
@@ -27,6 +27,7 @@
 #include "misc.h"
 
 #include <boost/lexical_cast.hpp>
+#include <fmt/core.h>
 // IWYU pragma: no_include <ext/alloc_traits.h>
 #include <stdio.h>
 #include <atomic>
@@ -50,6 +51,7 @@
 #include "runtime/rpc/dns_resolver.h" // IWYU pragma: keep
 #include "runtime/rpc/rpc_address.h"
 #include "runtime/rpc/rpc_host_port.h"
+#include "utils/filesystem.h"
 #include "utils/fmt_logging.h"
 #include "utils/rand.h"
 
@@ -195,15 +197,13 @@ void generate_node_fs_manager(const app_mapper &apps,
                               int total_disks)
 {
     nfm.clear();
-    const char *prefix = "/home/work/";
-    char pid_dir[256];
+    std::string prefix;
+    CHECK(dsn::utils::filesystem::get_current_directory(prefix), "");
     std::vector<std::string> data_dirs(total_disks);
     std::vector<std::string> tags(total_disks);
     for (int i = 0; i < data_dirs.size(); ++i) {
-        snprintf(pid_dir, 256, "%sdisk%d", prefix, i + 1);
-        data_dirs[i] = pid_dir;
-        snprintf(pid_dir, 256, "disk%d", i + 1);
-        tags[i] = pid_dir;
+        data_dirs[i] = fmt::format("{}disk{}", prefix, i + 1);
+        tags[i] = fmt::format("disk{}", i + 1);
     }
 
     for (const auto &kv : nodes) {
@@ -215,15 +215,13 @@ void generate_node_fs_manager(const app_mapper &apps,
         manager.initialize(data_dirs, tags);
         ns.for_each_partition([&](const dsn::gpid &pid) {
             const config_context &cc = *get_config_context(apps, pid);
-            snprintf(pid_dir,
-                     256,
-                     "%s%s/%d.%d.test",
-                     prefix,
-                     cc.find_from_serving(ns.host_port())->disk_tag.c_str(),
-                     pid.get_app_id(),
-                     pid.get_partition_index());
-            LOG_DEBUG("concat pid_dir({}) of node({})", pid_dir, 
ns.host_port());
-            manager.add_replica(pid, pid_dir);
+            const auto dir = fmt::format("{}{}/{}.{}.test",
+                                         prefix,
+                                         
cc.find_from_serving(ns.host_port())->disk_tag,
+                                         pid.get_app_id(),
+                                         pid.get_partition_index());
+            LOG_DEBUG("concat {} of node({})", dir, ns.host_port());
+            manager.add_replica(pid, dir);
             return true;
         });
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to