2022-03-14 05:24:15 +00:00
|
|
|
/*
|
|
|
|
|
* 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 "smInt.h"
|
2022-05-09 06:18:27 +00:00
|
|
|
#include "libs/function/function.h"
|
2023-09-26 03:47:53 +00:00
|
|
|
#include "libs/function/tudf.h"
|
2022-03-14 05:24:15 +00:00
|
|
|
|
2022-05-11 09:48:38 +00:00
|
|
|
static int32_t smRequire(const SMgmtInputOpt *pInput, bool *required) {
|
|
|
|
|
return dmReadFile(pInput->path, pInput->name, required);
|
2022-03-18 05:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:48:38 +00:00
|
|
|
static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { pOption->msgCb = pMgmt->msgCb; }
|
2022-03-18 05:37:19 +00:00
|
|
|
|
2022-05-11 09:48:38 +00:00
|
|
|
static void smClose(SSnodeMgmt *pMgmt) {
|
2022-03-18 05:37:19 +00:00
|
|
|
if (pMgmt->pSnode != NULL) {
|
|
|
|
|
smStopWorker(pMgmt);
|
|
|
|
|
sndClose(pMgmt->pSnode);
|
|
|
|
|
pMgmt->pSnode = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 16:29:53 +00:00
|
|
|
taosMemoryFree(pMgmt);
|
2022-03-18 05:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-14 10:16:52 +00:00
|
|
|
int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
2022-03-25 16:29:53 +00:00
|
|
|
SSnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SSnodeMgmt));
|
2022-03-18 05:37:19 +00:00
|
|
|
if (pMgmt == NULL) {
|
|
|
|
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 13:36:29 +00:00
|
|
|
pMgmt->pData = pInput->pData;
|
2022-05-11 09:48:38 +00:00
|
|
|
pMgmt->path = pInput->path;
|
|
|
|
|
pMgmt->name = pInput->name;
|
|
|
|
|
pMgmt->msgCb = pInput->msgCb;
|
2022-05-16 15:23:49 +00:00
|
|
|
pMgmt->msgCb.mgmt = pMgmt;
|
2022-10-28 09:03:17 +00:00
|
|
|
pMgmt->msgCb.putToQueueFp = (PutToQueueFp)smPutMsgToQueue;
|
2022-03-18 05:37:19 +00:00
|
|
|
|
2022-04-13 13:00:43 +00:00
|
|
|
SSnodeOpt option = {0};
|
|
|
|
|
smInitOption(pMgmt, &option);
|
|
|
|
|
pMgmt->pSnode = sndOpen(pMgmt->path, &option);
|
|
|
|
|
if (pMgmt->pSnode == NULL) {
|
|
|
|
|
dError("failed to open snode since %s", terrstr());
|
2022-05-11 09:48:38 +00:00
|
|
|
smClose(pMgmt);
|
2022-04-13 13:00:43 +00:00
|
|
|
return -1;
|
2022-03-18 05:37:19 +00:00
|
|
|
}
|
2023-04-14 04:00:09 +00:00
|
|
|
|
2022-05-11 09:48:38 +00:00
|
|
|
tmsgReportStartup("snode-impl", "initialized");
|
2022-03-18 05:37:19 +00:00
|
|
|
|
2022-04-13 13:00:43 +00:00
|
|
|
if (smStartWorker(pMgmt) != 0) {
|
|
|
|
|
dError("failed to start snode worker since %s", terrstr());
|
2022-05-11 09:48:38 +00:00
|
|
|
smClose(pMgmt);
|
2022-04-13 13:00:43 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2022-05-11 09:48:38 +00:00
|
|
|
tmsgReportStartup("snode-worker", "initialized");
|
2022-04-13 13:00:43 +00:00
|
|
|
|
2022-05-09 06:18:27 +00:00
|
|
|
if (udfcOpen() != 0) {
|
|
|
|
|
dError("failed to open udfc in snode");
|
2022-05-11 09:48:38 +00:00
|
|
|
smClose(pMgmt);
|
|
|
|
|
return -1;
|
2022-05-09 06:18:27 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:48:38 +00:00
|
|
|
pOutput->pMgmt = pMgmt;
|
2022-04-13 13:00:43 +00:00
|
|
|
return 0;
|
2022-03-18 05:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:48:38 +00:00
|
|
|
SMgmtFunc smGetMgmtFunc() {
|
|
|
|
|
SMgmtFunc mgmtFunc = {0};
|
|
|
|
|
mgmtFunc.openFp = smOpen;
|
|
|
|
|
mgmtFunc.closeFp = (NodeCloseFp)smClose;
|
|
|
|
|
mgmtFunc.createFp = (NodeCreateFp)smProcessCreateReq;
|
|
|
|
|
mgmtFunc.dropFp = (NodeDropFp)smProcessDropReq;
|
|
|
|
|
mgmtFunc.requiredFp = smRequire;
|
|
|
|
|
mgmtFunc.getHandlesFp = smGetMsgHandles;
|
2022-03-14 13:08:15 +00:00
|
|
|
|
2022-05-11 09:48:38 +00:00
|
|
|
return mgmtFunc;
|
2022-03-14 05:24:15 +00:00
|
|
|
}
|