tq.c 12.6 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * 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/>.
S
Shengliang Guan 已提交
14 15
 */

L
Liu Jicong 已提交
16
#include "tqInt.h"
L
Liu Jicong 已提交
17
#include "tqMetaStore.h"
S
Shengliang Guan 已提交
18

L
Liu Jicong 已提交
19 20
// static
// read next version data
L
Liu Jicong 已提交
21
//
L
Liu Jicong 已提交
22
// send to fetch queue
L
Liu Jicong 已提交
23
//
L
Liu Jicong 已提交
24
// handle management message
L
Liu Jicong 已提交
25
//
L
Liu Jicong 已提交
26

L
Liu Jicong 已提交
27 28 29
int tqGroupSSize(const STqGroup* pGroup);
int tqTopicSSize();
int tqItemSSize();
L
Liu Jicong 已提交
30

L
Liu Jicong 已提交
31 32 33
void* tqSerializeListHandle(STqList* listHandle, void* ptr);
void* tqSerializeTopic(STqTopic* pTopic, void* ptr);
void* tqSerializeItem(STqMsgItem* pItem, void* ptr);
L
Liu Jicong 已提交
34

L
Liu Jicong 已提交
35 36
const void* tqDeserializeTopic(const void* pBytes, STqTopic* pTopic);
const void* tqDeserializeItem(const void* pBytes, STqMsgItem* pItem);
L
Liu Jicong 已提交
37

L
Liu Jicong 已提交
38
STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemAllocatorFactory* allocFac) {
L
Liu Jicong 已提交
39
  STQ* pTq = malloc(sizeof(STQ));
L
Liu Jicong 已提交
40
  if (pTq == NULL) {
L
Liu Jicong 已提交
41
    terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
L
Liu Jicong 已提交
42 43
    return NULL;
  }
H
Hongze Cheng 已提交
44
  pTq->path = strdup(path);
L
Liu Jicong 已提交
45 46
  pTq->tqConfig = tqConfig;
  pTq->tqLogReader = tqLogReader;
H
more  
Hongze Cheng 已提交
47
#if 0
L
Liu Jicong 已提交
48 49 50
  pTq->tqMemRef.pAlloctorFactory = allocFac;
  pTq->tqMemRef.pAllocator = allocFac->create(allocFac);
  if (pTq->tqMemRef.pAllocator == NULL) {
L
Liu Jicong 已提交
51
    // TODO: error code of buffer pool
L
Liu Jicong 已提交
52
  }
H
more  
Hongze Cheng 已提交
53
#endif
L
Liu Jicong 已提交
54
  pTq->tqMeta = tqStoreOpen(path, (FTqSerialize)tqSerializeGroup, (FTqDeserialize)tqDeserializeGroup, free, 0);
L
Liu Jicong 已提交
55 56
  if (pTq->tqMeta == NULL) {
    // TODO: free STQ
L
Liu Jicong 已提交
57 58 59 60
    return NULL;
  }
  return pTq;
}
L
Liu Jicong 已提交
61 62 63
void tqClose(STQ* pTq) {
  // TODO
}
L
Liu Jicong 已提交
64

L
Liu Jicong 已提交
65
static int tqProtoCheck(STqMsgHead* pMsg) { return pMsg->protoVer == 0; }
L
Liu Jicong 已提交
66

L
Liu Jicong 已提交
67
static int tqAckOneTopic(STqTopic* pTopic, STqOneAck* pAck, STqQueryMsg** ppQuery) {
L
Liu Jicong 已提交
68
  // clean old item and move forward
L
Liu Jicong 已提交
69
  int32_t consumeOffset = pAck->consumeOffset;
L
Liu Jicong 已提交
70
  int     idx = consumeOffset % TQ_BUFFER_SIZE;
L
Liu Jicong 已提交
71 72
  ASSERT(pTopic->buffer[idx].content && pTopic->buffer[idx].executor);
  tfree(pTopic->buffer[idx].content);
L
Liu Jicong 已提交
73 74 75
  if (1 /* TODO: need to launch new query */) {
    STqQueryMsg* pNewQuery = malloc(sizeof(STqQueryMsg));
    if (pNewQuery == NULL) {
L
Liu Jicong 已提交
76
      terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
L
Liu Jicong 已提交
77 78
      return -1;
    }
L
Liu Jicong 已提交
79 80
    // TODO: lock executor
    // TODO: read from wal and assign to src
L
Liu Jicong 已提交
81 82 83 84 85
    /*pNewQuery->exec->executor = pTopic->buffer[idx].executor;*/
    /*pNewQuery->exec->src = 0;*/
    /*pNewQuery->exec->dest = &pTopic->buffer[idx];*/
    /*pNewQuery->next = *ppQuery;*/
    /**ppQuery = pNewQuery;*/
L
Liu Jicong 已提交
86
  }
L
Liu Jicong 已提交
87 88 89
  return 0;
}

