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;
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 60 61
void tqClose(STQ* pTq) {
  // TODO
}
L
Liu Jicong 已提交
62

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

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

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

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

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

L
Liu Jicong 已提交
127 128 129
  return 0;
}

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

L
Liu Jicong 已提交
142
  return pGroup;
L
Liu Jicong 已提交
143
}
L
Liu Jicong 已提交
144

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

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

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

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

L
Liu Jicong 已提交
199 200 201 202 203 204 205 206 207 208 209
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 已提交
210

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

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

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

L
Liu Jicong 已提交
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 270 271 272
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 已提交
273 274 275
  return 0;
}

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

L
Liu Jicong 已提交
321
  STqConsumeRsp* pRsp = (STqConsumeRsp*)pMsg;
L
Liu Jicong 已提交
322

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

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

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

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

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

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

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

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

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

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

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

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