You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by la...@apache.org on 2023/05/18 06:57:48 UTC

[incubator-pegasus] branch master updated: refactor: remove some useless code (#1480)

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 ccd01c593 refactor: remove some useless code (#1480)
ccd01c593 is described below

commit ccd01c593728a6159de9f6fcbb398a077f2c387f
Author: Yingchun Lai <la...@apache.org>
AuthorDate: Thu May 18 14:57:41 2023 +0800

    refactor: remove some useless code (#1480)
---
 src/common/fs_manager.cpp                  |   1 +
 src/common/test/fs_manager_test.cpp        |   1 +
 src/meta/test/balancer_validator.cpp       | 100 -----------------------------
 src/replica/replica.h                      |   9 +++
 src/replica/replica_init.cpp               |  11 +---
 src/replica/replica_test_utils.cpp         |  69 --------------------
 src/replica/replica_test_utils.h           |  53 ---------------
 src/server/test/pegasus_server_test_base.h |  17 +++--
 src/server/test/rocksdb_wrapper_test.cpp   |  14 ++--
 9 files changed, 30 insertions(+), 245 deletions(-)

diff --git a/src/common/fs_manager.cpp b/src/common/fs_manager.cpp
index 2ba683da4..35a801053 100644
--- a/src/common/fs_manager.cpp
+++ b/src/common/fs_manager.cpp
@@ -47,6 +47,7 @@
 #include "utils/fail_point.h"
 #include "utils/filesystem.h"
 #include "utils/fmt_logging.h"
+#include "utils/ports.h"
 #include "utils/string_view.h"
 
 namespace dsn {
diff --git a/src/common/test/fs_manager_test.cpp b/src/common/test/fs_manager_test.cpp
index d6bbcfa31..2d1f982f8 100644
--- a/src/common/test/fs_manager_test.cpp
+++ b/src/common/test/fs_manager_test.cpp
@@ -21,6 +21,7 @@
 // IWYU pragma: no_include <gtest/gtest-test-part.h>
 #include <gtest/gtest.h>
 #include <memory>
+#include <string>
 
 #include "common/fs_manager.h"
 #include "metadata_types.h"
diff --git a/src/meta/test/balancer_validator.cpp b/src/meta/test/balancer_validator.cpp
index d0e681ed8..8e1d45654 100644
--- a/src/meta/test/balancer_validator.cpp
+++ b/src/meta/test/balancer_validator.cpp
@@ -113,106 +113,6 @@ static void check_cure(app_mapper &apps, node_mapper &nodes, ::dsn::partition_co
     ns->put_partition(pc.pid, true);
 }
 
-// static void verbose_nodes(const node_mapper& nodes)
-//{
-//    std::cout << "------------" << std::endl;
-//    for (const auto& n: nodes)
-//    {
-//        const node_state& ns = n.second;
-//        printf("node: %s\ntotal_primaries: %d, total_secondaries: %d\n", n.first.to_string(),
-//        ns.primary_count(), ns.partition_count());
-//        for (int i=1; i<=2; ++i)
-//        {
-//            printf("app %d primaries: %d, app %d partitions: %d\n", i, ns.primary_count(i), i,
-//            ns.partition_count(i));
-//        }
-//    }
-//}
-//
-// static void verbose_app_node(const node_mapper& nodes)
-//{
-//    printf("Total_Pri: ");
-//    for (const auto& n: nodes)
-//    {
-//        const node_state& ns = n.second;
-//        printf("%*d", 3, ns.primary_count());
-//    }
-//    printf("\nTotal_Sec: ");
-//    for (const auto& n: nodes)
-//    {
-//        const node_state& ns = n.second;
-//        printf("%*d", 3, ns.secondary_count());
-//    }
-//    printf("\nApp01_Pri: ");
-//    for (const auto& n: nodes)
-//    {
-//        const node_state& ns = n.second;
-//        printf("%*d", 3, ns.primary_count(1));
-//    }
-//    printf("\nApp01_Sec: ");
-//    for (const auto& n: nodes)
-//    {
-//        const node_state& ns = n.second;
-//        printf("%*d", 3, ns.secondary_count(1));
-//    }
-//    printf("\nApp02_Pri: ");
-//    for (const auto& n: nodes)
-//    {
-//        const node_state& ns = n.second;
-//        printf("%*d", 3, ns.primary_count(2));
-//    }
-//    printf("\nApp02_Sec: ");
-//    for (const auto& n: nodes)
-//    {
-//        const node_state& ns = n.second;
-//        printf("%*d", 3, ns.secondary_count(2));
-//    }
-//    printf("\n");
-//}
-
-// static void verbose_app(const std::shared_ptr<app_state>& app)
-//{
-//    std::cout << app->app_name << " " << app->app_id << " " << app->partition_count << std::endl;
-//    for (int i=0; i<app->partition_count; ++i)
-//    {
-//        const partition_configuration& pc = app->partitions[i];
-//        std::cout << pc.primary.to_string();
-//        for (int j=0; j<pc.secondaries.size(); ++j)
-//        {
-//            std::cout << " " << pc.secondaries[j].to_string();
-//        }
-//        std::cout << std::endl;
-//    }
-//}
-// static void print_node_fs_manager(const app_mapper &apps,
-//                                  const node_mapper &nodes,
-//                                  const nodes_fs_manager &manager)
-//{
-//    int apps_count = apps.size();
-//    for (const auto &kv : nodes) {
-//        const node_state &ns = kv.second;
-//        printf("%s: %d primaries, %d partitions\n",
-//               ns.addr().to_string(),
-//               ns.primary_count(),
-//               ns.partition_count());
-//        printf("%8s", "tag");
-//        for (int i = 1; i <= apps_count; ++i) {
-//            std::string app = std::string("app") + std::to_string(i);
-//            printf("%8s", app.c_str());
-//        }
-//        printf("\n");
-//        const fs_manager &m = manager.find(ns.addr())->second;
-//        m.for_each_dir_node([apps_count](const dir_node &dn) {
-//            printf("%8s", dn.tag.c_str());
-//            for (int i = 1; i <= apps_count; ++i) {
-//                printf("%8u", dn.replicas_count(i));
-//            }
-//            printf("%8u\n", dn.replicas_count());
-//            return true;
-//        });
-//    }
-//}
-
 void meta_service_test_app::balancer_validator()
 {
     std::vector<dsn::rpc_address> node_list;
diff --git a/src/replica/replica.h b/src/replica/replica.h
index 2e8108371..612830c70 100644
--- a/src/replica/replica.h
+++ b/src/replica/replica.h
@@ -76,6 +76,13 @@
 #include "utils/throttling_controller.h"
 #include "utils/uniq_timestamp_us.h"
 
+namespace pegasus {
+namespace server {
+class pegasus_server_test_base;
+class rocksdb_wrapper_test;
+} // namespace server
+} // namespace pegasus
+
 namespace dsn {
 class gpid;
 class perf_counter;
@@ -550,6 +557,8 @@ private:
     friend class replica_disk_migrate_test;
     friend class open_replica_test;
     friend class replica_follower;
+    friend class ::pegasus::server::pegasus_server_test_base;
+    friend class ::pegasus::server::rocksdb_wrapper_test;
     FRIEND_TEST(replica_test, test_auto_trash);
 
     // replica configuration, updated by update_local_configuration ONLY
diff --git a/src/replica/replica_init.cpp b/src/replica/replica_init.cpp
index a28715647..01bb1a95c 100644
--- a/src/replica/replica_init.cpp
+++ b/src/replica/replica_init.cpp
@@ -68,16 +68,9 @@ DSN_DEFINE_int32(replication,
 
 error_code replica::initialize_on_new()
 {
-    // if (dsn::utils::filesystem::directory_exists(_dir) &&
-    //    !dsn::utils::filesystem::remove_path(_dir))
-    //{
-    //    LOG_ERROR("cannot allocate new replica @ {}, as the dir is already exists", _dir);
-    //    return ERR_PATH_ALREADY_EXIST;
-    //}
-    //
     // TODO: check if _dir contain other file or directory except for
-    // "restore.policy_name.backup_id"
-    // which is applied to restore from cold backup
+    // "restore.policy_name.backup_id" which is applied to restore from
+    // cold backup.
     if (!dsn::utils::filesystem::directory_exists(_dir) &&
         !dsn::utils::filesystem::create_directory(_dir)) {
         LOG_ERROR("cannot allocate new replica @ {}, because create dir failed", _dir);
diff --git a/src/replica/replica_test_utils.cpp b/src/replica/replica_test_utils.cpp
deleted file mode 100644
index ce60026c1..000000000
--- a/src/replica/replica_test_utils.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2015 Microsoft Corporation
- *
- * -=- Robust Distributed System Nucleus (rDSN) -=-
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "replica/replica_test_utils.h"
-
-#include "common/gpid.h"
-#include "replica.h"
-#include "replica_stub.h"
-
-namespace dsn {
-class app_info;
-
-namespace replication {
-
-class mock_replica : public replica
-{
-public:
-    mock_replica(replica_stub *stub,
-                 const gpid &gpid,
-                 const app_info &app,
-                 const char *dir,
-                 bool restore_if_necessary,
-                 bool is_duplication_follower)
-        : replica(stub, gpid, app, dir, restore_if_necessary, is_duplication_follower)
-    {
-    }
-};
-
-replica *create_test_replica(replica_stub *stub,
-                             gpid gpid,
-                             const app_info &app,
-                             const char *dir,
-                             bool restore_if_necessary,
-                             bool is_duplication_follower)
-{
-    return new mock_replica(stub, gpid, app, dir, restore_if_necessary, is_duplication_follower);
-}
-
-replica_stub *create_test_replica_stub() { return new replica_stub(); }
-
-void destroy_replica(replica *r) { delete r; }
-
-void destroy_replica_stub(replica_stub *rs) { delete rs; }
-
-} // namespace replication
-} // namespace dsn
diff --git a/src/replica/replica_test_utils.h b/src/replica/replica_test_utils.h
deleted file mode 100644
index e09d33873..000000000
--- a/src/replica/replica_test_utils.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2015 Microsoft Corporation
- *
- * -=- Robust Distributed System Nucleus (rDSN) -=-
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/// This file contains utilities for upper level applications (pegasus) which
-/// needs the hidden abstraction of rDSN in order to make unit test.
-
-namespace dsn {
-class app_info;
-class gpid;
-
-namespace replication {
-
-class replica;
-class replica_stub;
-
-extern replica *create_test_replica(replica_stub *stub,
-                                    gpid gpid,
-                                    const app_info &app,
-                                    const char *dir,
-                                    bool restore_if_necessary,
-                                    bool is_duplication_follower);
-
-extern replica_stub *create_test_replica_stub();
-
-extern void destroy_replica(replica *r);
-
-extern void destroy_replica_stub(replica_stub *rs);
-
-} // namespace replication
-} // namespace dsn
diff --git a/src/server/test/pegasus_server_test_base.h b/src/server/test/pegasus_server_test_base.h
index 92fcec925..5ebe2496e 100644
--- a/src/server/test/pegasus_server_test_base.h
+++ b/src/server/test/pegasus_server_test_base.h
@@ -23,7 +23,7 @@
 
 #include <gtest/gtest.h>
 #include <gmock/gmock.h>
-#include "replica/replica_test_utils.h"
+#include "replica/replica_stub.h"
 #include "utils/filesystem.h"
 
 namespace pegasus {
@@ -45,15 +45,14 @@ public:
     {
         // Remove rdb to prevent rocksdb recovery from last test.
         dsn::utils::filesystem::remove_path("./data/rdb");
-        _replica_stub = dsn::replication::create_test_replica_stub();
+        _replica_stub = new dsn::replication::replica_stub();
 
         _gpid = dsn::gpid(100, 1);
         dsn::app_info app_info;
         app_info.app_type = "pegasus";
 
-        _replica = dsn::replication::create_test_replica(
-            _replica_stub, _gpid, app_info, "./", false, false);
-
+        _replica =
+            new dsn::replication::replica(_replica_stub, _gpid, app_info, "./", false, false);
         _server = std::make_unique<mock_pegasus_server_impl>(_replica);
     }
 
@@ -77,14 +76,14 @@ public:
         // do not clear state
         _server->stop(false);
 
-        dsn::replication::destroy_replica_stub(_replica_stub);
-        dsn::replication::destroy_replica(_replica);
+        delete _replica_stub;
+        delete _replica;
     }
 
 protected:
     std::unique_ptr<mock_pegasus_server_impl> _server;
-    dsn::replication::replica *_replica;
-    dsn::replication::replica_stub *_replica_stub;
+    dsn::replication::replica *_replica = nullptr;
+    dsn::replication::replica_stub *_replica_stub = nullptr;
     dsn::gpid _gpid;
 };
 
diff --git a/src/server/test/rocksdb_wrapper_test.cpp b/src/server/test/rocksdb_wrapper_test.cpp
index b4bf0b0ff..f0ee6a8e4 100644
--- a/src/server/test/rocksdb_wrapper_test.cpp
+++ b/src/server/test/rocksdb_wrapper_test.cpp
@@ -30,12 +30,13 @@
 #include "pegasus_server_test_base.h"
 #include "pegasus_utils.h"
 #include "pegasus_value_schema.h"
-#include "replica/replica_test_utils.h"
+#include "replica/replica.h"
 #include "server/pegasus_server_write.h"
 #include "server/pegasus_write_service.h"
 #include "server/pegasus_write_service_impl.h"
 #include "server/rocksdb_wrapper.h"
 #include "utils/blob.h"
+#include "utils/error_code.h"
 #include "utils/string_view.h"
 
 namespace pegasus {
@@ -48,9 +49,11 @@ protected:
     dsn::blob _raw_key;
 
 public:
+    rocksdb_wrapper_test() = default;
+
     void SetUp() override
     {
-        start();
+        ASSERT_EQ(::dsn::ERR_OK, start());
         _server_write = std::make_unique<pegasus_server_write>(_server.get());
         _rocksdb_wrapper = _server_write->_write_svc->_impl->_rocksdb_wrapper.get();
 
@@ -74,13 +77,14 @@ public:
     void set_app_duplicating()
     {
         _server->stop(false);
-        dsn::replication::destroy_replica(_replica);
+        delete _replica;
 
         dsn::app_info app_info;
         app_info.app_type = "pegasus";
         app_info.duplicating = true;
-        _replica = dsn::replication::create_test_replica(
-            _replica_stub, _gpid, app_info, "./", false, false);
+
+        _replica =
+            new dsn::replication::replica(_replica_stub, _gpid, app_info, "./", false, false);
         _server = std::make_unique<mock_pegasus_server_impl>(_replica);
 
         SetUp();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org