mnodeSdb.h 2.9 KB
Newer Older
H
hzcheng 已提交
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/>.
 */

S
slguan 已提交
16 17 18 19 20 21
#ifndef TDENGINE_MNODE_SDB_H
#define TDENGINE_MNODE_SDB_H

#ifdef __cplusplus
extern "C" {
#endif
H
hzcheng 已提交
22

S
TD-2046  
Shengliang Guan 已提交
23
#include "mnode.h"
S
TD-2046  
Shengliang Guan 已提交
24
#include "twal.h"
S
TD-2046  
Shengliang Guan 已提交
25 26

struct SSdbTable;
27

S
slguan 已提交
28
typedef enum {
S
Shengliang Guan 已提交
29 30 31 32 33 34 35 36 37
  SDB_TABLE_CLUSTER = 0,
  SDB_TABLE_DNODE   = 1,
  SDB_TABLE_MNODE   = 2,
  SDB_TABLE_ACCOUNT = 3,
  SDB_TABLE_USER    = 4,
  SDB_TABLE_DB      = 5,
  SDB_TABLE_VGROUP  = 6,
  SDB_TABLE_STABLE  = 7,
  SDB_TABLE_CTABLE  = 8,
S
Shengliang Guan 已提交
38
  SDB_TABLE_MAX     = 9
S
slguan 已提交
39 40
} ESdbTable;

S
slguan 已提交
41
typedef enum {
S
TD-2046  
Shengliang Guan 已提交
42 43 44 45
  SDB_KEY_STRING     = 0, 
  SDB_KEY_INT        = 1,
  SDB_KEY_AUTO       = 2,
  SDB_KEY_VAR_STRING = 3,
S
slguan 已提交
46
} ESdbKey;
S
slguan 已提交
47

S
slguan 已提交
48
typedef enum {
S
TD-2046  
Shengliang Guan 已提交
49 50
  SDB_OPER_GLOBAL = 0,
  SDB_OPER_LOCAL  = 1
S
slguan 已提交
51
} ESdbOper;
S
slguan 已提交
52

S
TD-2046  
Shengliang Guan 已提交
53
typedef struct SSWriteMsg {
S
slguan 已提交
54
  ESdbOper type;
S
TD-2046  
Shengliang Guan 已提交
55
  int32_t  processedCount;  // for sync fwd callback
S
TD-2045  
Shengliang Guan 已提交
56
  int32_t  code;            // for callback in sdb queue
57
  int32_t  rowSize;
S
Shengliang Guan 已提交
58
  void *   rowData;
S
TD-2046  
Shengliang Guan 已提交
59
  int32_t  (*fpReq)(SMnodeMsg *pMsg);
S
TD-2045  
Shengliang Guan 已提交
60
  int32_t  (*fpRsp)(SMnodeMsg *pMsg, int32_t code);
S
TD-2046  
Shengliang Guan 已提交
61
  void *   pRow;
S
TD-2046  
Shengliang Guan 已提交
62 63
  SMnodeMsg *pMsg;
  struct SSdbTable *pTable;
S
TD-2046  
Shengliang Guan 已提交
64 65
  char     reserveForSync[16];
  SWalHead pHead[];
S
TD-2046  
Shengliang Guan 已提交
66
} SSWriteMsg;
S
slguan 已提交
67 68

typedef struct {
S
TD-2046  
Shengliang Guan 已提交
69
  char *    name;
S
TD-2046  
Shengliang Guan 已提交
70 71 72
  int32_t   hashSessions;
  int32_t   maxRowSize;
  int32_t   refCountPos;
S
TD-2046  
Shengliang Guan 已提交
73
  ESdbTable id;
S
slguan 已提交
74
  ESdbKey   keyType;
S
TD-2046  
Shengliang Guan 已提交
75 76 77 78 79 80
  int32_t (*fpInsert)(SSWriteMsg *pWrite);
  int32_t (*fpDelete)(SSWriteMsg *pWrite);
  int32_t (*fpUpdate)(SSWriteMsg *pWrite);
  int32_t (*fpEncode)(SSWriteMsg *pWrite);
  int32_t (*fpDecode)(SSWriteMsg *pWrite);  
  int32_t (*fpDestroy)(SSWriteMsg *pWrite);
S
TD-2046  
Shengliang Guan 已提交
81
  int32_t (*fpRestored)();
S
slguan 已提交
82
} SSdbTableDesc;
S
slguan 已提交
83

S
slguan 已提交
84 85
int32_t sdbInit();
void    sdbCleanUp();
S
slguan 已提交
86 87
void *  sdbOpenTable(SSdbTableDesc *desc);
void    sdbCloseTable(void *handle);
S
slguan 已提交
88
bool    sdbIsMaster();
S
slguan 已提交
89
bool    sdbIsServing();
S
slguan 已提交
90
void    sdbUpdateMnodeRoles();
S
slguan 已提交
91

S
TD-2046  
Shengliang Guan 已提交
92 93 94
int32_t sdbInsertRow(SSWriteMsg *pWrite);
int32_t sdbDeleteRow(SSWriteMsg *pWrite);
int32_t sdbUpdateRow(SSWriteMsg *pWrite);
S
TD-2046  
Shengliang Guan 已提交
95
int32_t sdbInsertRowToQueue(SSWriteMsg *pWrite);
S
slguan 已提交
96

S
TD-2046  
Shengliang Guan 已提交
97 98
void    *sdbGetRow(void *pTable, void *key);
void    *sdbFetchRow(void *pTable, void *pIter, void **ppRow);
S
Shengliang Guan 已提交
99
void     sdbFreeIter(void *pIter);
S
TD-2046  
Shengliang Guan 已提交
100 101 102 103
void     sdbIncRef(void *pTable, void *pRow);
void     sdbDecRef(void *pTable, void *pRow);
int64_t  sdbGetNumOfRows(void *pTable);
int32_t  sdbGetId(void *pTable);
S
slguan 已提交
104
uint64_t sdbGetVersion();
S
TD-2046  
Shengliang Guan 已提交
105
bool     sdbCheckRowDeleted(void *pTable, void *pRow);
S
slguan 已提交
106 107 108

#ifdef __cplusplus
}
H
hzcheng 已提交
109
#endif
S
slguan 已提交
110 111

#endif