patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -10,14 +10,16 @@
* See the Mulan PubL v2 for more details.
*/
#include "clog/ob_log_define.h"
#include <gtest/gtest.h>
#include "lib/net/ob_addr.h"
#include "lib/hash_func/murmur_hash.h"
namespace oceanbase {
namespace oceanbase
{
using namespace common;
namespace unittest {
int64_t cal_hash_v1(const uint64_t tenant_id, const common::ObAddr& addr, const int64_t cluster_id)
namespace unittest
{
int64_t cal_hash_v1(const uint64_t tenant_id, const common::ObAddr &addr, const int64_t cluster_id)
{
// This calculation may cause hash conflicts
int64_t ret_hash = murmurhash(&tenant_id, sizeof(tenant_id), addr.hash());
@ -25,10 +27,9 @@ int64_t cal_hash_v1(const uint64_t tenant_id, const common::ObAddr& addr, const
return ret_hash;
}
int64_t cal_hash_v2(const uint64_t tenant_id, const common::ObAddr& addr, const int64_t cluster_id)
int64_t cal_hash_v2(const uint64_t tenant_id, const common::ObAddr &addr, const int64_t cluster_id)
{
// ObAddr.hash() only generates a 32-bit value, so the algorithm of shifting cluster_id to the left by 32 bits is
// effective
// ObAddr.hash() only generates a 32-bit value, so the algorithm of shifting cluster_id to the left by 32 bits is effective
int64_t ret_hash = (addr.hash() | (cluster_id << 48));
ret_hash = murmurhash(&tenant_id, sizeof(tenant_id), ret_hash);
return ret_hash;
@ -48,8 +49,8 @@ TEST(test_cluster_id_hash_conflict, test_cluster_id_hash)
int64_t cluster_id_21 = 111;
int64_t cluster_id_22 = 112;
// EXPECT_NE(cal_hash_v1(tenant_id, addr, cluster_id_11), cal_hash_v1(tenant_id, addr, cluster_id_12)); // hash
// conflict
// EXPECT_NE(cal_hash_v1(tenant_id, addr, cluster_id_11), cal_hash_v1(tenant_id, addr, cluster_id_12)); // hash conflict
EXPECT_NE(cal_hash_v2(tenant_id, addr, cluster_id_11), cal_hash_v2(tenant_id, addr, cluster_id_12));
EXPECT_NE(cal_hash_v2(tenant_id, addr, cluster_id_21), cal_hash_v2(tenant_id, addr, cluster_id_22));
@ -63,11 +64,12 @@ TEST(test_cluster_id_hash_conflict, test_cluster_id_hash)
CLOG_LOG(INFO, "v2 ret_hash is ", "result", cal_hash_v2(tenant_id, addr, cluster_id_12));
CLOG_LOG(INFO, "v2 ret_hash is ", "result", cal_hash_v2(tenant_id, addr, cluster_id_21));
CLOG_LOG(INFO, "v2 ret_hash is ", "result", cal_hash_v2(tenant_id, addr, cluster_id_22));
}
} // namespace unittest
} // namespace oceanbase
int main(int argc, char** argv)
}
} // namespace unittest
} // namespace oceanbase
int main(int argc, char **argv)
{
OB_LOGGER.set_file_name("test_cluster_id_hash_conflict.log", true);
OB_LOGGER.set_log_level("INFO");