From e5021e77ea98e2a1f6354975eca198701f7ed448 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 20 Oct 2020 09:10:34 +0000 Subject: [PATCH] more code --- src/common/inc/tglobal.h | 5 ++++ src/common/inc/tpath.h | 53 +++++++++++++++++++++++++++++++++++++++ src/dnode/src/dnodeMain.c | 45 +++++++++++++++++++-------------- src/vnode/src/vnodeMain.c | 30 +++++++++++++++------- 4 files changed, 105 insertions(+), 28 deletions(-) create mode 100644 src/common/inc/tpath.h diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 515115c323..e08a56fb32 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -20,6 +20,8 @@ extern "C" { #endif +struct SDnodeTier; + // cluster extern char tsFirst[]; extern char tsSecond[]; @@ -156,6 +158,9 @@ extern char gitinfo[]; extern char gitinfoOfInternal[]; extern char buildinfo[]; +// dnode +extern struct SDnodeTier *pDnodeTier; + // log extern int32_t tsAsyncLog; extern int32_t tsNumOfLogLines; diff --git a/src/common/inc/tpath.h b/src/common/inc/tpath.h new file mode 100644 index 0000000000..c7557aa30a --- /dev/null +++ b/src/common/inc/tpath.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ +#ifndef _TD_TPATH_H_ +#define _TD_TPATH_H_ + +#include +#include "taosdef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static FORCE_INLINE void tdGetMnodeRootDir(char *rootDir, char *dirName) { + snprintf(dirName, TSDB_FILENAME_LEN, "%s/mnode", rootDir); +} + +static FORCE_INLINE void tdGetDnodeRootDir(char *rootDir, char *dirName) { + snprintf(dirName, TSDB_FILENAME_LEN, "%s/dnode", rootDir); +} + +static FORCE_INLINE void tdGetVnodeRootDir(char *rootDir, char *dirName) { + snprintf(dirName, TSDB_FILENAME_LEN, "%s/vnode", rootDir); +} + +static FORCE_INLINE void tdGetVnodeBackRootDir(char *rootDir, char *dirName) { + snprintf(dirName, TSDB_FILENAME_LEN, "%s/vnode_bak", rootDir); +} + +static FORCE_INLINE void tdGetVnodeDir(char *rootDir, int vid, char *dirName) { + snprintf(dirName, TSDB_FILENAME_LEN, "%s/vnode/vnode%d", rootDir, vid); +} + +static FORCE_INLINE void tdGetVnodeBackDir(char *rootDir, int vid, char *dirName) { + snprintf(dirName, TSDB_FILENAME_LEN, "%s/vnode_bak/vnode%d", rootDir, vid); +} + +#ifdef __cplusplus +} +#endif + +#endif // _TD_TPATH_H_ \ No newline at end of file diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 59c19554b0..6abe55e227 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -32,8 +32,9 @@ #include "dnodeMPeer.h" #include "dnodeShell.h" #include "dnodeTelemetry.h" +#include "tpath.h" -SDnodeTier *pDnodeTier = NULL; +struct SDnodeTier *pDnodeTier = NULL; static int32_t dnodeInitStorage(); static void dnodeCleanupStorage(); @@ -181,32 +182,38 @@ static int32_t dnodeInitStorage() { return -1; } - if (dnodeCreateDir(tsDataDir) < 0) { - dError("failed to create dir: %s, reason: %s", tsDataDir, strerror(errno)); - return -1; - } - sprintf(tsMnodeDir, "%s/mnode", tsDataDir); - sprintf(tsVnodeDir, "%s/vnode", tsDataDir); - sprintf(tsDnodeDir, "%s/dnode", tsDataDir); - sprintf(tsVnodeBakDir, "%s/vnode_bak", tsDataDir); - //TODO(dengyihao): no need to init here + tdGetMnodeRootDir(DNODE_PRIMARY_DISK(pDnodeTier)->dir, tsMnodeDir); if (dnodeCreateDir(tsMnodeDir) < 0) { dError("failed to create dir: %s, reason: %s", tsMnodeDir, strerror(errno)); return -1; } - //TODO(dengyihao): no need to init here - if (dnodeCreateDir(tsVnodeDir) < 0) { - dError("failed to create dir: %s, reason: %s", tsVnodeDir, strerror(errno)); - return -1; - } + + tdGetDnodeRootDir(DNODE_PRIMARY_DISK(pDnodeTier)->dir, tsDnodeDir); if (dnodeCreateDir(tsDnodeDir) < 0) { dError("failed to create dir: %s, reason: %s", tsDnodeDir, strerror(errno)); return -1; - } - if (dnodeCreateDir(tsVnodeBakDir) < 0) { - dError("failed to create dir: %s, reason: %s", tsVnodeBakDir, strerror(errno)); - return -1; + } + + for (int i = 0; i < pDnodeTier->nTiers; i++) { + char dirName[TSDB_FILENAME_LEN]; + + STier *pTier = pDnodeTier->tiers + i; + for (int j = 0; j < pTier->nDisks; j++) { + SDisk *pDisk = dnodeGetDisk(pDnodeTier, i, j); + + tdGetVnodeRootDir(dirName, pDisk->dir); + if (dnodeCreateDir(dirName) < 0) { + dError("failed to create dir: %s, reason: %s", dirName, strerror(errno)); + return -1; + } + + tdGetVnodeBackRootDir(dirName, pDisk->dir); + if (dnodeCreateDir(dirName) < 0) { + dError("failed to create dir: %s, reason: %s", dirName, strerror(errno)); + return -1; + } + } } dnodeCheckDataDirOpenned(tsDnodeDir); diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index a9bcf948b6..a05b8aa971 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -31,6 +31,7 @@ #include "vnodeInt.h" #include "query.h" #include "dnode.h" +#include "tpath.h" #define TSDB_VNODE_VERSION_CONTENT_LEN 31 @@ -395,17 +396,28 @@ void vnodeRelease(void *pVnodeRaw) { if (pVnode->dropped) { char rootDir[TSDB_FILENAME_LEN] = {0}; char newDir[TSDB_FILENAME_LEN] = {0}; - sprintf(rootDir, "%s/vnode%d", tsVnodeDir, vgId); - sprintf(newDir, "%s/vnode%d", tsVnodeBakDir, vgId); - if (0 == tsEnableVnodeBak) { - vInfo("vgId:%d, vnode backup not enabled", pVnode->vgId); - } else { - taosRemoveDir(newDir); - taosRename(rootDir, newDir); - } + for (int i = 0; i < pDnodeTier->nTiers; i++) { + STier *pTier = pDnodeTier->tiers + i; + for (int j = 0; j < pTier->nDisks; j++) { + SDisk *pDisk = pTier->disks[j]; + + tdGetVnodeDir(pDisk->dir, vgId, rootDir); + tdGetVnodeBackDir(pDisk->dir, vgId, newDir); - taosRemoveDir(rootDir); + if (access(rootDir, F_OK) == 0) { + if (0 == tsEnableVnodeBak) { + vInfo("vgId:%d, vnode backup not enabled", pVnode->vgId); + } else { + taosRemoveDir(newDir); + taosRename(rootDir, newDir); + } + + taosRemoveDir(rootDir); + } + } + } + dnodeSendStatusMsgToMnode(); } -- GitLab