2021-11-07 07:58:32 +00:00
|
|
|
/*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-09-20 01:54:28 +00:00
|
|
|
#include "sync.h"
|
2025-07-14 08:33:53 +00:00
|
|
|
#include "tss.h"
|
2025-01-16 00:43:47 +00:00
|
|
|
#include "tq.h"
|
2023-09-20 01:54:28 +00:00
|
|
|
#include "tsdb.h"
|
2022-04-26 11:04:26 +00:00
|
|
|
#include "vnd.h"
|
2021-11-07 07:58:32 +00:00
|
|
|
|
2024-09-10 02:05:38 +00:00
|
|
|
void vnodeGetPrimaryDir(const char *relPath, int32_t diskPrimary, STfs *pTfs, char *buf, size_t bufLen) {
|
2023-07-12 04:49:32 +00:00
|
|
|
if (pTfs) {
|
2023-07-14 10:24:53 +00:00
|
|
|
SDiskID diskId = {0};
|
|
|
|
|
diskId.id = diskPrimary;
|
|
|
|
|
snprintf(buf, bufLen - 1, "%s%s%s", tfsGetDiskPath(pTfs, diskId), TD_DIRSEP, relPath);
|
2023-07-12 04:49:32 +00:00
|
|
|
} else {
|
|
|
|
|
snprintf(buf, bufLen - 1, "%s", relPath);
|
|
|
|
|
}
|
|
|
|
|
buf[bufLen - 1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-12 07:39:29 +00:00
|
|
|
void vnodeGetPrimaryPath(SVnode *pVnode, bool mount, char *buf, size_t bufLen) {
|
|
|
|
|
if (pVnode->mounted) {
|
|
|
|
|
if (mount) { // mount path
|
|
|
|
|
SDiskID diskId = {0};
|
|
|
|
|
diskId.id = pVnode->diskPrimary;
|
|
|
|
|
snprintf(buf, bufLen - 1, "%s%svnode%svnode%d", tfsGetDiskPath(pVnode->pMountTfs, diskId), TD_DIRSEP, TD_DIRSEP,
|
|
|
|
|
pVnode->config.mountVgId);
|
|
|
|
|
} else { // host path
|
|
|
|
|
vnodeGetPrimaryDir(pVnode->path, 0, pVnode->pTfs, buf, bufLen);
|
|
|
|
|
}
|
|
|
|
|
buf[bufLen - 1] = '\0';
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, buf, bufLen);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 02:04:00 +00:00
|
|
|
static int32_t vnodeMkDir(STfs *pTfs, const char *path) {
|
|
|
|
|
if (pTfs) {
|
|
|
|
|
return tfsMkdirRecur(pTfs, path);
|
|
|
|
|
} else {
|
|
|
|
|
return taosMkDir(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 10:24:53 +00:00
|
|
|
int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, int32_t diskPrimary, STfs *pTfs) {
|
2024-08-14 09:50:20 +00:00
|
|
|
int32_t code = 0;
|
2022-04-15 05:47:57 +00:00
|
|
|
SVnodeInfo info = {0};
|
2022-10-20 08:47:03 +00:00
|
|
|
char dir[TSDB_FILENAME_LEN] = {0};
|
2022-04-14 12:36:35 +00:00
|
|
|
|
|
|
|
|
// check config
|
2024-08-14 09:50:20 +00:00
|
|
|
if ((code = vnodeCheckCfg(pCfg)) < 0) {
|
|
|
|
|
vError("vgId:%d, failed to create vnode since:%s", pCfg->vgId, tstrerror(code));
|
|
|
|
|
return code;
|
2022-04-14 12:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create vnode env
|
2023-07-18 02:04:00 +00:00
|
|
|
if (vnodeMkDir(pTfs, path)) {
|
2025-03-14 05:32:13 +00:00
|
|
|
vError("vgId:%d, failed to prepare vnode dir since %s, path: %s", pCfg->vgId, strerror(ERRNO), path);
|
|
|
|
|
return TAOS_SYSTEM_ERROR(ERRNO);
|
2022-04-15 05:47:57 +00:00
|
|
|
}
|
2024-09-10 02:05:38 +00:00
|
|
|
vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN);
|
2022-04-15 05:47:57 +00:00
|
|
|
|
2022-10-10 10:17:58 +00:00
|
|
|
if (pCfg) {
|
|
|
|
|
info.config = *pCfg;
|
|
|
|
|
} else {
|
|
|
|
|
info.config = vnodeCfgDefault;
|
|
|
|
|
}
|
2022-04-20 11:58:36 +00:00
|
|
|
info.state.committed = -1;
|
|
|
|
|
info.state.applied = -1;
|
2022-06-23 03:08:19 +00:00
|
|
|
info.state.commitID = 0;
|
2022-04-15 05:47:57 +00:00
|
|
|
|
2023-10-18 06:40:00 +00:00
|
|
|
SVnodeInfo oldInfo = {0};
|
|
|
|
|
oldInfo.config = vnodeCfgDefault;
|
|
|
|
|
if (vnodeLoadInfo(dir, &oldInfo) == 0) {
|
2024-12-09 02:42:24 +00:00
|
|
|
code = (oldInfo.config.dbId == info.config.dbId) ? 0 : TSDB_CODE_VND_ALREADY_EXIST_BUT_NOT_MATCH;
|
|
|
|
|
if (code == 0) {
|
|
|
|
|
vWarn("vgId:%d, vnode config info already exists at %s.", oldInfo.config.vgId, dir);
|
|
|
|
|
} else {
|
|
|
|
|
vError("vgId:%d, vnode config info already exists at %s. oldDbId:%" PRId64 "(%s) at cluster:%" PRId64
|
|
|
|
|
", newDbId:%" PRId64 "(%s) at cluser:%" PRId64 ", code:%s",
|
|
|
|
|
oldInfo.config.vgId, dir, oldInfo.config.dbId, oldInfo.config.dbname,
|
|
|
|
|
oldInfo.config.syncCfg.nodeInfo[oldInfo.config.syncCfg.myIndex].clusterId, info.config.dbId,
|
|
|
|
|
info.config.dbname, info.config.syncCfg.nodeInfo[info.config.syncCfg.myIndex].clusterId, tstrerror(code));
|
|
|
|
|
}
|
|
|
|
|
return code;
|
2023-10-18 06:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-22 06:29:14 +00:00
|
|
|
vInfo("vgId:%d, save config while create", info.config.vgId);
|
2024-08-14 09:50:20 +00:00
|
|
|
if ((code = vnodeSaveInfo(dir, &info)) < 0 || (code = vnodeCommitInfo(dir)) < 0) {
|
|
|
|
|
vError("vgId:%d, failed to save vnode config since %s", pCfg ? pCfg->vgId : 0, tstrerror(code));
|
|
|
|
|
return code;
|
2022-04-14 12:36:35 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-10 10:17:58 +00:00
|
|
|
vInfo("vgId:%d, vnode is created", info.config.vgId);
|
2022-10-20 08:47:03 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 07:16:58 +00:00
|
|
|
bool vnodeShouldRemoveWal(SVnode *pVnode) { return pVnode->config.walCfg.clearFiles == 1; }
|
|
|
|
|
|
2023-07-14 10:24:53 +00:00
|
|
|
int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t diskPrimary, STfs *pTfs) {
|
2022-10-20 08:47:03 +00:00
|
|
|
SVnodeInfo info = {0};
|
|
|
|
|
char dir[TSDB_FILENAME_LEN] = {0};
|
|
|
|
|
int32_t ret = 0;
|
|
|
|
|
|
2024-09-10 02:05:38 +00:00
|
|
|
vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN);
|
2022-04-15 06:27:04 +00:00
|
|
|
|
2022-10-20 08:47:03 +00:00
|
|
|
ret = vnodeLoadInfo(dir, &info);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
vError("vgId:%d, failed to read vnode config from %s since %s", pReq->vgId, path, tstrerror(terrno));
|
2024-08-14 09:50:20 +00:00
|
|
|
return ret;
|
2022-10-20 08:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SSyncCfg *pCfg = &info.config.syncCfg;
|
2023-07-03 10:39:47 +00:00
|
|
|
|
2023-04-18 11:03:45 +00:00
|
|
|
pCfg->replicaNum = 0;
|
|
|
|
|
pCfg->totalReplicaNum = 0;
|
2022-10-20 08:47:03 +00:00
|
|
|
memset(&pCfg->nodeInfo, 0, sizeof(pCfg->nodeInfo));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < pReq->replica; ++i) {
|
|
|
|
|
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
2022-12-30 09:01:50 +00:00
|
|
|
pNode->nodeId = pReq->replicas[i].id;
|
2022-10-20 08:47:03 +00:00
|
|
|
pNode->nodePort = pReq->replicas[i].port;
|
|
|
|
|
tstrncpy(pNode->nodeFqdn, pReq->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
2023-04-18 11:03:45 +00:00
|
|
|
pNode->nodeRole = TAOS_SYNC_ROLE_VOTER;
|
2024-09-24 02:06:30 +00:00
|
|
|
bool ret = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
2023-01-03 11:47:04 +00:00
|
|
|
vInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId);
|
2023-04-18 11:03:45 +00:00
|
|
|
pCfg->replicaNum++;
|
2022-10-20 08:47:03 +00:00
|
|
|
}
|
2023-08-18 08:38:26 +00:00
|
|
|
if (pReq->selfIndex != -1) {
|
2023-04-18 11:03:45 +00:00
|
|
|
pCfg->myIndex = pReq->selfIndex;
|
|
|
|
|
}
|
|
|
|
|
for (int i = pCfg->replicaNum; i < pReq->replica + pReq->learnerReplica; ++i) {
|
|
|
|
|
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
|
|
|
|
pNode->nodeId = pReq->learnerReplicas[pCfg->totalReplicaNum].id;
|
|
|
|
|
pNode->nodePort = pReq->learnerReplicas[pCfg->totalReplicaNum].port;
|
|
|
|
|
pNode->nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
|
|
|
|
tstrncpy(pNode->nodeFqdn, pReq->learnerReplicas[pCfg->totalReplicaNum].fqdn, sizeof(pNode->nodeFqdn));
|
2024-09-24 02:06:30 +00:00
|
|
|
bool ret = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
2023-04-18 11:03:45 +00:00
|
|
|
vInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId);
|
|
|
|
|
pCfg->totalReplicaNum++;
|
|
|
|
|
}
|
|
|
|
|
pCfg->totalReplicaNum += pReq->replica;
|
2023-08-18 08:38:26 +00:00
|
|
|
if (pReq->learnerSelfIndex != -1) {
|
2023-04-18 11:03:45 +00:00
|
|
|
pCfg->myIndex = pReq->replica + pReq->learnerSelfIndex;
|
|
|
|
|
}
|
2023-07-21 02:31:53 +00:00
|
|
|
pCfg->changeVersion = pReq->changeVersion;
|
2023-04-18 11:03:45 +00:00
|
|
|
|
2024-06-12 07:16:58 +00:00
|
|
|
if (info.config.walCfg.clearFiles) {
|
|
|
|
|
info.config.walCfg.clearFiles = 0;
|
|
|
|
|
|
|
|
|
|
vInfo("vgId:%d, reset wal clearFiles", pReq->vgId);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 10:01:31 +00:00
|
|
|
vInfo("vgId:%d, save config while alter, replicas:%d totalReplicas:%d selfIndex:%d changeVersion:%d", pReq->vgId,
|
|
|
|
|
pCfg->replicaNum, pCfg->totalReplicaNum, pCfg->myIndex, pCfg->changeVersion);
|
2022-10-20 08:47:03 +00:00
|
|
|
|
2022-10-24 03:57:26 +00:00
|
|
|
info.config.syncCfg = *pCfg;
|
2022-10-20 08:47:03 +00:00
|
|
|
ret = vnodeSaveInfo(dir, &info);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
vError("vgId:%d, failed to save vnode config since %s", pReq->vgId, tstrerror(terrno));
|
2024-08-14 09:50:20 +00:00
|
|
|
return ret;
|
2022-10-20 08:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-10 08:24:29 +00:00
|
|
|
ret = vnodeCommitInfo(dir);
|
2022-10-24 03:57:26 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
|
vError("vgId:%d, failed to commit vnode config since %s", pReq->vgId, tstrerror(terrno));
|
2024-08-14 09:50:20 +00:00
|
|
|
return ret;
|
2022-10-24 03:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-20 08:47:03 +00:00
|
|
|
vInfo("vgId:%d, vnode config is saved", info.config.vgId);
|
2022-04-14 12:36:35 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-14 13:38:25 +00:00
|
|
|
static int32_t vnodeVgroupIdLen(int32_t vgId) {
|
|
|
|
|
char tmp[TSDB_FILENAME_LEN];
|
2024-12-13 12:59:39 +00:00
|
|
|
(void)tsnprintf(tmp, TSDB_FILENAME_LEN, "%d", vgId);
|
2023-06-14 13:38:25 +00:00
|
|
|
return strlen(tmp);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 10:24:53 +00:00
|
|
|
int32_t vnodeRenameVgroupId(const char *srcPath, const char *dstPath, int32_t srcVgId, int32_t dstVgId,
|
|
|
|
|
int32_t diskPrimary, STfs *pTfs) {
|
2023-06-19 07:48:32 +00:00
|
|
|
int32_t ret = 0;
|
2023-01-31 08:28:28 +00:00
|
|
|
|
|
|
|
|
char oldRname[TSDB_FILENAME_LEN] = {0};
|
|
|
|
|
char newRname[TSDB_FILENAME_LEN] = {0};
|
|
|
|
|
char tsdbPath[TSDB_FILENAME_LEN] = {0};
|
|
|
|
|
char tsdbFilePrefix[TSDB_FILENAME_LEN] = {0};
|
2023-06-19 07:48:32 +00:00
|
|
|
snprintf(tsdbPath, TSDB_FILENAME_LEN, "%s%stsdb", srcPath, TD_DIRSEP);
|
2023-01-31 08:28:28 +00:00
|
|
|
snprintf(tsdbFilePrefix, TSDB_FILENAME_LEN, "tsdb%sv", TD_DIRSEP);
|
2023-07-04 07:36:42 +00:00
|
|
|
int32_t prefixLen = strlen(tsdbFilePrefix);
|
2023-01-31 08:28:28 +00:00
|
|
|
|
2024-07-21 03:43:39 +00:00
|
|
|
STfsDir *tsdbDir = NULL;
|
2024-09-24 02:06:30 +00:00
|
|
|
int32_t tret = tfsOpendir(pTfs, tsdbPath, &tsdbDir);
|
|
|
|
|
if (tsdbDir == NULL) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2023-01-31 08:28:28 +00:00
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
const STfsFile *tsdbFile = tfsReaddir(tsdbDir);
|
|
|
|
|
if (tsdbFile == NULL) break;
|
2023-02-22 06:29:14 +00:00
|
|
|
if (tsdbFile->rname[0] == '\0') continue;
|
2023-01-31 08:28:28 +00:00
|
|
|
tstrncpy(oldRname, tsdbFile->rname, TSDB_FILENAME_LEN);
|
|
|
|
|
|
|
|
|
|
char *tsdbFilePrefixPos = strstr(oldRname, tsdbFilePrefix);
|
|
|
|
|
if (tsdbFilePrefixPos == NULL) continue;
|
|
|
|
|
|
2024-12-13 07:03:01 +00:00
|
|
|
int32_t tsdbFileVgId = 0;
|
2024-12-04 05:35:11 +00:00
|
|
|
ret = taosStr2int32(tsdbFilePrefixPos + prefixLen, &tsdbFileVgId);
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
vError("vgId:%d, failed to get tsdb file vgid since %s", dstVgId, tstrerror(ret));
|
|
|
|
|
tfsClosedir(tsdbDir);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 08:28:28 +00:00
|
|
|
if (tsdbFileVgId == srcVgId) {
|
2023-07-04 07:36:42 +00:00
|
|
|
char *tsdbFileSurfixPos = tsdbFilePrefixPos + prefixLen + vnodeVgroupIdLen(srcVgId);
|
2023-01-31 08:28:28 +00:00
|
|
|
|
2023-07-04 07:36:42 +00:00
|
|
|
tsdbFilePrefixPos[prefixLen] = 0;
|
2023-01-31 08:28:28 +00:00
|
|
|
snprintf(newRname, TSDB_FILENAME_LEN, "%s%d%s", oldRname, dstVgId, tsdbFileSurfixPos);
|
|
|
|
|
vInfo("vgId:%d, rename file from %s to %s", dstVgId, tsdbFile->rname, newRname);
|
|
|
|
|
|
2023-07-18 05:58:43 +00:00
|
|
|
ret = tfsRename(pTfs, diskPrimary, tsdbFile->rname, newRname);
|
2023-01-31 08:28:28 +00:00
|
|
|
if (ret != 0) {
|
2023-06-19 07:48:32 +00:00
|
|
|
vError("vgId:%d, failed to rename file from %s to %s since %s", dstVgId, tsdbFile->rname, newRname, terrstr());
|
2023-01-31 08:28:28 +00:00
|
|
|
tfsClosedir(tsdbDir);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tfsClosedir(tsdbDir);
|
2023-06-19 07:48:32 +00:00
|
|
|
|
|
|
|
|
vInfo("vgId:%d, rename dir from %s to %s", dstVgId, srcPath, dstPath);
|
2023-07-18 05:58:43 +00:00
|
|
|
ret = tfsRename(pTfs, diskPrimary, srcPath, dstPath);
|
2023-06-19 07:48:32 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
|
vError("vgId:%d, failed to rename dir from %s to %s since %s", dstVgId, srcPath, dstPath, terrstr());
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
2023-01-31 08:28:28 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-14 10:24:53 +00:00
|
|
|
int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnodeHashRangeReq *pReq,
|
|
|
|
|
int32_t diskPrimary, STfs *pTfs) {
|
2023-01-30 09:46:42 +00:00
|
|
|
SVnodeInfo info = {0};
|
|
|
|
|
char dir[TSDB_FILENAME_LEN] = {0};
|
|
|
|
|
int32_t ret = 0;
|
|
|
|
|
|
2024-09-10 02:05:38 +00:00
|
|
|
vnodeGetPrimaryDir(srcPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN);
|
2023-01-31 08:40:53 +00:00
|
|
|
|
2023-01-30 09:46:42 +00:00
|
|
|
ret = vnodeLoadInfo(dir, &info);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
vError("vgId:%d, failed to read vnode config from %s since %s", pReq->srcVgId, srcPath, tstrerror(terrno));
|
2024-08-14 09:50:20 +00:00
|
|
|
return ret;
|
2023-01-30 09:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-03 06:40:12 +00:00
|
|
|
vInfo("vgId:%d, alter hashrange from [%u, %u] to [%u, %u]", pReq->srcVgId, info.config.hashBegin, info.config.hashEnd,
|
|
|
|
|
pReq->hashBegin, pReq->hashEnd);
|
2023-01-30 09:46:42 +00:00
|
|
|
info.config.vgId = pReq->dstVgId;
|
|
|
|
|
info.config.hashBegin = pReq->hashBegin;
|
|
|
|
|
info.config.hashEnd = pReq->hashEnd;
|
2023-05-04 05:51:48 +00:00
|
|
|
info.config.hashChange = true;
|
2023-01-30 09:46:42 +00:00
|
|
|
info.config.walCfg.vgId = pReq->dstVgId;
|
2023-07-21 02:31:53 +00:00
|
|
|
info.config.syncCfg.changeVersion = pReq->changeVersion;
|
2023-01-30 09:46:42 +00:00
|
|
|
|
|
|
|
|
SSyncCfg *pCfg = &info.config.syncCfg;
|
|
|
|
|
pCfg->myIndex = 0;
|
|
|
|
|
pCfg->replicaNum = 1;
|
2023-04-18 11:03:45 +00:00
|
|
|
pCfg->totalReplicaNum = 1;
|
2023-01-30 09:46:42 +00:00
|
|
|
memset(&pCfg->nodeInfo, 0, sizeof(pCfg->nodeInfo));
|
|
|
|
|
|
|
|
|
|
vInfo("vgId:%d, alter vnode replicas to 1", pReq->srcVgId);
|
|
|
|
|
SNodeInfo *pNode = &pCfg->nodeInfo[0];
|
|
|
|
|
pNode->nodePort = tsServerPort;
|
|
|
|
|
tstrncpy(pNode->nodeFqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
2024-09-24 02:06:30 +00:00
|
|
|
bool ret1 = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
2023-01-30 09:46:42 +00:00
|
|
|
vInfo("vgId:%d, ep:%s:%u dnode:%d", pReq->srcVgId, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId);
|
|
|
|
|
|
|
|
|
|
info.config.syncCfg = *pCfg;
|
|
|
|
|
|
|
|
|
|
ret = vnodeSaveInfo(dir, &info);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
vError("vgId:%d, failed to save vnode config since %s", pReq->dstVgId, tstrerror(terrno));
|
2024-08-14 09:50:20 +00:00
|
|
|
return ret;
|
2023-01-30 09:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-10 08:24:29 +00:00
|
|
|
ret = vnodeCommitInfo(dir);
|
2023-01-30 09:46:42 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
|
vError("vgId:%d, failed to commit vnode config since %s", pReq->dstVgId, tstrerror(terrno));
|
2024-08-14 09:50:20 +00:00
|
|
|
return ret;
|
2023-01-30 09:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-03 06:40:12 +00:00
|
|
|
vInfo("vgId:%d, rename %s to %s", pReq->dstVgId, srcPath, dstPath);
|
2023-07-14 10:24:53 +00:00
|
|
|
ret = vnodeRenameVgroupId(srcPath, dstPath, pReq->srcVgId, pReq->dstVgId, diskPrimary, pTfs);
|
2023-01-30 09:46:42 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
|
vError("vgId:%d, failed to rename vnode from %s to %s since %s", pReq->dstVgId, srcPath, dstPath,
|
|
|
|
|
tstrerror(terrno));
|
2024-08-14 09:50:20 +00:00
|
|
|
return ret;
|
2023-01-30 09:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vInfo("vgId:%d, vnode hashrange is altered", info.config.vgId);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 10:24:53 +00:00
|
|
|
int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t srcVgId, int32_t dstVgId,
|
|
|
|
|
int32_t diskPrimary, STfs *pTfs) {
|
2023-06-20 07:40:09 +00:00
|
|
|
SVnodeInfo info = {0};
|
|
|
|
|
char dir[TSDB_FILENAME_LEN] = {0};
|
2024-07-25 03:45:15 +00:00
|
|
|
int32_t code = 0;
|
2023-06-20 07:40:09 +00:00
|
|
|
|
2024-09-10 02:05:38 +00:00
|
|
|
vnodeGetPrimaryDir(dstPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN);
|
2023-06-20 07:40:09 +00:00
|
|
|
if (vnodeLoadInfo(dir, &info) == 0) {
|
|
|
|
|
if (info.config.vgId != dstVgId) {
|
|
|
|
|
vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId);
|
2024-07-25 03:45:15 +00:00
|
|
|
return TSDB_CODE_FAILED;
|
2023-06-20 07:40:09 +00:00
|
|
|
}
|
|
|
|
|
return dstVgId;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-10 02:05:38 +00:00
|
|
|
vnodeGetPrimaryDir(srcPath, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN);
|
2024-08-14 09:50:20 +00:00
|
|
|
if ((code = vnodeLoadInfo(dir, &info)) < 0) {
|
2023-06-20 07:40:09 +00:00
|
|
|
vError("vgId:%d, failed to read vnode config from %s since %s", srcVgId, srcPath, tstrerror(terrno));
|
2024-08-14 09:50:20 +00:00
|
|
|
return code;
|
2023-06-20 07:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info.config.vgId == srcVgId) {
|
|
|
|
|
vInfo("vgId:%d, rollback alter hashrange", srcVgId);
|
|
|
|
|
return srcVgId;
|
|
|
|
|
} else if (info.config.vgId != dstVgId) {
|
|
|
|
|
vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId);
|
2024-07-25 03:45:15 +00:00
|
|
|
return TSDB_CODE_FAILED;
|
2023-06-20 07:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vInfo("vgId:%d, rename %s to %s", dstVgId, srcPath, dstPath);
|
2023-07-14 10:24:53 +00:00
|
|
|
if (vnodeRenameVgroupId(srcPath, dstPath, srcVgId, dstVgId, diskPrimary, pTfs) < 0) {
|
2023-06-20 07:40:09 +00:00
|
|
|
vError("vgId:%d, failed to rename vnode from %s to %s since %s", dstVgId, srcPath, dstPath, tstrerror(terrno));
|
2024-07-25 03:45:15 +00:00
|
|
|
return TSDB_CODE_FAILED;
|
2023-06-20 07:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dstVgId;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-08 02:31:49 +00:00
|
|
|
void vnodeDestroy(int32_t vgId, const char *path, STfs *pTfs, int32_t nodeId) {
|
2022-10-20 08:47:03 +00:00
|
|
|
vInfo("path:%s is removed while destroy vnode", path);
|
2024-09-24 02:06:30 +00:00
|
|
|
if (tfsRmdir(pTfs, path) < 0) {
|
|
|
|
|
vError("failed to remove path:%s since %s", path, tstrerror(terrno));
|
|
|
|
|
}
|
2023-08-18 08:38:26 +00:00
|
|
|
|
2025-07-14 08:33:53 +00:00
|
|
|
#ifdef USE_SHARED_STORAGE
|
|
|
|
|
if (nodeId > 0 && vgId > 0 && tsSsEnabled) {
|
|
|
|
|
// we should only do this on the leader node, but it is ok to do this on all nodes
|
|
|
|
|
char prefix[TSDB_FILENAME_LEN];
|
|
|
|
|
snprintf(prefix, TSDB_FILENAME_LEN, "vnode%d/", vgId);
|
|
|
|
|
tssDeleteFileByPrefixFromDefault(prefix);
|
2023-08-18 08:38:26 +00:00
|
|
|
}
|
2025-03-14 05:32:13 +00:00
|
|
|
#endif
|
2022-10-20 08:47:03 +00:00
|
|
|
}
|
2022-04-16 07:04:25 +00:00
|
|
|
|
2023-07-18 07:39:29 +00:00
|
|
|
static int32_t vnodeCheckDisk(int32_t diskPrimary, STfs *pTfs) {
|
|
|
|
|
int32_t ndisk = 1;
|
|
|
|
|
if (pTfs) {
|
|
|
|
|
ndisk = tfsGetDisksAtLevel(pTfs, 0);
|
|
|
|
|
}
|
|
|
|
|
if (diskPrimary < 0 || diskPrimary >= ndisk) {
|
|
|
|
|
vError("disk:%d is unavailable from the %d disks mounted at level 0", diskPrimary, ndisk);
|
2024-07-25 03:45:15 +00:00
|
|
|
return terrno = TSDB_CODE_FS_INVLD_CFG;
|
2023-07-18 07:39:29 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-12 07:39:29 +00:00
|
|
|
SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, STfs *pMountTfs, SMsgCb msgCb, bool force) {
|
2022-04-16 07:16:10 +00:00
|
|
|
SVnode *pVnode = NULL;
|
|
|
|
|
SVnodeInfo info = {0};
|
2022-10-20 08:47:03 +00:00
|
|
|
char dir[TSDB_FILENAME_LEN] = {0};
|
|
|
|
|
char tdir[TSDB_FILENAME_LEN * 2] = {0};
|
|
|
|
|
int32_t ret = 0;
|
2025-07-12 07:39:29 +00:00
|
|
|
bool mounted = pMountTfs != NULL;
|
2023-10-11 12:49:43 +00:00
|
|
|
terrno = TSDB_CODE_SUCCESS;
|
2021-11-08 02:04:24 +00:00
|
|
|
|
2023-07-18 07:39:29 +00:00
|
|
|
if (vnodeCheckDisk(diskPrimary, pTfs)) {
|
|
|
|
|
vError("failed to open vnode from %s since %s. diskPrimary:%d", path, terrstr(), diskPrimary);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2024-09-10 02:05:38 +00:00
|
|
|
vnodeGetPrimaryDir(path, diskPrimary, pTfs, dir, TSDB_FILENAME_LEN);
|
2022-04-16 07:16:10 +00:00
|
|
|
|
2022-09-08 08:56:29 +00:00
|
|
|
info.config = vnodeCfgDefault;
|
|
|
|
|
|
2022-04-16 07:16:10 +00:00
|
|
|
// load vnode info
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to vnode load info %s", info.config.vgId, dir);
|
2022-04-16 07:16:10 +00:00
|
|
|
ret = vnodeLoadInfo(dir, &info);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
vError("failed to open vnode from %s since %s", path, tstrerror(terrno));
|
2023-10-19 10:55:12 +00:00
|
|
|
terrno = TSDB_CODE_NEED_RETRY;
|
2021-11-08 02:04:24 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-12 07:39:29 +00:00
|
|
|
if (!mounted && vnodeMkDir(pTfs, path)) {
|
2025-03-14 05:32:13 +00:00
|
|
|
vError("vgId:%d, failed to prepare vnode dir since %s, path: %s", info.config.vgId, strerror(ERRNO), path);
|
2023-10-08 10:28:47 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2023-01-16 07:41:50 +00:00
|
|
|
// save vnode info on dnode ep changed
|
|
|
|
|
bool updated = false;
|
|
|
|
|
SSyncCfg *pCfg = &info.config.syncCfg;
|
2023-04-18 11:03:45 +00:00
|
|
|
for (int32_t i = 0; i < pCfg->totalReplicaNum; ++i) {
|
2023-01-16 07:41:50 +00:00
|
|
|
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
|
|
|
|
if (tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort)) {
|
|
|
|
|
updated = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (updated) {
|
|
|
|
|
vInfo("vgId:%d, save vnode info since dnode info changed", info.config.vgId);
|
2024-09-24 02:06:30 +00:00
|
|
|
if (vnodeSaveInfo(dir, &info) < 0) {
|
|
|
|
|
vError("vgId:%d, failed to save vnode info since %s", info.config.vgId, tstrerror(terrno));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vnodeCommitInfo(dir) < 0) {
|
|
|
|
|
vError("vgId:%d, failed to commit vnode info since %s", info.config.vgId, tstrerror(terrno));
|
|
|
|
|
}
|
2023-01-16 07:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-16 08:19:21 +00:00
|
|
|
// create handle
|
2022-10-20 08:47:03 +00:00
|
|
|
pVnode = taosMemoryCalloc(1, sizeof(*pVnode) + strlen(path) + 1);
|
2021-11-08 02:04:24 +00:00
|
|
|
if (pVnode == NULL) {
|
2022-04-16 08:19:21 +00:00
|
|
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
2022-06-02 05:57:39 +00:00
|
|
|
vError("vgId:%d, failed to open vnode since %s", info.config.vgId, tstrerror(terrno));
|
2021-11-08 02:04:24 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 11:22:49 +00:00
|
|
|
pVnode->path = (char *)&pVnode[1];
|
2024-12-17 09:47:08 +00:00
|
|
|
memcpy(pVnode->path, path, strlen(path) + 1);
|
2022-04-16 08:19:21 +00:00
|
|
|
pVnode->config = info.config;
|
2022-05-21 03:13:58 +00:00
|
|
|
pVnode->state.committed = info.state.committed;
|
2022-07-06 09:46:14 +00:00
|
|
|
pVnode->state.commitTerm = info.state.commitTerm;
|
2022-06-23 03:08:19 +00:00
|
|
|
pVnode->state.commitID = info.state.commitID;
|
2022-11-30 14:41:33 +00:00
|
|
|
pVnode->state.applied = info.state.committed;
|
|
|
|
|
pVnode->state.applyTerm = info.state.commitTerm;
|
2022-04-16 08:19:21 +00:00
|
|
|
pVnode->pTfs = pTfs;
|
2025-07-12 07:39:29 +00:00
|
|
|
pVnode->pMountTfs = pMountTfs;
|
|
|
|
|
pVnode->mounted = mounted;
|
2023-07-17 12:43:31 +00:00
|
|
|
pVnode->diskPrimary = diskPrimary;
|
2022-04-16 08:19:21 +00:00
|
|
|
pVnode->msgCb = msgCb;
|
2024-07-29 05:54:50 +00:00
|
|
|
(void)taosThreadMutexInit(&pVnode->lock, NULL);
|
2022-08-12 08:32:11 +00:00
|
|
|
pVnode->blocked = false;
|
2024-08-08 10:25:43 +00:00
|
|
|
pVnode->disableWrite = false;
|
2022-04-16 08:19:21 +00:00
|
|
|
|
2024-09-24 10:04:58 +00:00
|
|
|
if (tsem_init(&pVnode->syncSem, 0, 0) != 0) {
|
|
|
|
|
vError("vgId:%d, failed to init semaphore", TD_VID(pVnode));
|
|
|
|
|
goto _err;
|
|
|
|
|
}
|
2024-07-29 05:54:50 +00:00
|
|
|
(void)taosThreadMutexInit(&pVnode->mutex, NULL);
|
|
|
|
|
(void)taosThreadCondInit(&pVnode->poolNotEmpty, NULL);
|
2022-04-16 08:19:21 +00:00
|
|
|
|
2025-07-22 05:25:21 +00:00
|
|
|
vInfo("vgId:%d, finished vnode load info %s, vnode committed:%" PRId64, info.config.vgId, dir, pVnode->state.committed);
|
|
|
|
|
|
2022-10-18 05:38:26 +00:00
|
|
|
int8_t rollback = vnodeShouldRollback(pVnode);
|
|
|
|
|
|
2022-04-16 10:17:33 +00:00
|
|
|
// open buffer pool
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to open vnode buffer pool", TD_VID(pVnode));
|
2022-10-09 05:52:44 +00:00
|
|
|
if (vnodeOpenBufPool(pVnode) < 0) {
|
2022-06-02 05:57:39 +00:00
|
|
|
vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
|
2022-04-16 10:17:33 +00:00
|
|
|
goto _err;
|
2021-11-08 06:50:20 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-16 10:17:33 +00:00
|
|
|
// open meta
|
2025-02-27 07:06:49 +00:00
|
|
|
(void)taosThreadRwlockInit(&pVnode->metaRWLock, NULL);
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to open vnode meta", TD_VID(pVnode));
|
2022-10-18 05:38:26 +00:00
|
|
|
if (metaOpen(pVnode, &pVnode->pMeta, rollback) < 0) {
|
2022-06-02 05:57:39 +00:00
|
|
|
vError("vgId:%d, failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno));
|
2022-04-16 10:17:33 +00:00
|
|
|
goto _err;
|
2021-11-08 05:40:45 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to upgrade meta", TD_VID(pVnode));
|
2025-07-12 07:39:29 +00:00
|
|
|
if (!mounted && metaUpgrade(pVnode, &pVnode->pMeta) < 0) {
|
2023-07-05 07:58:09 +00:00
|
|
|
vError("vgId:%d, failed to upgrade meta since %s", TD_VID(pVnode), tstrerror(terrno));
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 10:17:33 +00:00
|
|
|
// open tsdb
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to open vnode tsdb", TD_VID(pVnode));
|
2025-07-03 06:22:12 +00:00
|
|
|
if (!VND_IS_RSMA(pVnode) && (terrno = tsdbOpen(pVnode, &VND_TSDB(pVnode), VNODE_TSDB_DIR, NULL, rollback, force)) < 0) {
|
2022-06-02 05:57:39 +00:00
|
|
|
vError("vgId:%d, failed to open vnode tsdb since %s", TD_VID(pVnode), tstrerror(terrno));
|
2022-05-15 12:17:20 +00:00
|
|
|
goto _err;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 10:17:33 +00:00
|
|
|
// open wal
|
2024-12-13 12:59:39 +00:00
|
|
|
(void)tsnprintf(tdir, sizeof(tdir), "%s%s%s", dir, TD_DIRSEP, VNODE_WAL_DIR);
|
2024-09-26 03:27:01 +00:00
|
|
|
ret = taosRealPath(tdir, NULL, sizeof(tdir));
|
|
|
|
|
TAOS_UNUSED(ret);
|
2022-07-11 02:34:02 +00:00
|
|
|
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to open vnode wal", TD_VID(pVnode));
|
2022-04-16 10:17:33 +00:00
|
|
|
pVnode->pWal = walOpen(tdir, &(pVnode->config.walCfg));
|
2021-11-16 07:49:05 +00:00
|
|
|
if (pVnode->pWal == NULL) {
|
2022-09-30 05:57:38 +00:00
|
|
|
vError("vgId:%d, failed to open vnode wal since %s. wal:%s", TD_VID(pVnode), tstrerror(terrno), tdir);
|
2022-04-16 10:17:33 +00:00
|
|
|
goto _err;
|
2021-11-16 07:49:05 +00:00
|
|
|
}
|
2021-11-08 05:40:45 +00:00
|
|
|
|
2022-04-16 10:17:33 +00:00
|
|
|
// open tq
|
2024-12-13 12:59:39 +00:00
|
|
|
(void)tsnprintf(tdir, sizeof(tdir), "%s%s%s", dir, TD_DIRSEP, VNODE_TQ_DIR);
|
2024-09-26 03:27:01 +00:00
|
|
|
ret = taosRealPath(tdir, NULL, sizeof(tdir));
|
|
|
|
|
TAOS_UNUSED(ret);
|
2022-01-20 07:39:28 +00:00
|
|
|
|
2022-04-16 10:17:33 +00:00
|
|
|
// open query
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to open vnode query", TD_VID(pVnode));
|
2021-12-24 01:41:09 +00:00
|
|
|
if (vnodeQueryOpen(pVnode)) {
|
2022-06-02 05:57:39 +00:00
|
|
|
vError("vgId:%d, failed to open vnode query since %s", TD_VID(pVnode), tstrerror(terrno));
|
2022-05-13 09:40:22 +00:00
|
|
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
2022-04-16 10:17:33 +00:00
|
|
|
goto _err;
|
2021-12-24 01:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-30 02:14:01 +00:00
|
|
|
// sma required the tq is initialized before the vnode open
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to open vnode tq", TD_VID(pVnode));
|
2024-07-24 09:56:29 +00:00
|
|
|
if (tqOpen(tdir, pVnode)) {
|
2023-08-30 02:14:01 +00:00
|
|
|
vError("vgId:%d, failed to open vnode tq since %s", TD_VID(pVnode), tstrerror(terrno));
|
|
|
|
|
goto _err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// open sma
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to open vnode sma", TD_VID(pVnode));
|
2023-10-19 10:55:12 +00:00
|
|
|
if (smaOpen(pVnode, rollback, force)) {
|
2023-08-30 02:14:01 +00:00
|
|
|
vError("vgId:%d, failed to open vnode sma since %s", TD_VID(pVnode), tstrerror(terrno));
|
|
|
|
|
goto _err;
|
|
|
|
|
}
|
2025-07-22 05:25:21 +00:00
|
|
|
// open blob store engine
|
|
|
|
|
vInfo("vgId:%d, start to open blob store engine", TD_VID(pVnode));
|
|
|
|
|
(void)tsnprintf(tdir, sizeof(tdir), "%s%s%s", dir, TD_DIRSEP, VNODE_BSE_DIR);
|
|
|
|
|
|
|
|
|
|
SBseCfg cfg = {.vgId = pVnode->config.vgId, .keepDays = 365 * 24 * 3600};
|
|
|
|
|
ret = bseOpen(tdir, &cfg, &pVnode->pBse);
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
vError("vgId:%d, failed to open blob store engine since %s", TD_VID(pVnode), tstrerror(ret));
|
|
|
|
|
terrno = ret;
|
|
|
|
|
goto _err;
|
|
|
|
|
}
|
2023-08-30 02:14:01 +00:00
|
|
|
|
2022-04-19 13:10:03 +00:00
|
|
|
// vnode begin
|
2024-11-20 09:27:35 +00:00
|
|
|
vInfo("vgId:%d, start to begin vnode", TD_VID(pVnode));
|
2022-04-19 13:10:03 +00:00
|
|
|
if (vnodeBegin(pVnode) < 0) {
|
2022-06-02 05:57:39 +00:00
|
|
|
vError("vgId:%d, failed to begin since %s", TD_VID(pVnode), tstrerror(terrno));
|
2022-05-13 09:40:22 +00:00
|
|
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
2022-04-16 10:17:33 +00:00
|
|
|
goto _err;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-26 05:49:42 +00:00
|
|
|
// open sync
|
2023-07-21 02:31:53 +00:00
|
|
|
vInfo("vgId:%d, start to open sync, changeVersion:%d", TD_VID(pVnode), info.config.syncCfg.changeVersion);
|
|
|
|
|
if (vnodeSyncOpen(pVnode, dir, info.config.syncCfg.changeVersion)) {
|
2022-06-02 05:57:39 +00:00
|
|
|
vError("vgId:%d, failed to open sync since %s", TD_VID(pVnode), tstrerror(terrno));
|
2022-04-16 10:17:33 +00:00
|
|
|
goto _err;
|
|
|
|
|
}
|
2022-10-18 05:38:26 +00:00
|
|
|
|
|
|
|
|
if (rollback) {
|
|
|
|
|
vnodeRollback(pVnode);
|
|
|
|
|
}
|
2022-04-16 10:17:33 +00:00
|
|
|
|
2024-04-08 02:31:49 +00:00
|
|
|
snprintf(pVnode->monitor.strClusterId, TSDB_CLUSTER_ID_LEN, "%" PRId64, pVnode->config.syncCfg.nodeInfo[0].clusterId);
|
|
|
|
|
snprintf(pVnode->monitor.strDnodeId, TSDB_NODE_ID_LEN, "%" PRId32, pVnode->config.syncCfg.nodeInfo[0].nodeId);
|
|
|
|
|
snprintf(pVnode->monitor.strVgId, TSDB_VGROUP_ID_LEN, "%" PRId32, pVnode->config.vgId);
|
2024-01-24 09:44:44 +00:00
|
|
|
|
2022-04-16 10:17:33 +00:00
|
|
|
return pVnode;
|
|
|
|
|
|
|
|
|
|
_err:
|
|
|
|
|
if (pVnode->pQuery) vnodeQueryClose(pVnode);
|
|
|
|
|
if (pVnode->pTq) tqClose(pVnode->pTq);
|
|
|
|
|
if (pVnode->pWal) walClose(pVnode->pWal);
|
2024-09-24 02:06:30 +00:00
|
|
|
if (pVnode->pTsdb) tsdbClose(&pVnode->pTsdb);
|
|
|
|
|
if (pVnode->pSma) smaClose(pVnode->pSma);
|
|
|
|
|
if (pVnode->pMeta) metaClose(&pVnode->pMeta);
|
2024-09-10 06:35:43 +00:00
|
|
|
if (pVnode->freeList) vnodeCloseBufPool(pVnode);
|
2022-06-26 10:44:49 +00:00
|
|
|
|
2025-02-27 07:06:49 +00:00
|
|
|
(void)taosThreadRwlockDestroy(&pVnode->metaRWLock);
|
2022-04-16 10:17:33 +00:00
|
|
|
taosMemoryFree(pVnode);
|
|
|
|
|
return NULL;
|
2021-11-08 02:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-01 12:26:56 +00:00
|
|
|
void vnodePreClose(SVnode *pVnode) {
|
2025-07-22 08:38:37 +00:00
|
|
|
streamRemoveVnodeLeader(pVnode->config.vgId);
|
2022-12-01 12:26:56 +00:00
|
|
|
vnodeSyncPreClose(pVnode);
|
2023-08-22 03:30:40 +00:00
|
|
|
vnodeQueryPreClose(pVnode);
|
2022-11-11 09:13:55 +00:00
|
|
|
}
|
2022-07-12 06:46:52 +00:00
|
|
|
|
2023-01-05 04:00:27 +00:00
|
|
|
void vnodePostClose(SVnode *pVnode) { vnodeSyncPostClose(pVnode); }
|
2022-07-12 06:46:52 +00:00
|
|
|
|
2022-04-16 10:17:33 +00:00
|
|
|
void vnodeClose(SVnode *pVnode) {
|
2021-11-08 05:40:45 +00:00
|
|
|
if (pVnode) {
|
2025-07-22 05:25:21 +00:00
|
|
|
vInfo("start to close vnode");
|
|
|
|
|
vnodeAWait(&pVnode->commitTask2);
|
2024-09-10 06:35:43 +00:00
|
|
|
vnodeAWait(&pVnode->commitTask);
|
2022-04-20 02:54:27 +00:00
|
|
|
vnodeSyncClose(pVnode);
|
2022-03-09 08:13:46 +00:00
|
|
|
vnodeQueryClose(pVnode);
|
2022-04-16 10:17:33 +00:00
|
|
|
tqClose(pVnode->pTq);
|
2023-07-28 08:59:35 +00:00
|
|
|
walClose(pVnode->pWal);
|
2022-05-15 12:17:20 +00:00
|
|
|
if (pVnode->pTsdb) tsdbClose(&pVnode->pTsdb);
|
2024-09-24 02:06:30 +00:00
|
|
|
smaClose(pVnode->pSma);
|
2023-02-14 02:56:00 +00:00
|
|
|
if (pVnode->pMeta) metaClose(&pVnode->pMeta);
|
2024-09-10 06:35:43 +00:00
|
|
|
vnodeCloseBufPool(pVnode);
|
2022-12-23 12:16:23 +00:00
|
|
|
|
2025-07-22 05:25:21 +00:00
|
|
|
if (pVnode->pBse) {
|
|
|
|
|
bseClose(pVnode->pBse);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 10:17:33 +00:00
|
|
|
// destroy handle
|
2024-09-26 02:43:16 +00:00
|
|
|
if (tsem_destroy(&pVnode->syncSem) != 0) {
|
|
|
|
|
vError("vgId:%d, failed to destroy semaphore", TD_VID(pVnode));
|
|
|
|
|
}
|
2024-07-29 12:14:15 +00:00
|
|
|
(void)taosThreadCondDestroy(&pVnode->poolNotEmpty);
|
2024-07-29 05:54:50 +00:00
|
|
|
(void)taosThreadMutexDestroy(&pVnode->mutex);
|
|
|
|
|
(void)taosThreadMutexDestroy(&pVnode->lock);
|
2022-04-16 10:17:33 +00:00
|
|
|
taosMemoryFree(pVnode);
|
2021-11-08 05:40:45 +00:00
|
|
|
}
|
2022-01-20 07:18:33 +00:00
|
|
|
}
|
2022-04-19 09:07:42 +00:00
|
|
|
|
2022-04-25 07:39:52 +00:00
|
|
|
// start the sync timer after the queue is ready
|
2023-10-11 12:49:43 +00:00
|
|
|
int32_t vnodeStart(SVnode *pVnode) {
|
2024-08-20 02:43:28 +00:00
|
|
|
if (pVnode == NULL) {
|
|
|
|
|
return TSDB_CODE_INVALID_PARA;
|
|
|
|
|
}
|
2023-10-11 12:49:43 +00:00
|
|
|
return vnodeSyncStart(pVnode);
|
|
|
|
|
}
|
2022-04-25 07:39:52 +00:00
|
|
|
|
2023-08-18 08:38:26 +00:00
|
|
|
int32_t vnodeIsCatchUp(SVnode *pVnode) { return syncIsCatchUp(pVnode->sync); }
|
2023-04-18 11:03:45 +00:00
|
|
|
|
2023-08-18 08:38:26 +00:00
|
|
|
ESyncRole vnodeGetRole(SVnode *pVnode) { return syncGetRole(pVnode->sync); }
|
2023-04-24 02:23:43 +00:00
|
|
|
|
2024-03-15 01:14:54 +00:00
|
|
|
int32_t vnodeUpdateArbTerm(SVnode *pVnode, int64_t arbTerm) { return syncUpdateArbTerm(pVnode->sync, arbTerm); }
|
|
|
|
|
int32_t vnodeGetArbToken(SVnode *pVnode, char *outToken) { return syncGetArbToken(pVnode->sync, outToken); }
|
|
|
|
|
|
2022-04-25 07:39:52 +00:00
|
|
|
void vnodeStop(SVnode *pVnode) {}
|
|
|
|
|
|
2022-04-20 11:30:18 +00:00
|
|
|
int64_t vnodeGetSyncHandle(SVnode *pVnode) { return pVnode->sync; }
|