qmInt.c 2.5 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
  pMgmt->path = pInput->path;
  pMgmt->name = pInput->name;
  pMgmt->msgCb = pInput->msgCb;
S
Shengliang Guan 已提交
46
  pMgmt->msgCb.putToQueueFp = (PutToQueueFp)qmPutRpcMsgToQueue;
S
Shengliang 已提交
47
  pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)qmGetQueueSize;
48
  pMgmt->msgCb.mgmt = pMgmt;
S
shm  
Shengliang Guan 已提交
49

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

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

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

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

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

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