refactor(sync): add test syncRaftIdCheck

This commit is contained in:
Minghao Li 2022-06-14 15:50:44 +08:00
parent fa25fa32e0
commit 71dad1ea78
1 changed files with 20 additions and 1 deletions

View File

@ -14,6 +14,12 @@
*/
#include "syncUtil.h"
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>
#include "syncEnv.h"
void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port);
@ -22,7 +28,20 @@ void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port);
uint64_t syncUtilAddr2U64(const char* host, uint16_t port) {
uint64_t u64;
uint32_t hostU32 = (uint32_t)taosInetAddr(host);
// assert(hostU32 != (uint32_t)-1);
if (hostU32 == (uint32_t)-1) {
struct hostent* hostEnt = gethostbyname(host);
if (hostEnt == NULL) {
sError("Get IP address error");
return -1;
}
const char* newHost = taosInetNtoa(*(struct in_addr*)(hostEnt->h_addr_list[0]));
hostU32 = (uint32_t)taosInetAddr(newHost);
if (hostU32 == (uint32_t)-1) {
sError("change %s to id, error", newHost);
}
// ASSERT(hostU32 != (uint32_t)-1);
}
u64 = (((uint64_t)hostU32) << 32) | (((uint32_t)port) << 16);
return u64;
}