tsdbMemTable.h 2.2 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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
refact  
Hongze Cheng 已提交
16 17
#ifndef _TD_TSDB_MEM_TABLE_H_
#define _TD_TSDB_MEM_TABLE_H_
H
refact  
Hongze Cheng 已提交
18

H
refact  
Hongze Cheng 已提交
19 20
#include "tsdb.h"

H
refact  
Hongze Cheng 已提交
21 22 23 24
#ifdef __cplusplus
extern "C" {
#endif

H
Hongze Cheng 已提交
25 26 27 28 29 30 31 32 33 34
typedef struct {
  int   rowsInserted;
  int   rowsUpdated;
  int   rowsDeleteSucceed;
  int   rowsDeleteFailed;
  int   nOperations;
  TSKEY keyFirst;
  TSKEY keyLast;
} SMergeInfo;

H
more  
Hongze Cheng 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
typedef struct STbData {
  tb_uid_t   uid;
  TSKEY      keyMin;
  TSKEY      keyMax;
  int64_t    nrows;
  SSkipList *pData;
} STbData;

typedef struct STsdbMemTable {
  T_REF_DECLARE()
  SRWLatch       latch;
  TSKEY          keyMin;
  TSKEY          keyMax;
  uint64_t       nRow;
  SMemAllocator *pMA;
  // Container
  SSkipList *pSlIdx;  // SSkiplist<STbData>
  SHashObj * pHashIdx;
} STsdbMemTable;

H
Hongze Cheng 已提交
55 56
STsdbMemTable *tsdbNewMemTable(STsdb *pTsdb);
void           tsdbFreeMemTable(STsdb *pTsdb, STsdbMemTable *pMemTable);
S
Shengliang Guan 已提交
57
int            tsdbMemTableInsert(STsdb *pTsdb, STsdbMemTable *pMemTable, SSubmitReq *pMsg, SSubmitRsp *pRsp);
H
Hongze Cheng 已提交
58 59 60
int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols,
                          TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo);

C
Cary Xu 已提交
61
static FORCE_INLINE STSRow *tsdbNextIterRow(SSkipListIterator *pIter) {
H
Hongze Cheng 已提交
62 63 64 65 66
  if (pIter == NULL) return NULL;

  SSkipListNode *node = tSkipListIterGet(pIter);
  if (node == NULL) return NULL;

C
Cary Xu 已提交
67
  return (STSRow *)SL_GET_NODE_DATA(node);
H
Hongze Cheng 已提交
68
}
H
refact  
Hongze Cheng 已提交
69

H
more  
Hongze Cheng 已提交
70
static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator *pIter) {
C
Cary Xu 已提交
71
  STSRow *row = tsdbNextIterRow(pIter);
H
more  
Hongze Cheng 已提交
72 73
  if (row == NULL) return TSDB_DATA_TIMESTAMP_NULL;

C
Cary Xu 已提交
74
  return TD_ROW_KEY(row);
H
more  
Hongze Cheng 已提交
75 76
}

H
refact  
Hongze Cheng 已提交
77 78 79 80
#ifdef __cplusplus
}
#endif

H
refact  
Hongze Cheng 已提交
81
#endif /*_TD_TSDB_MEM_TABLE_H_*/