dataSinkMgt.h 3.0 KB
Newer Older
X
Xiaoyu Wang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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/>.
 */

#ifndef _DATA_SINK_MGT_H
#define _DATA_SINK_MGT_H

#ifdef __cplusplus
extern "C" {
#endif

#include "os.h"
X
Xiaoyu Wang 已提交
24
#include "thash.h"
D
dapan1121 已提交
25
#include "executor.h"
X
Xiaoyu Wang 已提交
26
#include "plannodes.h"
X
Xiaoyu Wang 已提交
27

X
Xiaoyu Wang 已提交
28 29 30
#define DS_BUF_LOW   1
#define DS_BUF_FULL  2
#define DS_BUF_EMPTY 3
X
Xiaoyu Wang 已提交
31 32 33 34

struct SDataSink;
struct SSDataBlock;

D
dapan1121 已提交
35 36 37 38 39 40 41 42 43 44 45 46
typedef struct SDeleterRes {
  uint64_t uid;
  SArray*  uidList;
  int64_t  skey;
  int64_t  ekey;
  int64_t  affectedRows;
} SDeleterRes;

typedef struct SDeleterParam {
  SArray* pUidList;
} SDeleterParam;

D
dapan1121 已提交
47 48 49 50
typedef struct SDataSinkStat {
  uint64_t cachedSize;
} SDataSinkStat;

X
Xiaoyu Wang 已提交
51
typedef struct SDataSinkMgtCfg {
52
  uint32_t maxDataBlockNum;           // todo: this should be numOfRows?
X
Xiaoyu Wang 已提交
53 54 55 56 57
  uint32_t maxDataBlockNumPerQuery;
} SDataSinkMgtCfg;

int32_t dsDataSinkMgtInit(SDataSinkMgtCfg *cfg);

58
typedef struct SInputData {
X
Xiaoyu Wang 已提交
59
  const struct SSDataBlock* pData;
60 61
} SInputData;

X
Xiaoyu Wang 已提交
62
typedef struct SOutputData {
63
  int32_t numOfRows;
64
  int32_t numOfCols;
65 66
  int8_t  compressed;
  char*   pData;
X
Xiaoyu Wang 已提交
67 68 69 70 71
  bool    queryEnd;
  int32_t bufStatus;
  int64_t useconds;
  int8_t  precision;
} SOutputData;
X
Xiaoyu Wang 已提交
72 73 74 75 76 77 78

/**
 * Create a subplan's datasinker handle for all later operations. 
 * @param pDataSink
 * @param pHandle output
 * @return error code
 */
D
dapan1121 已提交
79
int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam);
X
Xiaoyu Wang 已提交
80

D
dapan1121 已提交
81 82
int32_t dsDataSinkGetCacheSize(SDataSinkStat *pStat);

X
Xiaoyu Wang 已提交
83 84 85 86 87 88
/**
 * Put the result set returned by the executor into datasinker.
 * @param handle
 * @param pRes
 * @return error code
 */
X
Xiaoyu Wang 已提交
89
int32_t dsPutDataBlock(DataSinkHandle handle, const SInputData* pInput, bool* pContinue);
90

D
dapan1121 已提交
91
void dsEndPut(DataSinkHandle handle, uint64_t useconds);
X
Xiaoyu Wang 已提交
92 93 94 95

/**
 * Get the length of the data returned by the next call to dsGetDataBlock.
 * @param handle
X
Xiaoyu Wang 已提交
96
 * @param pLen data length
X
Xiaoyu Wang 已提交
97
 */
X
Xiaoyu Wang 已提交
98
void dsGetDataLength(DataSinkHandle handle, int32_t* pLen, bool* pQueryEnd);
X
Xiaoyu Wang 已提交
99 100 101 102

/**
 * Get data, the caller needs to allocate data memory.
 * @param handle
103 104
 * @param pOutput output
 * @param pStatus output
X
Xiaoyu Wang 已提交
105 106
 * @return error code
 */
X
Xiaoyu Wang 已提交
107
int32_t dsGetDataBlock(DataSinkHandle handle, SOutputData* pOutput);
X
Xiaoyu Wang 已提交
108

D
dapan1121 已提交
109 110
int32_t dsGetCacheSize(DataSinkHandle handle, uint64_t *pSize);

X
Xiaoyu Wang 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
/**
 * After dsGetStatus returns DS_NEED_SCHEDULE, the caller need to put this into the work queue.
 * @param ahandle
 * @param pItem
 */
void dsScheduleProcess(void* ahandle, void* pItem);

/**
 * Destroy the datasinker handle.
 * @param handle
 */
void dsDestroyDataSinker(DataSinkHandle handle);

#ifdef __cplusplus
}
#endif

#endif /*_DATA_SINK_MGT_H*/