TDengine/source/dnode/vnode/src/vnd/vnodeModule.c

57 lines
1.4 KiB
C
Raw Normal View History

2022-04-14 05:53:45 +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-11-02 12:13:29 +00:00
#include "cos.h"
2022-04-26 11:04:26 +00:00
#include "vnd.h"
2022-04-14 05:53:45 +00:00
2023-11-29 10:01:31 +00:00
static volatile int32_t VINIT = 0;
2022-04-14 05:53:45 +00:00
2023-11-29 10:01:31 +00:00
SVAsync* vnodeAsyncHandle[2];
2022-04-14 05:53:45 +00:00
int vnodeInit(int nthreads) {
2023-11-29 10:01:31 +00:00
int32_t init;
2022-04-14 05:53:45 +00:00
2023-11-29 10:01:31 +00:00
init = atomic_val_compare_exchange_32(&VINIT, 0, 1);
2022-04-14 05:53:45 +00:00
if (init) {
return 0;
}
2023-11-29 10:01:31 +00:00
// vnode-commit
vnodeAsyncInit(&vnodeAsyncHandle[0], "vnode-commit");
vnodeAsyncSetWorkers(vnodeAsyncHandle[0], nthreads);
2022-10-14 05:34:25 +00:00
2023-11-29 10:01:31 +00:00
// vnode-merge
vnodeAsyncInit(&vnodeAsyncHandle[1], "vnode-merge");
vnodeAsyncSetWorkers(vnodeAsyncHandle[1], nthreads);
2022-04-14 05:53:45 +00:00
if (walInit() < 0) {
return -1;
}
return 0;
}
void vnodeCleanup() {
2023-11-29 10:01:31 +00:00
int32_t init = atomic_val_compare_exchange_32(&VINIT, 1, 0);
2022-04-14 05:53:45 +00:00
if (init == 0) return;
// set stop
2023-11-29 10:01:31 +00:00
vnodeAsyncDestroy(&vnodeAsyncHandle[0]);
vnodeAsyncDestroy(&vnodeAsyncHandle[1]);
2022-04-14 05:53:45 +00:00
2022-06-01 11:57:03 +00:00
walCleanUp();
2022-07-09 07:44:37 +00:00
smaCleanUp();
2022-04-14 05:53:45 +00:00
}