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

S
Shengliang 已提交
19 20
static int32_t qmRequire(const SMgmtInputOpt *pInput, bool *required) {
  return dmReadFile(pInput->path, pInput->name, required);
S
shm  
Shengliang Guan 已提交
21 22
}

S
Shengliang 已提交
23
static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) { pOption->msgCb = pMgmt->msgCb; }
S
shm  
Shengliang Guan 已提交
24

S
Shengliang 已提交
25
static void qmClose(SQnodeMgmt *pMgmt) {
S
Shengliang Guan 已提交
26
  dInfo("qnode-mgmt start to cleanup");
S
shm  
Shengliang Guan 已提交
27 28 29 30 31 32
  if (pMgmt->pQnode != NULL) {
    qmStopWorker(pMgmt);
    qndClose(pMgmt->pQnode);
    pMgmt->pQnode = NULL;
  }

wafwerar's avatar
wafwerar 已提交
33
  taosMemoryFree(pMgmt);
S
shm  
Shengliang Guan 已提交
34 35 36
  dInfo("qnode-mgmt is cleaned up");
}

S
Shengliang 已提交
37
static int32_t qmOpen(const SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
S
shm  
Shengliang Guan 已提交
38
  dInfo("qnode-mgmt start to init");
wafwerar's avatar
wafwerar 已提交
39
  SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt));
S
shm  
Shengliang Guan 已提交
40 41 42 43 44
  if (pMgmt == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

S
Shengliang 已提交
45 46 47 48 49 50 51 52
  pMgmt->path = pInput->path;
  pMgmt->name = pInput->name;
  pMgmt->dnodeId = pInput->dnodeId;
  pMgmt->msgCb = pInput->msgCb;
  pMgmt->msgCb.queueFps[QUERY_QUEUE] = (PutToQueueFp)qmPutRpcMsgToQueryQueue;
  pMgmt->msgCb.queueFps[FETCH_QUEUE] = (PutToQueueFp)qmPutRpcMsgToFetchQueue;
  pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)qmGetQueueSize;
  pMgmt->msgCb.pMgmt = pMgmt;
S
shm  
Shengliang Guan 已提交
53

S
Shengliang Guan 已提交
54 55 56 57 58
  SQnodeOpt option = {0};
  qmInitOption(pMgmt, &option);
  pMgmt->pQnode = qndOpen(&option);
  if (pMgmt->pQnode == NULL) {
    dError("failed to open qnode since %s", terrstr());
S
Shengliang 已提交
59
    qmClose(pMgmt);
S
Shengliang Guan 已提交
60
    return -1;
S
shm  
Shengliang Guan 已提交
61
  }
S
Shengliang 已提交
62
  tmsgReportStartup("qnode-impl", "initialized");
S
shm  
Shengliang Guan 已提交
63

S
Shengliang 已提交
64 65 66 67 68 69
  if (udfcOpen() != 0) {
    dError("qnode can not open udfc");
    qmClose(pMgmt);
    return -1;
  }

S
Shengliang Guan 已提交
70 71
  if (qmStartWorker(pMgmt) != 0) {
    dError("failed to start qnode worker since %s", terrstr());
S
Shengliang 已提交
72
    qmClose(pMgmt);
S
Shengliang Guan 已提交
73 74
    return -1;
  }
S
Shengliang 已提交
75
  tmsgReportStartup("qnode-worker", "initialized");
S
Shengliang Guan 已提交
76

S
Shengliang 已提交
77
  pOutput->pMgmt = pMgmt;
S
Shengliang Guan 已提交
78 79
  dInfo("qnode-mgmt is initialized");
  return 0;
S
shm  
Shengliang Guan 已提交
80 81
}

S
Shengliang 已提交
82 83 84 85 86 87 88 89
SMgmtFunc qmGetMgmtFunc() {
  SMgmtFunc mgmtFunc = {0};
  mgmtFunc.openFp = qmOpen;
  mgmtFunc.closeFp = (NodeCloseFp)qmClose;
  mgmtFunc.createFp = (NodeCreateFp)qmProcessCreateReq;
  mgmtFunc.dropFp = (NodeDropFp)qmProcessDropReq;
  mgmtFunc.requiredFp = qmRequire;
  mgmtFunc.getHandlesFp = qmGetMsgHandles;
S
shm  
Shengliang Guan 已提交
90

S
Shengliang 已提交
91
  return mgmtFunc;
S
shm  
Shengliang Guan 已提交
92
}