TDengine/source/dnode/vnode/impl/src/vnodeMain.c

148 lines
3.4 KiB
C
Raw Normal View History

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/>.
*/
#include "vnodeDef.h"
2021-11-22 07:02:53 +00:00
static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg);
2021-11-08 02:04:24 +00:00
static void vnodeFree(SVnode *pVnode);
2021-11-08 02:17:51 +00:00
static int vnodeOpenImpl(SVnode *pVnode);
static void vnodeCloseImpl(SVnode *pVnode);
2021-11-08 02:04:24 +00:00
2021-11-22 07:02:53 +00:00
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
2021-11-07 07:58:32 +00:00
SVnode *pVnode = NULL;
2021-11-08 02:04:24 +00:00
// Set default options
2021-11-22 07:02:53 +00:00
if (pVnodeCfg == NULL) {
pVnodeCfg = &defaultVnodeOptions;
2021-11-08 02:04:24 +00:00
}
// Validate options
2021-11-22 07:02:53 +00:00
if (vnodeValidateOptions(pVnodeCfg) < 0) {
2021-11-08 02:04:24 +00:00
// TODO
return NULL;
}
2021-11-08 02:17:51 +00:00
// Create the handle
2021-11-22 07:02:53 +00:00
pVnode = vnodeNew(path, pVnodeCfg);
2021-11-08 02:04:24 +00:00
if (pVnode == NULL) {
// TODO: handle error
return NULL;
}
taosMkDir(path);
2021-11-08 02:17:51 +00:00
// Open the vnode
if (vnodeOpenImpl(pVnode) < 0) {
// TODO: handle error
return NULL;
}
2021-11-07 07:58:32 +00:00
return pVnode;
}
2021-11-08 02:17:51 +00:00
void vnodeClose(SVnode *pVnode) {
if (pVnode) {
vnodeCloseImpl(pVnode);
vnodeFree(pVnode);
}
2021-11-08 02:04:24 +00:00
}
void vnodeDestroy(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */
2021-11-22 07:02:53 +00:00
static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg) {
2021-11-08 02:17:51 +00:00
SVnode *pVnode = NULL;
pVnode = (SVnode *)calloc(1, sizeof(*pVnode));
if (pVnode == NULL) {
// TODO
return NULL;
}
pVnode->path = strdup(path);
2021-11-22 07:02:53 +00:00
vnodeOptionsCopy(&(pVnode->config), pVnodeCfg);
2021-11-08 02:17:51 +00:00
2021-12-20 08:52:39 +00:00
tsem_init(&(pVnode->canCommit), 0, 1);
2021-11-08 05:55:51 +00:00
return pVnode;
2021-11-07 07:58:32 +00:00
}
2021-11-08 02:04:24 +00:00
static void vnodeFree(SVnode *pVnode) {
if (pVnode) {
2021-12-20 08:52:39 +00:00
tsem_destroy(&(pVnode->canCommit));
2021-11-08 02:17:51 +00:00
tfree(pVnode->path);
free(pVnode);
2021-11-08 02:04:24 +00:00
}
2021-11-08 02:17:51 +00:00
}
static int vnodeOpenImpl(SVnode *pVnode) {
2021-11-08 05:40:45 +00:00
char dir[TSDB_FILENAME_LEN];
2021-11-12 09:50:46 +00:00
if (vnodeOpenBufPool(pVnode) < 0) {
2021-11-08 06:50:20 +00:00
// TODO: handle error
return -1;
}
2021-11-08 05:40:45 +00:00
// Open meta
sprintf(dir, "%s/meta", pVnode->path);
2021-12-16 07:28:53 +00:00
pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaCfg), vBufPoolGetMAF(pVnode));
2021-11-08 06:21:10 +00:00
if (pVnode->pMeta == NULL) {
2021-11-08 05:40:45 +00:00
// TODO: handle error
return -1;
}
// Open tsdb
sprintf(dir, "%s/tsdb", pVnode->path);
2021-12-16 07:24:33 +00:00
pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode));
2021-11-08 06:21:10 +00:00
if (pVnode->pTsdb == NULL) {
2021-11-08 05:40:45 +00:00
// TODO: handle error
return -1;
}
// TODO: Open TQ
2021-11-29 05:44:52 +00:00
sprintf(dir, "%s/tq", pVnode->path);
2021-12-16 07:24:33 +00:00
pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, vBufPoolGetMAF(pVnode));
2021-11-24 10:37:15 +00:00
if (pVnode->pTq == NULL) {
// TODO: handle error
return -1;
}
2021-11-16 07:49:05 +00:00
// Open WAL
sprintf(dir, "%s/wal", pVnode->path);
2021-11-24 10:37:15 +00:00
pVnode->pWal = walOpen(dir, &(pVnode->config.walCfg));
2021-11-16 07:49:05 +00:00
if (pVnode->pWal == NULL) {
// TODO: handle error
return -1;
}
2021-11-08 05:40:45 +00:00
2021-12-24 01:41:09 +00:00
// Open Query
if (vnodeQueryOpen(pVnode)) {
return -1;
}
2021-11-08 02:17:51 +00:00
// TODO
return 0;
}
static void vnodeCloseImpl(SVnode *pVnode) {
2022-01-07 09:17:37 +00:00
// vnodeSyncCommit(pVnode);
2021-11-08 05:40:45 +00:00
if (pVnode) {
2021-11-16 07:49:05 +00:00
vnodeCloseBufPool(pVnode);
2021-11-08 05:40:45 +00:00
metaClose(pVnode->pMeta);
2021-12-16 07:24:33 +00:00
tsdbClose(pVnode->pTsdb);
tqClose(pVnode->pTq);
walClose(pVnode->pWal);
2021-11-08 05:40:45 +00:00
}
2021-11-08 02:04:24 +00:00
}