qmInt.c 2.6 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
shm  
Shengliang Guan 已提交
26 27 28 29 30 31
  if (pMgmt->pQnode != NULL) {
    qmStopWorker(pMgmt);
    qndClose(pMgmt->pQnode);
    pMgmt->pQnode = NULL;
  }

wafwerar's avatar
wafwerar 已提交
32
  taosMemoryFree(pMgmt);
S
shm  
Shengliang Guan 已提交
33 34
}

S
Shengliang Guan 已提交
35
static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
wafwerar's avatar
wafwerar 已提交
36
  SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt));
S
shm  
Shengliang Guan 已提交
37 38 39 40 41
  if (pMgmt == NULL) {
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return -1;
  }

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

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

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

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

S
Shengliang 已提交
74
  pOutput->pMgmt = pMgmt;
S
Shengliang Guan 已提交
75
  return 0;
S
shm  
Shengliang Guan 已提交
76 77
}

S
Shengliang 已提交
78 79 80 81 82 83 84 85
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 已提交
86

S
Shengliang 已提交
87
  return mgmtFunc;
S
shm  
Shengliang Guan 已提交
88
}