tq.c 12.5 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;
L
Liu Jicong 已提交
47 48 49
  pTq->tqMemRef.pAlloctorFactory = allocFac;
  pTq->tqMemRef.pAllocator = allocFac->create(allocFac);
  if (pTq->tqMemRef.pAllocator == NULL) {
L
Liu Jicong 已提交
50
    // TODO: error code of buffer pool
L
Liu Jicong 已提交
51
  }
L
Liu Jicong 已提交
52
  pTq->tqMeta = tqStoreOpen(path, (FTqSerialize)tqSerializeGroup, (FTqDeserialize)tqDeserializeGroup, free, 0);
L
Liu Jicong 已提交
53 54
  if (pTq->tqMeta == NULL) {
    // TODO: free STQ
L
Liu Jicong 已提交
55 56 57 58
    return NULL;
  }
  return pTq;
}
L
Liu Jicong 已提交
59

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

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

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

L
Liu Jicong 已提交
109
static int tqCommitGroup(STqGroup* pGroup) {
L
Liu Jicong 已提交
110
  // persist modification into disk
L
Liu Jicong 已提交
111 112 113
  return 0;
}

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

L
Liu Jicong 已提交
124 125 126
  return 0;
}

L
Liu Jicong 已提交
127 128 129 130 131
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 已提交
132
      // TODO
L
Liu Jicong 已提交
133 134
      return NULL;
    }
L
Liu Jicong 已提交
135
    tqHandleMovePut(pTq->tqMeta, cId, pGroup);
L
Liu Jicong 已提交
136
  }
L
Liu Jicong 已提交
137
  ASSERT(pGroup);
L
Liu Jicong 已提交
138

L
Liu Jicong 已提交
139
  return pGroup;
L
Liu Jicong 已提交
140
}
L
Liu Jicong 已提交
141

L
Liu Jicong 已提交
142 143 144 145
int tqCloseGroup(STQ* pTq, int64_t topicId, int64_t cgId, int64_t cId) {
  // TODO
  return 0;
}
L
Liu Jicong 已提交
146

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

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

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

L
Liu Jicong 已提交
196 197 198 199 200 201 202 203 204 205 206
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 已提交
207

L
Liu Jicong 已提交
208
/*int tqMoveOffsetToNext(TqGroupHandle* gHandle) {*/
L
Liu Jicong 已提交
209
/*return 0;*/
L
Liu Jicong 已提交
210 211
/*}*/

L
Liu Jicong 已提交
212 213 214
int tqPushMsg(STQ* pTq, void* p, int64_t version) {
  // add reference
  // judge and launch new query
L
Liu Jicong 已提交
215 216 217
  return 0;
}

L
Liu Jicong 已提交
218
int tqCommit(STQ* pTq) {
L
Liu Jicong 已提交
219
  // do nothing
L
Liu Jicong 已提交
220 221 222
  return 0;
}

L
Liu Jicong 已提交
223 224 225 226 227 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
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 已提交
270 271 272
  return 0;
}

L
Liu Jicong 已提交
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
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 已提交
300
int tqConsume(STQ* pTq, STqConsumeReq* pMsg) {
L
Liu Jicong 已提交
301
  if (!tqProtoCheck((STqMsgHead*)pMsg)) {
L
Liu Jicong 已提交
302
    // proto version invalid
L
Liu Jicong 已提交
303 304
    return -1;
  }
L
Liu Jicong 已提交
305 306 307
  int64_t   clientId = pMsg->head.clientId;
  STqGroup* pGroup = tqGetGroup(pTq, clientId);
  if (pGroup == NULL) {
L
Liu Jicong 已提交
308
    // client not connect
L
Liu Jicong 已提交
309 310
    return -1;
  }
L
Liu Jicong 已提交
311
  if (pMsg->acks.ackNum != 0) {
L
Liu Jicong 已提交
312
    if (tqAck(pGroup, &pMsg->acks) != 0) {
L
Liu Jicong 已提交
313
      // ack not success
L
Liu Jicong 已提交
314 315 316 317
      return -1;
    }
  }

L
Liu Jicong 已提交
318
  STqConsumeRsp* pRsp = (STqConsumeRsp*)pMsg;
L
Liu Jicong 已提交
319

L
Liu Jicong 已提交
320
  if (tqFetch(pGroup, (void**)&pRsp->msgs) <= 0) {
L
Liu Jicong 已提交
321
    // fetch error
L
Liu Jicong 已提交
322 323 324
    return -1;
  }

L
Liu Jicong 已提交
325
  // judge and launch new query
L
Liu Jicong 已提交
326 327 328 329
  /*if (tqSendLaunchQuery(gHandle)) {*/
  // launch query error
  /*return -1;*/
  /*}*/
L
Liu Jicong 已提交
330 331
  return 0;
}
L
Liu Jicong 已提交
332
#endif
L
Liu Jicong 已提交
333

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

L
Liu Jicong 已提交
361 362
void* tqSerializeListHandle(STqList* listHandle, void* ptr) {
  STqList* node = listHandle;
363
  ASSERT(node != NULL);
L
Liu Jicong 已提交
364
  while (node) {
L
Liu Jicong 已提交
365
    ptr = tqSerializeTopic(&node->topic, ptr);
L
Liu Jicong 已提交
366 367
    node = node->next;
  }
368
  return ptr;
L
Liu Jicong 已提交
369
}
370

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

L
Liu Jicong 已提交
386
void* tqSerializeItem(STqMsgItem* bufItem, void* ptr) {
L
Liu Jicong 已提交
387 388
  // TODO: do we need serialize this?
  // mainly for executor
389
  return ptr;
L
Liu Jicong 已提交
390 391
}

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

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

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

L
Liu Jicong 已提交
445
// TODO: make this a macro
L
Liu Jicong 已提交
446
int tqGroupSSize(const STqGroup* gHandle) {
L
Liu Jicong 已提交
447 448
  return sizeof(int64_t) * 2  // cId + cgId
         + sizeof(int32_t)    // topicNum
L
Liu Jicong 已提交
449
         + gHandle->topicNum * tqTopicSSize();
L
Liu Jicong 已提交
450
}
451

L
Liu Jicong 已提交
452
// TODO: make this a macro
L
Liu Jicong 已提交
453
int tqTopicSSize() {
L
Liu Jicong 已提交
454 455
  return sizeof(int64_t) * 2    // nextConsumeOffset + topicId
         + sizeof(int32_t) * 2  // head + tail
L
Liu Jicong 已提交
456
         + TQ_BUFFER_SIZE * tqItemSSize();
L
Liu Jicong 已提交
457
}
458

L
Liu Jicong 已提交
459
int tqItemSSize() {
L
Liu Jicong 已提交
460 461
  // TODO: do this need serialization?
  // mainly for executor
L
Liu Jicong 已提交
462 463
  return 0;
}