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 32934bdbb refactor(partition_resolver): Move get_partition_index() as 
a public accessed function (#1934)
32934bdbb is described below

commit 32934bdbb50f3646ce3983ae03dc37af25ffa045
Author: Yingchun Lai <[email protected]>
AuthorDate: Thu Mar 7 19:50:49 2024 +0800

    refactor(partition_resolver): Move get_partition_index() as a public 
accessed function (#1934)
    
    Make get_partition_index() as public accessable, then we can reuse it in
    CLI tools, for example 
https://github.com/apache/incubator-pegasus/pull/1930.
---
 src/client/partition_resolver.cpp        |  5 +++++
 src/client/partition_resolver.h          | 21 ++++++++++-----------
 src/client/partition_resolver_simple.cpp |  4 ----
 src/client/partition_resolver_simple.h   |  2 --
 4 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/src/client/partition_resolver.cpp 
b/src/client/partition_resolver.cpp
index 1b8baa7a1..993e48774 100644
--- a/src/client/partition_resolver.cpp
+++ b/src/client/partition_resolver.cpp
@@ -45,6 +45,11 @@ partition_resolver_ptr 
partition_resolver::get_resolver(const char *cluster_name
     return partition_resolver_manager::instance().find_or_create(cluster_name, 
meta_list, app_name);
 }
 
+int partition_resolver::get_partition_index(int partition_count, uint64_t 
partition_hash)
+{
+    return partition_hash % static_cast<uint64_t>(partition_count);
+}
+
 DEFINE_TASK_CODE(LPC_RPC_DELAY_CALL, TASK_PRIORITY_COMMON, THREAD_POOL_DEFAULT)
 
 static inline bool error_retry(error_code err)
diff --git a/src/client/partition_resolver.h b/src/client/partition_resolver.h
index b870b2c7a..8ffdbf5d5 100644
--- a/src/client/partition_resolver.h
+++ b/src/client/partition_resolver.h
@@ -56,6 +56,16 @@ public:
                  const std::vector<dsn::rpc_address> &meta_list,
                  const char *app_name);
 
+    /**
+     * get zero-based partition index
+     *
+     * \param partition_count number of partitions.
+     * \param partition_hash  the partition hash.
+     *
+     * \return zero-based partition index.
+     */
+    static int get_partition_index(int partition_count, uint64_t 
partition_hash);
+
     template <typename TReq, typename TCallback>
     dsn::rpc_response_task_ptr call_op(dsn::task_code code,
                                        TReq &&request,
@@ -131,17 +141,6 @@ protected:
      */
     virtual void on_access_failure(int partition_index, error_code err) = 0;
 
-    /**
-     * get zero-based partition index
-     *
-     * \param partition_count number of partitions.
-     * \param partition_hash  the partition hash.
-     *
-     * \return zero-based partition index.
-     */
-
-    virtual int get_partition_index(int partition_count, uint64_t 
partition_hash) = 0;
-
     std::string _cluster_name;
     std::string _app_name;
     rpc_address _meta_server;
diff --git a/src/client/partition_resolver_simple.cpp 
b/src/client/partition_resolver_simple.cpp
index a0fd30224..ed2ef1248 100644
--- a/src/client/partition_resolver_simple.cpp
+++ b/src/client/partition_resolver_simple.cpp
@@ -448,9 +448,5 @@ error_code partition_resolver_simple::get_address(int 
partition_index, /*out*/ r
     }
 }
 
-int partition_resolver_simple::get_partition_index(int partition_count, 
uint64_t partition_hash)
-{
-    return partition_hash % static_cast<uint64_t>(partition_count);
-}
 } // namespace replication
 } // namespace dsn
diff --git a/src/client/partition_resolver_simple.h 
b/src/client/partition_resolver_simple.h
index 2ab1fb70c..2cfb97d83 100644
--- a/src/client/partition_resolver_simple.h
+++ b/src/client/partition_resolver_simple.h
@@ -59,8 +59,6 @@ public:
 
     virtual void on_access_failure(int partition_index, error_code err) 
override;
 
-    virtual int get_partition_index(int partition_count, uint64_t 
partition_hash) override;
-
     int get_partition_count() const { return _app_partition_count; }
 
 private:


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

Reply via email to