tsdbMemTable.c 2.3 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/>.
H
Hongze Cheng 已提交
14 15 16 17
 */

#include "tsdbDef.h"

H
Hongze Cheng 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#if 1
typedef struct STbData {
  TD_SLIST_NODE(STbData);
  SSubmitMsg *pMsg;
} STbData;
#else
typedef struct STbData {
  TD_SLIST_NODE(STbData);
  uint64_t   uid;  // TODO: change here as tb_uid_t
  TSKEY      keyMin;
  TSKEY      keyMax;
  uint64_t   nRows;
  SSkipList *pData;  // Here need a container, may not use the SL
  T_REF_DECLARE()
} STbData;
#endif

H
Hongze Cheng 已提交
35 36 37 38 39
struct STsdbMemTable {
  T_REF_DECLARE()
  SRWLatch       latch;
  TSKEY          keyMin;
  TSKEY          keyMax;
H
Hongze Cheng 已提交
40
  uint64_t       nRow;
H
Hongze Cheng 已提交
41
  SMemAllocator *pMA;
H
Hongze Cheng 已提交
42 43
  // Container
  TD_SLIST(STbData) list;
H
Hongze Cheng 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
};

STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
  STsdbMemTable *pMemTable;
  SMemAllocator *pMA;

  pMA = (*pMAF->create)(pMAF);
  ASSERT(pMA != NULL);

  pMemTable = (STsdbMemTable *)((*pMA->malloc)(pMA, sizeof(*pMemTable)));
  if (pMemTable == NULL) {
    (*pMAF->destroy)(pMAF, pMA);
    return NULL;
  }

  T_REF_INIT_VAL(pMemTable, 1);
  taosInitRWLatch(&(pMemTable->latch));
  pMemTable->keyMin = TSKEY_MAX;
  pMemTable->keyMax = TSKEY_MIN;
  pMemTable->nRow = 0;
  pMemTable->pMA = pMA;
H
Hongze Cheng 已提交
65
  tSListInit(&(pMemTable->list));
H
Hongze Cheng 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

  // TODO
  return pMemTable;
}

void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) {
  SMemAllocator *pMA = pMemTable->pMA;

  if (pMA->free) {
    // TODO
    ASSERT(0);
  }

  (*pMAF->destroy)(pMAF, pMA);
}

int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg) {
H
Hongze Cheng 已提交
83 84 85 86 87 88 89 90
  SMemAllocator *pMA = pMemTable->pMA;
  STbData *      pTbData = (STbData *)((*pMA->malloc)(pMA, sizeof(*pTbData)));
  if (pTbData == NULL) {
    // TODO
  }

  tSListPush(&(pMemTable->list), pTbData);

H
Hongze Cheng 已提交
91
  return 0;
H
Hongze Cheng 已提交
92 93 94
}

/* ------------------------ STATIC METHODS ------------------------ */