L
Liu Jicong 已提交
90
static int tqAck(STqGroup* pGroup, STqAcks* pAcks) {
L
Liu Jicong 已提交
91
  int32_t    ackNum = pAcks->ackNum;
L
Liu Jicong 已提交
92
  STqOneAck* acks = pAcks->acks;
L
Liu Jicong 已提交
93
  // double ptr for acks and list
L
Liu Jicong 已提交
94 95 96 97
  int          i = 0;
  STqList*     node = pGroup->head;
  int          ackCnt = 0;
  STqQueryMsg* pQuery = NULL;
L
Liu Jicong 已提交
98
  while (i < ackNum && node->next) {
L
Liu Jicong 已提交
99
    if (acks[i].topicId == node->next->topic.topicId) {
L
Liu Jicong 已提交
100
      ackCnt++;
L
Liu Jicong 已提交
101 102
      tqAckOneTopic(&node->next->topic, &acks[i], &pQuery);
    } else if (acks[i].topicId < node->next->topic.topicId) {
L
Liu Jicong 已提交
103 104 105
      i++;
    } else {
      node = node->next;
L
Liu Jicong 已提交
106 107
    }
  }
L
Liu Jicong 已提交
108 109
  if (pQuery) {
    // post message
L
Liu Jicong 已提交
110 111 112
  }
  return ackCnt;
}
L
Liu Jicong 已提交
113

L
Liu Jicong 已提交
114
static int tqCommitGroup(STqGroup* pGroup) {
L
Liu Jicong 已提交
115
  // persist modification into disk
L
Liu Jicong 已提交
116 117 118
  return 0;
}

L
Liu Jicong 已提交
119
int tqCreateGroup(STQ* pTq, int64_t topicId, int64_t cgId, int64_t cId, STqGroup** ppGroup) {
L
Liu Jicong 已提交
120
  // create in disk
L
Liu Jicong 已提交
121 122
  STqGroup* pGroup = (STqGroup*)malloc(sizeof(STqGroup));
  if (pGroup == NULL) {
L
Liu Jicong 已提交
123
    // TODO
L
Liu Jicong 已提交
124 125
    return -1;
  }
L
Liu Jicong 已提交
126 127
  *ppGroup = pGroup;
  memset(pGroup, 0, sizeof(STqGroup));
L
Liu Jicong 已提交
128

L
Liu Jicong 已提交
129 130 131
  return 0;
}

L
Liu Jicong 已提交
132 133 134 135 136
STqGroup* tqOpenGroup(STQ* pTq, int64_t topicId, int64_t cgId, int64_t cId) {
  STqGroup* pGroup = tqHandleGet(pTq->tqMeta, cId);
  if (pGroup == NULL) {
    int code = tqCreateGroup(pTq, topicId, cgId, cId, &pGroup);
    if (code < 0) {
L
Liu Jicong 已提交
137
      // TODO
L
Liu Jicong 已提交
138 139
      return NULL;
    }
L
Liu Jicong 已提交
140
    tqHandleMovePut(pTq->tqMeta, cId, pGroup);
L
Liu Jicong 已提交
141
  }
L
Liu Jicong 已提交
142
  ASSERT(pGroup);
L
Liu Jicong 已提交
143

L
Liu Jicong 已提交
144
  return pGroup;
L
Liu Jicong 已提交
145
}
L
Liu Jicong 已提交
146

L
Liu Jicong 已提交
147 148 149 150
int tqCloseGroup(STQ* pTq, int64_t topicId, int64_t cgId, int64_t cId) {
  // TODO
  return 0;
}
L
Liu Jicong 已提交
151

