tsdbMeta.h 3.6 KB
Newer Older
H
more  
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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/>.
 */
#if !defined(_TSDB_META_H_)
#define _TSDB_META_H_
H
more  
Hongze Cheng 已提交
17

H
more  
Hongze Cheng 已提交
18
#include <pthread.h>
H
more  
Hongze Cheng 已提交
19

H
hzcheng 已提交
20
#include "tsdb.h"
H
more  
hzcheng 已提交
21
#include "dataformat.h"
H
hzcheng 已提交
22
#include "tskiplist.h"
H
hzcheng 已提交
23
#include "tsdbMetaFile.h"
H
more  
hzcheng 已提交
24

H
more  
hzcheng 已提交
25 26 27 28
#ifdef __cplusplus
extern "C" {
#endif

H
more  
hzcheng 已提交
29
// #include "taosdef.h"
H
more  
Hongze Cheng 已提交
30

H
more  
Hongze Cheng 已提交
31 32
// Initially, there are 4 tables
#define TSDB_INIT_NUMBER_OF_SUPER_TABLE 4
H
more  
Hongze Cheng 已提交
33

H
hzcheng 已提交
34 35
#define IS_CREATE_STABLE(pCfg) ((pCfg)->tagValues != NULL)

H
TD-34  
hzcheng 已提交
36 37 38 39 40 41 42
typedef struct {
  TSKEY   keyFirst;
  TSKEY   keyLast;
  int32_t numOfPoints;
  void *  pData;
} SMemTable;

H
hzcheng 已提交
43
// ---------- TSDB TABLE DEFINITION
H
more  
Hongze Cheng 已提交
44
typedef struct STable {
H
TD-34  
hzcheng 已提交
45 46
  int8_t         type;
  STableId       tableId;
47
  int64_t        superUid;  // Super table UID
H
TD-34  
hzcheng 已提交
48 49 50 51 52 53 54
  int32_t        sversion;
  STSchema *     schema;
  STSchema *     tagSchema;
  SDataRow       tagVal;
  SMemTable *    mem;
  SMemTable *    imem;
  void *         pIndex;         // For TSDB_SUPER_TABLE, it is the skiplist index
H
hzcheng 已提交
55 56
  void *         eventHandler;   // TODO
  void *         streamHandler;  // TODO
H
TD-34  
hzcheng 已提交
57
  struct STable *next;           // TODO: remove the next
H
more  
Hongze Cheng 已提交
58 59
} STable;

H
hzcheng 已提交
60 61 62 63
void *  tsdbEncodeTable(STable *pTable, int *contLen);
STable *tsdbDecodeTable(void *cont, int contLen);
void *  tsdbFreeEncode(void *cont);

H
hzcheng 已提交
64
// ---------- TSDB META HANDLE DEFINITION
H
more  
Hongze Cheng 已提交
65
typedef struct {
H
hzcheng 已提交
66 67 68 69 70 71 72 73 74 75 76
  int32_t maxTables;  // Max number of tables

  int32_t nTables;  // Tables created

  STable **tables;  // table array

  STable *superList;  // super table list TODO: change  it to list container

  void *map; // table map of (uid ===> table)

  SMetaFile *mfh; // meta file handle
H
TD-34  
hzcheng 已提交
77 78
  int        maxRowBytes;
  int        maxCols;
H
hzcheng 已提交
79
} STsdbMeta;
H
more  
Hongze Cheng 已提交
80

H
hzcheng 已提交
81 82
STsdbMeta *tsdbInitMeta(const char *rootDir, int32_t maxTables);
int32_t    tsdbFreeMeta(STsdbMeta *pMeta);
H
TD-34  
hzcheng 已提交
83
STSchema * tsdbGetTableSchema(STsdbMeta *pMeta, STable *pTable);
H
hzcheng 已提交
84

H
more  
Hongze Cheng 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
// ---- Operation on STable
#define TSDB_TABLE_ID(pTable) ((pTable)->tableId)
#define TSDB_TABLE_UID(pTable) ((pTable)->uid)
#define TSDB_TABLE_NAME(pTable) ((pTable)->tableName)
#define TSDB_TABLE_TYPE(pTable) ((pTable)->type)
#define TSDB_TABLE_SUPER_TABLE_UID(pTable) ((pTable)->stableUid)
#define TSDB_TABLE_IS_SUPER_TABLE(pTable) (TSDB_TABLE_TYPE(pTable) == TSDB_SUPER_TABLE)
#define TSDB_TABLE_TAG_VALUE(pTable) ((pTable)->pTagVal)
#define TSDB_TABLE_CACHE_DATA(pTable) ((pTable)->content.pData)
#define TSDB_SUPER_TABLE_INDEX(pTable) ((pTable)->content.pIndex)

// ---- Operation on SMetaHandle
#define TSDB_NUM_OF_TABLES(pHandle) ((pHandle)->numOfTables)
#define TSDB_NUM_OF_SUPER_TABLES(pHandle) ((pHandle)->numOfSuperTables)
#define TSDB_TABLE_OF_ID(pHandle, id) ((pHandle)->pTables)[id]
H
more  
Hongze Cheng 已提交
100 101
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */

102 103
STsdbMeta* tsdbGetMeta(tsdb_repo_t* pRepo);

H
hzcheng 已提交
104 105
int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg);
int32_t tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId);
H
hzcheng 已提交
106
STable *tsdbIsValidTableToInsert(STsdbMeta *pMeta, STableId tableId);
H
TD-34  
hzcheng 已提交
107
// int32_t tsdbInsertRowToTableImpl(SSkipListNode *pNode, STable *pTable);
H
hzcheng 已提交
108
STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid);
H
TD-34  
hzcheng 已提交
109
char *getTupleKey(const void * data);
H
more  
hzcheng 已提交
110 111 112 113 114 115

#ifdef __cplusplus
}
#endif

#endif  // _TSDB_META_H_