提交 e5021e77 编写于 作者: H Hongze Cheng

more code

上级 7e61fc12
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
extern "C" { extern "C" {
#endif #endif
struct SDnodeTier;
// cluster // cluster
extern char tsFirst[]; extern char tsFirst[];
extern char tsSecond[]; extern char tsSecond[];
...@@ -156,6 +158,9 @@ extern char gitinfo[]; ...@@ -156,6 +158,9 @@ extern char gitinfo[];
extern char gitinfoOfInternal[]; extern char gitinfoOfInternal[];
extern char buildinfo[]; extern char buildinfo[];
// dnode
extern struct SDnodeTier *pDnodeTier;
// log // log
extern int32_t tsAsyncLog; extern int32_t tsAsyncLog;
extern int32_t tsNumOfLogLines; extern int32_t tsNumOfLogLines;
......
/*
* 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/>.
*/
#ifndef _TD_TPATH_H_
#define _TD_TPATH_H_
#include <stdio.h>
#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
...@@ -32,8 +32,9 @@ ...@@ -32,8 +32,9 @@
#include "dnodeMPeer.h" #include "dnodeMPeer.h"
#include "dnodeShell.h" #include "dnodeShell.h"
#include "dnodeTelemetry.h" #include "dnodeTelemetry.h"
#include "tpath.h"
SDnodeTier *pDnodeTier = NULL; struct SDnodeTier *pDnodeTier = NULL;
static int32_t dnodeInitStorage(); static int32_t dnodeInitStorage();
static void dnodeCleanupStorage(); static void dnodeCleanupStorage();
...@@ -181,34 +182,40 @@ static int32_t dnodeInitStorage() { ...@@ -181,34 +182,40 @@ static int32_t dnodeInitStorage() {
return -1; 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 //TODO(dengyihao): no need to init here
tdGetMnodeRootDir(DNODE_PRIMARY_DISK(pDnodeTier)->dir, tsMnodeDir);
if (dnodeCreateDir(tsMnodeDir) < 0) { if (dnodeCreateDir(tsMnodeDir) < 0) {
dError("failed to create dir: %s, reason: %s", tsMnodeDir, strerror(errno)); dError("failed to create dir: %s, reason: %s", tsMnodeDir, strerror(errno));
return -1; return -1;
} }
//TODO(dengyihao): no need to init here
if (dnodeCreateDir(tsVnodeDir) < 0) { tdGetDnodeRootDir(DNODE_PRIMARY_DISK(pDnodeTier)->dir, tsDnodeDir);
dError("failed to create dir: %s, reason: %s", tsVnodeDir, strerror(errno));
return -1;
}
if (dnodeCreateDir(tsDnodeDir) < 0) { if (dnodeCreateDir(tsDnodeDir) < 0) {
dError("failed to create dir: %s, reason: %s", tsDnodeDir, strerror(errno)); dError("failed to create dir: %s, reason: %s", tsDnodeDir, strerror(errno));
return -1; return -1;
} }
if (dnodeCreateDir(tsVnodeBakDir) < 0) {
dError("failed to create dir: %s, reason: %s", tsVnodeBakDir, strerror(errno)); 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; 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); dnodeCheckDataDirOpenned(tsDnodeDir);
dInfo("storage directory is initialized"); dInfo("storage directory is initialized");
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "vnodeInt.h" #include "vnodeInt.h"
#include "query.h" #include "query.h"
#include "dnode.h" #include "dnode.h"
#include "tpath.h"
#define TSDB_VNODE_VERSION_CONTENT_LEN 31 #define TSDB_VNODE_VERSION_CONTENT_LEN 31
...@@ -395,9 +396,16 @@ void vnodeRelease(void *pVnodeRaw) { ...@@ -395,9 +396,16 @@ void vnodeRelease(void *pVnodeRaw) {
if (pVnode->dropped) { if (pVnode->dropped) {
char rootDir[TSDB_FILENAME_LEN] = {0}; char rootDir[TSDB_FILENAME_LEN] = {0};
char newDir[TSDB_FILENAME_LEN] = {0}; char newDir[TSDB_FILENAME_LEN] = {0};
sprintf(rootDir, "%s/vnode%d", tsVnodeDir, vgId);
sprintf(newDir, "%s/vnode%d", tsVnodeBakDir, vgId);
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);
if (access(rootDir, F_OK) == 0) {
if (0 == tsEnableVnodeBak) { if (0 == tsEnableVnodeBak) {
vInfo("vgId:%d, vnode backup not enabled", pVnode->vgId); vInfo("vgId:%d, vnode backup not enabled", pVnode->vgId);
} else { } else {
...@@ -406,6 +414,10 @@ void vnodeRelease(void *pVnodeRaw) { ...@@ -406,6 +414,10 @@ void vnodeRelease(void *pVnodeRaw) {
} }
taosRemoveDir(rootDir); taosRemoveDir(rootDir);
}
}
}
dnodeSendStatusMsgToMnode(); dnodeSendStatusMsgToMnode();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册