L
Liu Jicong 已提交
152
int tqDropGroup(STQ* pTq, int64_t topicId, int64_t cgId, int64_t cId) {
L
Liu Jicong 已提交
153
  // delete from disk
L
Liu Jicong 已提交
154 155 156
  return 0;
}

L
Liu Jicong 已提交
157 158 159 160
static int tqFetch(STqGroup* pGroup, void** msg) {
  STqList* head = pGroup->head;
  STqList* node = head;
  int      totSize = 0;
L
Liu Jicong 已提交
161 162
  // TODO: make it a macro
  int            sizeLimit = 4 * 1024;
L
Liu Jicong 已提交
163
  STqMsgContent* buffer = malloc(sizeLimit);
L
Liu Jicong 已提交
164 165
  if (buffer == NULL) {
    // TODO:memory insufficient
L
Liu Jicong 已提交
166 167
    return -1;
  }
L
Liu Jicong 已提交
168 169 170
  // iterate the list to get msgs of all topics
  // until all topic iterated or msgs over sizeLimit
  while (node->next) {
L
Liu Jicong 已提交
171
    node = node->next;
L
Liu Jicong 已提交
172 173 174 175
    STqTopic* topicHandle = &node->topic;
    int       idx = topicHandle->nextConsumeOffset % TQ_BUFFER_SIZE;
    if (topicHandle->buffer[idx].content != NULL && topicHandle->buffer[idx].offset == topicHandle->nextConsumeOffset) {
      totSize += topicHandle->buffer[idx].size;
L
Liu Jicong 已提交
176 177 178
      if (totSize > sizeLimit) {
        void* ptr = realloc(buffer, totSize);
        if (ptr == NULL) {
L
Liu Jicong 已提交
179
          totSize -= topicHandle->buffer[idx].size;
L
Liu Jicong 已提交
180 181
          // TODO:memory insufficient
          // return msgs already copied
L
Liu Jicong 已提交
182 183 184
          break;
        }
      }
L
Liu Jicong 已提交
185
      *((int64_t*)buffer) = topicHandle->topicId;
L
Liu Jicong 已提交
186
      buffer = POINTER_SHIFT(buffer, sizeof(int64_t));
L
Liu Jicong 已提交
187
      *((int64_t*)buffer) = topicHandle->buffer[idx].size;
L
Liu Jicong 已提交
188
      buffer = POINTER_SHIFT(buffer, sizeof(int64_t));
L
Liu Jicong 已提交
189 190
      memcpy(buffer, topicHandle->buffer[idx].content, topicHandle->buffer[idx].size);
      buffer = POINTER_SHIFT(buffer, topicHandle->buffer[idx].size);
L
Liu Jicong 已提交
191
      if (totSize > sizeLimit) {
L
Liu Jicong 已提交
192 193 194 195 196
        break;
      }
    }
  }
  return totSize;
L
Liu Jicong 已提交
197 198
}

L
Liu Jicong 已提交
199
STqGroup* tqGetGroup(STQ* pTq, int64_t clientId) { return tqHandleGet(pTq->tqMeta, clientId); }
L
Liu Jicong 已提交
200

L
Liu Jicong 已提交
201 202 203 204 205 206 207 208 209 210 211
int tqSendLaunchQuery(STqMsgItem* bufItem, int64_t offset) {
  if (tqQueryExecuting(bufItem->status)) {
    return 0;
  }
  bufItem->status = 1;
  // load data from wal or buffer pool
  // put into exec
  // send exec into non blocking queue
  // when query finished, put into buffer pool
  return 0;
}
L
Liu Jicong 已提交
212

L
Liu Jicong 已提交
213
/*int tqMoveOffsetToNext(TqGroupHandle* gHandle) {*/
L
Liu Jicong 已提交
214
/*return 0;*/
L
Liu Jicong 已提交
215 216
/*}*/

L
Liu Jicong 已提交
217 218 219
int tqPushMsg(STQ* pTq, void* p, int64_t version) {
  // add reference
  // judge and launch new query
L
Liu Jicong 已提交
220 221 222
  return 0;
}

L
Liu Jicong 已提交
223
int tqCommit(STQ* pTq) {
L
Liu Jicong 已提交
224
  // do nothing
L
Liu Jicong 已提交
225 226 227
  return 0;
}

