meta.h 2.8 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

D
dapan1121 已提交
19
#include "taosmsg.h"
H
refact  
Hongze Cheng 已提交
20

H
more  
Hongze Cheng 已提交
21 22
#include "os.h"

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

H
more  
Hongze Cheng 已提交
27
/* ------------------------ APIs Exposed ------------------------ */
H
more  
Hongze Cheng 已提交
28 29

// Types exported
H
more  
Hongze Cheng 已提交
30
typedef uint64_t                tb_uid_t;
H
refact  
Hongze Cheng 已提交
31 32 33 34 35
typedef struct SMeta            SMeta;
typedef struct SMetaOpts        SMetaOpts;
typedef struct SMetaQueryHandle SMetaQueryHandle;
typedef struct SMetaQueryOpts   SMetaQueryOpts;
typedef struct STableOpts       STableOpts;
H
more  
Hongze Cheng 已提交
36 37 38

// SMeta operations
int    metaCreate(const char *path);
H
more  
Hongze Cheng 已提交
39
void   metaDestroy(const char *path);
H
refact  
Hongze Cheng 已提交
40
SMeta *metaOpen(SMetaOpts *);
H
more  
Hongze Cheng 已提交
41
void   metaClose(SMeta *);
H
more  
Hongze Cheng 已提交
42
int    metaCreateTable(SMeta *, const STableOpts *);
H
more  
Hongze Cheng 已提交
43 44 45 46 47
int    metaDropTable(SMeta *, uint64_t tuid_t);
int    metaAlterTable(SMeta *, void *);
int    metaCommit(SMeta *);

// Options
H
refact  
Hongze Cheng 已提交
48 49 50
SMetaOpts *metaOptionsCreate();
void       metaOptionsDestroy(SMetaOpts *);
void       metaOptionsSetCache(SMetaOpts *, size_t capacity);
H
more  
Hongze Cheng 已提交
51 52

// SMetaQueryHandle
H
refact  
Hongze Cheng 已提交
53
SMetaQueryHandle *metaQueryHandleCreate(SMetaQueryOpts *);
H
more  
Hongze Cheng 已提交
54
void              metaQueryHandleDestroy(SMetaQueryHandle *);
H
refact  
Hongze Cheng 已提交
55

H
refact  
Hongze Cheng 已提交
56 57 58
// SMetaQueryOpts
SMetaQueryOpts *metaQueryOptionsCreate();
void            metaQueryOptionsDestroy(SMetaQueryOpts *);
H
refact  
Hongze Cheng 已提交
59

H
more  
Hongze Cheng 已提交
60
// STableOpts
H
more  
Hongze Cheng 已提交
61 62 63
#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0};
void metaNormalTableOptsInit(STableOpts *, const char *name, const STSchema *pSchema);
void metaTableOptsDestroy(STableOpts *);
H
more  
Hongze Cheng 已提交
64

H
more  
Hongze Cheng 已提交
65
/* ------------------------ Impl should hidden ------------------------ */
H
more  
Hongze Cheng 已提交
66
typedef enum { META_INIT_TABLE = 0, META_SUPER_TABLE = 1, META_CHILD_TABLE = 2, META_NORMAL_TABLE = 3 } EMetaTableT;
H
more  
Hongze Cheng 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
typedef struct SSuperTableOpts {
  tb_uid_t  uid;
  STSchema *pSchema;     // (ts timestamp, a int)
  STSchema *pTagSchema;  // (tag1 binary(10), tag2 int)
} SSuperTableOpts;

typedef struct SChildTableOpts {
  tb_uid_t suid;  // super table uid
  SKVRow   tags;  // tag value of the child table
} SChildTableOpts;

typedef struct SNormalTableOpts {
  STSchema *pSchema;
} SNormalTableOpts;

struct STableOpts {
H
more  
Hongze Cheng 已提交
83 84
  int8_t type;
  char * name;
H
more  
Hongze Cheng 已提交
85 86 87 88 89 90 91
  union {
    SSuperTableOpts  superOpts;
    SChildTableOpts  childOpts;
    SNormalTableOpts normalOpts;
  };
};

H
refact  
Hongze Cheng 已提交
92 93 94 95
#ifdef __cplusplus
}
#endif

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