Merge branch '3.0' into feature/tq
This commit is contained in:
commit
ca9a566bd7
|
@ -50,6 +50,11 @@ if(${BUILD_WITH_LUCENE})
|
|||
cat("${CMAKE_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${DEPS_TMP_FILE})
|
||||
endif(${BUILD_WITH_LUCENE})
|
||||
|
||||
## NuRaft
|
||||
if(${BUILD_WITH_NURAFT})
|
||||
cat("${CMAKE_SUPPORT_DIR}/nuraft_CMakeLists.txt.in" ${DEPS_TMP_FILE})
|
||||
endif(${BUILD_WITH_NURAFT})
|
||||
|
||||
## download dependencies
|
||||
configure_file(${DEPS_TMP_FILE} "${CMAKE_SOURCE_DIR}/deps/deps-download/CMakeLists.txt")
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
|
||||
|
@ -69,4 +74,7 @@ target_include_directories(api INTERFACE "include/client")
|
|||
# src
|
||||
add_subdirectory(source)
|
||||
|
||||
# docs
|
||||
add_subdirectory(docs)
|
||||
|
||||
# tests (TODO)
|
||||
|
|
|
@ -142,7 +142,7 @@ pipeline {
|
|||
}
|
||||
}
|
||||
// stage('Parallel test stage') {
|
||||
// //only build pr
|
||||
// skip defaultCheckout
|
||||
// options { skipDefaultCheckout() }
|
||||
// when {
|
||||
// allOf{
|
||||
|
|
|
@ -16,7 +16,7 @@ option(
|
|||
option(
|
||||
BUILD_WITH_ROCKSDB
|
||||
"If build with rocksdb"
|
||||
OFF
|
||||
ON
|
||||
)
|
||||
|
||||
option(
|
||||
|
@ -25,8 +25,20 @@ option(
|
|||
OFF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_WITH_NURAFT
|
||||
"If build with NuRaft"
|
||||
OFF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_DEPENDENCY_TESTS
|
||||
"If build dependency tests"
|
||||
OFF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_DOCS
|
||||
"If use doxygen build documents"
|
||||
ON
|
||||
)
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
# NuRaft
|
||||
ExternalProject_Add(NuRaft
|
||||
GIT_REPOSITORY https://github.com/eBay/NuRaft.git
|
||||
GIT_TAG v1.3.0
|
||||
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/nuraft"
|
||||
BINARY_DIR "${CMAKE_SOURCE_DIR}/deps/nuraft"
|
||||
CONFIGURE_COMMAND "./prepare.sh"
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
|
@ -67,6 +67,12 @@ if(${BUILD_WITH_LUCENE})
|
|||
add_subdirectory(lucene)
|
||||
endif(${BUILD_WITH_LUCENE})
|
||||
|
||||
# NuRaft
|
||||
if(${BUILD_WITH_NURAFT})
|
||||
add_subdirectory(nuraft)
|
||||
endif(${BUILD_WITH_NURAFT})
|
||||
|
||||
|
||||
# ================================================================================================
|
||||
# DEPENDENCY TEST
|
||||
# ================================================================================================
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Generate API documentation
|
||||
## https://vicrucann.github.io/tutorials/quick-cmake-doxygen/
|
||||
if(${BUILD_DOCS})
|
||||
find_package(Doxygen)
|
||||
if (DOXYGEN_FOUND)
|
||||
# Build the doc
|
||||
set(DOXYGEN_IN ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in)
|
||||
set(DOXYGEN_OUT ${CMAKE_BINARY_DIR}/Doxyfile)
|
||||
|
||||
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
|
||||
message("Doxygen build start")
|
||||
|
||||
add_custom_target(
|
||||
tdengine_doxygen ALL
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Generating API doxumentation with Doxygen"
|
||||
VERBATIM
|
||||
)
|
||||
else(DOXYGEN_FOUND)
|
||||
message("Doxygen need to be installed to generate the doxygen documentation")
|
||||
endif(DOXYGEN_FOUND)
|
||||
endif(${BUILD_DOCS})
|
File diff suppressed because it is too large
Load Diff
|
@ -19,7 +19,7 @@
|
|||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tarray.h"
|
||||
|
||||
#include "tvariant.h"
|
||||
//typedef struct STimeWindow {
|
||||
// TSKEY skey;
|
||||
// TSKEY ekey;
|
||||
|
@ -66,4 +66,59 @@ typedef struct SColumnInfoData {
|
|||
char *pData; // the corresponding block data in memory
|
||||
} SColumnInfoData;
|
||||
|
||||
//======================================================================================================================
|
||||
// the following structure shared by parser and executor
|
||||
typedef struct SColumn {
|
||||
uint64_t uid;
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
int8_t flag; // column type: normal column, tag, or user-input column (integer/float/string)
|
||||
SColumnInfo info;
|
||||
} SColumn;
|
||||
|
||||
typedef struct SLimit {
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
} SLimit;
|
||||
|
||||
typedef struct SOrder {
|
||||
uint32_t order;
|
||||
int32_t orderColId;
|
||||
} SOrder;
|
||||
|
||||
typedef struct SGroupbyExpr {
|
||||
SArray* columnInfo; // SArray<SColIndex>, group by columns information
|
||||
bool groupbyTag; // group by tag or column
|
||||
} SGroupbyExpr;
|
||||
|
||||
// the structure for sql function in select clause
|
||||
typedef struct SSqlExpr {
|
||||
char token[TSDB_COL_NAME_LEN]; // original token
|
||||
SSchema resSchema;
|
||||
|
||||
int32_t numOfCols;
|
||||
SColumn* pColumns; // data columns that are required by query
|
||||
int32_t interBytes; // inter result buffer size
|
||||
int16_t numOfParams; // argument value of each function
|
||||
SVariant param[3]; // parameters are not more than 3
|
||||
} SSqlExpr;
|
||||
|
||||
typedef struct SExprInfo {
|
||||
struct SSqlExpr base;
|
||||
struct tExprNode *pExpr;
|
||||
} SExprInfo;
|
||||
|
||||
typedef struct SStateWindow {
|
||||
SColumn col;
|
||||
} SStateWindow;
|
||||
|
||||
typedef struct SSessionWindow {
|
||||
int64_t gap; // gap between two session window(in microseconds)
|
||||
SColumn col;
|
||||
} SSessionWindow;
|
||||
|
||||
#define QUERY_ASC_FORWARD_STEP 1
|
||||
#define QUERY_DESC_FORWARD_STEP -1
|
||||
|
||||
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
|
||||
|
||||
#endif // TDENGINE_COMMON_H
|
||||
|
|
|
@ -204,14 +204,14 @@ enum _mgmt_table {
|
|||
#define TSDB_COL_NORMAL 0x0u // the normal column of the table
|
||||
#define TSDB_COL_TAG 0x1u // the tag column type
|
||||
#define TSDB_COL_UDC 0x2u // the user specified normal string column, it is a dummy column
|
||||
#define TSDB_COL_NULL 0x4u // the column filter NULL or not
|
||||
#define TSDB_COL_TMP 0x4u // internal column generated by the previous operators
|
||||
#define TSDB_COL_NULL 0x8u // the column filter NULL or not
|
||||
|
||||
#define TSDB_COL_IS_TAG(f) (((f&(~(TSDB_COL_NULL)))&TSDB_COL_TAG) != 0)
|
||||
#define TSDB_COL_IS_NORMAL_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
|
||||
#define TSDB_COL_IS_UD_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_UDC)
|
||||
#define TSDB_COL_REQ_NULL(f) (((f)&TSDB_COL_NULL) != 0)
|
||||
|
||||
|
||||
extern char *taosMsg[];
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
@ -399,8 +399,6 @@ typedef struct {
|
|||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
int8_t privilege;
|
||||
int8_t flag;
|
||||
} SCreateUserMsg, SAlterUserMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -491,11 +489,6 @@ typedef struct SInterval {
|
|||
int64_t offset;
|
||||
} SInterval;
|
||||
|
||||
typedef struct SSessionWindow {
|
||||
int64_t gap; // gap between two session window(in microseconds)
|
||||
int32_t primaryColId; // primary timestamp column
|
||||
} SSessionWindow;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
char version[TSDB_VERSION_LEN];
|
||||
|
@ -520,7 +513,7 @@ typedef struct {
|
|||
int16_t orderColId;
|
||||
int16_t numOfCols; // the number of columns will be load from vnode
|
||||
SInterval interval;
|
||||
SSessionWindow sw; // session window
|
||||
// SSessionWindow sw; // session window
|
||||
uint16_t tagCondLen; // tag length in current query
|
||||
uint16_t colCondLen; // column length in current query
|
||||
int16_t numOfGroupCols; // num of group by columns
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef TDENGINE_TNAME_H
|
||||
#define TDENGINE_TNAME_H
|
||||
|
||||
#include "taosmsg.h"
|
||||
|
||||
#define TSDB_DB_NAME_T 1
|
||||
#define TSDB_TABLE_NAME_T 2
|
||||
|
||||
|
@ -52,6 +54,8 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type);
|
|||
|
||||
int32_t tNameSetAcctId(SName* dst, const char* acct);
|
||||
|
||||
SSchema* tGetTbnameColumnSchema();
|
||||
|
||||
#if 0
|
||||
int32_t tNameSetDbName(SName* dst, const char* acct, SToken* dbToken);
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_TREQUEST_H_
|
||||
#define _TD_TREQUEST_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SRequest SRequest;
|
||||
typedef struct SReqBatch SReqBatch;
|
||||
typedef struct SReqBatchIter SReqBatchIter;
|
||||
|
||||
// SRequest
|
||||
|
||||
// SReqBatch
|
||||
|
||||
// SReqBatchIter
|
||||
void tdInitRBIter(SReqBatchIter *pIter, SReqBatch *pReqBatch);
|
||||
const SRequest *tdRBIterNext(SReqBatchIter *pIter);
|
||||
void tdClearRBIter(SReqBatchIter *pIter);
|
||||
|
||||
/* ------------------------ TYPES DEFINITION ------------------------ */
|
||||
struct SReqBatchIter {
|
||||
int iReq;
|
||||
SReqBatch *pReqBatch;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_TREQUEST_H_*/
|
|
@ -21,7 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "tdef.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
#define MEM_BUF_SIZE (1 << 20)
|
|
@ -55,17 +55,16 @@ typedef struct {
|
|||
int32_t mnodeInit(SMnodePara para);
|
||||
void mnodeCleanup();
|
||||
|
||||
int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg);
|
||||
void mnodeUnDeploy(char *path);
|
||||
int32_t mnodeStart(char *path, SMnodeCfg *pCfg);
|
||||
int32_t mnodeDeploy(SMnodeCfg *pCfg);
|
||||
void mnodeUnDeploy();
|
||||
int32_t mnodeStart(SMnodeCfg *pCfg);
|
||||
int32_t mnodeAlter(SMnodeCfg *pCfg);
|
||||
void mnodeStop();
|
||||
|
||||
int32_t mnodeGetLoad(SMnodeLoad *pLoad);
|
||||
int32_t mnodeRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
|
||||
SMnodeMsg *mnodeInitMsg(int32_t msgNum);
|
||||
int32_t mnodeAppendMsg(SMnodeMsg *pMsg, SRpcMsg *pRpcMsg);
|
||||
SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg);
|
||||
void mnodeCleanupMsg(SMnodeMsg *pMsg);
|
||||
void mnodeProcessMsg(SMnodeMsg *pMsg, EMnMsgType msgType);
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_SDB_H_
|
||||
#define _TD_SDB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SDB_GET_INT64(pData, pRow, dataPos, val) \
|
||||
{ \
|
||||
if (sdbGetRawInt64(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRow(pRow); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int64_t); \
|
||||
}
|
||||
|
||||
#define SDB_GET_INT32(pData, pRow, dataPos, val) \
|
||||
{ \
|
||||
if (sdbGetRawInt32(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRow(pRow); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int32_t); \
|
||||
}
|
||||
|
||||
#define SDB_GET_INT8(pData, pRow, dataPos, val) \
|
||||
{ \
|
||||
if (sdbGetRawInt8(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRow(pRow); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int8_t); \
|
||||
}
|
||||
|
||||
#define SDB_GET_BINARY(pRaw, pRow, dataPos, val, valLen) \
|
||||
{ \
|
||||
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
|
||||
sdbFreeRow(pRow); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
}
|
||||
|
||||
#define SDB_SET_INT64(pData, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt64(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
dataPos += sizeof(int64_t); \
|
||||
}
|
||||
|
||||
#define SDB_SET_INT32(pData, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt32(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
dataPos += sizeof(int32_t); \
|
||||
}
|
||||
|
||||
#define SDB_SET_INT8(pData, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt8(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
dataPos += sizeof(int8_t); \
|
||||
}
|
||||
|
||||
#define SDB_SET_BINARY(pRaw, dataPos, val, valLen) \
|
||||
{ \
|
||||
if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
dataPos += valLen; \
|
||||
}
|
||||
|
||||
#define SDB_SET_DATALEN(pRaw, dataLen) \
|
||||
{ \
|
||||
if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
}; \
|
||||
}
|
||||
|
||||
typedef struct SSdbRaw SSdbRaw;
|
||||
typedef struct SSdbRow SSdbRow;
|
||||
typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType;
|
||||
typedef enum {
|
||||
SDB_STATUS_CREATING = 1,
|
||||
SDB_STATUS_READY = 2,
|
||||
SDB_STATUS_DROPPING = 3,
|
||||
SDB_STATUS_DROPPED = 4
|
||||
} ESdbStatus;
|
||||
|
||||
typedef enum {
|
||||
SDB_START = 0,
|
||||
SDB_TRANS = 1,
|
||||
SDB_CLUSTER = 2,
|
||||
SDB_DNODE = 3,
|
||||
SDB_MNODE = 4,
|
||||
SDB_USER = 5,
|
||||
SDB_AUTH = 6,
|
||||
SDB_ACCT = 7,
|
||||
SDB_DB = 8,
|
||||
SDB_VGROUP = 9,
|
||||
SDB_STABLE = 10,
|
||||
SDB_FUNC = 11,
|
||||
SDB_MAX = 12
|
||||
} ESdbType;
|
||||
|
||||
typedef int32_t (*SdbInsertFp)(void *pObj);
|
||||
typedef int32_t (*SdbUpdateFp)(void *pSrcObj, void *pDstObj);
|
||||
typedef int32_t (*SdbDeleteFp)(void *pObj);
|
||||
typedef int32_t (*SdbDeployFp)();
|
||||
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
|
||||
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
|
||||
|
||||
typedef struct {
|
||||
ESdbType sdbType;
|
||||
EKeyType keyType;
|
||||
SdbDeployFp deployFp;
|
||||
SdbEncodeFp encodeFp;
|
||||
SdbDecodeFp decodeFp;
|
||||
SdbInsertFp insertFp;
|
||||
SdbUpdateFp updateFp;
|
||||
SdbDeleteFp deleteFp;
|
||||
} SSdbTable;
|
||||
|
||||
int32_t sdbInit();
|
||||
void sdbCleanup();
|
||||
void sdbSetTable(SSdbTable table);
|
||||
|
||||
int32_t sdbOpen();
|
||||
void sdbClose();
|
||||
int32_t sdbWrite(SSdbRaw *pRaw);
|
||||
|
||||
int32_t sdbDeploy();
|
||||
void sdbUnDeploy();
|
||||
|
||||
void *sdbAcquire(ESdbType sdb, void *pKey);
|
||||
void sdbRelease(void *pObj);
|
||||
void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj);
|
||||
void sdbCancelFetch(void *pIter);
|
||||
int32_t sdbGetSize(ESdbType sdb);
|
||||
|
||||
SSdbRaw *sdbAllocRaw(ESdbType sdb, int8_t sver, int32_t dataLen);
|
||||
void sdbFreeRaw(SSdbRaw *pRaw);
|
||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val);
|
||||
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val);
|
||||
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val);
|
||||
int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen);
|
||||
int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen);
|
||||
int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status);
|
||||
int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val);
|
||||
int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val);
|
||||
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val);
|
||||
int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen);
|
||||
int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver);
|
||||
int32_t sdbGetRawTotalSize(SSdbRaw *pRaw);
|
||||
|
||||
SSdbRow *sdbAllocRow(int32_t objSize);
|
||||
void sdbFreeRow(SSdbRow *pRow);
|
||||
void *sdbGetRowObj(SSdbRow *pRow);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_SDB_H_*/
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_TRANSACTION_H_
|
||||
#define _TD_TRANSACTION_H_
|
||||
|
||||
#include "sdb.h"
|
||||
#include "taosmsg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct STrans STrans;
|
||||
typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;
|
||||
|
||||
int32_t trnInit();
|
||||
void trnCleanup();
|
||||
|
||||
STrans *trnCreate(ETrnPolicy);
|
||||
void trnDrop(STrans *pTrans);
|
||||
void trnSetRpcHandle(STrans *pTrans, void *rpcHandle);
|
||||
int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t trnAppendCommitLog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *, void *pMsg);
|
||||
int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *, void *pMsg);
|
||||
|
||||
int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData));
|
||||
int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code);
|
||||
int32_t trnExecute(int32_t tranId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_TRANSACTION_H_*/
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_META_IMPL_H_
|
||||
#define _TD_META_IMPL_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#include "taosmsg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef uint64_t tb_uid_t;
|
||||
|
||||
/* ------------------------ SMetaOptions ------------------------ */
|
||||
struct SMetaOptions {
|
||||
size_t lruCacheSize; // LRU cache size
|
||||
};
|
||||
|
||||
/* ------------------------ STbOptions ------------------------ */
|
||||
#define META_NORMAL_TABLE ((uint8_t)1)
|
||||
#define META_SUPER_TABLE ((uint8_t)2)
|
||||
#define META_CHILD_TABLE ((uint8_t)3)
|
||||
|
||||
typedef struct {
|
||||
} SSMAOptions;
|
||||
|
||||
// super table options
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
STSchema* pSchema;
|
||||
STSchema* pTagSchema;
|
||||
} SSTbOptions;
|
||||
|
||||
// child table options
|
||||
typedef struct {
|
||||
tb_uid_t suid;
|
||||
SKVRow tags;
|
||||
} SCTbOptions;
|
||||
|
||||
// normal table options
|
||||
typedef struct {
|
||||
STSchema* pSchame;
|
||||
} SNTbOptions;
|
||||
|
||||
struct STbOptions {
|
||||
uint8_t type;
|
||||
char* name;
|
||||
uint32_t ttl; // time to live in (SECONDS)
|
||||
SSMAOptions bsma; // Block-wise sma
|
||||
union {
|
||||
SSTbOptions stbOptions;
|
||||
SNTbOptions ntbOptions;
|
||||
SCTbOptions ctbOptions;
|
||||
};
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_META_IMPL_H_*/
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_META_H_
|
||||
#define _TD_META_H_
|
||||
|
||||
#include "impl/metaImpl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Types exported
|
||||
typedef struct SMeta SMeta;
|
||||
typedef struct SMetaOptions SMetaOptions;
|
||||
typedef struct STbOptions STbOptions;
|
||||
|
||||
// SMeta operations
|
||||
SMeta *metaOpen(const char *path, const SMetaOptions *);
|
||||
void metaClose(SMeta *);
|
||||
void metaRemove(const char *path);
|
||||
int metaCreateTable(SMeta *pMeta, const STbOptions *);
|
||||
int metaDropTable(SMeta *pMeta, tb_uid_t uid);
|
||||
int metaCommit(SMeta *);
|
||||
|
||||
// Options
|
||||
void metaOptionsInit(SMetaOptions *);
|
||||
void metaOptionsClear(SMetaOptions *);
|
||||
|
||||
// STableOpts
|
||||
#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0}
|
||||
void metaNormalTableOptsInit(STbOptions *, const char *name, const STSchema *pSchema);
|
||||
void metaSuperTableOptsInit(STbOptions *, const char *name, tb_uid_t uid, const STSchema *pSchema,
|
||||
const STSchema *pTagSchema);
|
||||
void metaChildTableOptsInit(STbOptions *, const char *name, tb_uid_t suid, const SKVRow tags);
|
||||
void metaTableOptsClear(STbOptions *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_META_H_*/
|
|
@ -23,6 +23,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
struct STsdbOptions {
|
||||
size_t lruCacheSize;
|
||||
/* TODO */
|
||||
};
|
||||
|
|
@ -17,14 +17,80 @@
|
|||
#define _TD_VNODE_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "trpc.h"
|
||||
#include "trequest.h"
|
||||
|
||||
#include "meta.h"
|
||||
#include "tq.h"
|
||||
#include "tsdb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SVnode SVnode;
|
||||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SVnode SVnode;
|
||||
typedef struct SVnodeOptions SVnodeOptions;
|
||||
|
||||
/* ------------------------ SVnode ------------------------ */
|
||||
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions);
|
||||
void vnodeClose(SVnode *pVnode);
|
||||
void vnodeDestroy(const char *path);
|
||||
int vnodeProcessWriteReqs(SVnode *pVnode, SReqBatch *pReqBatch);
|
||||
int vnodeApplyWriteRequest(SVnode *pVnode, const SRequest *pRequest);
|
||||
int vnodeProcessReadReq(SVnode *pVnode, SRequest *pReq);
|
||||
int vnodeProcessSyncReq(SVnode *pVnode, SRequest *pReq);
|
||||
|
||||
/* ------------------------ SVnodeOptions ------------------------ */
|
||||
void vnodeOptionsInit(SVnodeOptions *);
|
||||
void vnodeOptionsClear(SVnodeOptions *);
|
||||
|
||||
/* ------------------------ STRUCT DEFINITIONS ------------------------ */
|
||||
struct SVnodeOptions {
|
||||
/**
|
||||
* @brief write buffer size in BYTES
|
||||
*
|
||||
*/
|
||||
uint64_t wsize;
|
||||
|
||||
/**
|
||||
* @brief time to live of tables in this vnode
|
||||
* in SECONDS
|
||||
*
|
||||
*/
|
||||
uint32_t ttl;
|
||||
|
||||
/**
|
||||
* @brief if time-series requests eventual consistency
|
||||
*
|
||||
*/
|
||||
bool isWeak;
|
||||
|
||||
/**
|
||||
* @brief if the allocator is heap allcator or arena allocator
|
||||
*
|
||||
*/
|
||||
bool isHeapAllocator;
|
||||
|
||||
/**
|
||||
* @brief TSDB options
|
||||
*
|
||||
*/
|
||||
STsdbOptions tsdbOptions;
|
||||
|
||||
/**
|
||||
* @brief META options
|
||||
*
|
||||
*/
|
||||
SMetaOptions metaOptions;
|
||||
// STqOptions tqOptions; // TODO
|
||||
};
|
||||
|
||||
/* ------------------------ FOR COMPILE ------------------------ */
|
||||
|
||||
#if 1
|
||||
|
||||
#include "taosmsg.h"
|
||||
#include "trpc.h"
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
|
@ -71,8 +137,6 @@ typedef struct {
|
|||
int32_t vnodeInit(SVnodePara);
|
||||
void vnodeCleanup();
|
||||
|
||||
SVnode *vnodeOpen(int32_t vgId, const char *path);
|
||||
void vnodeClose(SVnode *pVnode);
|
||||
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
|
||||
SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg);
|
||||
void vnodeDrop(SVnode *pVnode);
|
||||
|
@ -86,6 +150,8 @@ int32_t vnodeAppendMsg(SVnodeMsg *pMsg, SRpcMsg *pRpcMsg);
|
|||
void vnodeCleanupMsg(SVnodeMsg *pMsg);
|
||||
void vnodeProcessMsg(SVnode *pVnode, SVnodeMsg *pMsg, EVnMsgType msgType);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -26,8 +26,8 @@ extern "C" {
|
|||
|
||||
#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results
|
||||
|
||||
#define FUNCTION_SCALAR 1
|
||||
#define FUNCTION_AGG 2
|
||||
#define FUNCTION_TYPE_SCALAR 1
|
||||
#define FUNCTION_TYPE_AGG 2
|
||||
|
||||
#define TOP_BOTTOM_QUERY_LIMIT 100
|
||||
#define FUNCTIONS_NAME_MAX_LENGTH 16
|
||||
|
@ -78,13 +78,30 @@ extern "C" {
|
|||
#define FUNCTION_MODE 36
|
||||
#define FUNCTION_SAMPLE 37
|
||||
|
||||
#define FUNCTION_COV 38
|
||||
|
||||
// determine the real data need to calculated the result
|
||||
enum {
|
||||
BLK_DATA_NO_NEEDED = 0x0,
|
||||
BLK_DATA_STATIS_NEEDED = 0x1,
|
||||
BLK_DATA_ALL_NEEDED = 0x3,
|
||||
BLK_DATA_DISCARD = 0x4, // discard current data block since it is not qualified for filter
|
||||
};
|
||||
|
||||
enum {
|
||||
MASTER_SCAN = 0x0u,
|
||||
REVERSE_SCAN = 0x1u,
|
||||
REPEAT_SCAN = 0x2u, //repeat scan belongs to the master scan
|
||||
MERGE_STAGE = 0x20u,
|
||||
};
|
||||
|
||||
typedef struct SPoint1 {
|
||||
int64_t key;
|
||||
union{double val; char* ptr;};
|
||||
} SPoint1;
|
||||
|
||||
struct SQLFunctionCtx;
|
||||
struct SResultRowCellInfo;
|
||||
struct SResultRowEntryInfo;
|
||||
|
||||
//for selectivity query, the corresponding tag value is assigned if the data is qualified
|
||||
typedef struct SExtTagsInfo {
|
||||
|
@ -93,6 +110,23 @@ typedef struct SExtTagsInfo {
|
|||
struct SQLFunctionCtx **pTagCtxList;
|
||||
} SExtTagsInfo;
|
||||
|
||||
typedef struct SResultDataInfo {
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
int32_t intermediateBytes;
|
||||
} SResultDataInfo;
|
||||
|
||||
#define GET_RES_INFO(ctx) ((ctx)->resultInfo)
|
||||
|
||||
typedef struct SFunctionFpSet {
|
||||
bool (*init)(struct SQLFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); // setup the execute environment
|
||||
void (*addInput)(struct SQLFunctionCtx *pCtx);
|
||||
|
||||
// finalizer must be called after all exec has been executed to generated final result.
|
||||
void (*finalize)(struct SQLFunctionCtx *pCtx);
|
||||
void (*combine)(struct SQLFunctionCtx *pCtx);
|
||||
} SFunctionFpSet;
|
||||
|
||||
// sql function runtime context
|
||||
typedef struct SQLFunctionCtx {
|
||||
int32_t size; // number of rows
|
||||
|
@ -101,9 +135,7 @@ typedef struct SQLFunctionCtx {
|
|||
int16_t inputType;
|
||||
int16_t inputBytes;
|
||||
|
||||
int16_t outputType;
|
||||
int16_t outputBytes; // size of results, determined by function and input column data type
|
||||
int32_t interBufBytes; // internal buffer size
|
||||
SResultDataInfo resDataInfo;
|
||||
bool hasNull; // null value exist in current block
|
||||
bool requireNull; // require null in some function
|
||||
bool stableQuery;
|
||||
|
@ -117,18 +149,21 @@ typedef struct SQLFunctionCtx {
|
|||
void *ptsOutputBuf; // corresponding output buffer for timestamp of each result, e.g., top/bottom*/
|
||||
SVariant tag;
|
||||
|
||||
bool isSmaSet;
|
||||
SColumnDataAgg sma;
|
||||
struct SResultRowCellInfo *resultInfo;
|
||||
bool isAggSet;
|
||||
SColumnDataAgg agg;
|
||||
struct SResultRowEntryInfo *resultInfo;
|
||||
SExtTagsInfo tagInfo;
|
||||
SPoint1 start;
|
||||
SPoint1 end;
|
||||
|
||||
SFunctionFpSet* fpSet;
|
||||
} SQLFunctionCtx;
|
||||
|
||||
enum {
|
||||
TEXPR_NODE_DUMMY = 0x0,
|
||||
TEXPR_BINARYEXPR_NODE= 0x1,
|
||||
TEXPR_UNARYEXPR_NODE = 0x2,
|
||||
TEXPR_FUNCTION_NODE = 0x3,
|
||||
TEXPR_COL_NODE = 0x4,
|
||||
TEXPR_VALUE_NODE = 0x8,
|
||||
};
|
||||
|
@ -137,10 +172,7 @@ typedef struct tExprNode {
|
|||
uint8_t nodeType;
|
||||
union {
|
||||
struct {
|
||||
union {
|
||||
int32_t optr; // binary operator
|
||||
int32_t functionId;// unary operator
|
||||
};
|
||||
int32_t optr; // binary operator
|
||||
void *info; // support filter operation on this expression only available for leaf node
|
||||
struct tExprNode *pLeft; // left child pointer
|
||||
struct tExprNode *pRight; // right child pointer
|
||||
|
@ -148,44 +180,52 @@ typedef struct tExprNode {
|
|||
|
||||
SSchema *pSchema;// column node
|
||||
struct SVariant *pVal; // value node
|
||||
|
||||
struct {// function node
|
||||
char functionName[FUNCTIONS_NAME_MAX_LENGTH];
|
||||
// int32_t functionId;
|
||||
int32_t num;
|
||||
|
||||
// Note that the attribute of pChild is not the parameter of function, it is the columns that involved in the
|
||||
// calculation instead.
|
||||
// E.g., Cov(col1, col2), the column information, w.r.t. the col1 and col2, is kept in pChild nodes.
|
||||
// The concat function, concat(col1, col2), is a binary scalar
|
||||
// operator and is kept in the attribute of _node.
|
||||
struct tExprNode **pChild;
|
||||
} _function;
|
||||
};
|
||||
} tExprNode;
|
||||
|
||||
//TODO create?
|
||||
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
||||
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
|
||||
|
||||
typedef struct SAggFunctionInfo {
|
||||
char name[FUNCTIONS_NAME_MAX_LENGTH];
|
||||
int8_t type; // Scalar function or aggregation function
|
||||
uint8_t functionId; // Function Id
|
||||
int8_t sFunctionId; // Transfer function for super table query
|
||||
uint16_t status;
|
||||
char name[FUNCTIONS_NAME_MAX_LENGTH];
|
||||
int8_t type; // Scalar function or aggregation function
|
||||
uint32_t functionId; // Function Id
|
||||
int8_t sFunctionId; // Transfer function for super table query
|
||||
uint16_t status;
|
||||
|
||||
bool (*init)(SQLFunctionCtx *pCtx, struct SResultRowCellInfo* pResultCellInfo); // setup the execute environment
|
||||
void (*exec)(SQLFunctionCtx *pCtx);
|
||||
bool (*init)(SQLFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); // setup the execute environment
|
||||
void (*addInput)(SQLFunctionCtx *pCtx);
|
||||
|
||||
// finalizer must be called after all exec has been executed to generated final result.
|
||||
void (*xFinalize)(SQLFunctionCtx *pCtx);
|
||||
void (*mergeFunc)(SQLFunctionCtx *pCtx);
|
||||
void (*finalize)(SQLFunctionCtx *pCtx);
|
||||
void (*combine)(SQLFunctionCtx *pCtx);
|
||||
|
||||
int32_t (*dataReqFunc)(SQLFunctionCtx *pCtx, STimeWindow* w, int32_t colId);
|
||||
} SAggFunctionInfo;
|
||||
|
||||
struct SScalarFuncParam;
|
||||
|
||||
typedef struct SScalarFunctionInfo {
|
||||
char name[FUNCTIONS_NAME_MAX_LENGTH];
|
||||
int8_t type; // scalar function or aggregation function
|
||||
uint8_t functionId; // index of scalar function
|
||||
|
||||
bool (*init)(SQLFunctionCtx *pCtx, struct SResultRowCellInfo* pResultCellInfo); // setup the execute environment
|
||||
void (*exec)(SQLFunctionCtx *pCtx);
|
||||
char name[FUNCTIONS_NAME_MAX_LENGTH];
|
||||
int8_t type; // scalar function or aggregation function
|
||||
uint32_t functionId; // index of scalar function
|
||||
void (*process)(struct SScalarFuncParam* pOutput, size_t numOfInput, const struct SScalarFuncParam *pInput);
|
||||
} SScalarFunctionInfo;
|
||||
|
||||
typedef struct SResultDataInfo {
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
int32_t intermediateBytes;
|
||||
} SResultDataInfo;
|
||||
|
||||
typedef struct SMultiFunctionsDesc {
|
||||
bool stableQuery;
|
||||
bool groupbyColumn;
|
||||
|
@ -195,11 +235,12 @@ typedef struct SMultiFunctionsDesc {
|
|||
bool hasFilter;
|
||||
bool onlyTagQuery;
|
||||
bool orderProjectQuery;
|
||||
bool stateWindow;
|
||||
bool globalMerge;
|
||||
bool multigroupResult;
|
||||
bool blockDistribution;
|
||||
bool stateWindow;
|
||||
bool timewindow;
|
||||
bool sessionWindow;
|
||||
bool topbotQuery;
|
||||
bool interpQuery;
|
||||
bool distinct;
|
||||
|
@ -215,16 +256,61 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
|
|||
* @param len
|
||||
* @return
|
||||
*/
|
||||
int32_t qIsBuiltinFunction(const char* name, int32_t len);
|
||||
int32_t qIsBuiltinFunction(const char* name, int32_t len, bool* scalarFunction);
|
||||
|
||||
bool qIsValidUdf(SArray* pUdfInfo, const char* name, int32_t len, int32_t* functionId);
|
||||
|
||||
const char* qGetFunctionName(int32_t functionId);
|
||||
bool qIsAggregateFunction(const char* functionName);
|
||||
|
||||
tExprNode* exprTreeFromBinary(const void* data, size_t size);
|
||||
|
||||
void extractFunctionDesc(SArray* pFunctionIdList, SMultiFunctionsDesc* pDesc);
|
||||
|
||||
tExprNode* exprdup(tExprNode* pTree);
|
||||
|
||||
void resetResultRowEntryResult(SQLFunctionCtx* pCtx, int32_t num);
|
||||
void cleanupResultRowEntry(struct SResultRowEntryInfo* pCell);
|
||||
int32_t getNumOfResult(SQLFunctionCtx* pCtx, int32_t num);
|
||||
bool isRowEntryCompleted(struct SResultRowEntryInfo* pEntry);
|
||||
bool isRowEntryInitialized(struct SResultRowEntryInfo* pEntry);
|
||||
|
||||
struct SScalarFunctionSupport* createScalarFuncSupport(int32_t num);
|
||||
void destroyScalarFuncSupport(struct SScalarFunctionSupport* pSupport, int32_t num);
|
||||
struct SScalarFunctionSupport* getScalarFuncSupport(struct SScalarFunctionSupport* pSupport, int32_t index);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// fill api
|
||||
struct SFillInfo;
|
||||
struct SFillColInfo;
|
||||
|
||||
typedef struct SPoint {
|
||||
int64_t key;
|
||||
void * val;
|
||||
} SPoint;
|
||||
|
||||
void taosFillSetStartInfo(struct SFillInfo* pFillInfo, int32_t numOfRows, TSKEY endKey);
|
||||
void taosResetFillInfo(struct SFillInfo* pFillInfo, TSKEY startTimestamp);
|
||||
void taosFillSetInputDataBlock(struct SFillInfo* pFillInfo, const struct SSDataBlock* pInput);
|
||||
struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, const int64_t* fillVal);
|
||||
bool taosFillHasMoreResults(struct SFillInfo* pFillInfo);
|
||||
|
||||
struct SFillInfo* taosCreateFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_t capacity, int32_t numOfCols,
|
||||
int64_t slidingTime, int8_t slidingUnit, int8_t precision, int32_t fillType,
|
||||
struct SFillColInfo* pFillCol, void* handle);
|
||||
|
||||
void* taosDestroyFillInfo(struct SFillInfo *pFillInfo);
|
||||
int64_t taosFillResultDataBlock(struct SFillInfo* pFillInfo, void** output, int32_t capacity);
|
||||
int64_t getFillInfoStart(struct SFillInfo *pFillInfo);
|
||||
|
||||
int32_t taosGetLinearInterpolationVal(SPoint* point, int32_t outputType, SPoint* point1, SPoint* point2, int32_t inputType);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// udf api
|
||||
struct SUdfInfo;
|
||||
|
||||
void qAddUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
|
||||
void qRemoveUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -26,50 +26,6 @@ extern "C" {
|
|||
#include "tvariant.h"
|
||||
#include "function.h"
|
||||
|
||||
typedef struct SColumn {
|
||||
uint64_t tableUid;
|
||||
int32_t columnIndex;
|
||||
SColumnInfo info;
|
||||
} SColumn;
|
||||
|
||||
// the structure for sql function in select clause
|
||||
typedef struct SSqlExpr {
|
||||
char token[TSDB_COL_NAME_LEN]; // original token
|
||||
SSchema resSchema;
|
||||
SColIndex colInfo;
|
||||
uint64_t uid; // table uid, todo refactor use the pointer
|
||||
int32_t interBytes; // inter result buffer size
|
||||
int16_t numOfParams; // argument value of each function
|
||||
SVariant param[3]; // parameters are not more than 3
|
||||
} SSqlExpr;
|
||||
|
||||
typedef struct SExprInfo {
|
||||
SSqlExpr base;
|
||||
struct tExprNode *pExpr;
|
||||
} SExprInfo;
|
||||
|
||||
//typedef struct SInterval {
|
||||
// int32_t tz; // query client timezone
|
||||
// char intervalUnit;
|
||||
// char slidingUnit;
|
||||
// char offsetUnit;
|
||||
// int64_t interval;
|
||||
// int64_t sliding;
|
||||
// int64_t offset;
|
||||
//} SInterval;
|
||||
//
|
||||
//typedef struct SSessionWindow {
|
||||
// int64_t gap; // gap between two session window(in microseconds)
|
||||
// int32_t primaryColId; // primary timestamp column
|
||||
//} SSessionWindow;
|
||||
|
||||
typedef struct SGroupbyExpr {
|
||||
int16_t tableIndex;
|
||||
SArray* columnInfo; // SArray<SColIndex>, group by columns information
|
||||
int16_t orderIndex; // order by column index
|
||||
int16_t orderType; // order by type: asc/desc
|
||||
} SGroupbyExpr;
|
||||
|
||||
typedef struct SField {
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
uint8_t type;
|
||||
|
@ -82,16 +38,6 @@ typedef struct SFieldInfo {
|
|||
SArray *internalField; // SArray<SInternalField>
|
||||
} SFieldInfo;
|
||||
|
||||
typedef struct SLimit {
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
} SLimit;
|
||||
|
||||
typedef struct SOrder {
|
||||
uint32_t order;
|
||||
int32_t orderColId;
|
||||
} SOrder;
|
||||
|
||||
typedef struct SCond {
|
||||
uint64_t uid;
|
||||
int32_t len; // length of tag query condition data
|
||||
|
@ -120,12 +66,6 @@ typedef struct STagCond {
|
|||
typedef struct STableMetaInfo {
|
||||
STableMeta *pTableMeta; // table meta, cached in client side and acquired by name
|
||||
SVgroupsInfo *vgroupList;
|
||||
|
||||
/*
|
||||
* 1. keep the vgroup index during the multi-vnode super table projection query
|
||||
* 2. keep the vgroup index for multi-vnode insertion
|
||||
*/
|
||||
int32_t vgroupIndex;
|
||||
SName name;
|
||||
char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql
|
||||
SArray *tagColList; // SArray<SColumn*>, involved tag columns
|
||||
|
@ -137,11 +77,11 @@ typedef struct SQueryStmtInfo {
|
|||
STimeWindow window; // the whole query time window
|
||||
SInterval interval; // tumble time window
|
||||
SSessionWindow sessionWindow; // session time window
|
||||
SStateWindow stateWindow; // state window query
|
||||
SGroupbyExpr groupbyExpr; // groupby tags info
|
||||
SArray * colList; // SArray<SColumn*>
|
||||
SFieldInfo fieldsInfo;
|
||||
SArray * exprList; // SArray<SExprInfo*>
|
||||
SArray * exprList1; // final exprlist in case of arithmetic expression exists
|
||||
SArray** exprList; // SArray<SExprInfo*>
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
STagCond tagCond;
|
||||
|
@ -172,6 +112,7 @@ typedef struct SQueryStmtInfo {
|
|||
struct SQueryStmtInfo *pDownstream;
|
||||
int32_t havingFieldNum;
|
||||
SMultiFunctionsDesc info;
|
||||
int32_t exprListLevelIndex;
|
||||
} SQueryStmtInfo;
|
||||
|
||||
typedef struct SColumnIndex {
|
||||
|
@ -225,14 +166,23 @@ void assignExprInfo(SExprInfo* dst, const SExprInfo* src);
|
|||
void columnListCopy(SArray* dst, const SArray* src, uint64_t uid);
|
||||
void columnListDestroy(SArray* pColumnList);
|
||||
|
||||
void dropAllExprInfo(SArray* pExprInfo);
|
||||
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SColumnIndex* pColIndex, struct tExprNode* pParamExpr, SSchema* pResSchema, int16_t interSize);
|
||||
void dropAllExprInfo(SArray** pExprInfo, int32_t numOfLevel);
|
||||
|
||||
typedef struct SSourceParam {
|
||||
SArray *pExprNodeList; //Array<struct tExprNode*>
|
||||
SArray *pColumnList; //Array<struct SColumn>
|
||||
int32_t num;
|
||||
} SSourceParam;
|
||||
|
||||
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize);
|
||||
int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
|
||||
|
||||
STableMetaInfo* getMetaInfo(SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
|
||||
SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex);
|
||||
SSchema createSchema(uint8_t type, int16_t bytes, int16_t colId, const char* name);
|
||||
|
||||
int32_t getNewResColId();
|
||||
void addIntoSourceParam(SSourceParam* pSourceParam, tExprNode* pNode, SColumn* pColumn);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ extern "C" {
|
|||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "osAtomic.h"
|
||||
#include "osDef.h"
|
||||
|
|
|
@ -22,7 +22,7 @@ extern "C" {
|
|||
|
||||
void taosRemoveDir(const char *dirname);
|
||||
bool taosDirExist(char *dirname);
|
||||
bool taosMkDir(char *dirname);
|
||||
bool taosMkDir(const char *dirname);
|
||||
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
||||
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen);
|
||||
bool taosRealPath(char *dirname, int32_t maxlen);
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_META_H_
|
||||
#define _TD_META_H_
|
||||
|
||||
#include "taosmsg.h"
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ------------------------ APIs Exposed ------------------------ */
|
||||
|
||||
// Types exported
|
||||
typedef uint64_t tb_uid_t;
|
||||
typedef struct SMeta SMeta;
|
||||
typedef struct SMetaOpts SMetaOpts;
|
||||
typedef struct SMetaQueryHandle SMetaQueryHandle;
|
||||
typedef struct SMetaQueryOpts SMetaQueryOpts;
|
||||
typedef struct STableOpts STableOpts;
|
||||
|
||||
// SMeta operations
|
||||
int metaCreate(const char *path);
|
||||
void metaDestroy(const char *path);
|
||||
SMeta *metaOpen(SMetaOpts *);
|
||||
void metaClose(SMeta *);
|
||||
int metaCreateTable(SMeta *, const STableOpts *);
|
||||
int metaDropTable(SMeta *, uint64_t tuid_t);
|
||||
int metaAlterTable(SMeta *, void *);
|
||||
int metaCommit(SMeta *);
|
||||
|
||||
// Options
|
||||
SMetaOpts *metaOptionsCreate();
|
||||
void metaOptionsDestroy(SMetaOpts *);
|
||||
void metaOptionsSetCache(SMetaOpts *, size_t capacity);
|
||||
|
||||
// SMetaQueryHandle
|
||||
SMetaQueryHandle *metaQueryHandleCreate(SMetaQueryOpts *);
|
||||
void metaQueryHandleDestroy(SMetaQueryHandle *);
|
||||
|
||||
// SMetaQueryOpts
|
||||
SMetaQueryOpts *metaQueryOptionsCreate();
|
||||
void metaQueryOptionsDestroy(SMetaQueryOpts *);
|
||||
|
||||
// STableOpts
|
||||
#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0}
|
||||
void metaNormalTableOptsInit(STableOpts *, const char *name, const STSchema *pSchema);
|
||||
void metaSuperTableOptsInit(STableOpts *, const char *name, tb_uid_t uid, const STSchema *pSchema,
|
||||
const STSchema *pTagSchema);
|
||||
void metaChildTableOptsInit(STableOpts *, const char *name, tb_uid_t suid, const SKVRow tags);
|
||||
void metaTableOptsClear(STableOpts *);
|
||||
|
||||
/* ------------------------ Impl should hidden ------------------------ */
|
||||
typedef enum { META_INIT_TABLE = 0, META_SUPER_TABLE = 1, META_CHILD_TABLE = 2, META_NORMAL_TABLE = 3 } EMetaTableT;
|
||||
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 {
|
||||
int8_t type;
|
||||
char * name;
|
||||
union {
|
||||
SSuperTableOpts superOpts;
|
||||
SChildTableOpts childOpts;
|
||||
SNormalTableOpts normalOpts;
|
||||
};
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_META_H_*/
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_AMALLOC_H_
|
||||
#define _TD_AMALLOC_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AMALLOC_APIS \
|
||||
void *(*malloc)(void *, size_t size); \
|
||||
void *(*calloc)(void *, size_t nmemb, size_t size); \
|
||||
void *(*realloc)(void *, size_t size); \
|
||||
void (*free)(void *ptr);
|
||||
|
||||
// Interfaces to implement
|
||||
typedef struct {
|
||||
AMALLOC_APIS
|
||||
} SMemAllocatorIf;
|
||||
|
||||
typedef struct {
|
||||
void *impl;
|
||||
AMALLOC_APIS
|
||||
} SMemAllocator;
|
||||
|
||||
#define amalloc(allocator, size) ((allocator) ? (*((allocator)->malloc))((allocator)->impl, (size)) : malloc(size))
|
||||
#define acalloc(allocator, nmemb, size) \
|
||||
((allocator) ? (*((allocator)->calloc))((allocator)->impl, (nmemb), (size)) : calloc((nmemb), (size)))
|
||||
#define arealloc(allocator, ptr, size) \
|
||||
((allocator) ? (*((allocator)->realloc))((allocator)->impl, (ptr), (size)) : realloc((ptr), (size)))
|
||||
#define afree(allocator, ptr, size) ((allocator) ? (*((allocator)->free))((allocator)->impl, (ptr), (size)) : free(ptr))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_AMALLOC_H_*/
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MALLOCATOR_H_
|
||||
#define _TD_MALLOCATOR_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SMemAllocator SMemAllocator;
|
||||
|
||||
#define MALLOCATOR_APIS \
|
||||
void *(*malloc)(SMemAllocator *, size_t size); \
|
||||
void *(*calloc)(SMemAllocator *, size_t nmemb, size_t size); \
|
||||
void *(*realloc)(SMemAllocator *, void *ptr, size_t size); \
|
||||
void (*free)(SMemAllocator *, void *ptr); \
|
||||
size_t (*usage)(SMemAllocator *);
|
||||
|
||||
// Interfaces to implement
|
||||
typedef struct {
|
||||
MALLOCATOR_APIS
|
||||
} SMemAllocatorIf;
|
||||
|
||||
struct SMemAllocator {
|
||||
void * impl;
|
||||
size_t usize;
|
||||
MALLOCATOR_APIS
|
||||
};
|
||||
|
||||
// heap allocator
|
||||
SMemAllocator *tdCreateHeapAllocator();
|
||||
void tdDestroyHeapAllocator(SMemAllocator *pMemAllocator);
|
||||
|
||||
// arena allocator
|
||||
SMemAllocator *tdCreateArenaAllocator(size_t size);
|
||||
void tdDestroyArenaAllocator(SMemAllocator *);
|
||||
|
||||
#define mMalloc(pMemAllocator, size) (*(pMemAllocator->malloc))(pMemAllocator, size)
|
||||
#define mCalloc(pMemAllocator, nmemb, size) (*(pMemAllocator->calloc))(pMemAllocator, nmemb, size)
|
||||
#define mRealloc(pMemAllocator, ptr, size) (*(pMemAllocator->realloc))(pMemAllocator, ptr, size)
|
||||
#define mFree(pMemAllocator, ptr) (*(pMemAllocator->free))(pMemAllocator, ptr)
|
||||
#define mUsage(pMemAllocator) (*(pMemAllocator->usage))(pMemAllocator)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MALLOCATOR_H_*/
|
|
@ -27,6 +27,7 @@ extern "C" {
|
|||
#define TAOS_FAILED(err) ((err) < 0)
|
||||
|
||||
const char* tstrerror(int32_t err);
|
||||
const char* terrstr();
|
||||
|
||||
int32_t* taosGetErrno();
|
||||
#define terrno (*taosGetErrno())
|
||||
|
@ -59,17 +60,20 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_RPC_INVALID_VERSION TAOS_DEF_ERROR_CODE(0, 0x0016) //"Invalid app version")
|
||||
|
||||
//common & util
|
||||
#define TSDB_CODE_COM_OPS_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x0100) //"Operation not supported")
|
||||
#define TSDB_CODE_COM_MEMORY_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0101) //"Memory corrupted")
|
||||
#define TSDB_CODE_COM_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0102) //"Out of memory")
|
||||
#define TSDB_CODE_COM_INVALID_CFG_MSG TAOS_DEF_ERROR_CODE(0, 0x0103) //"Invalid config message")
|
||||
#define TSDB_CODE_COM_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0104) //"Data file corrupted")
|
||||
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0105) //"Ref out of memory")
|
||||
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0106) //"too many Ref Objs")
|
||||
#define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0107) //"Ref ID is removed")
|
||||
#define TSDB_CODE_REF_INVALID_ID TAOS_DEF_ERROR_CODE(0, 0x0108) //"Invalid Ref ID")
|
||||
#define TSDB_CODE_REF_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0109) //"Ref is already there")
|
||||
#define TSDB_CODE_REF_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x010A) //"Ref is not there")
|
||||
#define TSDB_CODE_OPS_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x0100)
|
||||
#define TSDB_CODE_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0101)
|
||||
#define TSDB_CODE_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x0102)
|
||||
#define TSDB_CODE_INVALID_PTR TAOS_DEF_ERROR_CODE(0, 0x0103)
|
||||
#define TSDB_CODE_MEMORY_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0104)
|
||||
#define TSDB_CODE_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0106)
|
||||
#define TSDB_CODE_CHECKSUM_ERROR TAOS_DEF_ERROR_CODE(0, 0x0107)
|
||||
#define TSDB_CODE_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x0108)
|
||||
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0109)
|
||||
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x010A)
|
||||
#define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x010B)
|
||||
#define TSDB_CODE_REF_INVALID_ID TAOS_DEF_ERROR_CODE(0, 0x010C)
|
||||
#define TSDB_CODE_REF_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x010D)
|
||||
#define TSDB_CODE_REF_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x010E)
|
||||
|
||||
//client
|
||||
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200) //"Invalid Operation")
|
||||
|
@ -120,7 +124,6 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0307) //"Invalid message length")
|
||||
#define TSDB_CODE_MND_INVALID_MSG_TYPE TAOS_DEF_ERROR_CODE(0, 0x0308) //"Invalid message type")
|
||||
#define TSDB_CODE_MND_TOO_MANY_SHELL_CONNS TAOS_DEF_ERROR_CODE(0, 0x0309) //"Too many connections")
|
||||
#define TSDB_CODE_MND_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x030A) //"Out of memory in mnode")
|
||||
#define TSDB_CODE_MND_INVALID_SHOWOBJ TAOS_DEF_ERROR_CODE(0, 0x030B) //"Data expired")
|
||||
#define TSDB_CODE_MND_INVALID_QUERY_ID TAOS_DEF_ERROR_CODE(0, 0x030C) //"Invalid query id")
|
||||
#define TSDB_CODE_MND_INVALID_STREAM_ID TAOS_DEF_ERROR_CODE(0, 0x030D) //"Invalid stream id")
|
||||
|
@ -131,12 +134,18 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_FAILED_TO_CREATE_DIR TAOS_DEF_ERROR_CODE(0, 0x0313) //"failed to create mnode dir")
|
||||
#define TSDB_CODE_MND_FAILED_TO_INIT_STEP TAOS_DEF_ERROR_CODE(0, 0x0314) //"failed to init components")
|
||||
|
||||
#define TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0320) //"Object already there")
|
||||
#define TSDB_CODE_MND_SDB_ERROR TAOS_DEF_ERROR_CODE(0, 0x0321) //"Unexpected generic error in sdb")
|
||||
#define TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0322) //"Invalid table type")
|
||||
#define TSDB_CODE_MND_SDB_OBJ_NOT_THERE TAOS_DEF_ERROR_CODE(0, 0x0323) //"Object not there")
|
||||
#define TSDB_CODE_MND_SDB_INVAID_META_ROW TAOS_DEF_ERROR_CODE(0, 0x0324) //"Invalid meta row")
|
||||
#define TSDB_CODE_MND_SDB_INVAID_KEY_TYPE TAOS_DEF_ERROR_CODE(0, 0x0325) //"Invalid key type")
|
||||
#define TSDB_CODE_SDB_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0320)
|
||||
#define TSDB_CODE_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0321)
|
||||
#define TSDB_CODE_SDB_OBJ_NOT_THERE TAOS_DEF_ERROR_CODE(0, 0x0322)
|
||||
#define TSDB_CODE_SDB_OBJ_CREATING TAOS_DEF_ERROR_CODE(0, 0x0323)
|
||||
#define TSDB_CODE_SDB_OBJ_DROPPING TAOS_DEF_ERROR_CODE(0, 0x0324)
|
||||
#define TSDB_CODE_SDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0325)
|
||||
#define TSDB_CODE_SDB_INVALID_KEY_TYPE TAOS_DEF_ERROR_CODE(0, 0x0326)
|
||||
#define TSDB_CODE_SDB_INVALID_ACTION_TYPE TAOS_DEF_ERROR_CODE(0, 0x0327)
|
||||
#define TSDB_CODE_SDB_INVALID_STATUS_TYPE TAOS_DEF_ERROR_CODE(0, 0x0328)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0329)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x032A)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x032B)
|
||||
|
||||
#define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0330) //"DNode already exists")
|
||||
#define TSDB_CODE_MND_DNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0331) //"DNode does not exist")
|
||||
|
@ -155,12 +164,12 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED TAOS_DEF_ERROR_CODE(0, 0x033E) //"Dnode Ep not configured")
|
||||
|
||||
#define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340) //"Account already exists")
|
||||
#define TSDB_CODE_MND_INVALID_ACCT TAOS_DEF_ERROR_CODE(0, 0x0341) //"Invalid account")
|
||||
#define TSDB_CODE_MND_ACCT_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0341) //"Invalid account")
|
||||
#define TSDB_CODE_MND_INVALID_ACCT_OPTION TAOS_DEF_ERROR_CODE(0, 0x0342) //"Invalid account options")
|
||||
#define TSDB_CODE_MND_ACCT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0343) //"Account authorization has expired")
|
||||
|
||||
#define TSDB_CODE_MND_USER_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350) //"User already exists")
|
||||
#define TSDB_CODE_MND_INVALID_USER TAOS_DEF_ERROR_CODE(0, 0x0351) //"Invalid user")
|
||||
#define TSDB_CODE_MND_USER_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0351) //"Invalid user")
|
||||
#define TSDB_CODE_MND_INVALID_USER_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0352) //"Invalid user format")
|
||||
#define TSDB_CODE_MND_INVALID_PASS_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0353) //"Invalid password format")
|
||||
#define TSDB_CODE_MND_NO_USER_FROM_CONN TAOS_DEF_ERROR_CODE(0, 0x0354) //"Can not get user from conn")
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tdef.h"
|
||||
#include "taos.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#define COMP_OVERFLOW_BYTES 2
|
||||
|
|
|
@ -134,6 +134,15 @@ do { \
|
|||
#define TSDB_BINARY_OP_REMAINDER 4004
|
||||
#define TSDB_BINARY_OP_CONCAT 4005
|
||||
|
||||
#define FUNCTION_CEIL 4500
|
||||
#define FUNCTION_FLOOR 4501
|
||||
#define FUNCTION_ABS 4502
|
||||
#define FUNCTION_ROUND 4503
|
||||
|
||||
#define FUNCTION_LENGTH 4800
|
||||
#define FUNCTION_CONCAT 4801
|
||||
#define FUNCTION_LTRIM 4802
|
||||
#define FUNCTION_RTRIM 4803
|
||||
|
||||
#define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN))
|
||||
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_REMAINDER))
|
||||
|
@ -311,10 +320,6 @@ do { \
|
|||
#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
|
||||
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
|
||||
|
||||
#define TSDB_UDF_TYPE_SCALAR 1
|
||||
#define TSDB_UDF_TYPE_AGGREGATE 2
|
||||
|
||||
|
||||
/*
|
||||
* 1. ordinary sub query for select * from super_table
|
||||
* 2. all sqlobj generated by createSubqueryObj with this flag
|
||||
|
@ -367,21 +372,6 @@ do { \
|
|||
#define TSDB_MAX_DISKS_PER_TIER 16
|
||||
#define TSDB_MAX_DISKS (TSDB_MAX_TIERS * TSDB_MAX_DISKS_PER_TIER)
|
||||
|
||||
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
|
||||
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_INT 4 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_BINARY 8 // string
|
||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
||||
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
||||
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
||||
|
||||
enum { TRANS_STAT_INIT = 0, TRANS_STAT_EXECUTING, TRANS_STAT_EXECUTED, TRANS_STAT_ROLLBACKING, TRANS_STAT_ROLLBACKED };
|
||||
enum { TRANS_OPER_INIT = 0, TRANS_OPER_EXECUTE, TRANS_OPER_ROLLBACK };
|
||||
|
|
|
@ -21,7 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "os.h"
|
||||
//#include "tdef.h"
|
||||
#include "taos.h"
|
||||
#include "tarray.h"
|
||||
#include "tfunctional.h"
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ uint16_t tsArbitratorPort = 6042;
|
|||
int32_t tsStatusInterval = 1; // second
|
||||
int32_t tsNumOfMnodes = 1;
|
||||
int8_t tsEnableVnodeBak = 1;
|
||||
int8_t tsEnableTelemetryReporting = 1;
|
||||
int8_t tsEnableTelemetryReporting = 0;
|
||||
int8_t tsArbOnline = 0;
|
||||
int64_t tsArbOnlineTimestamp = TSDB_ARB_DUMMY_TIME;
|
||||
char tsEmail[TSDB_FQDN_LEN] = {0};
|
||||
|
|
|
@ -11,6 +11,6 @@ target_link_libraries(
|
|||
)
|
||||
target_include_directories(
|
||||
taosd
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/server/dnode"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
|
|
@ -302,6 +302,13 @@ PRASE_DNODE_OVER:
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (tsDnode.dnodeEps == NULL) {
|
||||
tsDnode.dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp));
|
||||
tsDnode.dnodeEps->dnodeNum = 1;
|
||||
tsDnode.dnodeEps->dnodeEps[0].dnodePort = tsServerPort;
|
||||
tstrncpy(tsDnode.dnodeEps->dnodeEps[0].dnodeFqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
}
|
||||
|
||||
dnodeResetDnodes(tsDnode.dnodeEps);
|
||||
|
||||
terrno = 0;
|
||||
|
|
|
@ -135,7 +135,7 @@ static int32_t dnodeInitMain() {
|
|||
|
||||
dnodeInitDir();
|
||||
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dnodeCleanupMain() {
|
||||
|
@ -145,14 +145,14 @@ static void dnodeCleanupMain() {
|
|||
}
|
||||
|
||||
int32_t dnodeInit() {
|
||||
SSteps *steps = taosStepInit(24, dnodeReportStartup);
|
||||
SSteps *steps = taosStepInit(10, dnodeReportStartup);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
taosStepAdd(steps, "dnode-main", dnodeInitMain, dnodeCleanupMain);
|
||||
taosStepAdd(steps, "dnode-rpc", rpcInit, rpcCleanup);
|
||||
taosStepAdd(steps, "dnode-tfs", NULL, NULL);
|
||||
taosStepAdd(steps, "dnode-wal", walInit, walCleanUp);
|
||||
taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp);
|
||||
//taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp);
|
||||
taosStepAdd(steps, "dnode-dnode", dnodeInitDnode, dnodeCleanupDnode);
|
||||
taosStepAdd(steps, "dnode-vnodes", dnodeInitVnodes, dnodeCleanupVnodes);
|
||||
taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, dnodeCleanupMnode);
|
||||
|
|
|
@ -136,8 +136,8 @@ static int32_t dnodeWriteMnodeFile() {
|
|||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"deployed\": \"%d\",\n", tsMnode.dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", tsMnode.dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"deployed\": \"%d\",\n", tsMnode.deployed);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\"\n", tsMnode.dropped);
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
|
@ -180,7 +180,7 @@ static int32_t dnodeStartMnode() {
|
|||
tsMnode.deployed = 1;
|
||||
taosWUnLockLatch(&tsMnode.latch);
|
||||
|
||||
return code;
|
||||
return mnodeStart(NULL);
|
||||
}
|
||||
|
||||
static void dnodeStopMnode() {
|
||||
|
@ -212,14 +212,14 @@ static int32_t dnodeUnDeployMnode() {
|
|||
}
|
||||
|
||||
dnodeStopMnode();
|
||||
mnodeUnDeploy(tsMnodeDir);
|
||||
mnodeUnDeploy();
|
||||
dnodeWriteMnodeFile();
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dnodeDeployMnode(SMnodeCfg *pCfg) {
|
||||
int32_t code = mnodeDeploy(tsMnodeDir, pCfg);
|
||||
int32_t code = mnodeDeploy(pCfg);
|
||||
if (code != 0) {
|
||||
dError("failed to deploy mnode since %s", tstrerror(code));
|
||||
return code;
|
||||
|
@ -335,12 +335,9 @@ static int32_t dnodeWriteMnodeMsgToQueue(taos_queue pQueue, SRpcMsg *pRpcMsg) {
|
|||
if (pQueue == NULL) {
|
||||
code = TSDB_CODE_DND_MSG_NOT_PROCESSED;
|
||||
} else {
|
||||
SMnodeMsg *pMsg = mnodeInitMsg(1);
|
||||
SMnodeMsg *pMsg = mnodeInitMsg(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
code = TSDB_CODE_DND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
mnodeAppendMsg(pMsg, pRpcMsg);
|
||||
code = taosWriteQitem(pQueue, pMsg);
|
||||
code = terrno;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -539,7 +536,7 @@ static int32_t dnodeOpenMnode() {
|
|||
SMnodeCfg cfg = {.replica = 1};
|
||||
cfg.replicas[0].port = tsServerPort;
|
||||
tstrncpy(cfg.replicas[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
return dnodeDeployMnode(&cfg);
|
||||
code = dnodeDeployMnode(&cfg);
|
||||
} else {
|
||||
dInfo("start to open mnode");
|
||||
return dnodeStartMnode();
|
||||
|
|
|
@ -376,7 +376,7 @@ static void *dnodeOpenVnodeFunc(void *param) {
|
|||
|
||||
char path[PATH_MAX + 20] = {0};
|
||||
snprintf(path, sizeof(path),"%s/vnode%d", tsVnodeDir, pVnode->vgId);
|
||||
SVnode *pImpl = vnodeOpen(pVnode->vgId, path);
|
||||
SVnode *pImpl = vnodeOpen(path, NULL);
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to open vnode by thread:%d", pVnode->vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
|
|
|
@ -1,12 +1,3 @@
|
|||
aux_source_directory(src MNODE_SRC)
|
||||
add_library(mnode ${MNODE_SRC})
|
||||
target_include_directories(
|
||||
mnode
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/server/mnode"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
mnode
|
||||
PUBLIC transport
|
||||
PUBLIC cjson
|
||||
)
|
||||
add_subdirectory(impl)
|
||||
add_subdirectory(sdb)
|
||||
add_subdirectory(transaction)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
aux_source_directory(src MNODE_SRC)
|
||||
add_library(mnode ${MNODE_SRC})
|
||||
target_include_directories(
|
||||
mnode
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
mnode
|
||||
PRIVATE sdb
|
||||
PRIVATE transaction
|
||||
PUBLIC transport
|
||||
PUBLIC cjson
|
||||
)
|
|
@ -57,27 +57,6 @@ typedef struct SVgObj SVgObj;
|
|||
typedef struct SSTableObj SSTableObj;
|
||||
typedef struct SFuncObj SFuncObj;
|
||||
typedef struct SOperObj SOperObj;
|
||||
typedef struct SMnMsg SMnMsg;
|
||||
|
||||
typedef enum {
|
||||
MN_SDB_START = 0,
|
||||
MN_SDB_CLUSTER = 1,
|
||||
MN_SDB_DNODE = 2,
|
||||
MN_SDB_MNODE = 3,
|
||||
MN_SDB_ACCT = 4,
|
||||
MN_SDB_AUTH = 5,
|
||||
MN_SDB_USER = 6,
|
||||
MN_SDB_DB = 7,
|
||||
MN_SDB_VGROUP = 8,
|
||||
MN_SDB_STABLE = 9,
|
||||
MN_SDB_FUNC = 10,
|
||||
MN_SDB_OPER = 11,
|
||||
MN_SDB_MAX = 12
|
||||
} EMnSdb;
|
||||
|
||||
typedef enum { MN_OP_START = 0, MN_OP_INSERT = 1, MN_OP_UPDATE = 2, MN_OP_DELETE = 3, MN_OP_MAX = 4 } EMnOp;
|
||||
|
||||
typedef enum { MN_KEY_START = 0, MN_KEY_BINARY = 1, MN_KEY_INT32 = 2, MN_KEY_INT64 = 3, MN_KEY_MAX } EMnKey;
|
||||
|
||||
typedef enum {
|
||||
MN_AUTH_ACCT_START = 0,
|
||||
|
@ -97,16 +76,9 @@ typedef enum {
|
|||
MN_AUTH_MAX
|
||||
} EMnAuthOp;
|
||||
|
||||
typedef enum { MN_SDB_STAT_AVAIL = 0, MN_SDB_STAT_DROPPED = 1 } EMnSdbStat;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
int8_t status;
|
||||
int8_t align[6];
|
||||
} SdbHead;
|
||||
|
||||
typedef struct SClusterObj {
|
||||
SdbHead head;
|
||||
int64_t id;
|
||||
char uid[TSDB_CLUSTER_ID_LEN];
|
||||
int64_t createdTime;
|
||||
|
@ -114,7 +86,6 @@ typedef struct SClusterObj {
|
|||
} SClusterObj;
|
||||
|
||||
typedef struct SDnodeObj {
|
||||
SdbHead head;
|
||||
int32_t id;
|
||||
int32_t vnodes;
|
||||
int64_t createdTime;
|
||||
|
@ -131,7 +102,6 @@ typedef struct SDnodeObj {
|
|||
} SDnodeObj;
|
||||
|
||||
typedef struct SMnodeObj {
|
||||
SdbHead head;
|
||||
int32_t id;
|
||||
int8_t status;
|
||||
int8_t role;
|
||||
|
@ -147,8 +117,8 @@ typedef struct {
|
|||
int32_t maxDbs;
|
||||
int32_t maxTimeSeries;
|
||||
int32_t maxStreams;
|
||||
int64_t maxStorage; // In unit of GB
|
||||
int8_t accessState; // Configured only by command
|
||||
int64_t maxStorage; // In unit of GB
|
||||
int32_t accessState; // Configured only by command
|
||||
} SAcctCfg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -161,18 +131,16 @@ typedef struct {
|
|||
} SAcctInfo;
|
||||
|
||||
typedef struct SAcctObj {
|
||||
SdbHead head;
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int32_t acctId;
|
||||
int8_t status;
|
||||
int32_t status;
|
||||
SAcctCfg cfg;
|
||||
SAcctInfo info;
|
||||
} SAcctObj;
|
||||
|
||||
typedef struct SUserObj {
|
||||
SdbHead head;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_KEY_LEN];
|
||||
char acct[TSDB_USER_LEN];
|
||||
|
@ -207,7 +175,6 @@ typedef struct {
|
|||
} SDbCfg;
|
||||
|
||||
typedef struct SDbObj {
|
||||
SdbHead head;
|
||||
char name[TSDB_FULL_DB_NAME_LEN];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
|
@ -251,7 +218,6 @@ typedef struct SVgObj {
|
|||
} SVgObj;
|
||||
|
||||
typedef struct SSTableObj {
|
||||
SdbHead head;
|
||||
char tableId[TSDB_TABLE_NAME_LEN];
|
||||
uint64_t uid;
|
||||
int64_t createdTime;
|
||||
|
@ -262,7 +228,6 @@ typedef struct SSTableObj {
|
|||
} SSTableObj;
|
||||
|
||||
typedef struct SFuncObj {
|
||||
SdbHead head;
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
char path[128];
|
||||
int32_t contLen;
|
||||
|
@ -299,8 +264,9 @@ typedef struct {
|
|||
void *rsp;
|
||||
} SMnRsp;
|
||||
|
||||
typedef struct SMnMsg {
|
||||
void (*fp)(SMnMsg *pMsg, int32_t code);
|
||||
typedef struct SMnodeMsg {
|
||||
void (*fp)(SMnodeMsg *pMsg, int32_t code);
|
||||
SRpcConnInfo conn;
|
||||
SUserObj *pUser;
|
||||
int16_t received;
|
||||
int16_t successed;
|
||||
|
@ -311,7 +277,7 @@ typedef struct SMnMsg {
|
|||
SMnRsp rpcRsp;
|
||||
SRpcMsg rpcMsg;
|
||||
char pCont[];
|
||||
} SMnReq;
|
||||
} SMnodeMsg;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -17,22 +17,25 @@
|
|||
#define _TD_MNODE_INT_H_
|
||||
|
||||
#include "mnodeDef.h"
|
||||
#include "sdb.h"
|
||||
#include "trn.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { MN_STATUS_UNINIT = 0, MN_STATUS_INIT = 1, MN_STATUS_READY = 2, MN_STATUS_CLOSING = 3 } EMnStatus;
|
||||
typedef void (*MnodeRpcFp)(SMnodeMsg *pMsg);
|
||||
|
||||
tmr_h mnodeGetTimer();
|
||||
int32_t mnodeGetDnodeId();
|
||||
int64_t mnodeGetClusterId();
|
||||
EMnStatus mnodeGetStatus();
|
||||
tmr_h mnodeGetTimer();
|
||||
int32_t mnodeGetDnodeId();
|
||||
int64_t mnodeGetClusterId();
|
||||
|
||||
void mnodeSendMsgToDnode(struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
void mnodeSendMsgToMnode(struct SRpcMsg *rpcMsg);
|
||||
void mnodeSendRedirectMsg(struct SRpcMsg *rpcMsg, bool forShell);
|
||||
|
||||
void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -24,6 +24,7 @@ extern "C" {
|
|||
|
||||
int32_t mnodeInitSync();
|
||||
void mnodeCleanUpSync();
|
||||
int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData);
|
||||
|
||||
bool mnodeIsMaster();
|
||||
|
|
@ -0,0 +1,393 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tstep.h"
|
||||
#include "tqueue.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeAuth.h"
|
||||
#include "mnodeBalance.h"
|
||||
#include "mnodeCluster.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeFunc.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeOper.h"
|
||||
#include "mnodeProfile.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeStable.h"
|
||||
#include "mnodeSync.h"
|
||||
#include "mnodeTelem.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
|
||||
static struct {
|
||||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
tmr_h timer;
|
||||
SSteps *pInitSteps;
|
||||
SSteps *pStartSteps;
|
||||
SMnodePara para;
|
||||
MnodeRpcFp msgFp[TSDB_MSG_TYPE_MAX];
|
||||
} tsMint;
|
||||
|
||||
int32_t mnodeGetDnodeId() { return tsMint.para.dnodeId; }
|
||||
|
||||
int64_t mnodeGetClusterId() { return tsMint.para.clusterId; }
|
||||
|
||||
void mnodeSendMsgToDnode(struct SEpSet *epSet, struct SRpcMsg *rpcMsg) { (*tsMint.para.SendMsgToDnode)(epSet, rpcMsg); }
|
||||
|
||||
void mnodeSendMsgToMnode(struct SRpcMsg *rpcMsg) { return (*tsMint.para.SendMsgToMnode)(rpcMsg); }
|
||||
|
||||
void mnodeSendRedirectMsg(struct SRpcMsg *rpcMsg, bool forShell) { (*tsMint.para.SendRedirectMsg)(rpcMsg, forShell); }
|
||||
|
||||
static int32_t mnodeInitTimer() {
|
||||
if (tsMint.timer == NULL) {
|
||||
tsMint.timer = taosTmrInit(tsMaxShellConns, 200, 3600000, "MND");
|
||||
}
|
||||
|
||||
if (tsMint.timer == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mnodeCleanupTimer() {
|
||||
if (tsMint.timer != NULL) {
|
||||
taosTmrCleanUp(tsMint.timer);
|
||||
tsMint.timer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
tmr_h mnodeGetTimer() { return tsMint.timer; }
|
||||
|
||||
static int32_t mnodeSetPara(SMnodePara para) {
|
||||
tsMint.para = para;
|
||||
|
||||
if (tsMint.para.SendMsgToDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsMint.para.SendMsgToMnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsMint.para.SendRedirectMsg == NULL) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsMint.para.PutMsgIntoApplyQueue == NULL) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsMint.para.dnodeId < 0) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsMint.para.clusterId < 0) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeAllocInitSteps() {
|
||||
struct SSteps *steps = taosStepInit(16, NULL);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
if (taosStepAdd(steps, "mnode-trans", trnInit, trnCleanup) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-cluster", mnodeInitCluster, mnodeCleanupCluster) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-dnode", mnodeInitDnode, mnodeCleanupDnode) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-mnode", mnodeInitMnode, mnodeCleanupMnode) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-acct", mnodeInitAcct, mnodeCleanupAcct) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-auth", mnodeInitAuth, mnodeCleanupAuth) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-user", mnodeInitUser, mnodeCleanupUser) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-db", mnodeInitDb, mnodeCleanupDb) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-vgroup", mnodeInitVgroup, mnodeCleanupVgroup) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-stable", mnodeInitStable, mnodeCleanupStable) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-func", mnodeInitFunc, mnodeCleanupFunc) != 0) return -1;
|
||||
if (taosStepAdd(steps, "mnode-sdb", sdbInit, sdbCleanup) != 0) return -1;
|
||||
|
||||
tsMint.pInitSteps = steps;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeAllocStartSteps() {
|
||||
struct SSteps *steps = taosStepInit(8, NULL);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
taosStepAdd(steps, "mnode-timer", mnodeInitTimer, NULL);
|
||||
taosStepAdd(steps, "mnode-sdb-file", sdbOpen, sdbClose);
|
||||
taosStepAdd(steps, "mnode-balance", mnodeInitBalance, mnodeCleanupBalance);
|
||||
taosStepAdd(steps, "mnode-profile", mnodeInitProfile, mnodeCleanupProfile);
|
||||
taosStepAdd(steps, "mnode-show", mnodeInitShow, mnodeCleanUpShow);
|
||||
taosStepAdd(steps, "mnode-sync", mnodeInitSync, mnodeCleanUpSync);
|
||||
taosStepAdd(steps, "mnode-telem", mnodeInitTelem, mnodeCleanupTelem);
|
||||
taosStepAdd(steps, "mnode-timer", NULL, mnodeCleanupTimer);
|
||||
|
||||
tsMint.pStartSteps = steps;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mnodeInit(SMnodePara para) {
|
||||
if (mnodeSetPara(para) != 0) {
|
||||
mError("failed to init mnode para since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnodeAllocInitSteps() != 0) {
|
||||
mError("failed to alloc init steps since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnodeAllocStartSteps() != 0) {
|
||||
mError("failed to alloc start steps since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return taosStepExec(tsMint.pInitSteps);
|
||||
}
|
||||
|
||||
void mnodeCleanup() { taosStepCleanup(tsMint.pInitSteps); }
|
||||
|
||||
int32_t mnodeDeploy(SMnodeCfg *pCfg) {
|
||||
if (tsMint.para.dnodeId <= 0 && tsMint.para.clusterId <= 0) {
|
||||
if (sdbDeploy() != 0) {
|
||||
mError("failed to deploy sdb since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
mDebug("mnode is deployed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeUnDeploy() { sdbUnDeploy(); }
|
||||
|
||||
int32_t mnodeStart(SMnodeCfg *pCfg) { return taosStepExec(tsMint.pStartSteps); }
|
||||
|
||||
int32_t mnodeAlter(SMnodeCfg *pCfg) { return 0; }
|
||||
|
||||
void mnodeStop() { taosStepCleanup(tsMint.pStartSteps); }
|
||||
|
||||
int32_t mnodeGetLoad(SMnodeLoad *pLoad) { return 0; }
|
||||
|
||||
SMnodeMsg *mnodeInitMsg(SRpcMsg *pRpcMsg) {
|
||||
SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (rpcGetConnInfo(pRpcMsg->handle, &pMsg->conn) != 0) {
|
||||
mnodeCleanupMsg(pMsg);
|
||||
mError("can not get user from conn:%p", pMsg->rpcMsg.handle);
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pMsg->rpcMsg = *pRpcMsg;
|
||||
pMsg->createdTime = taosGetTimestampSec();
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void mnodeCleanupMsg(SMnodeMsg *pMsg) {
|
||||
if (pMsg->pUser != NULL) {
|
||||
sdbRelease(pMsg->pUser);
|
||||
}
|
||||
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void mnodeProcessRpcMsg(SMnodeMsg *pMsg) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
|
||||
if (tsMint.msgFp[msgType] == NULL) {
|
||||
}
|
||||
|
||||
(*tsMint.msgFp[msgType])(pMsg);
|
||||
}
|
||||
|
||||
void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp) {
|
||||
if (msgType > 0 || msgType < TSDB_MSG_TYPE_MAX) {
|
||||
tsMint.msgFp[msgType] = fp;
|
||||
}
|
||||
}
|
||||
|
||||
void mnodeProcessMsg(SMnodeMsg *pMsg, EMnMsgType msgType) {
|
||||
if (!mnodeIsMaster()) {
|
||||
mnodeSendRedirectMsg(&pMsg->rpcMsg, true);
|
||||
mnodeCleanupMsg(pMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msgType) {
|
||||
case MN_MSG_TYPE_READ:
|
||||
case MN_MSG_TYPE_WRITE:
|
||||
case MN_MSG_TYPE_SYNC:
|
||||
mnodeProcessRpcMsg(pMsg);
|
||||
break;
|
||||
case MN_MSG_TYPE_APPLY:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
static void mnodeProcessWriteReq(SMnodeMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
goto PROCESS_WRITE_REQ_END;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
|
||||
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
code = TSDB_CODE_RPC_REDIRECT;
|
||||
goto PROCESS_WRITE_REQ_END;
|
||||
}
|
||||
|
||||
if (tsMworker.writeMsgFp[msgType] == NULL) {
|
||||
mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_WRITE_REQ_END;
|
||||
}
|
||||
|
||||
code = (*tsMworker.writeMsgFp[msgType])(pMsg);
|
||||
|
||||
PROCESS_WRITE_REQ_END:
|
||||
mnodeSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
static void mnodeProcessReadReq(SMnodeMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
||||
if (!epSet) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType],
|
||||
epSet->numOfEps, epSet->inUse);
|
||||
code = TSDB_CODE_RPC_REDIRECT;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
|
||||
if (tsMworker.readMsgFp[msgType] == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
|
||||
mTrace("msg:%p, app:%p type:%s will be processed in mread queue", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = (*tsMworker.readMsgFp[msgType])(pMsg);
|
||||
|
||||
PROCESS_READ_REQ_END:
|
||||
mnodeSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
static void mnodeProcessPeerReq(SMnodeMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
goto PROCESS_PEER_REQ_END;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
||||
mnodeGetMnodeEpSetForPeer(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SEpSet);
|
||||
|
||||
mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
|
||||
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
code = TSDB_CODE_RPC_REDIRECT;
|
||||
goto PROCESS_PEER_REQ_END;
|
||||
}
|
||||
|
||||
if (tsMworker.peerReqFp[msgType] == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_PEER_REQ_END;
|
||||
}
|
||||
|
||||
code = (*tsMworker.peerReqFp[msgType])(pMsg);
|
||||
|
||||
PROCESS_PEER_REQ_END:
|
||||
mnodeSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
static void mnodeProcessPeerRsp(SMnodeMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
SRpcMsg *pRpcMsg = &pMsg->rpcMsg;
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
mError("msg:%p, ahandle:%p type:%s not processed for not master", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
||||
mnodeCleanupMsg2(pMsg);
|
||||
}
|
||||
|
||||
if (tsMworker.peerRspFp[msgType]) {
|
||||
(*tsMworker.peerRspFp[msgType])(pRpcMsg);
|
||||
} else {
|
||||
mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
||||
}
|
||||
|
||||
mnodeCleanupMsg2(pMsg);
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#define SDB_ACCT_VER 1
|
||||
|
||||
static SSdbRaw *mnodeAcctActionEncode(SAcctObj *pAcct) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, SDB_ACCT_VER, sizeof(SAcctObj));
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->acctId)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->status)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != SDB_ACCT_VER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj));
|
||||
SAcctObj *pAcct = sdbGetRowObj(pRow);
|
||||
if (pAcct == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->updateTime)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->acctId)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->status)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxUsers)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxDbs)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxTimeSeries)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxStreams)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->cfg.maxStorage)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.accessState)
|
||||
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mnodeAcctActionInsert(SAcctObj *pAcct) { return 0; }
|
||||
|
||||
static int32_t mnodeAcctActionDelete(SAcctObj *pAcct) { return 0; }
|
||||
|
||||
static int32_t mnodeAcctActionUpdate(SAcctObj *pSrcAcct, SAcctObj *pDstAcct) {
|
||||
SAcctObj tObj;
|
||||
int32_t len = (int32_t)((int8_t *)&tObj.info - (int8_t *)&tObj);
|
||||
memcpy(pDstAcct, pSrcAcct, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateDefaultAcct() {
|
||||
int32_t code = 0;
|
||||
|
||||
SAcctObj acctObj = {0};
|
||||
tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
|
||||
acctObj.createdTime = taosGetTimestampMs();
|
||||
acctObj.updateTime = acctObj.createdTime;
|
||||
acctObj.acctId = 1;
|
||||
acctObj.cfg = (SAcctCfg){.maxUsers = 1024,
|
||||
.maxDbs = 1024,
|
||||
.maxTimeSeries = INT32_MAX,
|
||||
.maxStreams = 8092,
|
||||
.maxStorage = INT64_MAX,
|
||||
.accessState = TSDB_VN_ALL_ACCCESS};
|
||||
|
||||
SSdbRaw *pRaw = mnodeAcctActionEncode(&acctObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
return sdbWrite(pRaw);
|
||||
}
|
||||
|
||||
int32_t mnodeInitAcct() {
|
||||
SSdbTable table = {.sdbType = SDB_ACCT,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
.deployFp = (SdbDeployFp)mnodeCreateDefaultAcct,
|
||||
.encodeFp = (SdbEncodeFp)mnodeAcctActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mnodeAcctActionDecode,
|
||||
.insertFp = (SdbInsertFp)mnodeAcctActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mnodeAcctActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mnodeAcctActionDelete};
|
||||
sdbSetTable(table);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupAcct() {}
|
|
@ -20,4 +20,10 @@
|
|||
int32_t mnodeInitSync() { return 0; }
|
||||
void mnodeCleanUpSync() {}
|
||||
|
||||
int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData) {
|
||||
trnApply(pData, pData, 0);
|
||||
free(pData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool mnodeIsMaster() { return true; }
|
|
@ -17,6 +17,7 @@
|
|||
#include "mnodeTelem.h"
|
||||
#include "tbuffer.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnodeSync.h"
|
||||
|
||||
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
||||
#define TELEMETRY_PORT 80
|
||||
|
@ -255,7 +256,7 @@ static void* mnodeTelemThreadFp(void* param) {
|
|||
if (r == 0) break;
|
||||
if (r != ETIMEDOUT) continue;
|
||||
|
||||
if (mnodeGetStatus() == MN_STATUS_READY) {
|
||||
if (mnodeIsMaster()) {
|
||||
mnodeSendTelemetryReport();
|
||||
}
|
||||
end.tv_sec += REPORT_INTERVAL;
|
|
@ -0,0 +1,234 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mnodeSync.h"
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tkey.h"
|
||||
|
||||
#define SDB_USER_VER 1
|
||||
|
||||
static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, SDB_USER_VER, sizeof(SAcctObj));
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_KEY_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->rootAuth)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) {
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != SDB_USER_VER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SUserObj));
|
||||
SUserObj *pUser = sdbGetRowObj(pRow);
|
||||
if (pUser == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->user, TSDB_USER_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->pass, TSDB_KEY_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->acct, TSDB_USER_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->rootAuth)
|
||||
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionInsert(SUserObj *pUser) {
|
||||
pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pUser->prohibitDbHash == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pUser->pAcct = sdbAcquire(SDB_ACCT, pUser->acct);
|
||||
if (pUser->pAcct == NULL) {
|
||||
terrno = TSDB_CODE_MND_ACCT_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionDelete(SUserObj *pUser) {
|
||||
if (pUser->prohibitDbHash) {
|
||||
taosHashCleanup(pUser->prohibitDbHash);
|
||||
pUser->prohibitDbHash = NULL;
|
||||
}
|
||||
|
||||
if (pUser->acct != NULL) {
|
||||
sdbRelease(pUser->pAcct);
|
||||
pUser->pAcct = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) {
|
||||
SUserObj tObj;
|
||||
int32_t len = (int32_t)((int8_t *)tObj.prohibitDbHash - (int8_t *)&tObj);
|
||||
memcpy(pDstUser, pSrcUser, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
|
||||
SUserObj userObj = {0};
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = userObj.createdTime;
|
||||
|
||||
if (strcmp(user, TSDB_DEFAULT_USER) == 0) {
|
||||
userObj.rootAuth = 1;
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = mnodeUserActionEncode(&userObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
return sdbWrite(pRaw);
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateDefaultUsers() {
|
||||
if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "monitor", tsInternalPass) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, tsInternalPass) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pMsg) {
|
||||
SUserObj userObj = {0};
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.rootAuth = 0;
|
||||
|
||||
STrans *pTrans = trnCreate(TRN_POLICY_ROLLBACK);
|
||||
if (pTrans == NULL) return -1;
|
||||
trnSetRpcHandle(pTrans, pMsg->rpcMsg.handle);
|
||||
|
||||
SSdbRaw *pRedoRaw = mnodeUserActionEncode(&userObj);
|
||||
if (pRedoRaw == NULL || trnAppendRedoLog(pTrans, pRedoRaw) != 0) {
|
||||
trnDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mnodeUserActionEncode(&userObj);
|
||||
if (pUndoRaw == NULL || trnAppendUndoLog(pTrans, pUndoRaw) != 0) {
|
||||
trnDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
SSdbRaw *pCommitRaw = mnodeUserActionEncode(&userObj);
|
||||
if (pCommitRaw == NULL || trnAppendCommitLog(pTrans, pCommitRaw) != 0) {
|
||||
trnDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (trnPrepare(pTrans, mnodeSyncPropose) != 0) {
|
||||
trnDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
trnDrop(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
||||
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
|
||||
if (pCreate->user[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCreate->pass[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_PASS_FORMAT;
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pUser = sdbAcquire(SDB_USER, pCreate->user);
|
||||
if (pUser != NULL) {
|
||||
sdbRelease(pUser);
|
||||
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pOperUser = sdbAcquire(SDB_USER, pMsg->conn.user);
|
||||
if (pOperUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mnodeCreateUser(pOperUser->acct, pCreate->user, pCreate->pass, pMsg);
|
||||
sdbRelease(pOperUser);
|
||||
|
||||
if (code != 0) {
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
int32_t mnodeInitUser() {
|
||||
SSdbTable table = {.sdbType = SDB_USER,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
.deployFp = (SdbDeployFp)mnodeCreateDefaultUsers,
|
||||
.encodeFp = (SdbEncodeFp)mnodeUserActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mnodeUserActionDecode,
|
||||
.insertFp = (SdbInsertFp)mnodeUserActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mnodeUserActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mnodeUserActionDelete};
|
||||
sdbSetTable(table);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupUser() {}
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MNODE_SDB_H_
|
||||
#define _TD_MNODE_SDB_H_
|
||||
|
||||
#include "mnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*SdbDeployFp)();
|
||||
typedef void *(*SdbDecodeFp)(cJSON *root);
|
||||
typedef int32_t (*SdbEncodeFp)(void *pHead, char *buf, int32_t maxLen);
|
||||
|
||||
int32_t sdbInit();
|
||||
void sdbCleanup();
|
||||
|
||||
int32_t sdbRead();
|
||||
int32_t sdbCommit();
|
||||
|
||||
int32_t sdbDeploy();
|
||||
void sdbUnDeploy();
|
||||
|
||||
void *sdbInsertRow(EMnSdb sdb, void *pObj);
|
||||
void sdbDeleteRow(EMnSdb sdb, void *pHead);
|
||||
void *sdbUpdateRow(EMnSdb sdb, void *pHead);
|
||||
void *sdbGetRow(EMnSdb sdb, void *pKey);
|
||||
void *sdbFetchRow(EMnSdb sdb, void *pIter);
|
||||
void sdbCancelFetch(EMnSdb sdb, void *pIter);
|
||||
int32_t sdbGetCount(EMnSdb sdb);
|
||||
|
||||
void sdbSetFp(EMnSdb, EMnKey, SdbDeployFp, SdbEncodeFp, SdbDecodeFp, int32_t dataSize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MNODE_INT_H_*/
|
|
@ -0,0 +1,13 @@
|
|||
aux_source_directory(src MNODE_SRC)
|
||||
add_library(sdb ${MNODE_SRC})
|
||||
target_include_directories(
|
||||
sdb
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode/sdb"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
sdb
|
||||
PRIVATE os
|
||||
PRIVATE common
|
||||
PRIVATE util
|
||||
)
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_SDB_INT_H_
|
||||
#define _TD_SDB_INT_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "sdb.h"
|
||||
#include "taosmsg.h"
|
||||
#include "thash.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tlog.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
|
||||
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
|
||||
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
|
||||
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }}
|
||||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
#define SDB_MAX_SIZE (32 * 1024)
|
||||
|
||||
typedef struct SSdbRaw {
|
||||
int8_t sdb;
|
||||
int8_t sver;
|
||||
int8_t status;
|
||||
int8_t reserved;
|
||||
int32_t dataLen;
|
||||
char pData[];
|
||||
} SSdbRaw;
|
||||
|
||||
typedef struct SSdbRow {
|
||||
ESdbType sdb;
|
||||
ESdbStatus status;
|
||||
int32_t refCount;
|
||||
char pObj[];
|
||||
} SSdbRow;
|
||||
|
||||
typedef struct {
|
||||
char *currDir;
|
||||
char *syncDir;
|
||||
char *tmpDir;
|
||||
int64_t lastCommitVer;
|
||||
int64_t curVer;
|
||||
EKeyType keyTypes[SDB_MAX];
|
||||
SHashObj *hashObjs[SDB_MAX];
|
||||
SRWLatch locks[SDB_MAX];
|
||||
SdbInsertFp insertFps[SDB_MAX];
|
||||
SdbUpdateFp updateFps[SDB_MAX];
|
||||
SdbDeleteFp deleteFps[SDB_MAX];
|
||||
SdbDeployFp deployFps[SDB_MAX];
|
||||
SdbEncodeFp encodeFps[SDB_MAX];
|
||||
SdbDecodeFp decodeFps[SDB_MAX];
|
||||
} SSdbMgr;
|
||||
|
||||
extern SSdbMgr tsSdb;
|
||||
|
||||
int32_t sdbWriteImp(SSdbRaw *pRaw);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_SDB_INT_H_*/
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "sdbInt.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
SSdbMgr tsSdb = {0};
|
||||
|
||||
int32_t sdbInit() {
|
||||
char path[PATH_MAX + 100];
|
||||
|
||||
snprintf(path, PATH_MAX + 100, "%s%scur%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
||||
tsSdb.currDir = strdup(path);
|
||||
|
||||
snprintf(path, PATH_MAX + 100, "%s%ssync%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
||||
tsSdb.syncDir = strdup(path);
|
||||
|
||||
snprintf(path, PATH_MAX + 100, "%s%stmp%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
||||
tsSdb.tmpDir = strdup(path);
|
||||
|
||||
if (tsSdb.currDir == NULL || tsSdb.currDir == NULL || tsSdb.currDir == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SDB_MAX; ++i) {
|
||||
int32_t type;
|
||||
if (tsSdb.keyTypes[i] == SDB_KEY_INT32) {
|
||||
type = TSDB_DATA_TYPE_INT;
|
||||
} else if (tsSdb.keyTypes[i] == SDB_KEY_INT64) {
|
||||
type = TSDB_DATA_TYPE_BIGINT;
|
||||
} else {
|
||||
type = TSDB_DATA_TYPE_BINARY;
|
||||
}
|
||||
|
||||
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK);
|
||||
if (hash == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
tsSdb.hashObjs[i] = hash;
|
||||
taosInitRWLatch(&tsSdb.locks[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sdbCleanup() {
|
||||
if (tsSdb.currDir != NULL) {
|
||||
tfree(tsSdb.currDir);
|
||||
}
|
||||
|
||||
if (tsSdb.syncDir != NULL) {
|
||||
tfree(tsSdb.syncDir);
|
||||
}
|
||||
|
||||
if (tsSdb.tmpDir != NULL) {
|
||||
tfree(tsSdb.tmpDir);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SDB_MAX; ++i) {
|
||||
SHashObj *hash = tsSdb.hashObjs[i];
|
||||
if (hash != NULL) {
|
||||
taosHashCleanup(hash);
|
||||
}
|
||||
tsSdb.hashObjs[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void sdbSetTable(SSdbTable table) {
|
||||
ESdbType sdb = table.sdbType;
|
||||
tsSdb.keyTypes[sdb] = table.keyType;
|
||||
tsSdb.insertFps[sdb] = table.insertFp;
|
||||
tsSdb.updateFps[sdb] = table.updateFp;
|
||||
tsSdb.deleteFps[sdb] = table.deleteFp;
|
||||
tsSdb.deployFps[sdb] = table.deployFp;
|
||||
tsSdb.encodeFps[sdb] = table.encodeFp;
|
||||
tsSdb.decodeFps[sdb] = table.decodeFp;
|
||||
}
|
|
@ -0,0 +1,258 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "sdbInt.h"
|
||||
#include "tglobal.h"
|
||||
#include "tchecksum.h"
|
||||
|
||||
static int32_t sdbCreateDir() {
|
||||
mDebug("start to create mnode at %s", tsMnodeDir);
|
||||
|
||||
if (!taosMkDir(tsSdb.currDir)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", tsSdb.currDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsSdb.syncDir)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", tsSdb.syncDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsSdb.tmpDir)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", tsSdb.tmpDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbRunDeployFp() {
|
||||
mDebug("start to run deploy functions");
|
||||
|
||||
for (int32_t i = SDB_START; i < SDB_MAX; ++i) {
|
||||
SdbDeployFp fp = tsSdb.deployFps[i];
|
||||
if (fp == NULL) continue;
|
||||
if ((*fp)() != 0) {
|
||||
mError("failed to deploy sdb:%d since %s", i, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbReadDataFile() {
|
||||
SSdbRaw *pRaw = malloc(SDB_MAX_SIZE);
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char file[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
|
||||
FileFd fd = taosOpenFileRead(file);
|
||||
if (fd <= 0) {
|
||||
free(pRaw);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open file:%s for read since %s", file, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t offset = 0;
|
||||
int32_t code = 0;
|
||||
int32_t readLen = 0;
|
||||
int64_t ret = 0;
|
||||
|
||||
while (1) {
|
||||
readLen = sizeof(SSdbRaw);
|
||||
ret = taosReadFile(fd, pRaw, readLen);
|
||||
if (ret == 0) break;
|
||||
|
||||
if (ret < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to read file:%s since %s", file, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret != readLen) {
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
mError("failed to read file:%s since %s", file, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
readLen = pRaw->dataLen + sizeof(int32_t);
|
||||
ret = taosReadFile(fd, pRaw->pData, readLen);
|
||||
if (ret < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to read file:%s since %s", file, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret != readLen) {
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
mError("failed to read file:%s since %s", file, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
int32_t totalLen = sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t);
|
||||
if (!taosCheckChecksumWhole((const uint8_t *)pRaw, totalLen) != 0) {
|
||||
code = TSDB_CODE_CHECKSUM_ERROR;
|
||||
mError("failed to read file:%s since %s", file, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
code = sdbWriteImp(pRaw);
|
||||
if (code != 0) {
|
||||
mError("failed to read file:%s since %s", file, terrstr());
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
PARSE_SDB_DATA_ERROR:
|
||||
taosCloseFile(fd);
|
||||
sdbFreeRaw(pRaw);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t sdbWriteDataFile() {
|
||||
char tmpfile[PATH_MAX] = {0};
|
||||
snprintf(tmpfile, sizeof(tmpfile), "%ssdb.data", tsSdb.tmpDir);
|
||||
|
||||
FileFd fd = taosOpenFileCreateWrite(tmpfile);
|
||||
if (fd <= 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open file:%s for write since %s", tmpfile, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
|
||||
for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) {
|
||||
SdbEncodeFp encodeFp = tsSdb.encodeFps[i];
|
||||
if (encodeFp == NULL) continue;
|
||||
|
||||
SHashObj *hash = tsSdb.hashObjs[i];
|
||||
SRWLatch *pLock = &tsSdb.locks[i];
|
||||
taosWLockLatch(pLock);
|
||||
|
||||
SSdbRow **ppRow = taosHashIterate(hash, NULL);
|
||||
while (ppRow != NULL) {
|
||||
SSdbRow *pRow = *ppRow;
|
||||
if (pRow == NULL || pRow->status != SDB_STATUS_READY) {
|
||||
ppRow = taosHashIterate(hash, ppRow);
|
||||
continue;
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = (*encodeFp)(pRow->pObj);
|
||||
if (pRaw != NULL) {
|
||||
pRaw->status = pRow->status;
|
||||
int32_t writeLen = sizeof(SSdbRaw) + pRaw->dataLen;
|
||||
if (taosWriteFile(fd, pRaw, writeLen) != writeLen) {
|
||||
code = TAOS_SYSTEM_ERROR(terrno);
|
||||
taosHashCancelIterate(hash, ppRow);
|
||||
break;
|
||||
}
|
||||
|
||||
int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen);
|
||||
if (taosWriteFile(fd, &cksum, sizeof(int32_t)) != sizeof(int32_t)) {
|
||||
code = TAOS_SYSTEM_ERROR(terrno);
|
||||
taosHashCancelIterate(hash, ppRow);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
code = TSDB_CODE_SDB_APP_ERROR;
|
||||
taosHashCancelIterate(hash, ppRow);
|
||||
break;
|
||||
}
|
||||
|
||||
ppRow = taosHashIterate(hash, ppRow);
|
||||
}
|
||||
taosWUnLockLatch(pLock);
|
||||
}
|
||||
|
||||
if (code == 0) {
|
||||
code = taosFsyncFile(fd);
|
||||
}
|
||||
|
||||
taosCloseFile(fd);
|
||||
|
||||
if (code == 0) {
|
||||
char curfile[PATH_MAX] = {0};
|
||||
snprintf(curfile, sizeof(curfile), "%ssdb.data", tsSdb.currDir);
|
||||
code = taosRenameFile(tmpfile, curfile);
|
||||
}
|
||||
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("failed to write sdb file since %s", terrstr());
|
||||
} else {
|
||||
mDebug("write sdb file successfully");
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t sdbOpen() {
|
||||
mDebug("start to read mnode file");
|
||||
|
||||
if (sdbReadDataFile() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sdbClose() {
|
||||
if (tsSdb.curVer != tsSdb.lastCommitVer) {
|
||||
mDebug("start to write mnode file");
|
||||
sdbWriteDataFile();
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SDB_MAX; ++i) {
|
||||
SHashObj *hash = tsSdb.hashObjs[i];
|
||||
if (hash != NULL) {
|
||||
taosHashClear(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t sdbDeploy() {
|
||||
if (sdbCreateDir() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sdbRunDeployFp() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sdbWriteDataFile() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdbClose();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sdbUnDeploy() {
|
||||
mDebug("start to undeploy mnode");
|
||||
taosRemoveDir(tsMnodeDir);
|
||||
}
|
|
@ -0,0 +1,280 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "sdbInt.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
static SHashObj *sdbGetHash(int32_t sdb) {
|
||||
if (sdb >= SDB_MAX || sdb <= SDB_START) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SHashObj *hash = tsSdb.hashObjs[sdb];
|
||||
if (hash == NULL) {
|
||||
terrno = TSDB_CODE_SDB_APP_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
static int32_t sdbGetkeySize(ESdbType sdb, void *pKey) {
|
||||
int32_t keySize;
|
||||
EKeyType keyType = tsSdb.keyTypes[sdb];
|
||||
|
||||
if (keyType == SDB_KEY_INT32) {
|
||||
keySize = sizeof(int32_t);
|
||||
} else if (keyType == SDB_KEY_BINARY) {
|
||||
keySize = strlen(pKey) + 1;
|
||||
} else {
|
||||
keySize = sizeof(int64_t);
|
||||
}
|
||||
|
||||
return keySize;
|
||||
}
|
||||
|
||||
static int32_t sdbInsertRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
|
||||
SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
|
||||
taosWLockLatch(pLock);
|
||||
|
||||
SSdbRow *pDstRow = taosHashGet(hash, pRow->pObj, keySize);
|
||||
if (pDstRow != NULL) {
|
||||
terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE;
|
||||
taosWUnLockLatch(pLock);
|
||||
sdbFreeRow(pRow);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRow->refCount = 1;
|
||||
pRow->status = pRaw->status;
|
||||
|
||||
if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosWUnLockLatch(pLock);
|
||||
sdbFreeRow(pRow);
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosWUnLockLatch(pLock);
|
||||
|
||||
SdbInsertFp insertFp = tsSdb.insertFps[pRow->sdb];
|
||||
if (insertFp != NULL) {
|
||||
if ((*insertFp)(pRow->pObj) != 0) {
|
||||
taosWLockLatch(pLock);
|
||||
taosHashRemove(hash, pRow->pObj, keySize);
|
||||
taosWUnLockLatch(pLock);
|
||||
sdbFreeRow(pRow);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbUpdateRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
|
||||
SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
|
||||
taosRLockLatch(pLock);
|
||||
|
||||
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
|
||||
if (ppDstRow == NULL || *ppDstRow == NULL) {
|
||||
taosRUnLockLatch(pLock);
|
||||
return sdbInsertRow(hash, pRaw, pRow, keySize);
|
||||
}
|
||||
SSdbRow *pDstRow = *ppDstRow;
|
||||
|
||||
pRow->status = pRaw->status;
|
||||
taosRUnLockLatch(pLock);
|
||||
|
||||
SdbUpdateFp updateFp = tsSdb.updateFps[pRow->sdb];
|
||||
if (updateFp != NULL) {
|
||||
(*updateFp)(pRow->pObj, pDstRow->pObj);
|
||||
}
|
||||
|
||||
sdbFreeRow(pRow);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) {
|
||||
SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
|
||||
taosWLockLatch(pLock);
|
||||
|
||||
SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize);
|
||||
if (ppDstRow == NULL || *ppDstRow == NULL) {
|
||||
terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
|
||||
taosWUnLockLatch(pLock);
|
||||
sdbFreeRow(pRow);
|
||||
return -1;
|
||||
}
|
||||
SSdbRow *pDstRow = *ppDstRow;
|
||||
|
||||
pDstRow->status = pRaw->status;
|
||||
taosHashRemove(hash, pDstRow->pObj, keySize);
|
||||
taosWUnLockLatch(pLock);
|
||||
|
||||
SdbDeleteFp deleteFp = tsSdb.deleteFps[pDstRow->sdb];
|
||||
if (deleteFp != NULL) {
|
||||
(void)(*deleteFp)(pDstRow->pObj);
|
||||
}
|
||||
|
||||
sdbRelease(pDstRow->pObj);
|
||||
sdbFreeRow(pRow);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbWriteImp(SSdbRaw *pRaw) {
|
||||
SHashObj *hash = sdbGetHash(pRaw->sdb);
|
||||
if (hash == NULL) return -1;
|
||||
|
||||
SdbDecodeFp decodeFp = tsSdb.decodeFps[pRaw->sdb];
|
||||
SSdbRow *pRow = (*decodeFp)(pRaw);
|
||||
if (pRow == NULL) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_CONTENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRow->sdb = pRaw->sdb;
|
||||
|
||||
int32_t keySize = sdbGetkeySize(pRow->sdb, pRow->pObj);
|
||||
int32_t code = -1;
|
||||
|
||||
switch (pRaw->status) {
|
||||
case SDB_STATUS_CREATING:
|
||||
code = sdbInsertRow(hash, pRaw, pRow, keySize);
|
||||
break;
|
||||
case SDB_STATUS_READY:
|
||||
case SDB_STATUS_DROPPING:
|
||||
code = sdbUpdateRow(hash, pRaw, pRow, keySize);
|
||||
break;
|
||||
case SDB_STATUS_DROPPED:
|
||||
code = sdbDeleteRow(hash, pRaw, pRow, keySize);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_SDB_INVALID_ACTION_TYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t sdbWrite(SSdbRaw *pRaw) {
|
||||
int32_t code = sdbWriteImp(pRaw);
|
||||
sdbFreeRaw(pRaw);
|
||||
return code;
|
||||
}
|
||||
|
||||
void *sdbAcquire(ESdbType sdb, void *pKey) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) return NULL;
|
||||
|
||||
void *pRet = NULL;
|
||||
int32_t keySize = sdbGetkeySize(sdb, pKey);
|
||||
|
||||
SRWLatch *pLock = &tsSdb.locks[sdb];
|
||||
taosRLockLatch(pLock);
|
||||
|
||||
SSdbRow **ppRow = taosHashGet(hash, pKey, keySize);
|
||||
if (ppRow == NULL || *ppRow == NULL) {
|
||||
terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
|
||||
taosRUnLockLatch(pLock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = *ppRow;
|
||||
switch (pRow->status) {
|
||||
case SDB_STATUS_READY:
|
||||
atomic_add_fetch_32(&pRow->refCount, 1);
|
||||
pRet = pRow->pObj;
|
||||
break;
|
||||
case SDB_STATUS_CREATING:
|
||||
terrno = TSDB_CODE_SDB_OBJ_CREATING;
|
||||
break;
|
||||
case SDB_STATUS_DROPPING:
|
||||
terrno = TSDB_CODE_SDB_OBJ_DROPPING;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_SDB_APP_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
taosRUnLockLatch(pLock);
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void sdbRelease(void *pObj) {
|
||||
if (pObj == NULL) return;
|
||||
|
||||
SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow));
|
||||
if (pRow->sdb >= SDB_MAX || pRow->sdb <= SDB_START) return;
|
||||
|
||||
SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
|
||||
taosRLockLatch(pLock);
|
||||
|
||||
int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
|
||||
if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
|
||||
sdbFreeRow(pRow);
|
||||
}
|
||||
|
||||
taosRUnLockLatch(pLock);
|
||||
}
|
||||
|
||||
void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) return NULL;
|
||||
|
||||
SRWLatch *pLock = &tsSdb.locks[sdb];
|
||||
taosRLockLatch(pLock);
|
||||
|
||||
SSdbRow **ppRow = taosHashIterate(hash, ppRow);
|
||||
while (ppRow != NULL) {
|
||||
SSdbRow *pRow = *ppRow;
|
||||
if (pRow == NULL || pRow->status != SDB_STATUS_READY) {
|
||||
ppRow = taosHashIterate(hash, ppRow);
|
||||
continue;
|
||||
}
|
||||
|
||||
atomic_add_fetch_32(&pRow->refCount, 1);
|
||||
*ppObj = pRow->pObj;
|
||||
break;
|
||||
}
|
||||
taosRUnLockLatch(pLock);
|
||||
|
||||
return ppRow;
|
||||
}
|
||||
|
||||
void sdbCancelFetch(void *pIter) {
|
||||
if (pIter == NULL) return;
|
||||
SSdbRow *pRow = *(SSdbRow **)pIter;
|
||||
SHashObj *hash = sdbGetHash(pRow->sdb);
|
||||
if (hash == NULL) return;
|
||||
|
||||
SRWLatch *pLock = &tsSdb.locks[pRow->sdb];
|
||||
taosRLockLatch(pLock);
|
||||
taosHashCancelIterate(hash, pIter);
|
||||
taosRUnLockLatch(pLock);
|
||||
}
|
||||
|
||||
int32_t sdbGetSize(ESdbType sdb) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) return 0;
|
||||
|
||||
SRWLatch *pLock = &tsSdb.locks[sdb];
|
||||
taosRLockLatch(pLock);
|
||||
int32_t size = taosHashGetSize(hash);
|
||||
taosRUnLockLatch(pLock);
|
||||
|
||||
return size;
|
||||
}
|
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "sdbInt.h"
|
||||
|
||||
SSdbRaw *sdbAllocRaw(ESdbType sdb, int8_t sver, int32_t dataLen) {
|
||||
SSdbRaw *pRaw = calloc(1, dataLen + sizeof(SSdbRaw));
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pRaw->sdb = sdb;
|
||||
pRaw->sver = sver;
|
||||
pRaw->dataLen = dataLen;
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
void sdbFreeRaw(SSdbRaw *pRaw) { free(pRaw); }
|
||||
|
||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*(int8_t *)(pRaw->pData + dataPos) = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*(int32_t *)(pRaw->pData + dataPos) = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*(int64_t *)(pRaw->pData + dataPos) = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dataPos + valLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pRaw->pData + dataPos, pVal, valLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dataLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRaw->dataLen = dataLen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRaw->status = status;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*val = *(int8_t *)(pRaw->pData + dataPos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*val = *(int32_t *)(pRaw->pData + dataPos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*val = *(int64_t *)(pRaw->pData + dataPos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dataPos + valLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pVal, pRaw->pData + dataPos, valLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*sver = pRaw->sver;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbGetRawTotalSize(SSdbRaw *pRaw) {
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sizeof(SSdbRaw) + pRaw->dataLen;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "sdbInt.h"
|
||||
|
||||
SSdbRow *sdbAllocRow(int32_t objSize) {
|
||||
SSdbRow *pRow = calloc(1, objSize + sizeof(SSdbRow));
|
||||
if (pRow == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pRow;
|
||||
}
|
||||
|
||||
void *sdbGetRowObj(SSdbRow *pRow) {
|
||||
if (pRow == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pRow->pObj;
|
||||
}
|
||||
|
||||
void sdbFreeRow(SSdbRow *pRow) { free(pRow); }
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mnodeSdb.h"
|
||||
|
||||
static void mnodeCreateDefaultAcct() {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SAcctObj acctObj = {0};
|
||||
tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
|
||||
acctObj.cfg = (SAcctCfg){.maxUsers = 128,
|
||||
.maxDbs = 128,
|
||||
.maxTimeSeries = INT32_MAX,
|
||||
.maxStreams = 1000,
|
||||
.maxStorage = INT64_MAX,
|
||||
.accessState = TSDB_VN_ALL_ACCCESS};
|
||||
acctObj.acctId = 1;
|
||||
acctObj.createdTime = taosGetTimestampMs();
|
||||
acctObj.updateTime = taosGetTimestampMs();
|
||||
|
||||
sdbInsertRow(MN_SDB_ACCT, &acctObj);
|
||||
}
|
||||
|
||||
int32_t mnodeEncodeAcct(SAcctObj *pAcct, char *buf, int32_t maxLen) {
|
||||
int32_t len = 0;
|
||||
|
||||
len += snprintf(buf + len, maxLen - len, "{\"type\":%d, ", MN_SDB_ACCT);
|
||||
len += snprintf(buf + len, maxLen - len, "\"acct\":\"%s\", ", pAcct->acct);
|
||||
len += snprintf(buf + len, maxLen - len, "\"acctId\":\"%d\", ", pAcct->acctId);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxUsers\":\"%d\", ", pAcct->cfg.maxUsers);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxDbs\":\"%d\", ", pAcct->cfg.maxDbs);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxTimeSeries\":\"%d\", ", pAcct->cfg.maxTimeSeries);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxStreams\":\"%d\", ", pAcct->cfg.maxStreams);
|
||||
len += snprintf(buf + len, maxLen - len, "\"maxStorage\":\"%" PRIu64 "\", ", pAcct->cfg.maxStorage);
|
||||
len += snprintf(buf + len, maxLen - len, "\"accessState\":\"%d\", ", pAcct->cfg.accessState);
|
||||
len += snprintf(buf + len, maxLen - len, "\"createdTime\":\"%" PRIu64 "\", ", pAcct->createdTime);
|
||||
len += snprintf(buf + len, maxLen - len, "\"updateTime\":\"%" PRIu64 "\"}\n", pAcct->updateTime);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
SAcctObj *mnodeDecodeAcct(cJSON *root) {
|
||||
int32_t code = -1;
|
||||
SAcctObj *pAcct = calloc(1, sizeof(SAcctObj));
|
||||
|
||||
cJSON *acct = cJSON_GetObjectItem(root, "acct");
|
||||
if (!acct || acct->type != cJSON_String) {
|
||||
mError("failed to parse acct since acct not found");
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
tstrncpy(pAcct->acct, acct->valuestring, TSDB_USER_LEN);
|
||||
|
||||
cJSON *acctId = cJSON_GetObjectItem(root, "acctId");
|
||||
if (!acctId || acctId->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since acctId not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->acctId = atol(acctId->valuestring);
|
||||
|
||||
cJSON *maxUsers = cJSON_GetObjectItem(root, "maxUsers");
|
||||
if (!maxUsers || maxUsers->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxUsers not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxUsers = atol(maxUsers->valuestring);
|
||||
|
||||
cJSON *maxDbs = cJSON_GetObjectItem(root, "maxDbs");
|
||||
if (!maxDbs || maxDbs->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxDbs not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxDbs = atol(maxDbs->valuestring);
|
||||
|
||||
cJSON *maxTimeSeries = cJSON_GetObjectItem(root, "maxTimeSeries");
|
||||
if (!maxTimeSeries || maxTimeSeries->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxTimeSeries not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxTimeSeries = atol(maxTimeSeries->valuestring);
|
||||
|
||||
cJSON *maxStreams = cJSON_GetObjectItem(root, "maxStreams");
|
||||
if (!maxStreams || maxStreams->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxStreams not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxStreams = atol(maxStreams->valuestring);
|
||||
|
||||
cJSON *maxStorage = cJSON_GetObjectItem(root, "maxStorage");
|
||||
if (!maxStorage || maxStorage->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since maxStorage not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.maxStorage = atoll(maxStorage->valuestring);
|
||||
|
||||
cJSON *accessState = cJSON_GetObjectItem(root, "accessState");
|
||||
if (!accessState || accessState->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since accessState not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->cfg.accessState = atol(accessState->valuestring);
|
||||
|
||||
cJSON *createdTime = cJSON_GetObjectItem(root, "createdTime");
|
||||
if (!createdTime || createdTime->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since createdTime not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->createdTime = atol(createdTime->valuestring);
|
||||
|
||||
cJSON *updateTime = cJSON_GetObjectItem(root, "updateTime");
|
||||
if (!updateTime || updateTime->type != cJSON_String) {
|
||||
mError("acct:%s, failed to parse since updateTime not found", pAcct->acct);
|
||||
goto DECODE_ACCT_OVER;
|
||||
}
|
||||
pAcct->updateTime = atol(updateTime->valuestring);
|
||||
|
||||
code = 0;
|
||||
mTrace("acct:%s, parse success", pAcct->acct);
|
||||
|
||||
DECODE_ACCT_OVER:
|
||||
if (code != 0) {
|
||||
free(pAcct);
|
||||
pAcct = NULL;
|
||||
}
|
||||
return pAcct;
|
||||
}
|
||||
|
||||
int32_t mnodeInitAcct() {
|
||||
sdbSetFp(MN_SDB_ACCT, MN_KEY_BINARY, mnodeCreateDefaultAcct, (SdbEncodeFp)mnodeEncodeAcct,
|
||||
(SdbDecodeFp)(mnodeDecodeAcct), sizeof(SAcctObj));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupAcct() {}
|
|
@ -1,395 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "thash.h"
|
||||
#include "tglobal.h"
|
||||
#include "cJSON.h"
|
||||
#include "mnodeSdb.h"
|
||||
|
||||
static struct {
|
||||
char currDir[PATH_MAX];
|
||||
char backDir[PATH_MAX];
|
||||
char tmpDir[PATH_MAX];
|
||||
int64_t version;
|
||||
EMnKey hashKey[MN_SDB_MAX];
|
||||
int32_t dataSize[MN_SDB_MAX];
|
||||
SHashObj *hashObj[MN_SDB_MAX];
|
||||
SdbDeployFp deployFp[MN_SDB_MAX];
|
||||
SdbEncodeFp encodeFp[MN_SDB_MAX];
|
||||
SdbDecodeFp decodeFp[MN_SDB_MAX];
|
||||
} tsSdb = {0};
|
||||
|
||||
static int32_t sdbCreateDir() {
|
||||
if (!taosMkDir(tsSdb.currDir)) {
|
||||
mError("failed to create dir:%s", tsSdb.currDir);
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsSdb.backDir)) {
|
||||
mError("failed to create dir:%s", tsSdb.backDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!taosMkDir(tsSdb.tmpDir)) {
|
||||
mError("failed to create dir:%s", tsSdb.tmpDir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbRunDeployFp() {
|
||||
for (int32_t i = MN_SDB_START; i < MN_SDB_MAX; ++i) {
|
||||
SdbDeployFp fp = tsSdb.deployFp[i];
|
||||
if (fp) {
|
||||
(*fp)();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbReadVersion(cJSON *root) {
|
||||
cJSON *ver = cJSON_GetObjectItem(root, "version");
|
||||
if (!ver || ver->type != cJSON_String) {
|
||||
mError("failed to parse version since version not found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsSdb.version = (int64_t)atoll(ver->valuestring);
|
||||
mTrace("parse version success, version:%" PRIu64, tsSdb.version);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sdbWriteVersion(FileFd fd) {
|
||||
char content[128];
|
||||
int32_t len =
|
||||
snprintf(content, sizeof(content), "{\"type\":0, \"version\":\"%" PRIu64 "\", \"updateTime\":\"%" PRIu64 "\"}\n",
|
||||
tsSdb.version, taosGetTimestampMs());
|
||||
taosWriteFile(fd, content, len);
|
||||
}
|
||||
|
||||
static int32_t sdbReadDataFile() {
|
||||
ssize_t _bytes = 0;
|
||||
size_t len = 4096;
|
||||
char *line = calloc(1, len);
|
||||
int32_t code = -1;
|
||||
FILE *fp = NULL;
|
||||
cJSON *root = NULL;
|
||||
|
||||
char file[PATH_MAX + 20];
|
||||
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
|
||||
fp = fopen(file, "r");
|
||||
if (!fp) {
|
||||
mDebug("failed to open file:%s for read since %s", file, strerror(errno));
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
while (!feof(fp)) {
|
||||
memset(line, 0, len);
|
||||
_bytes = tgetline(&line, &len, fp);
|
||||
if (_bytes < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
line[len - 1] = 0;
|
||||
if (len <= 10) continue;
|
||||
|
||||
root = cJSON_Parse(line);
|
||||
if (root == NULL) {
|
||||
mError("failed to parse since invalid json format, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
cJSON *type = cJSON_GetObjectItem(root, "type");
|
||||
if (!type || type->type != cJSON_Number) {
|
||||
mError("failed to parse since invalid type not found, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
if (type->valueint >= MN_SDB_MAX || type->valueint < MN_SDB_START) {
|
||||
mError("failed to parse since invalid type, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
if (type->valueint == MN_SDB_START) {
|
||||
if (sdbReadVersion(root) != 0) {
|
||||
mError("failed to parse version, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
cJSON_Delete(root);
|
||||
root = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
SdbDecodeFp decodeFp = tsSdb.decodeFp[type->valueint];
|
||||
SdbHead *pHead = (*decodeFp)(root);
|
||||
if (pHead == NULL) {
|
||||
mError("failed to parse since decode error, %s", line);
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
}
|
||||
|
||||
pHead->type = type->valueint;
|
||||
pHead->status = MN_SDB_STAT_AVAIL;
|
||||
|
||||
sdbInsertRow(pHead->type, pHead);
|
||||
free(pHead);
|
||||
cJSON_Delete(root);
|
||||
root = NULL;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
PARSE_SDB_DATA_ERROR:
|
||||
if (line) free(line);
|
||||
if (fp) fclose(fp);
|
||||
if (root) cJSON_Delete(root);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t sdbWriteDataFile() {
|
||||
char file[PATH_MAX + 20] = {0};
|
||||
snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir);
|
||||
FileFd fd = taosOpenFileCreateWrite(file);
|
||||
if (fd <= 0) {
|
||||
mError("failed to open file:%s for write since %s", file, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t len;
|
||||
int32_t maxLen = 10240;
|
||||
char *buf = malloc(maxLen);
|
||||
|
||||
for (int32_t i = MN_SDB_START; i < MN_SDB_MAX; ++i) {
|
||||
SHashObj *hash = tsSdb.hashObj[i];
|
||||
if (!hash) continue;
|
||||
|
||||
SdbEncodeFp encodeFp = tsSdb.encodeFp[i];
|
||||
if (!encodeFp) continue;
|
||||
|
||||
SdbHead *pHead = taosHashIterate(hash, NULL);
|
||||
while (pHead != NULL) {
|
||||
len = (*encodeFp)(pHead, buf, maxLen);
|
||||
if (len >= 0) {
|
||||
taosWriteFile(fd, buf, len);
|
||||
}
|
||||
|
||||
pHead = taosHashIterate(hash, pHead);
|
||||
}
|
||||
}
|
||||
|
||||
sdbWriteVersion(fd);
|
||||
taosFsyncFile(fd);
|
||||
taosCloseFile(fd);
|
||||
|
||||
mInfo("write file:%s successfully", file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbCommit() {
|
||||
int32_t code = sdbWriteDataFile();
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbRead() {
|
||||
int32_t code = sdbReadDataFile();
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
mInfo("read sdb file successfully");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t sdbDeploy() {
|
||||
if (sdbCreateDir() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sdbRunDeployFp() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sdbCommit() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// if (!taosMkDir())
|
||||
// if (pMinfos == NULL) { // first deploy
|
||||
// tsMint.dnodeId = 1;
|
||||
// bool getuid = taosGetSystemUid(tsMint.clusterId);
|
||||
// if (!getuid) {
|
||||
// strcpy(tsMint.clusterId, "tdengine3.0");
|
||||
// mError("deploy new mnode but failed to get uid, set to default val %s", tsMint.clusterId);
|
||||
// } else {
|
||||
// mDebug("deploy new mnode and uid is %s", tsMint.clusterId);
|
||||
// }
|
||||
// } else { // todo
|
||||
// }
|
||||
|
||||
// if (mkdir(tsMnodeDir, 0755) != 0 && errno != EEXIST) {
|
||||
// mError("failed to init mnode dir:%s, reason:%s", tsMnodeDir, strerror(errno));
|
||||
// return -1;
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sdbUnDeploy() {}
|
||||
|
||||
int32_t sdbInit() {
|
||||
snprintf(tsSdb.currDir, PATH_MAX, "%s%scurrent%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
||||
snprintf(tsSdb.backDir, PATH_MAX, "%s%sbackup%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
||||
snprintf(tsSdb.tmpDir, PATH_MAX, "%s%stmp%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP);
|
||||
|
||||
for (int32_t i = 0; i < MN_SDB_MAX; ++i) {
|
||||
int32_t type;
|
||||
if (tsSdb.hashKey[i] == MN_KEY_INT32) {
|
||||
type = TSDB_DATA_TYPE_INT;
|
||||
} else if (tsSdb.hashKey[i] == MN_KEY_INT64) {
|
||||
type = TSDB_DATA_TYPE_BIGINT;
|
||||
} else {
|
||||
type = TSDB_DATA_TYPE_BINARY;
|
||||
}
|
||||
|
||||
SHashObj *hash = taosHashInit(128, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK);
|
||||
if (hash == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsSdb.hashObj[i] = hash;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sdbCleanup() {
|
||||
for (int32_t i = 0; i < MN_SDB_MAX; ++i) {
|
||||
SHashObj *hash = tsSdb.hashObj[i];
|
||||
if (hash != NULL) {
|
||||
taosHashCleanup(hash);
|
||||
}
|
||||
tsSdb.hashObj[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void sdbSetFp(EMnSdb sdb, EMnKey keyType, SdbDeployFp deployFp, SdbEncodeFp encodeFp, SdbDecodeFp decodeFp,
|
||||
int32_t dataSize) {
|
||||
tsSdb.deployFp[sdb] = deployFp;
|
||||
tsSdb.encodeFp[sdb] = encodeFp;
|
||||
tsSdb.decodeFp[sdb] = decodeFp;
|
||||
tsSdb.dataSize[sdb] = dataSize;
|
||||
tsSdb.hashKey[sdb] = keyType;
|
||||
}
|
||||
|
||||
static SHashObj *sdbGetHash(int32_t sdb) {
|
||||
if (sdb >= MN_SDB_MAX || sdb <= MN_SDB_START) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SHashObj *hash = tsSdb.hashObj[sdb];
|
||||
if (hash == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
void *sdbInsertRow(EMnSdb sdb, void *p) {
|
||||
SdbHead *pHead = p;
|
||||
pHead->type = sdb;
|
||||
pHead->status = MN_SDB_STAT_AVAIL;
|
||||
|
||||
char *pKey = (char *)pHead + sizeof(pHead);
|
||||
int32_t keySize;
|
||||
EMnKey keyType = tsSdb.hashKey[pHead->type];
|
||||
int32_t dataSize = tsSdb.dataSize[pHead->type];
|
||||
|
||||
SHashObj *hash = sdbGetHash(pHead->type);
|
||||
if (hash == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (keyType == MN_KEY_INT32) {
|
||||
keySize = sizeof(int32_t);
|
||||
} else if (keyType == MN_KEY_BINARY) {
|
||||
keySize = strlen(pKey) + 1;
|
||||
} else {
|
||||
keySize = sizeof(int64_t);
|
||||
}
|
||||
|
||||
taosHashPut(hash, pKey, keySize, pHead, dataSize);
|
||||
return taosHashGet(hash, pKey, keySize);
|
||||
}
|
||||
|
||||
void sdbDeleteRow(EMnSdb sdb, void *p) {
|
||||
SdbHead *pHead = p;
|
||||
pHead->status = MN_SDB_STAT_DROPPED;
|
||||
}
|
||||
|
||||
void *sdbUpdateRow(EMnSdb sdb, void *pHead) { return sdbInsertRow(sdb, pHead); }
|
||||
|
||||
void *sdbGetRow(EMnSdb sdb, void *pKey) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t keySize;
|
||||
EMnKey keyType = tsSdb.hashKey[sdb];
|
||||
|
||||
if (keyType == MN_KEY_INT32) {
|
||||
keySize = sizeof(int32_t);
|
||||
} else if (keyType == MN_KEY_BINARY) {
|
||||
keySize = strlen(pKey) + 1;
|
||||
} else {
|
||||
keySize = sizeof(int64_t);
|
||||
}
|
||||
|
||||
return taosHashGet(hash, pKey, keySize);
|
||||
}
|
||||
|
||||
void *sdbFetchRow(EMnSdb sdb, void *pIter) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return taosHashIterate(hash, pIter);
|
||||
}
|
||||
|
||||
void sdbCancelFetch(EMnSdb sdb, void *pIter) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosHashCancelIterate(hash, pIter);
|
||||
}
|
||||
|
||||
int32_t sdbGetCount(EMnSdb sdb) {
|
||||
SHashObj *hash = sdbGetHash(sdb);
|
||||
if (hash == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return taosHashGetSize(hash);
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tkey.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnodeSdb.h"
|
||||
|
||||
static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SUserObj userObj = {0};
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = taosGetTimestampMs();
|
||||
|
||||
if (strcmp(user, TSDB_DEFAULT_USER) == 0) {
|
||||
userObj.rootAuth = 1;
|
||||
}
|
||||
|
||||
sdbInsertRow(MN_SDB_USER, &userObj);
|
||||
}
|
||||
|
||||
static void mnodeCreateDefaultUsers() {
|
||||
mnodeCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS);
|
||||
mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "monitor", tsInternalPass);
|
||||
mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, tsInternalPass);
|
||||
}
|
||||
|
||||
int32_t mnodeEncodeUser(SUserObj *pUser, char *buf, int32_t maxLen) {
|
||||
int32_t len = 0;
|
||||
char *base64 = base64_encode((const unsigned char *)pUser->pass, TSDB_KEY_LEN);
|
||||
|
||||
len += snprintf(buf + len, maxLen - len, "{\"type\":%d, ", MN_SDB_USER);
|
||||
len += snprintf(buf + len, maxLen - len, "\"user\":\"%s\", ", pUser->user);
|
||||
len += snprintf(buf + len, maxLen - len, "\"auth\":\"%24s\", ", base64);
|
||||
len += snprintf(buf + len, maxLen - len, "\"acct\":\"%s\", ", pUser->acct);
|
||||
len += snprintf(buf + len, maxLen - len, "\"createdTime\":\"%" PRIu64 "\", ", pUser->createdTime);
|
||||
len += snprintf(buf + len, maxLen - len, "\"updateTime\":\"%" PRIu64 "\"}\n", pUser->updateTime);
|
||||
|
||||
free(base64);
|
||||
return len;
|
||||
}
|
||||
|
||||
SUserObj *mnodeDecodeUser(cJSON *root) {
|
||||
int32_t code = -1;
|
||||
SUserObj *pUser = calloc(1, sizeof(SUserObj));
|
||||
|
||||
cJSON *user = cJSON_GetObjectItem(root, "user");
|
||||
if (!user || user->type != cJSON_String) {
|
||||
mError("failed to parse user since user not found");
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
tstrncpy(pUser->user, user->valuestring, TSDB_USER_LEN);
|
||||
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
pUser->rootAuth = 1;
|
||||
}
|
||||
|
||||
cJSON *pass = cJSON_GetObjectItem(root, "auth");
|
||||
if (!pass || pass->type != cJSON_String) {
|
||||
mError("user:%s, failed to parse since auth not found", pUser->user);
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
|
||||
int32_t outlen = 0;
|
||||
char *base64 = (char *)base64_decode(pass->valuestring, strlen(pass->valuestring), &outlen);
|
||||
if (outlen != TSDB_KEY_LEN) {
|
||||
mError("user:%s, failed to parse since invalid auth format", pUser->user);
|
||||
free(base64);
|
||||
goto DECODE_USER_OVER;
|
||||
} else {
|
||||
memcpy(pUser->pass, base64, outlen);
|
||||
free(base64);
|
||||
}
|
||||
|
||||
cJSON *acct = cJSON_GetObjectItem(root, "acct");
|
||||
if (!acct || acct->type != cJSON_String) {
|
||||
mError("user:%s, failed to parse since acct not found", pUser->user);
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
tstrncpy(pUser->acct, acct->valuestring, TSDB_USER_LEN);
|
||||
|
||||
cJSON *createdTime = cJSON_GetObjectItem(root, "createdTime");
|
||||
if (!createdTime || createdTime->type != cJSON_String) {
|
||||
mError("user:%s, failed to parse since createdTime not found", pUser->user);
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
pUser->createdTime = atol(createdTime->valuestring);
|
||||
|
||||
cJSON *updateTime = cJSON_GetObjectItem(root, "updateTime");
|
||||
if (!updateTime || updateTime->type != cJSON_String) {
|
||||
mError("user:%s, failed to parse since updateTime not found", pUser->user);
|
||||
goto DECODE_USER_OVER;
|
||||
}
|
||||
pUser->updateTime = atol(updateTime->valuestring);
|
||||
|
||||
code = 0;
|
||||
mTrace("user:%s, parse success", pUser->user);
|
||||
|
||||
DECODE_USER_OVER:
|
||||
if (code != 0) {
|
||||
free(pUser);
|
||||
pUser = NULL;
|
||||
}
|
||||
return pUser;
|
||||
}
|
||||
|
||||
int32_t mnodeInitUser() {
|
||||
sdbSetFp(MN_SDB_USER, MN_KEY_BINARY, mnodeCreateDefaultUsers, (SdbEncodeFp)mnodeEncodeUser,
|
||||
(SdbDecodeFp)(mnodeDecodeUser), sizeof(SUserObj));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupUser() {}
|
|
@ -1,494 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tworker.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeSync.h"
|
||||
#include "mnodeWorker.h"
|
||||
|
||||
static struct {
|
||||
SWorkerPool read;
|
||||
SWorkerPool write;
|
||||
SWorkerPool peerReq;
|
||||
SWorkerPool peerRsp;
|
||||
taos_queue readQ;
|
||||
taos_queue writeQ;
|
||||
taos_queue peerReqQ;
|
||||
taos_queue peerRspQ;
|
||||
int32_t (*writeMsgFp[TSDB_MSG_TYPE_MAX])(SMnMsg *);
|
||||
int32_t (*readMsgFp[TSDB_MSG_TYPE_MAX])(SMnMsg *);
|
||||
int32_t (*peerReqFp[TSDB_MSG_TYPE_MAX])(SMnMsg *);
|
||||
void (*peerRspFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
|
||||
void (*msgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *pMsg);
|
||||
} tsMworker = {0};
|
||||
|
||||
static SMnMsg *mnodeInitMsg2(SRpcMsg *pRpcMsg) {
|
||||
int32_t size = sizeof(SMnMsg) + pRpcMsg->contLen;
|
||||
SMnMsg *pMsg = taosAllocateQitem(size);
|
||||
|
||||
pMsg->rpcMsg = *pRpcMsg;
|
||||
pMsg->rpcMsg.pCont = pMsg->pCont;
|
||||
pMsg->createdTime = taosGetTimestampSec();
|
||||
memcpy(pMsg->pCont, pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) == 0) {
|
||||
pMsg->pUser = sdbGetRow(MN_SDB_USER, connInfo.user);
|
||||
}
|
||||
|
||||
if (pMsg->pUser == NULL) {
|
||||
mError("can not get user from conn:%p", pMsg->rpcMsg.handle);
|
||||
taosFreeQitem(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
static void mnodeCleanupMsg2(SMnMsg *pMsg) {
|
||||
if (pMsg == NULL) return;
|
||||
if (pMsg->rpcMsg.pCont != pMsg->pCont) {
|
||||
tfree(pMsg->rpcMsg.pCont);
|
||||
}
|
||||
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void mnodeDispatchToWriteQueue(SRpcMsg *pRpcMsg) {
|
||||
if (mnodeGetStatus() != MN_STATUS_READY || tsMworker.writeQ == NULL) {
|
||||
mnodeSendRedirectMsg(pRpcMsg, true);
|
||||
} else {
|
||||
SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
} else {
|
||||
mTrace("msg:%p, app:%p type:%s is put into wqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
|
||||
taosWriteQitem(tsMworker.writeQ, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
void mnodeReDispatchToWriteQueue(SMnMsg *pMsg) {
|
||||
if (mnodeGetStatus() != MN_STATUS_READY || tsMworker.writeQ == NULL) {
|
||||
mnodeSendRedirectMsg(&pMsg->rpcMsg, true);
|
||||
mnodeCleanupMsg2(pMsg);
|
||||
} else {
|
||||
taosWriteQitem(tsMworker.writeQ, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
static void mnodeDispatchToReadQueue(SRpcMsg *pRpcMsg) {
|
||||
if (mnodeGetStatus() != MN_STATUS_READY || tsMworker.readQ == NULL) {
|
||||
mnodeSendRedirectMsg(pRpcMsg, true);
|
||||
} else {
|
||||
SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
} else {
|
||||
mTrace("msg:%p, app:%p type:%s is put into rqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]);
|
||||
taosWriteQitem(tsMworker.readQ, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
static void mnodeDispatchToPeerQueue(SRpcMsg *pRpcMsg) {
|
||||
if (mnodeGetStatus() != MN_STATUS_READY || tsMworker.peerReqQ == NULL) {
|
||||
mnodeSendRedirectMsg(pRpcMsg, false);
|
||||
} else {
|
||||
SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
} else {
|
||||
mTrace("msg:%p, app:%p type:%s is put into peer req queue", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType]);
|
||||
taosWriteQitem(tsMworker.peerReqQ, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
void mnodeDispatchToPeerRspQueue(SRpcMsg *pRpcMsg) {
|
||||
SMnMsg *pMsg = mnodeInitMsg2(pRpcMsg);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_MND_INVALID_USER};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
} else {
|
||||
mTrace("msg:%p, app:%p type:%s is put into peer rsp queue", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType]);
|
||||
taosWriteQitem(tsMworker.peerRspQ, pMsg);
|
||||
}
|
||||
|
||||
// rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
void mnodeSendRsp(SMnMsg *pMsg, int32_t code) {
|
||||
if (pMsg == NULL) return;
|
||||
if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return;
|
||||
if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) {
|
||||
mnodeReDispatchToWriteQueue(pMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pMsg->rpcMsg.handle,
|
||||
.pCont = pMsg->rpcRsp.rsp,
|
||||
.contLen = pMsg->rpcRsp.len,
|
||||
.code = code,
|
||||
};
|
||||
|
||||
rpcSendResponse(&rpcRsp);
|
||||
mnodeCleanupMsg2(pMsg);
|
||||
}
|
||||
|
||||
static void mnodeInitMsgFp() {
|
||||
// // peer req
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE] = mnodeDispatchToPeerQueue;
|
||||
// tsMworker.peerReqFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE] = mnodeProcessTableCfgMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE] = mnodeDispatchToPeerQueue;
|
||||
// tsMworker.peerReqFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE] = mnodeProcessVnodeCfgMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_AUTH] = mnodeDispatchToPeerQueue;
|
||||
// tsMworker.peerReqFp[TSDB_MSG_TYPE_AUTH] = mnodeProcessAuthMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_GRANT] = mnodeDispatchToPeerQueue;
|
||||
// // tsMworker.peerReqFp[TSDB_MSG_TYPE_GRANT] = grantProcessMsgInMgmt;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_STATUS] = mnodeDispatchToPeerQueue;
|
||||
// tsMworker.peerReqFp[TSDB_MSG_TYPE_STATUS] = mnodeProcessDnodeStatusMsg;
|
||||
|
||||
// // peer rsp
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP] = mnodeProcessCfgDnodeMsgRsp;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_DROP_STABLE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_DROP_STABLE_RSP] = mnodeProcessDropSuperTableRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP] = mnodeProcessCreateChildTableRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_DROP_TABLE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_DROP_TABLE_RSP] = mnodeProcessDropChildTableRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP] = mnodeProcessAlterTableRsp;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP] = mnodeProcessCreateVnodeRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP] = mnodeProcessAlterVnodeRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE_RSP] = mnodeProcessCompactVnodeRsp;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE_RSP] = mnodeDispatchToPeerRspQueue;
|
||||
// tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_DROP_VNODE_RSP] = mnodeProcessDropVnodeRsp;
|
||||
|
||||
// // read msg
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_HEARTBEAT] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_HEARTBEAT] = mnodeProcessHeartBeatMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CONNECT] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_CONNECT] = mnodeProcessConnectMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_USE_DB] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_USE_DB] = mnodeProcessUseMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_TABLE_META] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_TABLE_META] = mnodeProcessTableMetaMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_TABLES_META] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_TABLES_META] = mnodeProcessMultiTableMetaMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = mnodeProcessSuperTableVgroupMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_SHOW] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_SHOW] = mnodeProcessShowMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = mnodeProcessRetrieveMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_RETRIEVE_FUNC] = mnodeDispatchToReadQueue;
|
||||
// tsMworker.readMsgFp[TSDB_MSG_TYPE_RETRIEVE_FUNC] = mnodeProcessRetrieveFuncReq;
|
||||
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_ACCT] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CREATE_ACCT] = acctProcessCreateAcctMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_ACCT] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_ALTER_ACCT] = acctProcessDropAcctMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_DROP_ACCT] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_DROP_ACCT] = acctProcessAlterAcctMsg;
|
||||
|
||||
// // write msg
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_USER] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_USER] = mnodeProcessCreateUserMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_USER] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_ALTER_USER] = mnodeProcessAlterUserMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_USER] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_USER] = mnodeProcessDropUserMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_DNODE] = mnodeProcessCreateDnodeMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_DNODE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_DNODE] = mnodeProcessDropDnodeMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = mnodeProcessCfgDnodeMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_DB] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_DB] = mnodeProcessCreateDbMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_DB] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_ALTER_DB] = mnodeProcessAlterDbMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_DB] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_DB] = mnodeProcessDropDbMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_SYNC_DB] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_SYNC_DB] = mnodeProcessSyncDbMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_COMPACT_VNODE] = mnodeProcessCompactMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = mnodeProcessCreateFuncMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = mnodeProcessDropFuncMsg;
|
||||
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_TP] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CREATE_TP] = tpProcessCreateTpMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_DROP_TP] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_DROP_TP] = tpProcessAlterTpMsg;
|
||||
// // tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_TP] = mnodeDispatchToWriteQueue;
|
||||
// // tsMworker.readMsgFp[TSDB_MSG_TYPE_ALTER_TP] = tpProcessDropTpMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_TABLE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_TABLE] = mnodeProcessCreateTableMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_TABLE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_TABLE] = mnodeProcessDropTableMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_ALTER_TABLE] = mnodeProcessAlterTableMsg;
|
||||
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_STREAM] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_ALTER_STREAM] = NULL;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_KILL_QUERY] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_KILL_QUERY] = mnodeProcessKillQueryMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_KILL_STREAM] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_KILL_STREAM] = mnodeProcessKillStreamMsg;
|
||||
// tsMworker.msgFp[TSDB_MSG_TYPE_KILL_CONN] = mnodeDispatchToWriteQueue;
|
||||
// tsMworker.writeMsgFp[TSDB_MSG_TYPE_KILL_CONN] = mnodeProcessKillConnectionMsg;
|
||||
}
|
||||
|
||||
static void mnodeProcessWriteReq(SMnMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
goto PROCESS_WRITE_REQ_END;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
|
||||
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
code = TSDB_CODE_RPC_REDIRECT;
|
||||
goto PROCESS_WRITE_REQ_END;
|
||||
}
|
||||
|
||||
if (tsMworker.writeMsgFp[msgType] == NULL) {
|
||||
mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_WRITE_REQ_END;
|
||||
}
|
||||
|
||||
code = (*tsMworker.writeMsgFp[msgType])(pMsg);
|
||||
|
||||
PROCESS_WRITE_REQ_END:
|
||||
mnodeSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
static void mnodeProcessReadReq(SMnMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
||||
if (!epSet) {
|
||||
code = TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
mnodeGetMnodeEpSetForShell(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType],
|
||||
epSet->numOfEps, epSet->inUse);
|
||||
code = TSDB_CODE_RPC_REDIRECT;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
|
||||
if (tsMworker.readMsgFp[msgType] == NULL) {
|
||||
mError("msg:%p, app:%p type:%s in mread queue, not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_READ_REQ_END;
|
||||
}
|
||||
|
||||
mTrace("msg:%p, app:%p type:%s will be processed in mread queue", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = (*tsMworker.readMsgFp[msgType])(pMsg);
|
||||
|
||||
PROCESS_READ_REQ_END:
|
||||
mnodeSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
static void mnodeProcessPeerReq(SMnMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
int32_t code = 0;
|
||||
|
||||
if (pMsg->rpcMsg.pCont == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, content is null", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
goto PROCESS_PEER_REQ_END;
|
||||
}
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
SMnRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
|
||||
mnodeGetMnodeEpSetForPeer(epSet, true);
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SEpSet);
|
||||
|
||||
mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
|
||||
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
code = TSDB_CODE_RPC_REDIRECT;
|
||||
goto PROCESS_PEER_REQ_END;
|
||||
}
|
||||
|
||||
if (tsMworker.peerReqFp[msgType] == NULL) {
|
||||
mError("msg:%p, ahandle:%p type:%s in mpeer queue, not processed", pMsg, ahandle, taosMsg[msgType]);
|
||||
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
goto PROCESS_PEER_REQ_END;
|
||||
}
|
||||
|
||||
code = (*tsMworker.peerReqFp[msgType])(pMsg);
|
||||
|
||||
PROCESS_PEER_REQ_END:
|
||||
mnodeSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
static void mnodeProcessPeerRsp(SMnMsg *pMsg, void *unused) {
|
||||
int32_t msgType = pMsg->rpcMsg.msgType;
|
||||
SRpcMsg *pRpcMsg = &pMsg->rpcMsg;
|
||||
|
||||
if (!mnodeIsMaster()) {
|
||||
mError("msg:%p, ahandle:%p type:%s not processed for not master", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
||||
mnodeCleanupMsg2(pMsg);
|
||||
}
|
||||
|
||||
if (tsMworker.peerRspFp[msgType]) {
|
||||
(*tsMworker.peerRspFp[msgType])(pRpcMsg);
|
||||
} else {
|
||||
mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
|
||||
}
|
||||
|
||||
mnodeCleanupMsg2(pMsg);
|
||||
}
|
||||
|
||||
int32_t mnodeInitWorker() {
|
||||
mnodeInitMsgFp();
|
||||
|
||||
SWorkerPool *pPool = &tsMworker.write;
|
||||
pPool->name = "mnode-write";
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tsMworker.writeQ = tWorkerAllocQueue(pPool, NULL, (FProcessItem)mnodeProcessWriteReq);
|
||||
}
|
||||
|
||||
pPool = &tsMworker.read;
|
||||
pPool->name = "mnode-read";
|
||||
pPool->min = 2;
|
||||
pPool->max = (int32_t)(tsNumOfCores * tsNumOfThreadsPerCore / 2);
|
||||
pPool->max = MAX(2, pPool->max);
|
||||
pPool->max = MIN(4, pPool->max);
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tsMworker.readQ = tWorkerAllocQueue(pPool, NULL, (FProcessItem)mnodeProcessReadReq);
|
||||
}
|
||||
|
||||
pPool = &tsMworker.peerReq;
|
||||
pPool->name = "mnode-peer-req";
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tsMworker.peerReqQ = tWorkerAllocQueue(pPool, NULL, (FProcessItem)mnodeProcessPeerReq);
|
||||
}
|
||||
|
||||
pPool = &tsMworker.peerRsp;
|
||||
pPool->name = "mnode-peer-rsp";
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tsMworker.peerRspQ = tWorkerAllocQueue(pPool, NULL, (FProcessItem)mnodeProcessPeerRsp);
|
||||
}
|
||||
|
||||
mInfo("mnode worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupWorker() {
|
||||
tWorkerFreeQueue(&tsMworker.write, tsMworker.writeQ);
|
||||
tWorkerCleanup(&tsMworker.write);
|
||||
tsMworker.writeQ = NULL;
|
||||
|
||||
tWorkerFreeQueue(&tsMworker.read, tsMworker.readQ);
|
||||
tWorkerCleanup(&tsMworker.read);
|
||||
tsMworker.readQ = NULL;
|
||||
|
||||
tWorkerFreeQueue(&tsMworker.peerReq, tsMworker.peerReqQ);
|
||||
tWorkerCleanup(&tsMworker.peerReq);
|
||||
tsMworker.peerReqQ = NULL;
|
||||
|
||||
tWorkerFreeQueue(&tsMworker.peerRsp, tsMworker.peerRspQ);
|
||||
tWorkerCleanup(&tsMworker.peerRsp);
|
||||
tsMworker.peerRspQ = NULL;
|
||||
|
||||
mInfo("mnode worker is closed");
|
||||
}
|
||||
|
||||
SMnodeMsg *mnodeInitMsg(int32_t msgNum) { return NULL; }
|
||||
|
||||
int32_t mnodeAppendMsg(SMnodeMsg *pMsg, SRpcMsg *pRpcMsg) { return 0; }
|
||||
|
||||
void mnodeCleanupMsg(SMnodeMsg *pMsg) {}
|
||||
void mnodeProcessMsg(SMnodeMsg *pMsg, EMnMsgType msgType) {}
|
|
@ -1,250 +0,0 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tstep.h"
|
||||
#include "mnodeAcct.h"
|
||||
#include "mnodeAuth.h"
|
||||
#include "mnodeBalance.h"
|
||||
#include "mnodeCluster.h"
|
||||
#include "mnodeDb.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeFunc.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeOper.h"
|
||||
#include "mnodeProfile.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeStable.h"
|
||||
#include "mnodeSync.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
#include "mnodeWorker.h"
|
||||
#include "mnodeTelem.h"
|
||||
|
||||
static struct {
|
||||
int32_t state;
|
||||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
tmr_h timer;
|
||||
SSteps *steps1;
|
||||
SSteps *steps2;
|
||||
SMnodePara para;
|
||||
} tsMint;
|
||||
|
||||
tmr_h mnodeGetTimer() { return tsMint.timer; }
|
||||
|
||||
int32_t mnodeGetDnodeId() { return tsMint.para.dnodeId; }
|
||||
|
||||
int64_t mnodeGetClusterId() { return tsMint.para.clusterId; }
|
||||
|
||||
EMnStatus mnodeGetStatus() { return tsMint.state; }
|
||||
|
||||
void mnodeSendMsgToDnode(struct SEpSet *epSet, struct SRpcMsg *rpcMsg) {
|
||||
(*tsMint.para.SendMsgToDnode)(epSet, rpcMsg);
|
||||
}
|
||||
|
||||
void mnodeSendMsgToMnode(struct SRpcMsg *rpcMsg) { return (*tsMint.para.SendMsgToMnode)(rpcMsg); }
|
||||
|
||||
void mnodeSendRedirectMsg(struct SRpcMsg *rpcMsg, bool forShell) { (*tsMint.para.SendRedirectMsg)(rpcMsg, forShell); }
|
||||
|
||||
int32_t mnodeGetLoad(SMnodeLoad *pLoad) { return 0; }
|
||||
|
||||
static int32_t mnodeSetPara(SMnodePara para) {
|
||||
tsMint.para = para;
|
||||
|
||||
if (tsMint.para.SendMsgToDnode == NULL) return -1;
|
||||
if (tsMint.para.SendMsgToMnode == NULL) return -1;
|
||||
if (tsMint.para.SendRedirectMsg == NULL) return -1;
|
||||
if (tsMint.para.PutMsgIntoApplyQueue == NULL) return -1;
|
||||
if (tsMint.para.dnodeId < 0) return -1;
|
||||
if (tsMint.para.clusterId < 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeInitTimer() {
|
||||
if (tsMint.timer == NULL) {
|
||||
tsMint.timer = taosTmrInit(tsMaxShellConns, 200, 3600000, "MND");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mnodeCleanupTimer() {
|
||||
if (tsMint.timer != NULL) {
|
||||
taosTmrCleanUp(tsMint.timer);
|
||||
tsMint.timer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mnodeInitStep1() {
|
||||
struct SSteps *steps = taosStepInit(16, NULL);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
taosStepAdd(steps, "mnode-sdb", sdbInit, sdbCleanup);
|
||||
taosStepAdd(steps, "mnode-cluster", mnodeInitCluster, mnodeCleanupCluster);
|
||||
taosStepAdd(steps, "mnode-dnode", mnodeInitDnode, mnodeCleanupDnode);
|
||||
taosStepAdd(steps, "mnode-mnode", mnodeInitMnode, mnodeCleanupMnode);
|
||||
taosStepAdd(steps, "mnode-acct", mnodeInitAcct, mnodeCleanupAcct);
|
||||
taosStepAdd(steps, "mnode-auth", mnodeInitAuth, mnodeCleanupAuth);
|
||||
taosStepAdd(steps, "mnode-user", mnodeInitUser, mnodeCleanupUser);
|
||||
taosStepAdd(steps, "mnode-db", mnodeInitDb, mnodeCleanupDb);
|
||||
taosStepAdd(steps, "mnode-vgroup", mnodeInitVgroup, mnodeCleanupVgroup);
|
||||
taosStepAdd(steps, "mnode-stable", mnodeInitStable, mnodeCleanupStable);
|
||||
taosStepAdd(steps, "mnode-func", mnodeInitFunc, mnodeCleanupFunc);
|
||||
taosStepAdd(steps, "mnode-oper", mnodeInitOper, mnodeCleanupOper);
|
||||
|
||||
tsMint.steps1 = steps;
|
||||
return taosStepExec(tsMint.steps1);
|
||||
}
|
||||
|
||||
static int32_t mnodeInitStep2() {
|
||||
struct SSteps *steps = taosStepInit(12, NULL);
|
||||
if (steps == NULL) return -1;
|
||||
|
||||
taosStepAdd(steps, "mnode-timer", mnodeInitTimer, NULL);
|
||||
taosStepAdd(steps, "mnode-worker", mnodeInitWorker, NULL);
|
||||
taosStepAdd(steps, "mnode-balance", mnodeInitBalance, mnodeCleanupBalance);
|
||||
taosStepAdd(steps, "mnode-profile", mnodeInitProfile, mnodeCleanupProfile);
|
||||
taosStepAdd(steps, "mnode-show", mnodeInitShow, mnodeCleanUpShow);
|
||||
taosStepAdd(steps, "mnode-sync", mnodeInitSync, mnodeCleanUpSync);
|
||||
taosStepAdd(steps, "mnode-worker", NULL, mnodeCleanupWorker);
|
||||
taosStepAdd(steps, "mnode-telem", mnodeInitTelem, mnodeCleanupTelem);
|
||||
taosStepAdd(steps, "mnode-timer", NULL, mnodeCleanupTimer);
|
||||
|
||||
tsMint.steps2 = steps;
|
||||
return taosStepExec(tsMint.steps2);
|
||||
}
|
||||
|
||||
static void mnodeCleanupStep1() { taosStepCleanup(tsMint.steps1); }
|
||||
|
||||
static void mnodeCleanupStep2() { taosStepCleanup(tsMint.steps2); }
|
||||
|
||||
static bool mnodeNeedDeploy() {
|
||||
if (tsMint.para.dnodeId > 0) return false;
|
||||
if (tsMint.para.clusterId > 0) return false;
|
||||
if (strcmp(tsFirst, tsLocalEp) != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t mnodeDeploy(char *path, SMnodeCfg *pCfg) {
|
||||
if (tsMint.state != MN_STATUS_UNINIT) {
|
||||
mError("failed to deploy mnode since its deployed");
|
||||
return 0;
|
||||
} else {
|
||||
tsMint.state = MN_STATUS_INIT;
|
||||
}
|
||||
|
||||
if (tsMint.para.dnodeId <= 0 || tsMint.para.clusterId <= 0) {
|
||||
mError("failed to deploy mnode since cluster not ready");
|
||||
return TSDB_CODE_MND_NOT_READY;
|
||||
}
|
||||
|
||||
mInfo("starting to deploy mnode");
|
||||
|
||||
int32_t code = mnodeInitStep1();
|
||||
if (code != 0) {
|
||||
mError("failed to deploy mnode since init step1 error");
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return TSDB_CODE_MND_SDB_ERROR;
|
||||
}
|
||||
|
||||
code = mnodeInitStep2();
|
||||
if (code != 0) {
|
||||
mnodeCleanupStep1();
|
||||
mError("failed to deploy mnode since init step2 error");
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return TSDB_CODE_MND_SDB_ERROR;
|
||||
}
|
||||
|
||||
mDebug("mnode is deployed and waiting for raft to confirm");
|
||||
tsMint.state = MN_STATUS_READY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeUnDeploy(char *path) {
|
||||
sdbUnDeploy();
|
||||
mnodeCleanup();
|
||||
}
|
||||
|
||||
int32_t mnodeInit(SMnodePara para) {
|
||||
mDebugFlag = 207;
|
||||
if (tsMint.state != MN_STATUS_UNINIT) {
|
||||
return 0;
|
||||
} else {
|
||||
tsMint.state = MN_STATUS_INIT;
|
||||
}
|
||||
|
||||
mInfo("starting to initialize mnode ...");
|
||||
|
||||
int32_t code = mnodeSetPara(para);
|
||||
if (code != 0) {
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return code;
|
||||
}
|
||||
|
||||
code = mnodeInitStep1();
|
||||
if (code != 0) {
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
code = sdbRead();
|
||||
if (code != 0) {
|
||||
if (mnodeNeedDeploy()) {
|
||||
code = sdbDeploy();
|
||||
if (code != 0) {
|
||||
mnodeCleanupStep1();
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
mnodeCleanupStep1();
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
code = mnodeInitStep2();
|
||||
if (code != 0) {
|
||||
mnodeCleanupStep1();
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tsMint.state = MN_STATUS_READY;
|
||||
mInfo("mnode is initialized successfully");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanup() {
|
||||
if (tsMint.state != MN_STATUS_UNINIT && tsMint.state != MN_STATUS_CLOSING) {
|
||||
mInfo("starting to clean up mnode");
|
||||
tsMint.state = MN_STATUS_CLOSING;
|
||||
|
||||
mnodeCleanupStep2();
|
||||
mnodeCleanupStep1();
|
||||
|
||||
tsMint.state = MN_STATUS_UNINIT;
|
||||
mInfo("mnode is cleaned up");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mnodeStart(char *path, SMnodeCfg *pCfg) { return 0; }
|
||||
int32_t mnodeAlter(SMnodeCfg *pCfg) { return 0; }
|
||||
void mnodeStop() {}
|
|
@ -0,0 +1,15 @@
|
|||
aux_source_directory(src MNODE_SRC)
|
||||
add_library(transaction ${MNODE_SRC})
|
||||
target_include_directories(
|
||||
transaction
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode/transaction"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
transaction
|
||||
PRIVATE os
|
||||
PRIVATE common
|
||||
PRIVATE util
|
||||
PRIVATE sdb
|
||||
PRIVATE transport
|
||||
)
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_TRANSACTION_INT_H_
|
||||
#define _TD_TRANSACTION_INT_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "trn.h"
|
||||
#include "tglobal.h"
|
||||
#include "tarray.h"
|
||||
#include "tlog.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
|
||||
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
|
||||
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
|
||||
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }}
|
||||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
#define TRN_VER 1
|
||||
#define TRN_DEFAULT_ARRAY_SIZE 8
|
||||
|
||||
typedef enum {
|
||||
TRN_STAGE_PREPARE = 1,
|
||||
TRN_STAGE_EXECUTE = 2,
|
||||
TRN_STAGE_COMMIT = 3,
|
||||
TRN_STAGE_ROLLBACK = 4,
|
||||
TRN_STAGE_RETRY = 5
|
||||
} ETrnStage;
|
||||
|
||||
typedef struct STrans {
|
||||
int32_t id;
|
||||
int8_t stage;
|
||||
int8_t policy;
|
||||
void *rpcHandle;
|
||||
SArray *redoLogs;
|
||||
SArray *undoLogs;
|
||||
SArray *commitLogs;
|
||||
SArray *redoActions;
|
||||
SArray *undoActions;
|
||||
} STrans;
|
||||
|
||||
SSdbRaw *trnActionEncode(STrans *pTrans);
|
||||
STrans *trnActionDecode(SSdbRaw *pRaw);
|
||||
int32_t trnActionInsert(STrans *pTrans);
|
||||
int32_t trnActionDelete(STrans *pTrans);
|
||||
int32_t trnActionUpdate(STrans *pSrcTrans, STrans *pDstTrans);
|
||||
int32_t trnGenerateTransId();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_TRANSACTION_INT_H_*/
|
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "trnInt.h"
|
||||
|
||||
#define SDB_TRANS_VER 1
|
||||
|
||||
SSdbRaw *trnActionEncode(STrans *pTrans) {
|
||||
int32_t rawDataLen = 10 * sizeof(int32_t);
|
||||
int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs);
|
||||
int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs);
|
||||
int32_t commitLogNum = taosArrayGetSize(pTrans->commitLogs);
|
||||
int32_t redoActionNum = taosArrayGetSize(pTrans->redoActions);
|
||||
int32_t undoActionNum = taosArrayGetSize(pTrans->undoActions);
|
||||
|
||||
for (int32_t index = 0; index < redoLogNum; ++index) {
|
||||
SSdbRaw *pRaw = taosArrayGet(pTrans->redoLogs, index);
|
||||
rawDataLen += sdbGetRawTotalSize(pRaw);
|
||||
}
|
||||
|
||||
for (int32_t index = 0; index < undoLogNum; ++index) {
|
||||
SSdbRaw *pRaw = taosArrayGet(pTrans->undoLogs, index);
|
||||
rawDataLen += sdbGetRawTotalSize(pRaw);
|
||||
}
|
||||
|
||||
for (int32_t index = 0; index < commitLogNum; ++index) {
|
||||
SSdbRaw *pRaw = taosArrayGet(pTrans->commitLogs, index);
|
||||
rawDataLen += sdbGetRawTotalSize(pRaw);
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, SDB_TRANS_VER, rawDataLen);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pData, dataPos, pTrans->id)
|
||||
SDB_SET_INT8(pData, dataPos, pTrans->stage)
|
||||
SDB_SET_INT8(pData, dataPos, pTrans->policy)
|
||||
SDB_SET_INT32(pData, dataPos, redoLogNum)
|
||||
SDB_SET_INT32(pData, dataPos, undoLogNum)
|
||||
SDB_SET_INT32(pData, dataPos, commitLogNum)
|
||||
SDB_SET_INT32(pData, dataPos, redoActionNum)
|
||||
SDB_SET_INT32(pData, dataPos, undoActionNum)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
STrans *trnActionDecode(SSdbRaw *pRaw) {
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != SDB_TRANS_VER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(STrans));
|
||||
STrans *pTrans = sdbGetRowObj(pRow);
|
||||
if (pTrans == NULL) return NULL;
|
||||
|
||||
int32_t redoLogNum = 0;
|
||||
int32_t undoLogNum = 0;
|
||||
int32_t commitLogNum = 0;
|
||||
int32_t redoActionNum = 0;
|
||||
int32_t undoActionNum = 0;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pTrans->id)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pTrans->stage)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pTrans->policy)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &redoLogNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &undoLogNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &commitLogNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &redoActionNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &undoActionNum)
|
||||
|
||||
for (int32_t index = 0; index < redoLogNum; ++index) {
|
||||
int32_t dataLen = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
||||
|
||||
char *pData = malloc(dataLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen);
|
||||
void *ret = taosArrayPush(pTrans->redoLogs, pData);
|
||||
if (ret == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if (code != 0) {
|
||||
// trnDrop(pTrans);
|
||||
// terrno = code;
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
return pTrans;
|
||||
}
|
||||
|
||||
int32_t trnActionInsert(STrans *pTrans) {
|
||||
SArray *pArray = pTrans->redoLogs;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
for (int32_t index = 0; index < arraySize; ++index) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, index);
|
||||
int32_t code = sdbWrite(pRaw);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t trnActionDelete(STrans *pTrans) {
|
||||
SArray *pArray = pTrans->redoLogs;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
for (int32_t index = 0; index < arraySize; ++index) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, index);
|
||||
int32_t code = sdbWrite(pRaw);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t trnActionUpdate(STrans *pSrcTrans, STrans *pDstTrans) { return 0; }
|
||||
|
||||
int32_t trnGenerateTransId() { return 1; }
|
||||
|
||||
STrans *trnCreate(ETrnPolicy policy) {
|
||||
STrans *pTrans = calloc(1, sizeof(STrans));
|
||||
if (pTrans == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTrans->id = trnGenerateTransId();
|
||||
pTrans->stage = TRN_STAGE_PREPARE;
|
||||
pTrans->policy = policy;
|
||||
pTrans->redoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->commitLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
|
||||
|
||||
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
|
||||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pTrans;
|
||||
}
|
||||
|
||||
static void trnDropArray(SArray *pArray) {
|
||||
for (int32_t index = 0; index < pArray->size; ++index) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, index);
|
||||
tfree(pRaw);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
}
|
||||
|
||||
void trnDrop(STrans *pTrans) {
|
||||
trnDropArray(pTrans->redoLogs);
|
||||
trnDropArray(pTrans->undoLogs);
|
||||
trnDropArray(pTrans->commitLogs);
|
||||
trnDropArray(pTrans->redoActions);
|
||||
trnDropArray(pTrans->undoActions);
|
||||
tfree(pTrans);
|
||||
}
|
||||
|
||||
void trnSetRpcHandle(STrans *pTrans, void *rpcHandle) { pTrans->rpcHandle = rpcHandle; }
|
||||
|
||||
static int32_t trnAppendArray(SArray *pArray, SSdbRaw *pRaw) {
|
||||
if (pArray == NULL || pRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *ptr = taosArrayPush(pArray, &pRaw);
|
||||
if (ptr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw) { return trnAppendArray(pTrans->redoLogs, pRaw); }
|
||||
|
||||
int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw) { return trnAppendArray(pTrans->undoLogs, pRaw); }
|
||||
|
||||
int32_t trnAppendCommitLog(STrans *pTrans, SSdbRaw *pRaw) { return trnAppendArray(pTrans->commitLogs, pRaw); }
|
||||
|
||||
int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
||||
return trnAppendArray(pTrans->redoActions, pMsg);
|
||||
}
|
||||
|
||||
int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
||||
return trnAppendArray(pTrans->undoActions, pMsg);
|
||||
}
|
||||
|
||||
int32_t trnInit() {
|
||||
SSdbTable table = {.sdbType = SDB_TRANS,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
.encodeFp = (SdbEncodeFp)trnActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)trnActionDecode,
|
||||
.insertFp = (SdbInsertFp)trnActionInsert,
|
||||
.updateFp = (SdbUpdateFp)trnActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)trnActionDelete};
|
||||
sdbSetTable(table);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void trnCleanup() {}
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "trnInt.h"
|
||||
#include "trpc.h"
|
||||
|
||||
int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) {
|
||||
if (syncfp == NULL) return -1;
|
||||
|
||||
SSdbRaw *pRaw = trnActionEncode(pTrans);
|
||||
if (pRaw == NULL) {
|
||||
mError("tranId:%d, failed to decode trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sdbWrite(pRaw) != 0) {
|
||||
mError("tranId:%d, failed to write trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((*syncfp)(pRaw, pTrans->rpcHandle) != 0) {
|
||||
mError("tranId:%d, failed to sync trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void trnSendRpcRsp(void *rpcHandle, int32_t code) {
|
||||
if (rpcHandle != NULL) {
|
||||
SRpcMsg rspMsg = {.handle = rpcHandle, .code = terrno};
|
||||
rpcSendResponse(&rspMsg);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code) {
|
||||
if (code != 0) {
|
||||
trnSendRpcRsp(pData, terrno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sdbWrite(pData) != 0) {
|
||||
code = terrno;
|
||||
trnSendRpcRsp(pData, code);
|
||||
terrno = code;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t trnExecuteArray(SArray *pArray) {
|
||||
for (int32_t index = 0; index < pArray->size; ++index) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, index);
|
||||
if (sdbWrite(pRaw) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t trnExecuteRedoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->redoLogs); }
|
||||
|
||||
static int32_t trnExecuteUndoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->undoLogs); }
|
||||
|
||||
static int32_t trnExecuteCommitLogs(STrans *pTrans) { return trnExecuteArray(pTrans->commitLogs); }
|
||||
|
||||
static int32_t trnExecuteRedoActions(STrans *pTrans) { return trnExecuteArray(pTrans->redoActions); }
|
||||
|
||||
static int32_t trnExecuteUndoActions(STrans *pTrans) { return trnExecuteArray(pTrans->undoActions); }
|
||||
|
||||
static int32_t trnPerformPrepareStage(STrans *pTrans) {
|
||||
if (trnExecuteRedoLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t trnPerformExecuteStage(STrans *pTrans) {
|
||||
int32_t code = trnExecuteRedoActions(pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_COMMIT;
|
||||
return 0;
|
||||
} else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
return -1;
|
||||
} else {
|
||||
if (pTrans->policy == TRN_POLICY_RETRY) {
|
||||
pTrans->stage = TRN_STAGE_RETRY;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t trnPerformCommitStage(STrans *pTrans) {
|
||||
if (trnExecuteCommitLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t trnPerformRollbackStage(STrans *pTrans) {
|
||||
if (trnExecuteCommitLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t trnPerformRetryStage(STrans *pTrans) {
|
||||
if (trnExecuteCommitLogs(pTrans) == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
return 0;
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t trnExecute(int32_t tranId) {
|
||||
int32_t code = 0;
|
||||
|
||||
STrans *pTrans = sdbAcquire(SDB_TRANS, &tranId);
|
||||
if (pTrans == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_PREPARE) {
|
||||
if (trnPerformPrepareStage(pTrans) != 0) {
|
||||
sdbRelease(pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_EXECUTE) {
|
||||
if (trnPerformExecuteStage(pTrans) != 0) {
|
||||
sdbRelease(pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_COMMIT) {
|
||||
if (trnPerformCommitStage(pTrans) != 0) {
|
||||
sdbRelease(pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_ROLLBACK) {
|
||||
if (trnPerformRollbackStage(pTrans) != 0) {
|
||||
sdbRelease(pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_RETRY) {
|
||||
if (trnPerformRetryStage(pTrans) != 0) {
|
||||
sdbRelease(pTrans);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
sdbRelease(pTrans);
|
||||
return 0;
|
||||
}
|
|
@ -2,6 +2,6 @@ aux_source_directory(src QNODE_SRC)
|
|||
add_library(qnode ${QNODE_SRC})
|
||||
target_include_directories(
|
||||
qnode
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/server/qnode"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/qnode"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
|
@ -2,11 +2,12 @@ aux_source_directory(src VNODE_SRC)
|
|||
add_library(vnode STATIC ${VNODE_SRC})
|
||||
target_include_directories(
|
||||
vnode
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/server/vnode"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/vnode"
|
||||
private "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
vnode
|
||||
PUBLIC os
|
||||
PUBLIC transport
|
||||
PUBLIC meta
|
||||
PUBLIC tq
|
||||
|
|
|
@ -13,20 +13,27 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_COMMON_QARITHMETICOPERATOR_H_
|
||||
#define _TD_COMMON_QARITHMETICOPERATOR_H_
|
||||
#ifndef _TD_VNODE_ALLOCATOR_POOL_H_
|
||||
#define _TD_VNODE_ALLOCATOR_POOL_H_
|
||||
|
||||
#include "vnode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*_arithmetic_operator_fn_t)(void *left, int32_t numLeft, int32_t leftType, void *right, int32_t numRight,
|
||||
int32_t rightType, void *output, int32_t order);
|
||||
typedef struct {
|
||||
int nexta;
|
||||
int enda;
|
||||
SMemAllocator *free[3];
|
||||
SMemAllocator *used[3];
|
||||
} SVAllocatorPool;
|
||||
|
||||
_arithmetic_operator_fn_t getArithmeticOperatorFn(int32_t arithmeticOptr);
|
||||
int vnodeOpenAllocatorPool(SVnode *pVnode);
|
||||
void vnodeCloseAllocatorPool(SVnode *pVnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_QARITHMETICOPERATOR_H_*/
|
||||
#endif /*_TD_VNODE_ALLOCATOR_POOL_H_*/
|
|
@ -16,13 +16,14 @@
|
|||
#ifndef _TD_VNODE_COMMIT_H_
|
||||
#define _TD_VNODE_COMMIT_H_
|
||||
|
||||
#include "vnodeInt.h"
|
||||
#include "vnode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int vnodeAsyncCommit(SVnode *pVnode);
|
||||
bool vnodeShouldCommit(SVnode *pVnode);
|
||||
int vnodeAsyncCommit(SVnode *pVnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_VNODE_DEF_H_
|
||||
#define _TD_VNODE_DEF_H_
|
||||
|
||||
#include "mallocator.h"
|
||||
#include "sync.h"
|
||||
#include "tlockfree.h"
|
||||
|
||||
#include "vnode.h"
|
||||
#include "vnodeAllocatorPool.h"
|
||||
#include "vnodeCommit.h"
|
||||
#include "vnodeFileSystem.h"
|
||||
#include "vnodeOptions.h"
|
||||
#include "vnodeStateMgr.h"
|
||||
#include "vnodeSync.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct SVnode {
|
||||
char* path;
|
||||
SVnodeOptions options;
|
||||
SVState state;
|
||||
SVAllocatorPool* pool;
|
||||
SMemAllocator* inuse;
|
||||
SMeta* pMeta;
|
||||
STsdb* pTsdb;
|
||||
STQ* pTq;
|
||||
SVnodeSync* pSync;
|
||||
SVnodeFS* pFs;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_VNODE_DEF_H_*/
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue