dataSinkMgt.c 3.1 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

H
Hongze Cheng 已提交
21
SDataSinkStat           gDataSinkStat = {0};
22

D
dapan1121 已提交
23 24 25 26 27 28 29 30 31
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg, SStorageAPI* pAPI, void** ppSinkManager) {
  SDataSinkManager* pSinkManager = taosMemoryMalloc(sizeof(SDataSinkManager));
  if (NULL == pSinkManager) {
    return TSDB_CODE_OUT_OF_MEMORY;
  }
  pSinkManager->cfg = *cfg;
  pSinkManager->pAPI = pAPI;

  *ppSinkManager = pSinkManager;
H
Hongze Cheng 已提交
32
  return 0;  // to avoid compiler eror
X
Xiaoyu Wang 已提交
33 34
}

H
Hongze Cheng 已提交
35
int32_t dsDataSinkGetCacheSize(SDataSinkStat* pStat) {
D
dapan1121 已提交
36 37 38 39 40
  pStat->cachedSize = atomic_load_64(&gDataSinkStat.cachedSize);

  return 0;
}

D
dapan1121 已提交
41 42
int32_t dsCreateDataSinker(void* pSinkManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam, const char* id) {
  SDataSinkManager* pManager = pSinkManager;
wafwerar's avatar
wafwerar 已提交
43
  switch ((int)nodeType(pDataSink)) {
D
dapan1121 已提交
44
    case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
D
dapan1121 已提交
45
      return createDataDispatcher(pManager, pDataSink, pHandle);
46
    case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
D
dapan1121 已提交
47
      return createDataDeleter(pManager, pDataSink, pHandle, pParam);
48 49
    }
    case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
D
dapan1121 已提交
50
      return createDataInserter(pManager, pDataSink, pHandle, pParam);
51
    }
D
dapan1121 已提交
52 53
    default:
      break;
X
Xiaoyu Wang 已提交
54
  }
H
Haojun Liao 已提交
55

D
dapan1121 已提交
56
  taosMemoryFree(pSinkManager);
H
Haojun Liao 已提交
57 58
  qError("invalid input node type:%d, %s", nodeType(pDataSink), id);
  return TSDB_CODE_QRY_INVALID_INPUT;
X
Xiaoyu Wang 已提交
59 60
}

X
Xiaoyu Wang 已提交
61
int32_t dsPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* pContinue) {
X
Xiaoyu Wang 已提交
62
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
X
Xiaoyu Wang 已提交
63
  return pHandleImpl->fPut(pHandleImpl, pInput, pContinue);
X
Xiaoyu Wang 已提交
64 65
}

D
dapan1121 已提交
66
void dsEndPut(DataSinkHandle handle, uint64_t useconds) {
67
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
X
Xiaoyu Wang 已提交
68
  return pHandleImpl->fEndPut(pHandleImpl, useconds);
X
Xiaoyu Wang 已提交
69 70
}

D
dapan1121 已提交
71
void dsGetDataLength(DataSinkHandle handle, int64_t* pLen, bool* pQueryEnd) {
X
Xiaoyu Wang 已提交
72
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
X
Xiaoyu Wang 已提交
73
  pHandleImpl->fGetLen(pHandleImpl, pLen, pQueryEnd);
X
Xiaoyu Wang 已提交
74 75
}

X
Xiaoyu Wang 已提交
76
int32_t dsGetDataBlock(DataSinkHandle handle, SOutputData* pOutput) {
77
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
X
Xiaoyu Wang 已提交
78
  return pHandleImpl->fGetData(pHandleImpl, pOutput);
X
Xiaoyu Wang 已提交
79 80
}

H
Hongze Cheng 已提交
81
int32_t dsGetCacheSize(DataSinkHandle handle, uint64_t* pSize) {
D
dapan1121 已提交
82 83 84 85
  SDataSinkHandle* pHandleImpl = (SDataSinkHandle*)handle;
  return pHandleImpl->fGetCacheSize(pHandleImpl, pSize);
}

X
Xiaoyu Wang 已提交
86 87 88 89 90 91 92
void dsScheduleProcess(void* ahandle, void* pItem) {
  // todo
}

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