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

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,
S
Shengliang Guan 已提交
36
  SDB_TABLE_MAX     = 9
S
slguan 已提交
37 38
} ESdbTable;

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

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

S
TD-2046  
Shengliang Guan 已提交
51 52 53 54 55 56 57 58 59
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 已提交
60
  int32_t  (*fpReq)(SMnodeMsg *pMsg);
S
TD-2045  
Shengliang Guan 已提交
61
  int32_t  (*fpRsp)(SMnodeMsg *pMsg, int32_t code);
S
TD-2428  
Shengliang Guan 已提交
62
  char       reserveForSync[24];
63
  SWalHead   pHead;
S
TD-2046  
Shengliang Guan 已提交
64
} SSdbRow;
S
slguan 已提交
65 66

typedef struct {
S
TD-2046  
Shengliang Guan 已提交
67
  char *    name;
S
TD-2046  
Shengliang Guan 已提交
68 69 70
  int32_t   hashSessions;
  int32_t   maxRowSize;
  int32_t   refCountPos;
S
TD-2046  
Shengliang Guan 已提交
71
  ESdbTable id;
S
slguan 已提交
72
  ESdbKey   keyType;
S
TD-2046  
Shengliang Guan 已提交
73 74 75 76 77 78
  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 已提交
79
  int32_t (*fpRestored)();
S
slguan 已提交
80
} SSdbTableDesc;
S
slguan 已提交
81

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

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

S
Shengliang Guan 已提交
99 100 101
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 已提交
102 103 104 105
void     sdbIncRef(void *pTable, void *pRow);
void     sdbDecRef(void *pTable, void *pRow);
int64_t  sdbGetNumOfRows(void *pTable);
int32_t  sdbGetId(void *pTable);
S
slguan 已提交
106
uint64_t sdbGetVersion();
S
TD-2046  
Shengliang Guan 已提交
107
bool     sdbCheckRowDeleted(void *pTable, void *pRow);
S
slguan 已提交
108 109 110

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

#endif