L
Liu Jicong 已提交
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
int tqBufferSetOffset(STqTopic* pTopic, int64_t offset) {
  int code;
  memset(pTopic->buffer, 0, sizeof(pTopic->buffer));
  // launch query
  for (int i = offset; i < offset + TQ_BUFFER_SIZE; i++) {
    int pos = i % TQ_BUFFER_SIZE;
    code = tqSendLaunchQuery(&pTopic->buffer[pos], offset);
    if (code < 0) {
      // TODO: error handling
    }
  }
  // set offset
  pTopic->nextConsumeOffset = offset;
  pTopic->floatingCursor = offset;
  return 0;
}

STqTopic* tqFindTopic(STqGroup* pGroup, int64_t topicId) {
  // TODO
  return NULL;
}

int tqSetCursor(STQ* pTq, STqSetCurReq* pMsg) {
  int       code;
  int64_t   clientId = pMsg->head.clientId;
  int64_t   topicId = pMsg->topicId;
  int64_t   offset = pMsg->offset;
  STqGroup* gHandle = tqGetGroup(pTq, clientId);
  if (gHandle == NULL) {
    // client not connect
    return -1;
  }
  STqTopic* topicHandle = tqFindTopic(gHandle, topicId);
  if (topicHandle == NULL) {
    return -1;
  }
  if (pMsg->offset == topicHandle->nextConsumeOffset) {
    return 0;
  }
  // TODO: check log last version

  code = tqBufferSetOffset(topicHandle, offset);
  if (code < 0) {
    // set error code
    return -1;
  }

L
Liu Jicong 已提交
275 276 277
  return 0;
}

L
Liu Jicong 已提交
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
int tqConsume(STQ* pTq, STqConsumeReq* pMsg) {
  int64_t   clientId = pMsg->head.clientId;
  STqGroup* pGroup = tqGetGroup(pTq, clientId);
  if (pGroup == NULL) {
    terrno = TSDB_CODE_TQ_GROUP_NOT_SET;
    return -1;
  }

  STqConsumeRsp* pRsp = (STqConsumeRsp*)pMsg;
  int            numOfMsgs = tqFetch(pGroup, (void**)&pRsp->msgs);
  if (numOfMsgs < 0) {
    return -1;
  }
  if (numOfMsgs == 0) {
    // most recent data has been fetched

    // enable timer for blocking wait
    // once new data written during wait time
    // launch query and response
  }

  // fetched a num of msgs, rpc response

  return 0;
}

#if 0
L
Liu Jicong 已提交
305
int tqConsume(STQ* pTq, STqConsumeReq* pMsg) {
L
Liu Jicong 已提交
306
  if (!tqProtoCheck((STqMsgHead*)pMsg)) {
L
Liu Jicong 已提交
307
    // proto version invalid
L
Liu Jicong 已提交
308 309
    return -1;
  }
L
Liu Jicong 已提交
310 311 312
  int64_t   clientId = pMsg->head.clientId;
  STqGroup* pGroup = tqGetGroup(pTq, clientId);
  if (pGroup == NULL) {
L
Liu Jicong 已提交
313
    // client not connect
L
Liu Jicong 已提交
314 315
    return -1;
  }
L
Liu Jicong 已提交
316
  if (pMsg->acks.ackNum != 0) {
L
Liu Jicong 已提交
317
    if (tqAck(pGroup, &pMsg->acks) != 0) {
L
Liu Jicong 已提交
318
      // ack not success
L
Liu Jicong 已提交
319 320 321 322
      return -1;
    }
  }

L
Liu Jicong 已提交
323
  STqConsumeRsp* pRsp = (STqConsumeRsp*)pMsg;
L
Liu Jicong 已提交
324

L
Liu Jicong 已提交
325
  if (tqFetch(pGroup, (void**)&pRsp->msgs) <= 0) {
L
Liu Jicong 已提交
326
    // fetch error
L
Liu Jicong 已提交
327 328 329
    return -1;
  }

L
Liu Jicong 已提交
330
  // judge and launch new query
L
Liu Jicong 已提交
331 332 333 334
  /*if (tqSendLaunchQuery(gHandle)) {*/
  // launch query error
  /*return -1;*/
  /*}*/
L
Liu Jicong 已提交
335 336
  return 0;
}
L
Liu Jicong 已提交
337
#endif
L
Liu Jicong 已提交
338

