Skip to content

Commit

Permalink
Merge pull request #23919 from taosdata/fix/xsren/TD-27561/fqdnFailedMsg
Browse files Browse the repository at this point in the history
fix error msg if failed get ip from fqdn
  • Loading branch information
dapan1121 committed Dec 4, 2023
2 parents 674a995 + 0fe26f1 commit aa4efa0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/common/src/tglobal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
static int32_t taosCheckGlobalCfg() {
uint32_t ipv4 = taosGetIpv4FromFqdn(tsLocalFqdn);
if (ipv4 == 0xffffffff) {
terrno = TAOS_SYSTEM_ERROR(errno);
terrno = TSDB_CODE_RPC_FQDN_ERROR;
uError("failed to get ip from fqdn:%s since %s, dnode can not be initialized", tsLocalFqdn, terrstr());
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion source/libs/transport/src/transCli.c
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn)
if (v == NULL) {
addr = taosGetIpv4FromFqdn(fqdn);
if (addr == 0xffffffff) {
terrno = TAOS_SYSTEM_ERROR(errno);
terrno = TSDB_CODE_RPC_FQDN_ERROR;
tError("failed to get ip from fqdn:%s since %s", fqdn, terrstr());
return addr;
}
Expand Down
29 changes: 29 additions & 0 deletions source/os/test/osTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,35 @@

#ifdef WINDOWS
#include <windows.h>
#else

#include <arpa/inet.h>

TEST(osTest, osFQDNSuccess) {
char fqdn[1024];
char ipString[INET_ADDRSTRLEN];
int code = taosGetFqdn(fqdn);
uint32_t ipv4 = taosGetIpv4FromFqdn(fqdn);
ASSERT_NE(ipv4, 0xffffffff);

struct in_addr addr;
addr.s_addr = htonl(ipv4);
snprintf(ipString, INET_ADDRSTRLEN, "%u.%u.%u.%u", (unsigned int)(addr.s_addr >> 24) & 0xFF,
(unsigned int)(addr.s_addr >> 16) & 0xFF, (unsigned int)(addr.s_addr >> 8) & 0xFF,
(unsigned int)(addr.s_addr) & 0xFF);
printf("fqdn:%s ip:%s\n", fqdn, ipString);
}

TEST(osTest, osFQDNFailed) {
char fqdn[1024] = "fqdn_test_not_found";
char ipString[24];
uint32_t ipv4 = taosGetIpv4FromFqdn(fqdn);
ASSERT_EQ(ipv4, 0xffffffff);

terrno = TSDB_CODE_RPC_FQDN_ERROR;
printf("fqdn:%s transfer to ip failed!\n", fqdn);
}

#endif // WINDOWS

TEST(osTest, osSystem) {
Expand Down

0 comments on commit aa4efa0

Please sign in to comment.