tq.h 5.9 KB
Newer Older
L
Liu Jicong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * 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/>.
 */
H
Hongze Cheng 已提交
15 16 17 18

#ifndef _TD_VNODE_TQ_H_
#define _TD_VNODE_TQ_H_

H
Hongze Cheng 已提交
19 20
#include "vnodeInt.h"

L
Liu Jicong 已提交
21 22 23 24
#include "executor.h"
#include "os.h"
#include "thash.h"
#include "tmsg.h"
25
#include "tqueue.h"
L
Liu Jicong 已提交
26
#include "trpc.h"
L
Liu Jicong 已提交
27 28 29
#include "ttimer.h"
#include "wal.h"

H
Hongze Cheng 已提交
30 31 32 33
#ifdef __cplusplus
extern "C" {
#endif

H
Hongze Cheng 已提交
34 35
// tqDebug ===================
// clang-format off
L
Liu Jicong 已提交
36 37 38 39 40 41
#define tqFatal(...) do { if (tqDebugFlag & DEBUG_FATAL) { taosPrintLog("TQ  FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}     while(0)
#define tqError(...) do { if (tqDebugFlag & DEBUG_ERROR) { taosPrintLog("TQ  ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}     while(0)
#define tqWarn(...)  do { if (tqDebugFlag & DEBUG_WARN)  { taosPrintLog("TQ  WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}       while(0)
#define tqInfo(...)  do { if (tqDebugFlag & DEBUG_INFO)  { taosPrintLog("TQ  ", DEBUG_INFO, 255, __VA_ARGS__); }}            while(0)
#define tqDebug(...) do { if (tqDebugFlag & DEBUG_DEBUG) { taosPrintLog("TQ  ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); }} while(0)
#define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ  ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0)
L
Liu Jicong 已提交
42

H
Hongze Cheng 已提交
43 44
// clang-format on

H
Hongze Cheng 已提交
45 46
typedef struct STqOffsetStore STqOffsetStore;

L
Liu Jicong 已提交
47 48
// tqPush

L
Liu Jicong 已提交
49
typedef struct {
L
Liu Jicong 已提交
50
  // msg info
L
Liu Jicong 已提交
51
  int64_t consumerId;
L
Liu Jicong 已提交
52 53
  int64_t reqOffset;
  int64_t processedVer;
L
Liu Jicong 已提交
54
  int32_t epoch;
L
Liu Jicong 已提交
55 56 57
  // rpc info
  int64_t        reqId;
  SRpcHandleInfo rpcInfo;
L
Liu Jicong 已提交
58 59
  tmr_h          timerId;
  int8_t         tmrStopped;
L
Liu Jicong 已提交
60
  // exec
L
Liu Jicong 已提交
61 62 63 64
  int8_t       inputStatus;
  int8_t       execStatus;
  SStreamQueue inputQ;
  SRWLatch     lock;
L
Liu Jicong 已提交
65
} STqPushHandle;
L
Liu Jicong 已提交
66 67 68 69

// tqExec

typedef struct {
70
  char* qmsg;   // SubPlanToString
L
Liu Jicong 已提交
71 72 73
} STqExecCol;

typedef struct {
L
Liu Jicong 已提交
74
  int64_t suid;
L
Liu Jicong 已提交
75 76 77
} STqExecTb;

typedef struct {
L
Liu Jicong 已提交
78
  SHashObj* pFilterOutTbUid;
L
Liu Jicong 已提交
79 80 81
} STqExecDb;

typedef struct {
82
  int8_t      subType;
L
Liu Jicong 已提交
83
  STqReader*  pExecReader;
84
  qTaskInfo_t task;
L
Liu Jicong 已提交
85 86 87 88
  union {
    STqExecCol execCol;
    STqExecTb  execTb;
    STqExecDb  execDb;
L
Liu Jicong 已提交
89
  };
L
Liu Jicong 已提交
90
  int32_t numOfCols;  // number of out pout column, temporarily used
91
  bool         stop;  // denote if needs to be stopped or not
L
Liu Jicong 已提交
92
} STqExecHandle;
H
Hongze Cheng 已提交
93

L
Liu Jicong 已提交
94
typedef struct {
95 96 97 98 99 100 101 102 103
  char          subKey[TSDB_SUBSCRIBE_KEY_LEN];
  int64_t       consumerId;
  int32_t       epoch;
  int8_t        fetchMeta;
  int64_t       snapshotVer;
  SWalReader*   pWalReader;
  SWalRef*      pRef;
  STqPushHandle pushHandle;    // push
  STqExecHandle execHandle;    // exec
104
  int8_t        execStatus;    // this handle is used to handle the poll requirement
L
Liu Jicong 已提交
105
} STqHandle;
106

L
Liu Jicong 已提交
107 108
typedef struct {
  SMqDataRsp     dataRsp;
L
Liu Jicong 已提交
109
  char           subKey[TSDB_SUBSCRIBE_KEY_LEN];
L
Liu Jicong 已提交
110 111 112
  SRpcHandleInfo pInfo;
} STqPushEntry;

H
Hongze Cheng 已提交
113
struct STQ {
L
Liu Jicong 已提交
114 115
  SVnode* pVnode;
  char*   path;
L
Liu Jicong 已提交
116
  int64_t walLogLastVer;
L
Liu Jicong 已提交
117 118 119 120

  SRWLatch pushLock;

  SHashObj* pPushMgr;    // consumerId -> STqPushEntry
121 122
  SHashObj* pHandle;     // subKey -> STqHandle
  SHashObj* pCheckInfo;  // topic -> SAlterCheckInfo
L
Liu Jicong 已提交
123

124
  STqOffsetStore* pOffsetStore;
L
Liu Jicong 已提交
125

126
  TDB* pMetaDB;
L
Liu Jicong 已提交
127
  TTB* pExecStore;
128
  TTB* pCheckStore;
L
Liu Jicong 已提交
129

L
Liu Jicong 已提交
130
  SStreamMeta* pStreamMeta;
H
Hongze Cheng 已提交
131 132 133 134 135 136 137
};

typedef struct {
  int8_t inited;
  tmr_h  timer;
} STqMgmt;

L
Liu Jicong 已提交
138
static STqMgmt tqMgmt = {0};
H
Hongze Cheng 已提交
139

L
Liu Jicong 已提交
140 141 142
int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle);
int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle);

