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
};

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

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

H
refact  
Hongze Cheng 已提交
53
  pMemTable = (STsdbMemTable *)TD_MA_MALLOC(pMA, sizeof(*pMemTable));
H
Hongze Cheng 已提交
54 55 56 57 58 59 60 61 62 63 64
  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
  TD_SLIST_INIT(&(pMemTable->list));
H
Hongze Cheng 已提交
66 67 68 69 70 71 72 73

  // TODO
  return pMemTable;
}

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

H
refact  
Hongze Cheng 已提交
74
  if (TD_MA_FREE_FUNC(pMA) != NULL) {
H
Hongze Cheng 已提交
75 76 77 78 79 80 81 82
    // TODO
    ASSERT(0);
  }

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

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

H
Hongze Cheng 已提交
89
  TD_SLIST_PUSH(&(pMemTable->list), pTbData);
H
Hongze Cheng 已提交
90

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

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