dmEnv.c 1.6 KB
Newer Older
S
shm  
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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/>.
 */

#define _DEFAULT_SOURCE
S
Shengliang 已提交
17
#include "dmUtil.h"
S
shm  
Shengliang Guan 已提交
18

S
shm  
Shengliang Guan 已提交
19 20
static int8_t once = DND_ENV_INIT;

S
Shengliang Guan 已提交
21
int32_t dmInit() {
S
Shengliang Guan 已提交
22
  dInfo("start to init env");
S
shm  
Shengliang Guan 已提交
23
  if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
S
Shengliang Guan 已提交
24
    dError("env is already initialized");
S
shm  
Shengliang Guan 已提交
25 26 27 28 29 30 31 32
    terrno = TSDB_CODE_REPEAT_INIT;
    return -1;
  }

  taosIgnSIGPIPE();
  taosBlockSIGPIPE();
  taosResolveCRC();

S
Shengliang 已提交
33 34 35 36 37 38 39 40 41 42
  SMonCfg monCfg = {0};
  monCfg.maxLogs = tsMonitorMaxLogs;
  monCfg.port = tsMonitorPort;
  monCfg.server = tsMonitorFqdn;
  monCfg.comp = tsMonitorComp;
  if (monInit(&monCfg) != 0) {
    dError("failed to init monitor since %s", terrstr());
    return -1;
  }

S
Shengliang Guan 已提交
43
  dInfo("env is initialized");
S
shm  
Shengliang Guan 已提交
44 45 46
  return 0;
}

S
Shengliang Guan 已提交
47
void dmCleanup() {
S
Shengliang Guan 已提交
48
  dDebug("start to cleanup env");
S
shm  
Shengliang Guan 已提交
49
  if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) {
S
Shengliang Guan 已提交
50
    dError("env is already cleaned up");
S
shm  
Shengliang Guan 已提交
51 52 53 54
    return;
  }

  monCleanup();
S
Shengliang Guan 已提交
55
  syncCleanUp();
S
shm  
Shengliang Guan 已提交
56
  walCleanUp();
S
Shengliang Guan 已提交
57
  udfcClose();
S
Shengliang 已提交
58
  udfStopUdfd();
S
shm  
Shengliang Guan 已提交
59
  taosStopCacheRefreshWorker();
S
Shengliang Guan 已提交
60
  dInfo("env is cleaned up");
S
shm  
Shengliang Guan 已提交
61
}