dnodeInt.c 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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
#include "os.h"
18
#if 0
19 20 21 22
#include "qScript.h"
#include "tfile.h"
#include "tsync.h"
#include "twal.h"
23 24
#endif
#include "tstep.h"
25 26 27 28 29 30
#include "dnodeCfg.h"
#include "dnodeCheck.h"
#include "dnodeEps.h"
#include "dnodeMain.h"
#include "dnodeMnodeEps.h"
#include "dnodeStatus.h"
31
#include "dnodeTelem.h"
32 33 34 35
#include "dnodeTrans.h"
#include "mnode.h"
#include "vnode.h"

36 37 38
static Dnode tsDnode = {0};

Dnode *dnodeInst() { return &tsDnode; }
39

40
static int32_t dnodeInitVnodeModule(void **unused) {
41 42 43 44 45
  SVnodePara para;
  para.fp.GetDnodeEp = dnodeGetDnodeEp;
  para.fp.SendMsgToDnode = dnodeSendMsgToDnode;
  para.fp.SendMsgToMnode = dnodeSendMsgToMnode;

46
  return vnodeInit(para);
47 48
}

49 50
static int32_t dnodeInitMnodeModule(void **unused) {
  Dnode *dnode = dnodeInst();
51 52 53 54 55 56 57 58 59

  SMnodePara para;
  para.fp.GetDnodeEp = dnodeGetDnodeEp;
  para.fp.SendMsgToDnode = dnodeSendMsgToDnode;
  para.fp.SendMsgToMnode = dnodeSendMsgToMnode;
  para.fp.SendRedirectMsg = dnodeSendRedirectMsg;
  para.dnodeId = dnode->cfg->dnodeId;
  strncpy(para.clusterId, dnode->cfg->clusterId, sizeof(para.clusterId));

60
  return mnodeInit(para);
61 62
}

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
int32_t dnodeInit() {
  struct SSteps *steps = taosStepInit(24, dnodeReportStartup);
  if (steps == NULL) return -1;

  Dnode *dnode = dnodeInst();

  taosStepAdd(steps, "dnode-main", (void **)&dnode->main, (InitFp)dnodeInitMain, (CleanupFp)dnodeCleanupMain);
  taosStepAdd(steps, "dnode-storage", NULL, (InitFp)dnodeInitStorage, (CleanupFp)dnodeCleanupStorage);
  //taosStepAdd(steps, "dnode-tfs-env", NULL, (InitFp)tfInit, (CleanupFp)tfCleanup);
  taosStepAdd(steps, "dnode-rpc-env", NULL, (InitFp)rpcInit, (CleanupFp)rpcCleanup);
  taosStepAdd(steps, "dnode-check", (void **)&dnode->check, (InitFp)dnodeInitCheck, (CleanupFp)dnodeCleanupCheck);
  taosStepAdd(steps, "dnode-cfg", (void **)&dnode->cfg, (InitFp)dnodeInitCfg, (CleanupFp)dnodeCleanupCfg);
  taosStepAdd(steps, "dnode-deps", (void **)&dnode->eps, (InitFp)dnodeInitEps, (CleanupFp)dnodeCleanupEps);
  taosStepAdd(steps, "dnode-meps", (void **)&dnode->meps, (InitFp)dnodeInitMnodeEps, (CleanupFp)dnodeCleanupMnodeEps);
  //taosStepAdd(steps, "dnode-wal", NULL, (InitFp)walInit, (CleanupFp)walCleanUp);
  //taosStepAdd(steps, "dnode-sync", NULL, (InitFp)syncInit, (CleanupFp)syncCleanUp);
  taosStepAdd(steps, "dnode-vnode", NULL, (InitFp)dnodeInitVnodeModule, (CleanupFp)vnodeCleanup);
  taosStepAdd(steps, "dnode-mnode", NULL, (InitFp)dnodeInitMnodeModule, (CleanupFp)mnodeCleanup);
  taosStepAdd(steps, "dnode-trans", (void **)&dnode->trans, (InitFp)dnodeInitTrans, (CleanupFp)dnodeCleanupTrans);
  taosStepAdd(steps, "dnode-status", (void **)&dnode->status, (InitFp)dnodeInitStatus, (CleanupFp)dnodeCleanupStatus);
  taosStepAdd(steps, "dnode-telem", (void **)&dnode->meps, (InitFp)dnodeInitTelem, (CleanupFp)dnodeCleanupTelem);
  //taosStepAdd(steps, "dnode-script", NULL, (InitFp)scriptEnvPoolInit, (CleanupFp)scriptEnvPoolCleanup);
85 86 87 88 89 90

  dnode->steps = steps;
  taosStepExec(dnode->steps);

  if (dnode->main) {
    dnode->main->runStatus = TD_RUN_STAT_RUNNING;
91
    dnodeReportStartupFinished("TDengine", "initialized successfully");
92 93 94
    dInfo("TDengine is initialized successfully");
  }

95
  return 0;
96 97
}

98 99
void dnodeCleanup() {
  Dnode *dnode = dnodeInst();
100 101 102 103 104
  if (dnode->main->runStatus != TD_RUN_STAT_STOPPED) {
    dnode->main->runStatus = TD_RUN_STAT_STOPPED;
    taosStepCleanup(dnode->steps);
  }
}