tq.h 5.0 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)
H
Hongze Cheng 已提交
42 43
// clang-format on

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

L
Liu Jicong 已提交
47 48
// tqRead

H
Hongze Cheng 已提交
49 50 51 52 53 54
struct STqReadHandle {
  int64_t           ver;
  const SSubmitReq* pMsg;
  SSubmitBlk*       pBlock;
  SSubmitMsgIter    msgIter;
  SSubmitBlkIter    blkIter;
L
Liu Jicong 已提交
55 56 57 58 59 60 61 62 63

  SMeta*    pVnodeMeta;
  SHashObj* tbIdHash;
  SArray*   pColIdList;  // SArray<int16_t>

  int32_t         cachedSchemaVer;
  int64_t         cachedSchemaUid;
  SSchemaWrapper* pSchemaWrapper;
  STSchema*       pSchema;
H
Hongze Cheng 已提交
64 65
};

L
Liu Jicong 已提交
66 67
// tqPush

H
Hongze Cheng 已提交
68
typedef struct {
69 70 71 72 73 74
  int64_t        consumerId;
  int32_t        epoch;
  int32_t        skipLogNum;
  int64_t        reqOffset;
  SRpcHandleInfo info;
  SRWLatch       lock;
L
Liu Jicong 已提交
75 76
} STqPushHandle;

L
Liu Jicong 已提交
77
#if 0
L
Liu Jicong 已提交
78
typedef struct {
L
Liu Jicong 已提交
79 80 81 82 83 84 85
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
  int64_t consumerId;
  int32_t epoch;
  int8_t  subType;
  // int8_t        withTbName;
  // int8_t        withSchema;
  // int8_t        withTag;
L
Liu Jicong 已提交
86
  char*         qmsg;
87
  SHashObj*     pDropTbUid;
L
Liu Jicong 已提交
88
  STqPushHandle pushHandle;
L
Liu Jicong 已提交
89
  // SRWLatch        lock;
L
Liu Jicong 已提交
90
  SWalReadHandle* pWalReader;
L
Liu Jicong 已提交
91 92 93
  // task number should be the same with fetch thread
  STqReadHandle* pExecReader[5];
  qTaskInfo_t    task[5];
L
Liu Jicong 已提交
94
} STqExec;
L
Liu Jicong 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#endif

// tqExec

typedef struct {
  char*       qmsg;
  qTaskInfo_t task[5];
} STqExecCol;

typedef struct {
  int64_t suid;
} STqExecTb;

typedef struct {
  SHashObj* pFilterOutTbUid;
} STqExecDb;

typedef struct {
  int8_t subType;

  STqReadHandle* pExecReader[5];
  union {
    STqExecCol execCol;
    STqExecTb  execTb;
    STqExecDb  execDb;
  } exec;
} STqExecHandle;
H
Hongze Cheng 已提交
122

L
Liu Jicong 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
typedef struct {
  // info
  char    subKey[TSDB_SUBSCRIBE_KEY_LEN];
  int64_t consumerId;
  int32_t epoch;

  // reader
  SWalReadHandle* pWalReader;

  // push
  STqPushHandle pushHandle;

  // exec
  STqExecHandle execHandle;
} STqHandle;
138

H
Hongze Cheng 已提交
139
struct STQ {
L
Liu Jicong 已提交
140
  char*     path;
L
Liu Jicong 已提交
141 142 143
  SHashObj* pushMgr;       // consumerId -> STqHandle*
  SHashObj* handles;       // subKey -> STqHandle
  SHashObj* pStreamTasks;  // taksId -> SStreamTask
L
Liu Jicong 已提交
144 145
  SVnode*   pVnode;
  SWal*     pWal;
146 147
  TDB*      pMetaStore;
  TTB*      pExecStore;
H
Hongze Cheng 已提交
148 149 150 151 152 153 154
};

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

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

H
Hongze Cheng 已提交
157 158 159 160
// init once
int  tqInit();
void tqCleanUp();

L
Liu Jicong 已提交
161 162 163 164 165 166 167 168 169 170
// int32_t tEncodeSTqExec(SEncoder* pEncoder, const STqExec* pExec);
// int32_t tDecodeSTqExec(SDecoder* pDecoder, STqExec* pExec);

int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle);
int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle);

int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead** pHeadWithCkSum);

int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkRsp* pRsp, int32_t workerId);

L
Liu Jicong 已提交
171 172 173 174 175 176 177
// 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);

H
Hongze Cheng 已提交
178 179 180 181 182 183 184 185 186
// tqOffset
STqOffsetStore* STqOffsetOpen(STqOffsetCfg*);
void            STqOffsetClose(STqOffsetStore*);

int64_t tqOffsetFetch(STqOffsetStore* pStore, const char* subscribeKey);
int32_t tqOffsetCommit(STqOffsetStore* pStore, const char* subscribeKey, int64_t offset);
int32_t tqOffsetPersist(STqOffsetStore* pStore, const char* subscribeKey);
int32_t tqOffsetPersistAll(STqOffsetStore* pStore);

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

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