meta.h 3.5 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_META_H_
#define _TD_META_H_
H
refact  
Hongze Cheng 已提交
18

H
refact  
Hongze Cheng 已提交
19 20
#include "os.h"
#include "trow.h"
H
more  
Hongze Cheng 已提交
21

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

H
more  
Hongze Cheng 已提交
26
// Types exported
H
refact  
Hongze Cheng 已提交
27 28 29
typedef uint64_t     tb_uid_t;
typedef struct SMeta SMeta;

H
more  
Hongze Cheng 已提交
30 31 32 33
#define META_SUPER_TABLE 0
#define META_CHILD_TABLE 1
#define META_NORMAL_TABLE 2

H
refact  
Hongze Cheng 已提交
34 35 36 37 38 39 40 41 42 43
typedef struct SMetaCfg {
  /// LRU cache size
  uint64_t lruSize;
} SMetaCfg;

typedef struct STbCfg {
  /// name of the table
  char *name;
  /// time to live of the table
  uint32_t ttl;
H
more  
Hongze Cheng 已提交
44 45
  /// keep time of this table
  uint32_t keep;
H
refact  
Hongze Cheng 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  /// type of table
  uint8_t type;
  union {
    /// super table configurations
    struct {
      /// super table UID
      tb_uid_t suid;
      /// row schema
      STSchema *pSchema;
      /// tag schema
      STSchema *pTagSchema;
    } stbCfg;

    /// normal table configuration
    struct {
      /// row schema
      STSchema *pSchema;
    } ntbCfg;
    /// child table configuration
    struct {
      /// super table UID
      tb_uid_t suid;
H
more  
Hongze Cheng 已提交
68
      SKVRow   pTag;
H
refact  
Hongze Cheng 已提交
69 70 71
    } ctbCfg;
  };
} STbCfg;
H
more  
Hongze Cheng 已提交
72 73

// SMeta operations
H
more  
Hongze Cheng 已提交
74
SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg);
H
more  
Hongze Cheng 已提交
75
void   metaClose(SMeta *pMeta);
H
more  
Hongze Cheng 已提交
76
void   metaRemove(const char *path);
H
more  
Hongze Cheng 已提交
77
int    metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg);
H
more  
Hongze Cheng 已提交
78
int    metaDropTable(SMeta *pMeta, tb_uid_t uid);
H
more  
Hongze Cheng 已提交
79
int    metaCommit(SMeta *pMeta);
H
more  
Hongze Cheng 已提交
80 81

// Options
H
more  
Hongze Cheng 已提交
82 83
void metaOptionsInit(SMetaCfg *pMetaCfg);
void metaOptionsClear(SMetaCfg *pMetaCfg);
H
refact  
Hongze Cheng 已提交
84

H
more  
Hongze Cheng 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
// STbCfg
#define META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA)                   \
  {                                                                                     \
    .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_SUPER_TABLE, .stbCfg = { \
      .suid = (SUID),                                                                   \
      .pSchema = (PSCHEMA),                                                             \
      .pTagSchema = (PTAGSCHEMA)                                                        \
    }                                                                                   \
  }

#define META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG)                                                                \
  {                                                                                                                   \
    .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_CHILD_TABLE, .ctbCfg = {.suid = (SUID), .pTag = PTAG } \
  }

#define META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA)                                                      \
  {                                                                                                            \
    .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_NORMAL_TABLE, .ntbCfg = {.pSchema = (PSCHEMA) } \
  }

#define META_CLEAR_TB_CFG(pTbCfg)

int   metaEncodeTbCfg(void **pBuf, STbCfg *pTbCfg);
H
more  
Hongze Cheng 已提交
108
void *metaDecodeTbCfg(void *pBuf, STbCfg *pTbCfg);
H
more  
Hongze Cheng 已提交
109

H
refact  
Hongze Cheng 已提交
110 111 112 113
#ifdef __cplusplus
}
#endif

D
dapan1121 已提交
114
#endif /*_TD_META_H_*/