mgmtSystem.c 3.7 KB
Newer Older
S
slguan 已提交
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
17
#include "os.h"
S
slguan 已提交
18 19
#include "taosdef.h"
#include "tsched.h"
S
slguan 已提交
20
#include "mnode.h"
S
#1177  
slguan 已提交
21 22 23 24 25 26 27
#include "mgmtAcct.h"
#include "mgmtBalance.h"
#include "mgmtDb.h"
#include "mgmtDnode.h"
#include "mgmtDnodeInt.h"
#include "mgmtVgroup.h"
#include "mgmtUser.h"
S
slguan 已提交
28
#include "mgmtSystem.h"
S
#1177  
slguan 已提交
29 30
#include "mgmtTable.h"
#include "mgmtShell.h"
S
slguan 已提交
31

S
slguan 已提交
32 33 34 35
char tsMgmtDirectory[128] = {0};
void *tsMgmtTmr           = NULL;
void *tsMgmtTranQhandle   = NULL;
void *tsMgmtStatisTimer   = NULL;
S
slguan 已提交
36 37

void mgmtCleanUpSystem() {
S
slguan 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  mPrint("starting to clean up mgmt");

  taosTmrStopA(&tsMgmtStatisTimer);
  mgmtCleanUpRedirect();
  sdbCleanUpPeers();
  mgmtCleanupBalance();
  mgmtCleanUpDnodeInt();
  mgmtCleanUpShell();
  mgmtCleanUpMeters();
  mgmtCleanUpVgroups();
  mgmtCleanUpDbs();
  mgmtCleanUpDnodes();
  mgmtCleanUpUsers();
  mgmtCleanUpAccts();
  taosTmrCleanUp(tsMgmtTmr);
  taosCleanUpScheduler(tsMgmtTranQhandle);

  mPrint("mgmt is cleaned up");
S
slguan 已提交
56 57
}

S
slguan 已提交
58
int32_t mgmtStartSystem() {
S
slguan 已提交
59 60 61
  mPrint("starting to initialize TDengine mgmt ...");

  struct stat dirstat;
S
slguan 已提交
62 63
  if (stat(tsMgmtDirectory, &dirstat) < 0) {
    mkdir(tsMgmtDirectory, 0755);
S
slguan 已提交
64 65
  }

S
#1177  
slguan 已提交
66
  if (mgmtCheckMgmtRunning() != 0) {
S
slguan 已提交
67 68 69 70
    mPrint("TDengine mgmt module already started...");
    return 0;
  }

S
slguan 已提交
71
  tsMgmtTranQhandle = taosInitScheduler(tsMaxDnodes + tsMaxShellConns, 1, "mnodeT");
S
slguan 已提交
72

S
slguan 已提交
73 74
  tsMgmtTmr = taosTmrInit((tsMaxDnodes + tsMaxShellConns) * 3, 200, 3600000, "MND");
  if (tsMgmtTmr == NULL) {
S
slguan 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    mError("failed to init timer, exit");
    return -1;
  }

  if (mgmtInitAccts() < 0) {
    mError("failed to init accts");
    return -1;
  }

  if (mgmtInitUsers() < 0) {
    mError("failed to init users");
    return -1;
  }

  if (mgmtInitDnodes() < 0) {
    mError("failed to init dnodes");
    return -1;
  }

  if (mgmtInitDbs() < 0) {
    mError("failed to init dbs");
    return -1;
  }

  if (mgmtInitVgroups() < 0) {
    mError("failed to init vgroups");
    return -1;
  }

S
slguan 已提交
104
  if (mgmtInitTables() < 0) {
S
slguan 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118
    mError("failed to init meters");
    return -1;
  }

  if (mgmtInitDnodeInt() < 0) {
    mError("failed to init inter-mgmt communication");
    return -1;
  }

  if (mgmtInitShell() < 0) {
    mError("failed to init shell");
    return -1;
  }

S
slguan 已提交
119
  if (sdbInitPeers(tsMgmtDirectory) < 0) {
S
slguan 已提交
120 121 122 123 124 125 126 127
    mError("failed to init peers");
    return -1;
  }

  if (mgmtInitBalance() < 0) {
    mError("failed to init dnode balance")
  }

S
slguan 已提交
128
  taosTmrReset(mgmtDoStatistic, tsStatusInterval * 30000, NULL, tsMgmtTmr, &tsMgmtStatisTimer);
S
slguan 已提交
129 130 131 132 133

  mPrint("TDengine mgmt is initialized successfully");

  return 0;
}
S
#1177  
slguan 已提交
134

S
slguan 已提交
135
int32_t mgmtInitSystemImp() {
S
slguan 已提交
136 137 138 139 140 141 142
  int32_t code = mgmtStartSystem();
  if (code != 0) {
    return code;
  }

  taosTmrReset(mgmtProcessDnodeStatus, 500, NULL, tsMgmtTmr, &mgmtStatusTimer);
  return code;
S
slguan 已提交
143 144
}

S
#1177  
slguan 已提交
145 146
int32_t (*mgmtInitSystem)() = mgmtInitSystemImp;

S
slguan 已提交
147 148 149 150
int32_t mgmtCheckMgmtRunningImp() {
  return 0;
}

S
#1177  
slguan 已提交
151 152 153 154
int32_t (*mgmtCheckMgmtRunning)() = mgmtCheckMgmtRunningImp;

void mgmtDoStatisticImp(void *handle, void *tmrId) {}

S
slguan 已提交
155
void (*mgmtDoStatistic)(void *handle, void *tmrId) = mgmtDoStatisticImp;
S
#1177  
slguan 已提交
156 157

void mgmtStopSystemImp() {}
S
slguan 已提交
158

S
#1177  
slguan 已提交
159 160 161 162
void (*mgmtStopSystem)() = mgmtStopSystemImp;

void mgmtCleanUpRedirectImp() {}

S
slguan 已提交
163
void (*mgmtCleanUpRedirect)() = mgmtCleanUpRedirectImp;