L
Liu Jicong 已提交
339
int tqSerializeGroup(const STqGroup* pGroup, STqSerializedHead** ppHead) {
L
Liu Jicong 已提交
340
  // calculate size
L
Liu Jicong 已提交
341
  int sz = tqGroupSSize(pGroup) + sizeof(STqSerializedHead);
L
Liu Jicong 已提交
342
  if (sz > (*ppHead)->ssize) {
L
Liu Jicong 已提交
343
    void* tmpPtr = realloc(*ppHead, sz);
L
Liu Jicong 已提交
344
    if (tmpPtr == NULL) {
L
Liu Jicong 已提交
345
      free(*ppHead);
L
Liu Jicong 已提交
346
      // TODO: memory err
L
Liu Jicong 已提交
347 348 349 350
      return -1;
    }
    *ppHead = tmpPtr;
    (*ppHead)->ssize = sz;
L
Liu Jicong 已提交
351
  }
L
Liu Jicong 已提交
352
  void* ptr = (*ppHead)->content;
L
Liu Jicong 已提交
353
  // do serialization
L
Liu Jicong 已提交
354
  *(int64_t*)ptr = pGroup->clientId;
L
Liu Jicong 已提交
355
  ptr = POINTER_SHIFT(ptr, sizeof(int64_t));
L
Liu Jicong 已提交
356
  *(int64_t*)ptr = pGroup->cgId;
L
Liu Jicong 已提交
357
  ptr = POINTER_SHIFT(ptr, sizeof(int64_t));
L
Liu Jicong 已提交
358
  *(int32_t*)ptr = pGroup->topicNum;
359
  ptr = POINTER_SHIFT(ptr, sizeof(int32_t));
L
Liu Jicong 已提交
360 361
  if (pGroup->topicNum > 0) {
    tqSerializeListHandle(pGroup->head, ptr);
L
Liu Jicong 已提交
362 363 364 365
  }
  return 0;
}

L
Liu Jicong 已提交
366 367
void* tqSerializeListHandle(STqList* listHandle, void* ptr) {
  STqList* node = listHandle;
368
  ASSERT(node != NULL);
L
Liu Jicong 已提交
369
  while (node) {
L
Liu Jicong 已提交
370
    ptr = tqSerializeTopic(&node->topic, ptr);
L
Liu Jicong 已提交
371 372
    node = node->next;
  }
373
  return ptr;
L
Liu Jicong 已提交
374
}
375

L
Liu Jicong 已提交
376 377
void* tqSerializeTopic(STqTopic* pTopic, void* ptr) {
  *(int64_t*)ptr = pTopic->nextConsumeOffset;
L
Liu Jicong 已提交
378
  ptr = POINTER_SHIFT(ptr, sizeof(int64_t));
L
Liu Jicong 已提交
379
  *(int64_t*)ptr = pTopic->topicId;
L
Liu Jicong 已提交
380
  ptr = POINTER_SHIFT(ptr, sizeof(int64_t));
L
Liu Jicong 已提交
381
  *(int32_t*)ptr = pTopic->head;
L
Liu Jicong 已提交
382
  ptr = POINTER_SHIFT(ptr, sizeof(int32_t));
L
Liu Jicong 已提交
383
  *(int32_t*)ptr = pTopic->tail;
L
Liu Jicong 已提交
384
  ptr = POINTER_SHIFT(ptr, sizeof(int32_t));
L
Liu Jicong 已提交
385
  for (int i = 0; i < TQ_BUFFER_SIZE; i++) {
L
Liu Jicong 已提交
386
    ptr = tqSerializeItem(&pTopic->buffer[i], ptr);
L
Liu Jicong 已提交
387
  }
388
  return ptr;
L
Liu Jicong 已提交
389 390
}

L
Liu Jicong 已提交
391
void* tqSerializeItem(STqMsgItem* bufItem, void* ptr) {
L
Liu Jicong 已提交
392 393
  // TODO: do we need serialize this?
  // mainly for executor
394
  return ptr;
L
Liu Jicong 已提交
395 396
}

