dmInt.c 2.5 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * 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 "dmInt.h"

static int32_t dmStartMgmt(SDnodeMgmt *pMgmt) {
  if (dmStartStatusThread(pMgmt) != 0) {
    return -1;
  }
  if (dmStartMonitorThread(pMgmt) != 0) {
    return -1;
  }
D
dapan1121 已提交
26 27 28
  if (dmStartCrashReportThread(pMgmt) != 0) {
    return -1;
  }
S
Shengliang Guan 已提交
29 30 31 32
  return 0;
}

static void dmStopMgmt(SDnodeMgmt *pMgmt) {
S
Shengliang Guan 已提交
33
  pMgmt->pData->stopped = true;
S
Shengliang Guan 已提交
34 35
  dmStopMonitorThread(pMgmt);
  dmStopStatusThread(pMgmt);
D
dapan1121 已提交
36
  dmStopCrashReportThread(pMgmt);
S
Shengliang Guan 已提交
37 38
}

S
Shengliang Guan 已提交
39
static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
S
Shengliang Guan 已提交
40 41 42 43 44 45
  SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt));
  if (pMgmt == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

S
Shengliang Guan 已提交
46
  pMgmt->pData = pInput->pData;
S
Shengliang Guan 已提交
47 48 49
  pMgmt->msgCb = pInput->msgCb;
  pMgmt->path = pInput->path;
  pMgmt->name = pInput->name;
S
Shengliang Guan 已提交
50
  pMgmt->processCreateNodeFp = pInput->processCreateNodeFp;
C
cadem 已提交
51
  pMgmt->processAlterNodeTypeFp = pInput->processAlterNodeTypeFp;
S
Shengliang Guan 已提交
52
  pMgmt->processDropNodeFp = pInput->processDropNodeFp;
S
Shengliang Guan 已提交
53 54 55
  pMgmt->sendMonitorReportFp = pInput->sendMonitorReportFp;
  pMgmt->getVnodeLoadsFp = pInput->getVnodeLoadsFp;
  pMgmt->getMnodeLoadsFp = pInput->getMnodeLoadsFp;
D
dapan1121 已提交
56
  pMgmt->getQnodeLoadsFp = pInput->getQnodeLoadsFp;
S
Shengliang Guan 已提交
57 58 59 60 61

  if (dmStartWorker(pMgmt) != 0) {
    return -1;
  }

S
Shengliang Guan 已提交
62
  if (udfStartUdfd(pMgmt->pData->dnodeId) != 0) {
S
Shengliang Guan 已提交
63 64 65
    dError("failed to start udfd");
  }

S
Shengliang Guan 已提交
66
  pOutput->pMgmt = pMgmt;
S
Shengliang Guan 已提交
67 68 69 70 71
  return 0;
}

static void dmCloseMgmt(SDnodeMgmt *pMgmt) {
  dmStopWorker(pMgmt);
S
Shengliang Guan 已提交
72
  taosMemoryFree(pMgmt);
S
Shengliang Guan 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
}

static int32_t dmRequireMgmt(const SMgmtInputOpt *pInput, bool *required) {
  *required = true;
  return 0;
}

SMgmtFunc dmGetMgmtFunc() {
  SMgmtFunc mgmtFunc = {0};
  mgmtFunc.openFp = dmOpenMgmt;
  mgmtFunc.closeFp = (NodeCloseFp)dmCloseMgmt;
  mgmtFunc.startFp = (NodeStartFp)dmStartMgmt;
  mgmtFunc.stopFp = (NodeStopFp)dmStopMgmt;
  mgmtFunc.requiredFp = dmRequireMgmt;
  mgmtFunc.getHandlesFp = dmGetMsgHandles;

  return mgmtFunc;
}