mnodeSdb.h 2.8 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 24 25
#include "mnode.h"

struct SSdbTable;
26

S
slguan 已提交
27
typedef enum {
S
Shengliang Guan 已提交
28 29 30 31 32 33 34 35 36
  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 已提交
37
  SDB_TABLE_MAX     = 9
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
typedef struct SSWriteMsg {
S
slguan 已提交
53
  ESdbOper type;
S
TD-2046  
Shengliang Guan 已提交
54
  int32_t  processedCount;  // for sync fwd callback
S
TD-2045  
Shengliang Guan 已提交
55
  int32_t  code;            // for callback in sdb queue
56
  int32_t  rowSize;
S
Shengliang Guan 已提交
57
  void *   rowData;
S
TD-2046  
Shengliang Guan 已提交
58
  int32_t  (*fpReq)(SMnodeMsg *pMsg);
S
TD-2045  
Shengliang Guan 已提交
59
  int32_t  (*fpRsp)(SMnodeMsg *pMsg, int32_t code);
S
TD-2046  
Shengliang Guan 已提交
60
  void *   pRow;
S
TD-2046  
Shengliang Guan 已提交
61 62
  SMnodeMsg *pMsg;
  struct SSdbTable *pTable;
S
TD-2046  
Shengliang Guan 已提交
63
} SSWriteMsg;
S
slguan 已提交
64 65

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

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

S
TD-2046  
Shengliang Guan 已提交
89 90 91 92
int32_t sdbInsertRow(SSWriteMsg *pWrite);
int32_t sdbDeleteRow(SSWriteMsg *pWrite);
int32_t sdbUpdateRow(SSWriteMsg *pWrite);
int32_t sdbInsertRowImp(SSWriteMsg *pWrite);
S
slguan 已提交
93

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

#ifdef __cplusplus
}
H
hzcheng 已提交
106
#endif
S
slguan 已提交
107 108

#endif