tsdbMeta.h 3.4 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
more  
hzcheng 已提交
20 21
#include "dataformat.h"

H
more  
hzcheng 已提交
22 23 24 25
#ifdef __cplusplus
extern "C" {
#endif

H
more  
hzcheng 已提交
26
// #include "taosdef.h"
H
more  
Hongze Cheng 已提交
27

H
more  
Hongze Cheng 已提交
28 29
// Initially, there are 4 tables
#define TSDB_INIT_NUMBER_OF_SUPER_TABLE 4
H
more  
Hongze Cheng 已提交
30

H
more  
Hongze Cheng 已提交
31
typedef enum {
H
more  
Hongze Cheng 已提交
32 33 34 35
  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 已提交
36 37

typedef struct STable {
H
more  
hzcheng 已提交
38
  STableId        tableId;
H
more  
Hongze Cheng 已提交
39
  TSDB_TABLE_TYPE type;
H
more  
Hongze Cheng 已提交
40 41 42

  int64_t createdTime;

H
more  
hzcheng 已提交
43 44 45 46
  // super table UID -1 for normal table
  int32_t stableUid;

  int32_t numOfCols;
H
more  
Hongze Cheng 已提交
47

H
more  
Hongze Cheng 已提交
48 49 50 51
  // 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 已提交
52
  SSchema *pSchema;
H
more  
Hongze Cheng 已提交
53 54 55 56

  // 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  
hzcheng 已提交
57
  SDataRow pTagVal;
H
more  
Hongze Cheng 已提交
58

H
more  
Hongze Cheng 已提交
59 60 61 62 63 64 65 66 67
  // 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
H
more  
hzcheng 已提交
68
  void *eventHandler;
H
more  
Hongze Cheng 已提交
69 70

  // A handle to deal with stream
H
more  
hzcheng 已提交
71
  void *streamHandler;
H
more  
Hongze Cheng 已提交
72

H
more  
hzcheng 已提交
73 74
  struct STable *next;

H
more  
Hongze Cheng 已提交
75 76
} STable;

H
more  
Hongze Cheng 已提交
77
typedef struct {
H
more  
hzcheng 已提交
78 79 80 81
  int32_t  maxTables;
  STable **tables;    // array of normal tables
  STable * stables;   // linked list of super tables
  void *   tableMap;  // hash map of uid ==> STable *
H
hzcheng 已提交
82
} STsdbMeta;
H
more  
Hongze Cheng 已提交
83 84 85 86 87 88 89 90 91 92 93 94

// ---- 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 已提交
95
SSchema *tsdbGetTableSchema(STable *pTable);
H
more  
Hongze Cheng 已提交
96

H
more  
Hongze Cheng 已提交
97 98 99 100
// ---- 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 已提交
101 102 103
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */

// Create a new meta handle with configuration
H
more  
hzcheng 已提交
104 105
STsdbMeta *tsdbCreateMeta(int32_t maxTables);
int32_t    tsdbFreeMeta(STsdbMeta *pMeta);
H
more  
Hongze Cheng 已提交
106 107

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

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

H
more  
hzcheng 已提交
112 113 114 115 116 117 118
int32_t tsdbInsertDataImpl(STsdbMeta *pMeta, STableId tableId, char *pData);

#ifdef __cplusplus
}
#endif

#endif  // _TSDB_META_H_