tsdbMeta.h 2.8 KB
Newer Older
H
more  
Hongze Cheng 已提交
1 2 3 4
/************************************
 * For internal usage
 ************************************/

H
more  
Hongze Cheng 已提交
5
#include <pthread.h>
H
more  
Hongze Cheng 已提交
6

H
more  
hzcheng 已提交
7
// #include "taosdef.h"
H
more  
Hongze Cheng 已提交
8

H
more  
Hongze Cheng 已提交
9 10
// Initially, there are 4 tables
#define TSDB_INIT_NUMBER_OF_SUPER_TABLE 4
H
more  
Hongze Cheng 已提交
11

H
more  
Hongze Cheng 已提交
12
typedef enum {
H
more  
Hongze Cheng 已提交
13 14 15 16
  TSDB_SUPER_TABLE,  // super table
  TSDB_NTABLE,       // table not created from super table
  TSDB_STABLE        // table created from super table
} TSDB_TABLE_TYPE;
H
more  
Hongze Cheng 已提交
17 18

typedef struct STable {
H
more  
hzcheng 已提交
19
  int32_t         tableId;
H
more  
Hongze Cheng 已提交
20 21
  int64_t         uid;
  TSDB_TABLE_TYPE type;
H
more  
Hongze Cheng 已提交
22 23 24 25

  int64_t createdTime;

  // super table UID
H
more  
hzcheng 已提交
26
  int32_t superTableId;
H
more  
Hongze Cheng 已提交
27

H
more  
Hongze Cheng 已提交
28 29 30 31
  // Schema for this table
  // For TSDB_SUPER_TABLE, it is the schema including tags
  // For TSDB_NTABLE, it is only the schema, not including tags
  // For TSDB_STABLE, it is NULL
H
more  
hzcheng 已提交
32
  SSchema *pSchema;
H
more  
Hongze Cheng 已提交
33 34 35 36

  // Tag value for this table
  // For TSDB_SUPER_TABLE and TSDB_NTABLE, it is NULL
  // For TSDB_STABLE, it is the tag value string
H
more  
Hongze Cheng 已提交
37
  char *pTagVal;
H
more  
Hongze Cheng 已提交
38

H
more  
Hongze Cheng 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52
  // Object content;
  // For TSDB_SUPER_TABLE, it is the index of tables created from it
  // For TSDB_STABLE and TSDB_NTABLE, it is the cache data
  union {
    void *pData;
    void *pIndex;
  } content;

  // A handle to deal with event
  void *eventHandle;

  // A handle to deal with stream
  void *streamHandle;

H
more  
hzcheng 已提交
53 54
  struct STable *next;

H
more  
Hongze Cheng 已提交
55 56
} STable;

H
more  
Hongze Cheng 已提交
57
typedef struct {
H
more  
hzcheng 已提交
58 59 60 61
  int32_t          maxTables;
  int32_t          numOfSuperTables;  // Number of super tables (#TSDB_SUPER_TABLE)
  STable **        tables;            // array of normal tables
  STable *         stables;           // linked list of super tables
H
more  
hzcheng 已提交
62
  void *           tableMap;          // hash map of uid ==> STable *
H
hzcheng 已提交
63
} STsdbMeta;
H
more  
Hongze Cheng 已提交
64 65 66 67 68 69 70 71 72 73 74 75

// ---- 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)

H
more  
hzcheng 已提交
76
SSchema *tsdbGetTableSchema(STable *pTable);
H
more  
Hongze Cheng 已提交
77

H
more  
Hongze Cheng 已提交
78 79 80 81
// ---- 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 已提交
82 83 84
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */

// Create a new meta handle with configuration
H
more  
hzcheng 已提交
85 86
STsdbMeta *tsdbCreateMeta(int32_t maxTables);
int32_t    tsdbFreeMeta(STsdbMeta *pMeta);
H
more  
Hongze Cheng 已提交
87 88

// Recover the meta handle from the file
H
more  
hzcheng 已提交
89
STsdbMeta *tsdbOpenMetaHandle(char *tsdbDir);
H
more  
hzcheng 已提交
90

H
more  
hzcheng 已提交
91
int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg);