2022-01-06 23:34:51 +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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "dataSinkMgt.h"
|
|
|
|
|
#include "dataSinkInt.h"
|
|
|
|
|
#include "planner.h"
|
2022-10-13 05:41:36 +00:00
|
|
|
#include "tarray.h"
|
2022-01-06 23:34:51 +00:00
|
|
|
|
2024-05-16 15:30:35 +00:00
|
|
|
SDataSinkStat gDataSinkStat = {0};
|
2022-01-07 20:02:33 +00:00
|
|
|
|
2023-08-22 10:29:25 +00:00
|
|
|
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg, SStorageAPI* pAPI, void** ppSinkManager) {
|
|
|
|
|
SDataSinkManager* pSinkManager = taosMemoryMalloc(sizeof(SDataSinkManager));
|
|
|
|
|
if (NULL == pSinkManager) {
|
2024-07-22 10:42:43 +00:00
|
|
|
return terrno;
|
2023-08-22 10:29:25 +00:00
|
|
|
}
|
2024-05-16 15:30:35 +00:00
|
|
|
|
2023-08-22 10:29:25 +00:00
|
|
|
pSinkManager->cfg = *cfg;
|
|
|
|
|
pSinkManager->pAPI = pAPI;
|
|
|
|
|
|
|
|
|
|
*ppSinkManager = pSinkManager;
|
2024-07-22 10:42:43 +00:00
|
|
|
return TSDB_CODE_SUCCESS; // to avoid compiler eror
|
2022-01-06 23:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-13 05:41:36 +00:00
|
|
|
int32_t dsDataSinkGetCacheSize(SDataSinkStat* pStat) {
|
2022-05-31 06:03:47 +00:00
|
|
|
pStat->cachedSize = atomic_load_64(&gDataSinkStat.cachedSize);
|
|
|
|
|
|
2024-07-22 10:42:43 +00:00
|
|
|
return TSDB_CODE_SUCCESS;
|
2022-05-31 06:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-22 10:29:25 +00:00
|
|
|
int32_t dsCreateDataSinker(void* pSinkManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam, const char* id) {
|
|
|
|
|
SDataSinkManager* pManager = pSinkManager;
|
2022-07-02 09:40:23 +00:00
|
|
|
switch ((int)nodeType(pDataSink)) {
|
2022-06-06 12:59:36 +00:00
|
|
|
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
2023-08-22 10:29:25 +00:00
|
|
|
return createDataDispatcher(pManager, pDataSink, pHandle);
|
2023-02-28 08:28:02 +00:00
|
|
|
case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
|
2023-08-22 10:29:25 +00:00
|
|
|
return createDataDeleter(pManager, pDataSink, pHandle, pParam);
|
2023-02-28 08:28:02 +00:00
|
|
|
}
|
|
|
|
|
case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
|
2023-08-22 10:29:25 +00:00
|
|
|
return createDataInserter(pManager, pDataSink, pHandle, pParam);
|
2023-02-28 08:28:02 +00:00
|
|
|
}
|
2023-08-22 10:40:42 +00:00
|
|
|
default:
|
|
|
|
|
break;
|
2022-01-06 23:34:51 +00:00
|
|
|
}
|
2022-10-21 06:00:46 +00:00
|
|
|
|
2023-08-22 10:40:42 +00:00
|
|
|
taosMemoryFree(pSinkManager);
|
2022-10-21 06:00:46 +00:00
|
|
|
qError("invalid input node type:%d, %s", nodeType(pDataSink), id);
|
2024-07-22 10:42:43 +00:00
|
|
|
|
2022-10-21 06:00:46 +00:00
|
|
|
return TSDB_CODE_QRY_INVALID_INPUT;
|
2022-01-06 23:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-11 07:56:24 +00:00
|
|
|
int32_t dsPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* pContinue) {
|
2022-01-06 23:34:51 +00:00
|
|
|
SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
|
2022-01-11 07:56:24 +00:00
|
|
|
return pHandleImpl->fPut(pHandleImpl, pInput, pContinue);
|
2022-01-06 23:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-18 06:12:25 +00:00
|
|
|
void dsEndPut(DataSinkHandle handle, uint64_t useconds) {
|
2022-01-07 20:02:33 +00:00
|
|
|
SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
|
2022-01-11 07:56:24 +00:00
|
|
|
return pHandleImpl->fEndPut(pHandleImpl, useconds);
|
2022-01-06 23:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-26 05:54:58 +00:00
|
|
|
void dsReset(DataSinkHandle handle) {
|
|
|
|
|
SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
|
|
|
|
|
if (pHandleImpl->fReset) {
|
|
|
|
|
return pHandleImpl->fReset(pHandleImpl);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 07:55:48 +00:00
|
|
|
void dsGetDataLength(DataSinkHandle handle, int64_t* pLen, int64_t* pRawLen, bool* pQueryEnd) {
|
2022-01-06 23:34:51 +00:00
|
|
|
SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
|
2024-05-16 07:55:48 +00:00
|
|
|
pHandleImpl->fGetLen(pHandleImpl, pLen, pRawLen, pQueryEnd);
|
2022-01-06 23:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-11 07:56:24 +00:00
|
|
|
int32_t dsGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) {
|
2022-01-07 20:02:33 +00:00
|
|
|
SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
|
2022-01-11 07:56:24 +00:00
|
|
|
return pHandleImpl->fGetData(pHandleImpl, pOutput);
|
2022-01-06 23:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-13 05:41:36 +00:00
|
|
|
int32_t dsGetCacheSize(DataSinkHandle handle, uint64_t* pSize) {
|
2022-05-31 06:03:47 +00:00
|
|
|
SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
|
|
|
|
|
return pHandleImpl->fGetCacheSize(pHandleImpl, pSize);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-06 23:34:51 +00:00
|
|
|
void dsScheduleProcess(void* ahandle, void* pItem) {
|
|
|
|
|
// todo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dsDestroyDataSinker(DataSinkHandle handle) {
|
|
|
|
|
SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
|
2024-07-22 10:42:43 +00:00
|
|
|
(void)pHandleImpl->fDestroy(pHandleImpl);
|
2022-05-06 14:11:33 +00:00
|
|
|
taosMemoryFree(pHandleImpl);
|
2022-01-06 23:34:51 +00:00
|
|
|
}
|