tsdbMeta.h 2.5 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  
Hongze Cheng 已提交
7
#include "tsdb.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  
Hongze Cheng 已提交
19 20 21 22
  tsdb_id_t       tableId;
  int64_t         uid;
  char *          tableName;
  TSDB_TABLE_TYPE type;
H
more  
Hongze Cheng 已提交
23 24 25 26

  int64_t createdTime;

  // super table UID
H
more  
Hongze Cheng 已提交
27
  tsdb_id_t superTableId;
H
more  
Hongze Cheng 已提交
28

H
more  
Hongze Cheng 已提交
29 30 31 32 33 34 35 36 37
  // 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
  SVSchema *pSchema;

  // 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 已提交
38
  char *pTagVal;
H
more  
Hongze Cheng 已提交
39

H
more  
Hongze Cheng 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53
  // 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  
Hongze Cheng 已提交
54 55
} STable;

H
more  
Hongze Cheng 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
typedef struct {
  int32_t numOfTables;       // Number of tables not including TSDB_SUPER_TABLE (#TSDB_NTABLE + #TSDB_STABLE)
  int32_t numOfSuperTables;  // Number of super tables (#TSDB_SUPER_TABLE)
  // An array of tables (TSDB_NTABLE and TSDB_STABLE) in this TSDB repository
  STable **pTables;

  // A map of tableName->tableId
  // TODO: May use hash table
  void *pNameTableMap;
} SMetaHandle;

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

SVSchema *tsdbGetTableSchema(STable *pTable);
H
more  
Hongze Cheng 已提交
79

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