TDengine/source/dnode/xnode/src/xnode.c

92 lines
3.1 KiB
C

/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libs/txnode/txnode.h"
#include "xndInt.h"
static SXnode xnodeInstance = {0};
SXnode *xndInstance() { return &xnodeInstance; }
int32_t xndOpen(const SXnodeOpt *pOption, SXnode **pXnode) {
*pXnode = &xnodeInstance;
(*pXnode)->protocol = (int8_t)pOption->proto;
(*pXnode)->dnodeId = pOption->dnodeId;
(*pXnode)->clusterId = pOption->clusterId;
(*pXnode)->ep = pOption->ep;
// if (TSDB_XNODE_OPT_PROTO == (*pXnode)->protocol) {
// // if ((code = xnodeMgmtStartXnoded((*pXnode)->dnodeId)) != 0) {
// if ((code = xnodeMgmtStartXnoded(*pXnode)) != 0) {
// xndError("failed to start xnoded since %s", tstrerror(code));
// taosMemoryFree(*pXnode);
// TAOS_RETURN(code);
// }
// } else {
// xndError("Unknown xnode proto: %hhd.", (*pXnode)->protocol);
// taosMemoryFree(*pXnode);
// TAOS_RETURN(code);
// }
xndInfo("xnode: opened & initialized by dnode");
return TSDB_CODE_SUCCESS;
}
void xndClose(SXnode *pXnode) {
xndInfo("xnode: dnode is closing xnoded");
xnodeMgmtStopXnoded();
}
int32_t mndOpenXnd(const SXnodeOpt *pOption) {
int32_t code = 0;
SXnode *pXnode = xndInstance();
pXnode->dnodeId = pOption->dnodeId;
pXnode->clusterId = pOption->clusterId;
pXnode->upLen = pOption->upLen;
pXnode->ep = pOption->ep;
memset(pXnode->userPass, 0, XNODE_USER_PASS_LEN);
memcpy(pXnode->userPass, pOption->userPass, pOption->upLen);
memset(pXnode->token, 0, sizeof(pXnode->token));
memcpy(pXnode->token, pOption->token, TSDB_TOKEN_LEN);
if ((code = xnodeMgmtStartXnoded(pXnode)) != 0) {
xndError("failed to start xnoded since %s", tstrerror(code));
TAOS_RETURN(code);
}
return code;
}
void mndCloseXnd() { xnodeMgmtStopXnoded(); }
void getXnodedPipeName(char *pipeName, int32_t size) {
int32_t len = strlen(tsDataDir);
if (len > 0 && (tsDataDir[len - 1] != '/' && tsDataDir[len - 1] != '\\')) {
#ifdef _WIN32
snprintf(pipeName, size, "%s\\.%s.%x", tsDataDir, XNODED_MGMT_LISTEN_PIPE_NAME_PREFIX, MurmurHash3_32(tsDataDir, strlen(tsDataDir)));
#else
snprintf(pipeName, size, "%s/%s", tsDataDir, XNODED_MGMT_LISTEN_PIPE_NAME_PREFIX);
#endif
} else {
#ifdef _WIN32
snprintf(pipeName, size, "%s.%s.%x", tsDataDir, XNODED_MGMT_LISTEN_PIPE_NAME_PREFIX, MurmurHash3_32(tsDataDir, strlen(tsDataDir)));
#else
snprintf(pipeName, size, "%s%s", tsDataDir, XNODED_MGMT_LISTEN_PIPE_NAME_PREFIX);
#endif
}
xndDebug("xnode get unix socket pipe path:%s", pipeName);
}