mnodeSdb.h 3.0 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

S
slguan 已提交
26
typedef enum {
S
Shengliang Guan 已提交
27 28 29 30 31 32 33 34 35
  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,
36 37
  SDB_TABLE_FUNC    = 9,
  SDB_TABLE_MAX     = 10
S
slguan 已提交
38 39
} ESdbTable;

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

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

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

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

S
TD-2264  
Shengliang Guan 已提交
83 84
int32_t sdbInitRef();
void    sdbCleanUpRef();
S
slguan 已提交
85 86
int32_t sdbInit();
void    sdbCleanUp();
S
TD-2264  
Shengliang Guan 已提交
87 88 89
int64_t sdbOpenTable(SSdbTableDesc *desc);
void    sdbCloseTable(int64_t rid);
void*   sdbGetTableByRid(int64_t rid);
S
slguan 已提交
90
bool    sdbIsMaster();
S
slguan 已提交
91
bool    sdbIsServing();
S
slguan 已提交
92
void    sdbUpdateMnodeRoles();
S
TD-2331  
Shengliang Guan 已提交
93
int32_t sdbGetReplicaNum();
S
slguan 已提交
94

S
TD-2046  
Shengliang Guan 已提交
95 96 97 98
int32_t sdbInsertRow(SSdbRow *pRow);
int32_t sdbDeleteRow(SSdbRow *pRow);
int32_t sdbUpdateRow(SSdbRow *pRow);
int32_t sdbInsertRowToQueue(SSdbRow *pRow);
S
slguan 已提交
99

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

#ifdef __cplusplus
}
H
hzcheng 已提交
112
#endif
S
slguan 已提交
113

114
#endif