L
Liu Jicong 已提交
143
// tqRead
L
Liu Jicong 已提交
144
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* offset);
145
int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* pOffset);
wmmhello's avatar
wmmhello 已提交
146
int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** pHeadWithCkSum);
L
Liu Jicong 已提交
147

wmmhello's avatar
wmmhello 已提交
148
// tqExec
L
Liu Jicong 已提交
149
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxRsp* pRsp);
L
Liu Jicong 已提交
150
// int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp* pRsp);
L
Liu Jicong 已提交
151
int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, SMqDataRsp* pRsp, int32_t numOfCols, int8_t precision);
L
Liu Jicong 已提交
152
int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp);
L
Liu Jicong 已提交
153
int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry);
L
Liu Jicong 已提交
154

L
Liu Jicong 已提交
155 156 157 158 159
// tqMeta
int32_t tqMetaOpen(STQ* pTq);
int32_t tqMetaClose(STQ* pTq);
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle);
int32_t tqMetaDeleteHandle(STQ* pTq, const char* key);
L
Liu Jicong 已提交
160
int32_t tqMetaRestoreHandle(STQ* pTq);
161 162 163
int32_t tqMetaSaveCheckInfo(STQ* pTq, const char* key, const void* value, int32_t vLen);
int32_t tqMetaDeleteCheckInfo(STQ* pTq, const char* key);
int32_t tqMetaRestoreCheckInfo(STQ* pTq);
L
Liu Jicong 已提交
164

165 166 167
typedef struct {
  int32_t size;
} STqOffsetHead;
L
Liu Jicong 已提交
168

169
STqOffsetStore* tqOffsetOpen();
L
Liu Jicong 已提交
170
void            tqOffsetClose(STqOffsetStore*);
171 172
STqOffset*      tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey);
int32_t         tqOffsetWrite(STqOffsetStore* pStore, const STqOffset* pOffset);
L
Liu Jicong 已提交
173
int32_t         tqOffsetDelete(STqOffsetStore* pStore, const char* subscribeKey);
L
Liu Jicong 已提交
174
int32_t         tqOffsetCommitFile(STqOffsetStore* pStore);
175 176

// tqSink
L
Liu Jicong 已提交
177 178 179
int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBlock* pDataBlock,
                         SBatchDeleteReq* deleteReq);
void    tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
H
Hongze Cheng 已提交
180

L
Liu Jicong 已提交
181
// tqOffset
182
char*   tqOffsetBuildFName(const char* path, int32_t fVer);
L
Liu Jicong 已提交
183 184
int32_t tqOffsetRestoreFromFile(STqOffsetStore* pStore, const char* fname);

L
Liu Jicong 已提交
185
// tqStream
186
int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver);
L
Liu Jicong 已提交
187

H
Hongze Cheng 已提交
188 189 190 191
#ifdef __cplusplus
}
#endif

L
Liu Jicong 已提交
192
#endif /*_TD_VNODE_TQ_H_*/