dmEnv.c 1.7 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 Guan 已提交
17
#include "dmInt.h"
S
xshm  
Shengliang Guan 已提交
18
#include "wal.h"
S
shm  
Shengliang Guan 已提交
19

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

S
shm  
Shengliang Guan 已提交
22
int32_t dndInit() {
S
Shengliang Guan 已提交
23
  dDebug("start to init dnode env");
S
shm  
Shengliang Guan 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
    terrno = TSDB_CODE_REPEAT_INIT;
    dError("failed to init dnode env since %s", terrstr());
    return -1;
  }

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

  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
shm  
Shengliang Guan 已提交
44
  dInfo("dnode env is initialized");
S
shm  
Shengliang Guan 已提交
45 46 47 48
  return 0;
}

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

  monCleanup();
S
shm  
Shengliang Guan 已提交
56
  walCleanUp();
S
shm  
Shengliang Guan 已提交
57
  taosStopCacheRefreshWorker();
S
shm  
Shengliang Guan 已提交
58
  dInfo("dnode env is cleaned up");
S
shm  
Shengliang Guan 已提交
59
}