L
Liu Jicong 已提交
397 398 399
const void* tqDeserializeGroup(const STqSerializedHead* pHead, STqGroup** ppGroup) {
  STqGroup*   gHandle = *ppGroup;
  const void* ptr = pHead->content;
L
Liu Jicong 已提交
400
  gHandle->clientId = *(int64_t*)ptr;
401 402 403 404 405 406 407
  ptr = POINTER_SHIFT(ptr, sizeof(int64_t));
  gHandle->cgId = *(int64_t*)ptr;
  ptr = POINTER_SHIFT(ptr, sizeof(int64_t));
  gHandle->ahandle = NULL;
  gHandle->topicNum = *(int32_t*)ptr;
  ptr = POINTER_SHIFT(ptr, sizeof(int32_t));
  gHandle->head = NULL;
L
Liu Jicong 已提交
408
  STqList* node = gHandle->head;
L
Liu Jicong 已提交
409 410
  for (int i = 0; i < gHandle->topicNum; i++) {
    if (gHandle->head == NULL) {
L
Liu Jicong 已提交
411
      if ((node = malloc(sizeof(STqList))) == NULL) {
L
Liu Jicong 已提交
412
        // TODO: error
413 414
        return NULL;
      }
L
Liu Jicong 已提交
415
      node->next = NULL;
L
Liu Jicong 已提交
416
      ptr = tqDeserializeTopic(ptr, &node->topic);
417 418
      gHandle->head = node;
    } else {
L
Liu Jicong 已提交
419
      node->next = malloc(sizeof(STqList));
L
Liu Jicong 已提交
420 421
      if (node->next == NULL) {
        // TODO: error
422 423 424
        return NULL;
      }
      node->next->next = NULL;
L
Liu Jicong 已提交
425
      ptr = tqDeserializeTopic(ptr, &node->next->topic);
426 427 428 429
      node = node->next;
    }
  }
  return ptr;
L
Liu Jicong 已提交
430
}
431

L
Liu Jicong 已提交
432
const void* tqDeserializeTopic(const void* pBytes, STqTopic* topic) {
433
  const void* ptr = pBytes;
L
Liu Jicong 已提交
434
  topic->nextConsumeOffset = *(int64_t*)ptr;
435
  ptr = POINTER_SHIFT(ptr, sizeof(int64_t));
L
Liu Jicong 已提交
436
  topic->topicId = *(int64_t*)ptr;
437
  ptr = POINTER_SHIFT(ptr, sizeof(int64_t));
L
Liu Jicong 已提交
438
  topic->head = *(int32_t*)ptr;
439
  ptr = POINTER_SHIFT(ptr, sizeof(int32_t));
L
Liu Jicong 已提交
440
  topic->tail = *(int32_t*)ptr;
441
  ptr = POINTER_SHIFT(ptr, sizeof(int32_t));
L
Liu Jicong 已提交
442
  for (int i = 0; i < TQ_BUFFER_SIZE; i++) {
L
Liu Jicong 已提交
443
    ptr = tqDeserializeItem(ptr, &topic->buffer[i]);
444 445
  }
  return ptr;
L
Liu Jicong 已提交
446 447
}

L
Liu Jicong 已提交
448
const void* tqDeserializeItem(const void* pBytes, STqMsgItem* bufItem) { return pBytes; }
L
Liu Jicong 已提交
449

L
Liu Jicong 已提交
450
// TODO: make this a macro
L
Liu Jicong 已提交
451
int tqGroupSSize(const STqGroup* gHandle) {
L
Liu Jicong 已提交
452 453
  return sizeof(int64_t) * 2  // cId + cgId
         + sizeof(int32_t)    // topicNum
L
Liu Jicong 已提交
454
         + gHandle->topicNum * tqTopicSSize();
L
Liu Jicong 已提交
455
}
456

L
Liu Jicong 已提交
457
// TODO: make this a macro
L
Liu Jicong 已提交
458
int tqTopicSSize() {
L
Liu Jicong 已提交
459 460
  return sizeof(int64_t) * 2    // nextConsumeOffset + topicId
         + sizeof(int32_t) * 2  // head + tail
L
Liu Jicong 已提交
461
         + TQ_BUFFER_SIZE * tqItemSSize();
L
Liu Jicong 已提交
462
}
463

L
Liu Jicong 已提交
464
int tqItemSSize() {
L
Liu Jicong 已提交
465 466
  // TODO: do this need serialization?
  // mainly for executor
L
Liu Jicong 已提交
467 468
  return 0;
}