dataSinkMgt.c 2.8 KB
Newer Older
X
Xiaoyu Wang 已提交
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/>.
 */

#include "dataSinkMgt.h"
#include "dataSinkInt.h"
#include "planner.h"
H
Hongze Cheng 已提交
19
#include "tarray.h"
X
Xiaoyu Wang 已提交
20

21
static SDataSinkManager gDataSinkManager = {0};
H
Hongze Cheng 已提交
22
SDataSinkStat           gDataSinkStat = {0};
23

H
Hongze Cheng 已提交
24
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg) {
25
  gDataSinkManager.cfg = *cfg;
wafwerar's avatar
wafwerar 已提交
26
  taosThreadMutexInit(&gDataSinkManager.mutex, NULL);
H
Hongze Cheng 已提交
27
  return 0;  // to avoid compiler eror
X
Xiaoyu Wang 已提交
28 29
}

H
Hongze Cheng 已提交
30
int32_t dsDataSinkGetCacheSize(SDataSinkStat* pStat) {
D
dapan1121 已提交
31 32 33 34 35
  pStat->cachedSize = atomic_load_64(&gDataSinkStat.cachedSize);

  return 0;
}

H
Hongze Cheng 已提交
36
int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam) {
wafwerar's avatar
wafwerar 已提交
37
  switch ((int)nodeType(pDataSink)) {
D
dapan1121 已提交
38 39 40 41
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
      return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle);
    case QUERY_NODE_PHYSICAL_PLAN_DELETE:
      return createDataDeleter(&gDataSinkManager, pDataSink, pHandle, pParam);
D
dapan1121 已提交
42 43
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT:
      return createDataInserter(&gDataSinkManager, pDataSink, pHandle, pParam);
X
Xiaoyu Wang 已提交
44 45 46 47
  }
  return TSDB_CODE_FAILED;
}

X
Xiaoyu Wang 已提交
48
int32_t dsPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* pContinue) {
X
Xiaoyu Wang 已提交
49
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
X
Xiaoyu Wang 已提交
50
  return pHandleImpl->fPut(pHandleImpl, pInput, pContinue);
X
Xiaoyu Wang 已提交
51 52
}

D
dapan1121 已提交
53
void dsEndPut(DataSinkHandle handle, uint64_t useconds) {
54
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
X
Xiaoyu Wang 已提交
55
  return pHandleImpl->fEndPut(pHandleImpl, useconds);
X
Xiaoyu Wang 已提交
56 57
}

D
dapan1121 已提交
58
void dsGetDataLength(DataSinkHandle handle, int64_t* pLen, bool* pQueryEnd) {
X
Xiaoyu Wang 已提交
59
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
X
Xiaoyu Wang 已提交
60
  pHandleImpl->fGetLen(pHandleImpl, pLen, pQueryEnd);
X
Xiaoyu Wang 已提交
61 62
}

X
Xiaoyu Wang 已提交
63
int32_t dsGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) {
64
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
X
Xiaoyu Wang 已提交
65
  return pHandleImpl->fGetData(pHandleImpl, pOutput);
X
Xiaoyu Wang 已提交
66 67
}

H
Hongze Cheng 已提交
68
int32_t dsGetCacheSize(DataSinkHandle handle, uint64_t* pSize) {
D
dapan1121 已提交
69 70 71 72
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
  return pHandleImpl->fGetCacheSize(pHandleImpl, pSize);
}

X
Xiaoyu Wang 已提交
73 74 75 76 77 78 79
void dsScheduleProcess(void* ahandle, void* pItem) {
  // todo
}

void dsDestroyDataSinker(DataSinkHandle handle) {
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
  pHandleImpl->fDestroy(pHandleImpl);
D
dapan1121 已提交
80
  taosMemoryFree(pHandleImpl);
X
Xiaoyu Wang 已提交
81
}