Merge branch '3.0' into feature/tq
This commit is contained in:
commit
7437c5dd71
|
@ -105,15 +105,17 @@ pipeline {
|
|||
abort_previous()
|
||||
abortPreviousBuilds()
|
||||
}
|
||||
pre_test()
|
||||
sh'''
|
||||
cd ${WKC}/tests
|
||||
./test-all.sh b1fq
|
||||
'''
|
||||
sh'''
|
||||
cd ${WKC}/debug
|
||||
ctest
|
||||
'''
|
||||
timeout(time: 45, unit: 'MINUTES'){
|
||||
pre_test()
|
||||
sh'''
|
||||
cd ${WKC}/tests
|
||||
./test-all.sh b1fq
|
||||
'''
|
||||
sh'''
|
||||
cd ${WKC}/debug
|
||||
ctest
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,13 +31,12 @@ extern "C" {
|
|||
memcpy(varDataVal(x), (str), __len); \
|
||||
} while (0);
|
||||
|
||||
#define STR_TO_NET_VARSTR(x, str) \
|
||||
do { \
|
||||
VarDataLenT __len = (VarDataLenT)strlen(str); \
|
||||
*(VarDataLenT *)(x) = htons(__len); \
|
||||
memcpy(varDataVal(x), (str), __len); \
|
||||
} while (0);
|
||||
|
||||
#define STR_TO_NET_VARSTR(x, str) \
|
||||
do { \
|
||||
VarDataLenT __len = (VarDataLenT)strlen(str); \
|
||||
*(VarDataLenT *)(x) = htons(__len); \
|
||||
memcpy(varDataVal(x), (str), __len); \
|
||||
} while (0);
|
||||
|
||||
#define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \
|
||||
do { \
|
||||
|
@ -71,11 +70,12 @@ typedef struct {
|
|||
|
||||
// ----------------- TSDB SCHEMA DEFINITION
|
||||
typedef struct {
|
||||
int version; // version
|
||||
int numOfCols; // Number of columns appended
|
||||
int tlen; // maximum length of a SDataRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + (bytes))
|
||||
uint16_t flen; // First part length in a SDataRow after the header part
|
||||
uint16_t vlen; // pure value part length, excluded the overhead (bytes only)
|
||||
int version; // version
|
||||
int numOfCols; // Number of columns appended
|
||||
int tlen; // maximum length of a SDataRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) +
|
||||
// (bytes))
|
||||
uint16_t flen; // First part length in a SDataRow after the header part
|
||||
uint16_t vlen; // pure value part length, excluded the overhead (bytes only)
|
||||
STColumn columns[];
|
||||
} STSchema;
|
||||
|
||||
|
@ -202,7 +202,6 @@ void tdFreeDataRow(SDataRow row);
|
|||
void tdInitDataRow(SDataRow row, STSchema *pSchema);
|
||||
SDataRow tdDataRowDup(SDataRow row);
|
||||
|
||||
|
||||
// offset here not include dataRow header length
|
||||
static FORCE_INLINE int tdAppendDataColVal(SDataRow row, const void *value, bool isCopyVarData, int8_t type,
|
||||
int32_t offset) {
|
||||
|
@ -228,7 +227,6 @@ static FORCE_INLINE int tdAppendDataColVal(SDataRow row, const void *value, bool
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// offset here not include dataRow header length
|
||||
static FORCE_INLINE int tdAppendColVal(SDataRow row, const void *value, int8_t type, int32_t offset) {
|
||||
return tdAppendDataColVal(row, value, true, type, offset);
|
||||
|
@ -249,27 +247,28 @@ static FORCE_INLINE void *tdGetPtrToCol(SDataRow row, STSchema *pSchema, int idx
|
|||
|
||||
static FORCE_INLINE void *tdGetColOfRowBySchema(SDataRow row, STSchema *pSchema, int idx) {
|
||||
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
|
||||
return tdGetRowDataOfCol(row, type, offset);
|
||||
}
|
||||
|
||||
static FORCE_INLINE bool tdIsColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int idx) {
|
||||
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
|
||||
return isNull(tdGetRowDataOfCol(row, type, offset), type);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tdSetColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int idx) {
|
||||
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
int16_t bytes = pSchema->columns[idx].bytes;
|
||||
|
||||
setNull(tdGetRowDataOfCol(row, type, offset), type, bytes);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSchema, int dstIdx, SDataRow src, STSchema *pSrcSchema, int srcIdx) {
|
||||
static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSchema, int dstIdx, SDataRow src,
|
||||
STSchema *pSrcSchema, int srcIdx) {
|
||||
int8_t type = pDstSchema->columns[dstIdx].type;
|
||||
assert(type == pSrcSchema->columns[srcIdx].type);
|
||||
void *pData = tdGetPtrToCol(dst, pDstSchema, dstIdx);
|
||||
|
@ -319,7 +318,6 @@ static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSche
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------- Data column structure
|
||||
typedef struct SDataCol {
|
||||
int8_t type; // column type
|
||||
|
@ -339,7 +337,7 @@ static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }
|
|||
int tdAllocMemForCol(SDataCol *pCol, int maxPoints);
|
||||
|
||||
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints);
|
||||
int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints);
|
||||
int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints);
|
||||
void dataColSetOffset(SDataCol *pCol, int nEle);
|
||||
|
||||
bool isNEleNull(SDataCol *pCol, int nEle);
|
||||
|
@ -367,15 +365,15 @@ static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) {
|
|||
}
|
||||
|
||||
typedef struct {
|
||||
int maxCols; // max number of columns
|
||||
int maxPoints; // max number of points
|
||||
int numOfRows;
|
||||
int numOfCols; // Total number of cols
|
||||
int sversion; // TODO: set sversion
|
||||
int maxCols; // max number of columns
|
||||
int maxPoints; // max number of points
|
||||
int numOfRows;
|
||||
int numOfCols; // Total number of cols
|
||||
int sversion; // TODO: set sversion
|
||||
SDataCol *cols;
|
||||
} SDataCols;
|
||||
|
||||
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
||||
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
||||
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)] // the idx row of column-wised data
|
||||
#define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx))
|
||||
static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) {
|
||||
|
@ -454,6 +452,7 @@ typedef struct {
|
|||
#define kvRowValLen(r) (kvRowLen(r) - TD_KV_ROW_HEAD_SIZE - sizeof(SColIdx) * kvRowNCols(r))
|
||||
#define kvRowTKey(r) (*(TKEY *)(kvRowValues(r)))
|
||||
#define kvRowKey(r) tdGetKey(kvRowTKey(r))
|
||||
#define kvRowKeys(r) POINTER_SHIFT(r, *(uint16_t *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE + sizeof(int16_t)))
|
||||
#define kvRowDeleted(r) TKEY_IS_DELETED(kvRowTKey(r))
|
||||
|
||||
SKVRow tdKVRowDup(SKVRow row);
|
||||
|
@ -547,7 +546,7 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
|
|||
static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, const void *value) {
|
||||
if (pBuilder->nCols >= pBuilder->tCols) {
|
||||
pBuilder->tCols *= 2;
|
||||
SColIdx* pColIdx = (SColIdx *)realloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols);
|
||||
SColIdx *pColIdx = (SColIdx *)realloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols);
|
||||
if (pColIdx == NULL) return -1;
|
||||
pBuilder->pColIdx = pColIdx;
|
||||
}
|
||||
|
@ -562,7 +561,7 @@ static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId,
|
|||
while (tlen > pBuilder->alloc - pBuilder->size) {
|
||||
pBuilder->alloc *= 2;
|
||||
}
|
||||
void* buf = realloc(pBuilder->buf, pBuilder->alloc);
|
||||
void *buf = realloc(pBuilder->buf, pBuilder->alloc);
|
||||
if (buf == NULL) return -1;
|
||||
pBuilder->buf = buf;
|
||||
}
|
||||
|
@ -654,6 +653,7 @@ static FORCE_INLINE char *memRowEnd(SMemRow row) {
|
|||
|
||||
#define memRowTKey(r) (isDataRow(r) ? dataRowTKey(memRowDataBody(r)) : kvRowTKey(memRowKvBody(r)))
|
||||
#define memRowKey(r) (isDataRow(r) ? dataRowKey(memRowDataBody(r)) : kvRowKey(memRowKvBody(r)))
|
||||
#define memRowKeys(r) (isDataRow(r) ? dataRowTuple(memRowDataBody(r)) : kvRowKeys(memRowKvBody(r)))
|
||||
#define memRowSetTKey(r, k) \
|
||||
do { \
|
||||
if (isDataRow(r)) { \
|
||||
|
@ -750,10 +750,10 @@ static FORCE_INLINE void tdGetColAppendDeltaLen(const void *value, int8_t colTyp
|
|||
typedef struct {
|
||||
int16_t colId;
|
||||
uint8_t colType;
|
||||
char* colVal;
|
||||
char * colVal;
|
||||
} SColInfo;
|
||||
|
||||
static FORCE_INLINE void setSColInfo(SColInfo* colInfo, int16_t colId, uint8_t colType, char* colVal) {
|
||||
static FORCE_INLINE void setSColInfo(SColInfo *colInfo, int16_t colId, uint8_t colType, char *colVal) {
|
||||
colInfo->colId = colId;
|
||||
colInfo->colType = colType;
|
||||
colInfo->colVal = colVal;
|
||||
|
@ -813,4 +813,4 @@ static FORCE_INLINE char *payloadNextCol(char *pCol) { return (char *)POINTER_SH
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_DATA_FORMAT_H_*/
|
||||
#endif /*_TD_COMMON_DATA_FORMAT_H_*/
|
||||
|
|
|
@ -264,11 +264,29 @@ typedef struct SSubmitBlk {
|
|||
// Submit message for this TSDB
|
||||
typedef struct SSubmitMsg {
|
||||
SMsgHead header;
|
||||
int64_t version;
|
||||
int32_t length;
|
||||
int32_t numOfBlocks;
|
||||
char blocks[];
|
||||
} SSubmitMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t totalLen;
|
||||
int32_t len;
|
||||
SMemRow row;
|
||||
} SSubmitBlkIter;
|
||||
|
||||
typedef struct {
|
||||
int32_t totalLen;
|
||||
int32_t len;
|
||||
void* pMsg;
|
||||
} SSubmitMsgIter;
|
||||
|
||||
int tInitSubmitMsgIter(SSubmitMsg* pMsg, SSubmitMsgIter* pIter);
|
||||
int tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
||||
int tInitSubmitBlkIter(SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||
SMemRow tGetSubmitBlkNext(SSubmitBlkIter* pIter);
|
||||
|
||||
typedef struct {
|
||||
int32_t index; // index of failed block in submit blocks
|
||||
int32_t vnode; // vnode index of failed block
|
||||
|
@ -390,7 +408,7 @@ typedef struct {
|
|||
char app[TSDB_APP_NAME_LEN];
|
||||
char db[TSDB_DB_NAME_LEN];
|
||||
int64_t startTime;
|
||||
} SConnectMsg;
|
||||
} SConnectReq;
|
||||
|
||||
typedef struct SEpSet {
|
||||
int8_t inUse;
|
||||
|
@ -738,6 +756,7 @@ typedef struct {
|
|||
int32_t sver;
|
||||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
int64_t dver;
|
||||
int64_t rebootTime;
|
||||
int64_t updateTime;
|
||||
int32_t numOfCores;
|
||||
|
@ -745,7 +764,7 @@ typedef struct {
|
|||
char dnodeEp[TSDB_EP_LEN];
|
||||
SClusterCfg clusterCfg;
|
||||
SVnodeLoads vnodeLoads;
|
||||
} SStatusMsg;
|
||||
} SStatusReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t reserved;
|
||||
|
@ -770,6 +789,7 @@ typedef struct {
|
|||
} SDnodeEps;
|
||||
|
||||
typedef struct {
|
||||
int64_t dver;
|
||||
SDnodeCfg dnodeCfg;
|
||||
SDnodeEps dnodeEps;
|
||||
} SStatusRsp;
|
||||
|
@ -805,19 +825,19 @@ typedef struct {
|
|||
int8_t replica;
|
||||
int8_t selfIndex;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
} SCreateVnodeMsg, SAlterVnodeMsg;
|
||||
} SCreateVnodeReq, SAlterVnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int32_t dnodeId;
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
uint64_t dbUid;
|
||||
} SDropVnodeMsg, SSyncVnodeMsg, SCompactVnodeMsg;
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
} SDropVnodeReq, SSyncVnodeReq, SCompactVnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int8_t accessState;
|
||||
} SAuthVnodeMsg;
|
||||
} SAuthVnodeReq;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead header;
|
||||
|
@ -889,6 +909,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
int64_t uid;
|
||||
int32_t vgVersion;
|
||||
int32_t vgNum;
|
||||
int8_t hashMethod;
|
||||
|
@ -921,26 +942,26 @@ typedef struct SShowRsp {
|
|||
typedef struct {
|
||||
char fqdn[TSDB_FQDN_LEN]; // end point, hostname:port
|
||||
int32_t port;
|
||||
} SCreateDnodeMsg;
|
||||
} SCreateDnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
} SDropDnodeMsg;
|
||||
} SDropDnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
char config[TSDB_DNODE_CONFIG_LEN];
|
||||
} SCfgDnodeMsg;
|
||||
} SMCfgDnodeReq, SDCfgDnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
} SMCreateMnodeMsg, SMDropMnodeMsg, SDDropMnodeMsg;
|
||||
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int8_t replica;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
} SDCreateMnodeMsg, SDAlterMnodeMsg;
|
||||
} SDCreateMnodeReq, SDAlterMnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
|
@ -986,7 +1007,7 @@ typedef struct {
|
|||
int32_t numOfStreams;
|
||||
char app[TSDB_APP_NAME_LEN];
|
||||
char pData[];
|
||||
} SHeartBeatMsg;
|
||||
} SHeartBeatReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t connId;
|
||||
|
@ -999,19 +1020,14 @@ typedef struct {
|
|||
SEpSet epSet;
|
||||
} SHeartBeatRsp;
|
||||
|
||||
typedef struct {
|
||||
int32_t connId;
|
||||
int32_t streamId;
|
||||
} SKillStreamMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t connId;
|
||||
int32_t queryId;
|
||||
} SKillQueryMsg;
|
||||
} SKillQueryReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t connId;
|
||||
} SKillConnMsg;
|
||||
} SKillConnReq;
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
|
@ -1019,7 +1035,7 @@ typedef struct {
|
|||
char encrypt;
|
||||
char secret[TSDB_PASSWORD_LEN];
|
||||
char ckey[TSDB_PASSWORD_LEN];
|
||||
} SAuthMsg, SAuthRsp;
|
||||
} SAuthReq, SAuthRsp;
|
||||
|
||||
typedef struct {
|
||||
int8_t finished;
|
||||
|
|
|
@ -281,6 +281,15 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
|
|||
*/
|
||||
int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type);
|
||||
|
||||
/**
|
||||
* @brief Get the version of the table
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param pIter The type of the table.
|
||||
* @return int32_t The version of the table
|
||||
*/
|
||||
int64_t sdbGetTableVer(SSdb *pSdb, ESdbType type);
|
||||
|
||||
/**
|
||||
* @brief Update the version of sdb
|
||||
*
|
||||
|
|
|
@ -22,21 +22,45 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SDataStatis {
|
||||
int16_t colId;
|
||||
int64_t sum;
|
||||
int64_t max;
|
||||
int64_t min;
|
||||
int16_t maxIndex;
|
||||
int16_t minIndex;
|
||||
int16_t numOfNull;
|
||||
} SDataStatis;
|
||||
|
||||
typedef struct STable {
|
||||
int32_t tid;
|
||||
uint64_t uid;
|
||||
STSchema *pSchema;
|
||||
} STable;
|
||||
|
||||
#define TABLE_TID(t) (t)->tid
|
||||
#define TABLE_UID(t) (t)->uid
|
||||
|
||||
// TYPES EXPOSED
|
||||
typedef struct STsdb STsdb;
|
||||
|
||||
typedef struct STsdbCfg {
|
||||
int8_t precision;
|
||||
uint64_t lruCacheSize;
|
||||
uint32_t keep0;
|
||||
uint32_t keep1;
|
||||
uint32_t keep2;
|
||||
int32_t daysPerFile;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t keep;
|
||||
int32_t keep1;
|
||||
int32_t keep2;
|
||||
int8_t update;
|
||||
} STsdbCfg;
|
||||
|
||||
// STsdb
|
||||
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
|
||||
void tsdbClose(STsdb *);
|
||||
void tsdbRemove(const char *path);
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg);
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg, SSubmitRsp *pRsp);
|
||||
int tsdbPrepareCommit(STsdb *pTsdb);
|
||||
int tsdbCommit(STsdb *pTsdb);
|
||||
|
||||
|
|
|
@ -0,0 +1,433 @@
|
|||
/*
|
||||
* 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_TSDB_H_
|
||||
#define _TD_TSDB_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "taosdef.h"
|
||||
#include "tarray.h"
|
||||
#include "tdataformat.h"
|
||||
#include "thash.h"
|
||||
#include "tlist.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tmsg.h"
|
||||
#include "tname.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TSDB_VERSION_MAJOR 1
|
||||
#define TSDB_VERSION_MINOR 0
|
||||
|
||||
#define TSDB_INVALID_SUPER_TABLE_ID -1
|
||||
|
||||
#define TSDB_STATUS_COMMIT_START 1
|
||||
#define TSDB_STATUS_COMMIT_OVER 2
|
||||
#define TSDB_STATUS_COMMIT_NOBLOCK 3 // commit no block, need to be solved
|
||||
|
||||
// TSDB STATE DEFINITION
|
||||
#define TSDB_STATE_OK 0x0
|
||||
#define TSDB_STATE_BAD_META 0x1
|
||||
#define TSDB_STATE_BAD_DATA 0x2
|
||||
|
||||
typedef struct SDataStatis {
|
||||
int16_t colId;
|
||||
int64_t sum;
|
||||
int64_t max;
|
||||
int64_t min;
|
||||
int16_t maxIndex;
|
||||
int16_t minIndex;
|
||||
int16_t numOfNull;
|
||||
} SDataStatis;
|
||||
|
||||
// --------- TSDB APPLICATION HANDLE DEFINITION
|
||||
|
||||
// --------- TSDB REPOSITORY CONFIGURATION DEFINITION
|
||||
typedef struct {
|
||||
int32_t tsdbId;
|
||||
int32_t cacheBlockSize;
|
||||
int32_t totalBlocks;
|
||||
int32_t daysPerFile; // day per file sharding policy
|
||||
int32_t keep; // day of data to keep
|
||||
int32_t keep1;
|
||||
int32_t keep2;
|
||||
int32_t lruCacheSize;
|
||||
int32_t minRowsPerFileBlock; // minimum rows per file block
|
||||
int32_t maxRowsPerFileBlock; // maximum rows per file block
|
||||
int8_t precision;
|
||||
int8_t compression;
|
||||
int8_t update;
|
||||
int8_t cacheLastRow; // 0:no cache, 1: cache last row, 2: cache last NULL column 3: 1&2
|
||||
} STsdbCfg;
|
||||
|
||||
#define CACHE_NO_LAST(c) ((c)->cacheLastRow == 0)
|
||||
#define CACHE_LAST_ROW(c) (((c)->cacheLastRow & 1) > 0)
|
||||
#define CACHE_LAST_NULL_COLUMN(c) (((c)->cacheLastRow & 2) > 0)
|
||||
|
||||
// --------- TSDB REPOSITORY USAGE STATISTICS
|
||||
typedef struct {
|
||||
int64_t totalStorage; // total bytes occupie
|
||||
int64_t compStorage;
|
||||
int64_t pointsWritten; // total data points written
|
||||
} STsdbStat;
|
||||
|
||||
typedef struct STsdb STsdb;
|
||||
|
||||
STsdbCfg *tsdbGetCfg(const STsdb *repo);
|
||||
|
||||
// --------- TSDB REPOSITORY DEFINITION
|
||||
// int32_t tsdbCreateRepo(int repoid);
|
||||
// int32_t tsdbDropRepo(int repoid);
|
||||
STsdb * tsdbOpen(STsdbCfg *pCfg, STsdbAppH *pAppH);
|
||||
int tsdbClose(STsdb *repo, int toCommit);
|
||||
int32_t tsdbConfigRepo(STsdb *repo, STsdbCfg *pCfg);
|
||||
int tsdbGetState(STsdb *repo);
|
||||
int8_t tsdbGetCompactState(STsdb *repo);
|
||||
// --------- TSDB TABLE DEFINITION
|
||||
typedef struct {
|
||||
uint64_t uid; // the unique table ID
|
||||
int32_t tid; // the table ID in the repository.
|
||||
} STableId;
|
||||
|
||||
// --------- TSDB TABLE configuration
|
||||
typedef struct {
|
||||
ETableType type;
|
||||
char * name;
|
||||
STableId tableId;
|
||||
int32_t sversion;
|
||||
char * sname; // super table name
|
||||
uint64_t superUid;
|
||||
STSchema * schema;
|
||||
STSchema * tagSchema;
|
||||
SKVRow tagValues;
|
||||
char * sql;
|
||||
} STableCfg;
|
||||
|
||||
void tsdbClearTableCfg(STableCfg *config);
|
||||
|
||||
void *tsdbGetTableTagVal(const void *pTable, int32_t colId, int16_t type);
|
||||
char *tsdbGetTableName(void *pTable);
|
||||
|
||||
#define TSDB_TABLEID(_table) ((STableId *)(_table))
|
||||
#define TSDB_PREV_ROW 0x1
|
||||
#define TSDB_NEXT_ROW 0x2
|
||||
|
||||
STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg);
|
||||
|
||||
int tsdbCreateTable(STsdb *repo, STableCfg *pCfg);
|
||||
int tsdbDropTable(STsdb *pRepo, STableId tableId);
|
||||
int tsdbUpdateTableTagValue(STsdb *repo, SUpdateTableTagValMsg *pMsg);
|
||||
|
||||
uint32_t tsdbGetFileInfo(STsdb *repo, char *name, uint32_t *index, uint32_t eindex, int64_t *size);
|
||||
|
||||
// the TSDB repository info
|
||||
typedef struct STsdbRepoInfo {
|
||||
STsdbCfg tsdbCfg;
|
||||
uint64_t version; // version of the repository
|
||||
int64_t tsdbTotalDataSize; // the original inserted data size
|
||||
int64_t tsdbTotalDiskSize; // the total disk size taken by this TSDB repository
|
||||
// TODO: Other informations to add
|
||||
} STsdbRepoInfo;
|
||||
STsdbRepoInfo *tsdbGetStatus(STsdb *pRepo);
|
||||
|
||||
// the meter information report structure
|
||||
typedef struct {
|
||||
STableCfg tableCfg;
|
||||
uint64_t version;
|
||||
int64_t tableTotalDataSize; // In bytes
|
||||
int64_t tableTotalDiskSize; // In bytes
|
||||
} STableInfo;
|
||||
|
||||
// -- FOR INSERT DATA
|
||||
/**
|
||||
* Insert data to a table in a repository
|
||||
* @param pRepo the TSDB repository handle
|
||||
* @param pData the data to insert (will give a more specific description)
|
||||
*
|
||||
* @return the number of points inserted, -1 for failure and the error number is set
|
||||
*/
|
||||
int32_t tsdbInsertData(STsdb *repo, SSubmitMsg *pMsg, SShellSubmitRspMsg *pRsp);
|
||||
|
||||
// -- FOR QUERY TIME SERIES DATA
|
||||
|
||||
typedef void *TsdbQueryHandleT; // Use void to hide implementation details
|
||||
|
||||
#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1
|
||||
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
|
||||
#define BLOCK_LOAD_TABLE_RR_ORDER 3
|
||||
|
||||
// query condition to build multi-table data block iterator
|
||||
typedef struct STsdbQueryCond {
|
||||
STimeWindow twindow;
|
||||
int32_t order; // desc|asc order to iterate the data block
|
||||
int64_t offset; // skip offset put down to tsdb
|
||||
int32_t numOfCols;
|
||||
SColumnInfo *colList;
|
||||
bool loadExternalRows; // load external rows or not
|
||||
int32_t type; // data block load type:
|
||||
} STsdbQueryCond;
|
||||
|
||||
typedef struct STableData STableData;
|
||||
typedef struct {
|
||||
T_REF_DECLARE()
|
||||
SRWLatch latch;
|
||||
TSKEY keyFirst;
|
||||
TSKEY keyLast;
|
||||
int64_t numOfRows;
|
||||
int32_t maxTables;
|
||||
STableData **tData;
|
||||
SList * actList;
|
||||
SList * extraBuffList;
|
||||
SList * bufBlockList;
|
||||
int64_t pointsAdd; // TODO
|
||||
int64_t storageAdd; // TODO
|
||||
} SMemTable;
|
||||
|
||||
typedef struct {
|
||||
SMemTable *mem;
|
||||
SMemTable *imem;
|
||||
SMemTable mtable;
|
||||
SMemTable *omem;
|
||||
} SMemSnapshot;
|
||||
|
||||
typedef struct SMemRef {
|
||||
int32_t ref;
|
||||
SMemSnapshot snapshot;
|
||||
} SMemRef;
|
||||
|
||||
#if 0
|
||||
typedef struct SFileBlockInfo {
|
||||
int32_t numBlocksOfStep;
|
||||
} SFileBlockInfo;
|
||||
|
||||
typedef struct {
|
||||
void *pTable;
|
||||
TSKEY lastKey;
|
||||
} STableKeyInfo;
|
||||
|
||||
typedef struct {
|
||||
uint32_t numOfTables;
|
||||
SArray * pGroupList;
|
||||
SHashObj *map; // speedup acquire the tableQueryInfo by table uid
|
||||
} STableGroupInfo;
|
||||
|
||||
#define TSDB_BLOCK_DIST_STEP_ROWS 16
|
||||
typedef struct {
|
||||
uint16_t rowSize;
|
||||
uint16_t numOfFiles;
|
||||
uint32_t numOfTables;
|
||||
uint64_t totalSize;
|
||||
uint64_t totalRows;
|
||||
int32_t maxRows;
|
||||
int32_t minRows;
|
||||
int32_t firstSeekTimeUs;
|
||||
uint32_t numOfRowsInMemTable;
|
||||
uint32_t numOfSmallBlocks;
|
||||
SArray * dataBlockInfos;
|
||||
} STableBlockDist;
|
||||
|
||||
/**
|
||||
* Get the data block iterator, starting from position according to the query condition
|
||||
*
|
||||
* @param tsdb tsdb handle
|
||||
* @param pCond query condition, including time window, result set order, and basic required columns for each block
|
||||
* @param tableInfoGroup table object list in the form of set, grouped into different sets according to the
|
||||
* group by condition
|
||||
* @param qinfo query info handle from query processor
|
||||
* @return
|
||||
*/
|
||||
TsdbQueryHandleT *tsdbQueryTables(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId,
|
||||
SMemRef *pRef);
|
||||
|
||||
/**
|
||||
* Get the last row of the given query time window for all the tables in STableGroupInfo object.
|
||||
* Note that only one data block with only row will be returned while invoking retrieve data block function for
|
||||
* all tables in this group.
|
||||
*
|
||||
* @param tsdb tsdb handle
|
||||
* @param pCond query condition, including time window, result set order, and basic required columns for each block
|
||||
* @param tableInfo table list.
|
||||
* @return
|
||||
*/
|
||||
TsdbQueryHandleT tsdbQueryLastRow(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfo, uint64_t qId,
|
||||
SMemRef *pRef);
|
||||
|
||||
TsdbQueryHandleT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId,
|
||||
SMemRef *pMemRef);
|
||||
|
||||
bool isTsdbCacheLastRow(TsdbQueryHandleT *pQueryHandle);
|
||||
|
||||
/**
|
||||
* get the queried table object list
|
||||
* @param pHandle
|
||||
* @return
|
||||
*/
|
||||
SArray *tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle);
|
||||
|
||||
/**
|
||||
* get the group list according to table id from client
|
||||
* @param tsdb
|
||||
* @param pCond
|
||||
* @param groupList
|
||||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
TsdbQueryHandleT tsdbQueryRowsInExternalWindow(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList,
|
||||
uint64_t qId, SMemRef *pRef);
|
||||
|
||||
/**
|
||||
* get num of rows in mem table
|
||||
*
|
||||
* @param pHandle
|
||||
* @return row size
|
||||
*/
|
||||
|
||||
int64_t tsdbGetNumOfRowsInMemTable(TsdbQueryHandleT *pHandle);
|
||||
|
||||
/**
|
||||
* move to next block if exists
|
||||
*
|
||||
* @param pQueryHandle
|
||||
* @return
|
||||
*/
|
||||
bool tsdbNextDataBlock(TsdbQueryHandleT pQueryHandle);
|
||||
|
||||
/**
|
||||
* Get current data block information
|
||||
*
|
||||
* @param pQueryHandle
|
||||
* @param pBlockInfo
|
||||
* @return
|
||||
*/
|
||||
void tsdbRetrieveDataBlockInfo(TsdbQueryHandleT *pQueryHandle, SDataBlockInfo *pBlockInfo);
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the pre-calculated information w.r.t. current data block.
|
||||
*
|
||||
* In case of data block in cache, the pBlockStatis will always be NULL.
|
||||
* If a block is not completed loaded from disk, the pBlockStatis will be NULL.
|
||||
|
||||
* @pBlockStatis the pre-calculated value for current data blocks. if the block is a cache block, always return 0
|
||||
* @return
|
||||
*/
|
||||
int32_t tsdbRetrieveDataBlockStatisInfo(TsdbQueryHandleT *pQueryHandle, SDataStatis **pBlockStatis);
|
||||
|
||||
/**
|
||||
*
|
||||
* The query condition with primary timestamp is passed to iterator during its constructor function,
|
||||
* the returned data block must be satisfied with the time window condition in any cases,
|
||||
* which means the SData data block is not actually the completed disk data blocks.
|
||||
*
|
||||
* @param pQueryHandle query handle
|
||||
* @param pColumnIdList required data columns id list
|
||||
* @return
|
||||
*/
|
||||
SArray *tsdbRetrieveDataBlock(TsdbQueryHandleT *pQueryHandle, SArray *pColumnIdList);
|
||||
|
||||
/**
|
||||
* Get the qualified table id for a super table according to the tag query expression.
|
||||
* @param stableid. super table sid
|
||||
* @param pTagCond. tag query condition
|
||||
*/
|
||||
int32_t tsdbQuerySTableByTagCond(STsdb *tsdb, uint64_t uid, TSKEY key, const char *pTagCond, size_t len,
|
||||
STableGroupInfo *pGroupList, SColIndex *pColIndex, int32_t numOfCols);
|
||||
|
||||
/**
|
||||
* destroy the created table group list, which is generated by tag query
|
||||
* @param pGroupList
|
||||
*/
|
||||
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
||||
|
||||
/**
|
||||
* create the table group result including only one table, used to handle the normal table query
|
||||
*
|
||||
* @param tsdb tsdbHandle
|
||||
* @param uid table uid
|
||||
* @param pGroupInfo the generated result
|
||||
* @return
|
||||
*/
|
||||
int32_t tsdbGetOneTableGroup(STsdb *tsdb, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tsdb
|
||||
* @param pTableIdList
|
||||
* @param pGroupInfo
|
||||
* @return
|
||||
*/
|
||||
int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo);
|
||||
|
||||
/**
|
||||
* clean up the query handle
|
||||
* @param queryHandle
|
||||
*/
|
||||
void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle);
|
||||
|
||||
void tsdbResetQueryHandle(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond);
|
||||
|
||||
void tsdbResetQueryHandleForNewTable(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond, STableGroupInfo *groupList);
|
||||
|
||||
int32_t tsdbGetFileBlocksDistInfo(TsdbQueryHandleT *queryHandle, STableBlockDist *pTableBlockInfo);
|
||||
|
||||
// obtain queryHandle attribute
|
||||
int64_t tsdbSkipOffset(TsdbQueryHandleT queryHandle);
|
||||
|
||||
/**
|
||||
* get the statistics of repo usage
|
||||
* @param repo. point to the tsdbrepo
|
||||
* @param totalPoints. total data point written
|
||||
* @param totalStorage. total bytes took by the tsdb
|
||||
* @param compStorage. total bytes took by the tsdb after compressed
|
||||
*/
|
||||
void tsdbReportStat(void *repo, int64_t *totalPoints, int64_t *totalStorage, int64_t *compStorage);
|
||||
|
||||
int tsdbInitCommitQueue();
|
||||
void tsdbDestroyCommitQueue();
|
||||
int tsdbSyncCommit(STsdb *repo);
|
||||
void tsdbIncCommitRef(int vgId);
|
||||
void tsdbDecCommitRef(int vgId);
|
||||
void tsdbSwitchTable(TsdbQueryHandleT pQueryHandle);
|
||||
|
||||
// For TSDB file sync
|
||||
int tsdbSyncSend(void *pRepo, SOCKET socketFd);
|
||||
int tsdbSyncRecv(void *pRepo, SOCKET socketFd);
|
||||
|
||||
// // For TSDB Compact
|
||||
// int tsdbCompact(STsdb *pRepo);
|
||||
|
||||
// For TSDB Health Monitor
|
||||
|
||||
// // no problem return true
|
||||
// bool tsdbNoProblem(STsdb *pRepo);
|
||||
// // unit of walSize: MB
|
||||
// int tsdbCheckWal(STsdb *pRepo, uint32_t walSize);
|
||||
|
||||
// // for json tag
|
||||
// void *getJsonTagValueElment(void *data, char *key, int32_t keyLen, char *out, int16_t bytes);
|
||||
// void getJsonTagValueAll(void *data, void *dst, int16_t bytes);
|
||||
// char *parseTagDatatoJson(void *p);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _TD_TSDB_H_
|
|
@ -32,6 +32,8 @@ extern "C" {
|
|||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SVnode SVnode;
|
||||
typedef struct SVnodeCfg {
|
||||
int32_t vgId;
|
||||
|
||||
/** vnode buffer pool options */
|
||||
struct {
|
||||
/** write buffer size */
|
||||
|
|
|
@ -48,8 +48,22 @@ typedef struct SMetaData {
|
|||
typedef struct SCatalogCfg {
|
||||
uint32_t maxTblCacheNum;
|
||||
uint32_t maxDBCacheNum;
|
||||
uint32_t dbRentSec;
|
||||
uint32_t stableRentSec;
|
||||
} SCatalogCfg;
|
||||
|
||||
typedef struct SSTableMetaVersion {
|
||||
uint64_t suid;
|
||||
int16_t sversion;
|
||||
int16_t tversion;
|
||||
} SSTableMetaVersion;
|
||||
|
||||
typedef struct SDbVgVersion {
|
||||
int64_t dbId;
|
||||
int32_t vgVersion;
|
||||
} SDbVgVersion;
|
||||
|
||||
|
||||
int32_t catalogInit(SCatalogCfg *cfg);
|
||||
|
||||
/**
|
||||
|
@ -60,19 +74,27 @@ int32_t catalogInit(SCatalogCfg *cfg);
|
|||
*/
|
||||
int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle);
|
||||
|
||||
/**
|
||||
* Free a cluster's all catalog info, usually it's not necessary, until the application is closing.
|
||||
* no current or future usage should be guaranteed by application
|
||||
* @param pCatalog (input, NO more usage)
|
||||
* @return error code
|
||||
*/
|
||||
void catalogFreeHandle(struct SCatalog* pCatalog);
|
||||
|
||||
int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version);
|
||||
|
||||
/**
|
||||
* Get a DB's all vgroup info.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pDBName (input, full db name)
|
||||
* @param forceUpdate (input, force update db vgroup info from mnode)
|
||||
* @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, int32_t forceUpdate, SArray** pVgroupList);
|
||||
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const char* pDBName, bool forceUpdate, SArray** pVgroupList);
|
||||
|
||||
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo);
|
||||
|
||||
|
@ -87,15 +109,28 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB
|
|||
*/
|
||||
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
/**
|
||||
* Get a super table's meta data.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param pTableMeta(output, table meta data, NEED to free it by calller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetSTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName);
|
||||
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable);
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data and get the new one.
|
||||
|
@ -104,21 +139,23 @@ int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, co
|
|||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param pTableMeta(output, table meta data, NEED to free it by calller)
|
||||
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a table's actual vgroup, for stable it's all possible vgroup list.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
|
||||
int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
|
||||
|
||||
/**
|
||||
* Get a table's vgroup from its name's hash value.
|
||||
|
@ -135,17 +172,20 @@ int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter
|
|||
/**
|
||||
* Get all meta data required in pReq.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pReq (input, reqest info)
|
||||
* @param pRsp (output, response data)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
|
||||
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
|
||||
|
||||
|
||||
int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SArray* pQnodeList);
|
||||
int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, SArray* pQnodeList);
|
||||
|
||||
int32_t catalogGetExpiredSTables(struct SCatalog* pCatalog, SSTableMetaVersion **stables, uint32_t *num);
|
||||
|
||||
int32_t catalogGetExpiredDBs(struct SCatalog* pCatalog, SDbVgVersion **dbs, uint32_t *num);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,16 +20,16 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* qinfo_t;
|
||||
typedef void* qTaskInfo_t;
|
||||
|
||||
/**
|
||||
* create the qinfo object according to QueryTableMsg
|
||||
* @param tsdb
|
||||
* @param pQueryTableMsg
|
||||
* @param qinfo
|
||||
* @param pTaskInfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableInfo* pQueryTableMsg, qinfo_t* qinfo, uint64_t qId);
|
||||
int32_t qCreateTask(void* tsdb, int32_t vgId, void* pQueryTableMsg, qTaskInfo_t* pTaskInfo, uint64_t qId);
|
||||
|
||||
/**
|
||||
* the main query execution function, including query on both table and multiple tables,
|
||||
|
@ -38,7 +38,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableInfo* pQueryTableM
|
|||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
bool qTableQuery(qinfo_t qinfo, uint64_t *qId);
|
||||
bool qExecTask(qTaskInfo_t qinfo, uint64_t *qId);
|
||||
|
||||
/**
|
||||
* Retrieve the produced results information, if current query is not paused or completed,
|
||||
|
@ -48,7 +48,7 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId);
|
|||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContext);
|
||||
int32_t qRetrieveQueryResultInfo(qTaskInfo_t qinfo, bool* buildRes, void* pRspContext);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -60,41 +60,41 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex
|
|||
* @param contLen payload length
|
||||
* @return
|
||||
*/
|
||||
int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp** pRsp, int32_t* contLen, bool* continueExec);
|
||||
int32_t qDumpRetrieveResult(qTaskInfo_t qinfo, SRetrieveTableRsp** pRsp, int32_t* contLen, bool* continueExec);
|
||||
|
||||
/**
|
||||
* return the transporter context (RPC)
|
||||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
void* qGetResultRetrieveMsg(qinfo_t qinfo);
|
||||
void* qGetResultRetrieveMsg(qTaskInfo_t qinfo);
|
||||
|
||||
/**
|
||||
* kill the ongoing query and free the query handle and corresponding resources automatically
|
||||
* @param qinfo qhandle
|
||||
* @return
|
||||
*/
|
||||
int32_t qKillQuery(qinfo_t qinfo);
|
||||
int32_t qKillTask(qTaskInfo_t qinfo);
|
||||
|
||||
/**
|
||||
* return whether query is completed or not
|
||||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qIsQueryCompleted(qinfo_t qinfo);
|
||||
int32_t qIsQueryCompleted(qTaskInfo_t qinfo);
|
||||
|
||||
/**
|
||||
* destroy query info structure
|
||||
* @param qHandle
|
||||
*/
|
||||
void qDestroyQueryInfo(qinfo_t qHandle);
|
||||
void qDestroyTask(qTaskInfo_t qHandle);
|
||||
|
||||
/**
|
||||
* Get the queried table uid
|
||||
* @param qHandle
|
||||
* @return
|
||||
*/
|
||||
int64_t qGetQueriedTableUid(qinfo_t qHandle);
|
||||
int64_t qGetQueriedTableUid(qTaskInfo_t qHandle);
|
||||
|
||||
/**
|
||||
* Extract the qualified table id list, and than pass them to the TSDB driver to load the required table data blocks.
|
||||
|
@ -121,7 +121,7 @@ int32_t qCreateTableGroupByGroupExpr(SArray* pTableIdList, TSKEY skey, STableGro
|
|||
* @param type operation type: ADD|DROP
|
||||
* @return
|
||||
*/
|
||||
int32_t qUpdateQueriedTableIdList(qinfo_t qinfo, int64_t uid, int32_t type);
|
||||
int32_t qUpdateQueriedTableIdList(qTaskInfo_t qinfo, int64_t uid, int32_t type);
|
||||
|
||||
//================================================================================================
|
||||
// query handle management
|
||||
|
@ -130,13 +130,13 @@ int32_t qUpdateQueriedTableIdList(qinfo_t qinfo, int64_t uid, int32_t type);
|
|||
* @param vgId
|
||||
* @return
|
||||
*/
|
||||
void* qOpenQueryMgmt(int32_t vgId);
|
||||
void* qOpenTaskMgmt(int32_t vgId);
|
||||
|
||||
/**
|
||||
* broadcast the close information and wait for all query stop.
|
||||
* @param pExecutor
|
||||
*/
|
||||
void qQueryMgmtNotifyClosed(void* pExecutor);
|
||||
void qTaskMgmtNotifyClosing(void* pExecutor);
|
||||
|
||||
/**
|
||||
* Re-open the query handle management module when opening the vnode again.
|
||||
|
@ -148,7 +148,7 @@ void qQueryMgmtReOpen(void *pExecutor);
|
|||
* Close query mgmt and clean up resources.
|
||||
* @param pExecutor
|
||||
*/
|
||||
void qCleanupQueryMgmt(void* pExecutor);
|
||||
void qCleanupTaskMgmt(void* pExecutor);
|
||||
|
||||
/**
|
||||
* Add the query into the query mgmt object
|
||||
|
@ -157,7 +157,7 @@ void qCleanupQueryMgmt(void* pExecutor);
|
|||
* @param qInfo
|
||||
* @return
|
||||
*/
|
||||
void** qRegisterQInfo(void* pMgmt, uint64_t qId, void *qInfo);
|
||||
void** qRegisterTask(void* pMgmt, uint64_t qId, void *qInfo);
|
||||
|
||||
/**
|
||||
* acquire the query handle according to the key from query mgmt object.
|
||||
|
@ -165,7 +165,7 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qId, void *qInfo);
|
|||
* @param key
|
||||
* @return
|
||||
*/
|
||||
void** qAcquireQInfo(void* pMgmt, uint64_t key);
|
||||
void** qAcquireTask(void* pMgmt, uint64_t key);
|
||||
|
||||
/**
|
||||
* release the query handle and decrease the reference count in cache
|
||||
|
@ -174,7 +174,7 @@ void** qAcquireQInfo(void* pMgmt, uint64_t key);
|
|||
* @param freeHandle
|
||||
* @return
|
||||
*/
|
||||
void** qReleaseQInfo(void* pMgmt, void* pQInfo);
|
||||
void** qReleaseTask(void* pMgmt, void* pQInfo, bool freeHandle);
|
||||
|
||||
/**
|
||||
* De-register the query handle from the management module and free it immediately.
|
||||
|
|
|
@ -89,7 +89,7 @@ enum {
|
|||
};
|
||||
|
||||
enum {
|
||||
MASTER_SCAN = 0x0u,
|
||||
MAIN_SCAN = 0x0u,
|
||||
REVERSE_SCAN = 0x1u,
|
||||
REPEAT_SCAN = 0x2u, //repeat scan belongs to the master scan
|
||||
MERGE_STAGE = 0x20u,
|
||||
|
@ -183,7 +183,6 @@ typedef struct tExprNode {
|
|||
|
||||
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
|
||||
|
|
|
@ -76,25 +76,20 @@ void indexOptsDestroy(SIndexOpts* opts);
|
|||
* @param:
|
||||
*/
|
||||
|
||||
SIndexTerm* indexTermCreate(int64_t suid,
|
||||
SIndexOperOnColumn operType,
|
||||
uint8_t colType,
|
||||
const char* colName,
|
||||
int32_t nColName,
|
||||
const char* colVal,
|
||||
int32_t nColVal);
|
||||
SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn operType, uint8_t colType, const char* colName,
|
||||
int32_t nColName, const char* colVal, int32_t nColVal);
|
||||
void indexTermDestroy(SIndexTerm* p);
|
||||
|
||||
/*
|
||||
* init index
|
||||
*
|
||||
*/
|
||||
int32_t indexInit();
|
||||
/*
|
||||
* destory index
|
||||
* init index env
|
||||
*
|
||||
*/
|
||||
void indexInit();
|
||||
|
||||
/*
|
||||
* destory index env
|
||||
*
|
||||
*/
|
||||
void indexCleanUp();
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -135,9 +135,8 @@ typedef struct SQueryStmtInfo {
|
|||
SArray *pUdfInfo;
|
||||
|
||||
struct SQueryStmtInfo *sibling; // sibling
|
||||
struct SQueryStmtInfo *pDownstream;
|
||||
SMultiFunctionsDesc info;
|
||||
SArray *pUpstream; // SArray<struct SQueryStmtInfo>
|
||||
SArray *pDownstream; // SArray<struct SQueryStmtInfo>
|
||||
int32_t havingFieldNum;
|
||||
int32_t exprListLevelIndex;
|
||||
} SQueryStmtInfo;
|
||||
|
|
|
@ -24,7 +24,6 @@ extern "C" {
|
|||
|
||||
typedef struct SParseContext {
|
||||
SParseBasicCtx ctx;
|
||||
int8_t schemaAttached; // denote if submit block is built with table schema or not
|
||||
const char *pSql; // sql string
|
||||
size_t sqlLen; // length of the sql string
|
||||
char *pMsg; // extended error message if exists to help identifying the problem in sql statement.
|
||||
|
@ -41,8 +40,17 @@ typedef struct SParseContext {
|
|||
*/
|
||||
int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery);
|
||||
|
||||
bool qIsDdlQuery(const SQueryNode* pQuery);
|
||||
/**
|
||||
* Return true if it is a ddl/dcl sql statement
|
||||
* @param pQuery
|
||||
* @return
|
||||
*/
|
||||
bool qIsDdlQuery(const SQueryNode* pQueryNode);
|
||||
|
||||
/**
|
||||
* Destroy logic query plan
|
||||
* @param pQueryNode
|
||||
*/
|
||||
void qDestroyQuery(SQueryNode* pQueryNode);
|
||||
|
||||
/**
|
||||
|
@ -62,8 +70,8 @@ void columnListDestroy(SArray* pColumnList);
|
|||
void dropAllExprInfo(SArray** pExprInfo, int32_t numOfLevel);
|
||||
|
||||
typedef struct SSourceParam {
|
||||
SArray *pExprNodeList; //Array<struct tExprNode*>
|
||||
SArray *pColumnList; //Array<struct SColumn>
|
||||
SArray *pExprNodeList; //Array<struct tExprNode*>
|
||||
SArray *pColumnList; //Array<struct SColumn>
|
||||
int32_t num;
|
||||
} SSourceParam;
|
||||
|
||||
|
|
|
@ -51,8 +51,10 @@ struct SQueryStmtInfo;
|
|||
typedef SSchema SSlotSchema;
|
||||
|
||||
typedef struct SDataBlockSchema {
|
||||
SSlotSchema *pSchema;
|
||||
int32_t numOfCols; // number of columns
|
||||
SSlotSchema *pSchema;
|
||||
int32_t numOfCols; // number of columns
|
||||
int32_t resultRowSize;
|
||||
int16_t precision;
|
||||
} SDataBlockSchema;
|
||||
|
||||
typedef struct SQueryNodeBasicInfo {
|
||||
|
@ -62,6 +64,7 @@ typedef struct SQueryNodeBasicInfo {
|
|||
|
||||
typedef struct SDataSink {
|
||||
SQueryNodeBasicInfo info;
|
||||
SDataBlockSchema schema;
|
||||
} SDataSink;
|
||||
|
||||
typedef struct SDataDispatcher {
|
||||
|
@ -140,16 +143,20 @@ typedef struct SQueryDag {
|
|||
|
||||
struct SQueryNode;
|
||||
|
||||
/**
|
||||
* Create the physical plan for the query, according to the AST.
|
||||
*/
|
||||
/**
|
||||
* Create the physical plan for the query, according to the AST.
|
||||
* @param pQueryInfo
|
||||
* @param pDag
|
||||
* @param requestId
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag, uint64_t requestId);
|
||||
|
||||
// Set datasource of this subplan, multiple calls may be made to a subplan.
|
||||
// @subplan subplan to be schedule
|
||||
// @templateId templateId of a group of datasource subplans of this @subplan
|
||||
// @ep one execution location of this group of datasource subplans
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep);
|
||||
void qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep);
|
||||
|
||||
int32_t qExplainQuery(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, char** str);
|
||||
|
||||
|
|
|
@ -76,6 +76,7 @@ typedef struct STableMeta {
|
|||
|
||||
typedef struct SDBVgroupInfo {
|
||||
SRWLatch lock;
|
||||
int64_t dbId;
|
||||
int32_t vgVersion;
|
||||
int8_t hashMethod;
|
||||
SHashObj *vgInfo; //key:vgId, value:SVgroupInfo
|
||||
|
@ -86,8 +87,16 @@ typedef struct SUseDbOutput {
|
|||
SDBVgroupInfo dbVgroup;
|
||||
} SUseDbOutput;
|
||||
|
||||
enum {
|
||||
META_TYPE_NON_TABLE = 1,
|
||||
META_TYPE_CTABLE,
|
||||
META_TYPE_TABLE,
|
||||
META_TYPE_BOTH_TABLE
|
||||
};
|
||||
|
||||
|
||||
typedef struct STableMetaOutput {
|
||||
int32_t metaNum;
|
||||
int32_t metaType;
|
||||
char ctbFname[TSDB_TABLE_FNAME_LEN];
|
||||
char tbFname[TSDB_TABLE_FNAME_LEN];
|
||||
SCTableMeta ctbMeta;
|
||||
|
@ -100,6 +109,11 @@ void initQueryModuleMsgHandle();
|
|||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen);
|
||||
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize);
|
||||
|
||||
#define SET_META_TYPE_NONE(t) (t) = META_TYPE_NON_TABLE
|
||||
#define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE
|
||||
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE
|
||||
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
|
||||
|
||||
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
|||
#include "catalog.h"
|
||||
|
||||
typedef struct SSchedulerCfg {
|
||||
int32_t maxJobNum;
|
||||
uint32_t maxJobNum;
|
||||
} SSchedulerCfg;
|
||||
|
||||
typedef struct SQueryProfileSummary {
|
||||
|
@ -75,6 +75,12 @@ int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void
|
|||
*/
|
||||
int32_t scheduleAsyncExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void** pJob);
|
||||
|
||||
/**
|
||||
* Fetch query result from the remote query executor
|
||||
* @param pJob
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
int32_t scheduleFetchRows(void *pJob, void **data);
|
||||
|
||||
|
||||
|
@ -85,6 +91,10 @@ int32_t scheduleFetchRows(void *pJob, void **data);
|
|||
*/
|
||||
int32_t scheduleCancelJob(void *pJob);
|
||||
|
||||
/**
|
||||
* Free the query job
|
||||
* @param pJob
|
||||
*/
|
||||
void scheduleFreeJob(void *pJob);
|
||||
|
||||
void schedulerDestroy(void);
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* 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_TFS_H
|
||||
#define TD_TFS_H
|
||||
|
||||
#include "tglobal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int level;
|
||||
int id;
|
||||
} SDiskID;
|
||||
|
||||
#define TFS_UNDECIDED_LEVEL -1
|
||||
#define TFS_UNDECIDED_ID -1
|
||||
#define TFS_PRIMARY_LEVEL 0
|
||||
#define TFS_PRIMARY_ID 0
|
||||
#define TFS_MIN_LEVEL 0
|
||||
#define TFS_MAX_LEVEL (TSDB_MAX_TIERS - 1)
|
||||
|
||||
// FS APIs ====================================
|
||||
typedef struct {
|
||||
int64_t tsize;
|
||||
int64_t used;
|
||||
int64_t avail;
|
||||
} SFSMeta;
|
||||
|
||||
typedef struct {
|
||||
int64_t size;
|
||||
int64_t used;
|
||||
int64_t free;
|
||||
int16_t nAvailDisks; // # of Available disks
|
||||
} STierMeta;
|
||||
|
||||
int tfsInit(SDiskCfg *pDiskCfg, int ndisk);
|
||||
void tfsDestroy();
|
||||
void tfsUpdateInfo(SFSMeta *pFSMeta, STierMeta *tierMetas, int8_t numLevels);
|
||||
void tfsGetMeta(SFSMeta *pMeta);
|
||||
void tfsAllocDisk(int expLevel, int *level, int *id);
|
||||
|
||||
const char *TFS_PRIMARY_PATH();
|
||||
const char *TFS_DISK_PATH(int level, int id);
|
||||
|
||||
// TFILE APIs ====================================
|
||||
typedef struct {
|
||||
int level;
|
||||
int id;
|
||||
char rname[TSDB_FILENAME_LEN]; // REL name
|
||||
char aname[TSDB_FILENAME_LEN]; // ABS name
|
||||
} TFILE;
|
||||
|
||||
#define TFILE_LEVEL(pf) ((pf)->level)
|
||||
#define TFILE_ID(pf) ((pf)->id)
|
||||
#define TFILE_NAME(pf) ((pf)->aname)
|
||||
#define TFILE_REL_NAME(pf) ((pf)->rname)
|
||||
|
||||
#define tfsopen(pf, flags) open(TFILE_NAME(pf), flags)
|
||||
#define tfsclose(fd) close(fd)
|
||||
#define tfsremove(pf) remove(TFILE_NAME(pf))
|
||||
#define tfscopy(sf, df) taosCopyFile(TFILE_NAME(sf), TFILE_NAME(df))
|
||||
#define tfsrename(sf, df) taosRename(TFILE_NAME(sf), TFILE_NAME(df))
|
||||
|
||||
void tfsInitFile(TFILE *pf, int level, int id, const char *bname);
|
||||
bool tfsIsSameFile(const TFILE *pf1, const TFILE *pf2);
|
||||
int tfsEncodeFile(void **buf, TFILE *pf);
|
||||
void *tfsDecodeFile(void *buf, TFILE *pf);
|
||||
void tfsbasename(const TFILE *pf, char *dest);
|
||||
void tfsdirname(const TFILE *pf, char *dest);
|
||||
|
||||
// DIR APIs ====================================
|
||||
int tfsMkdirAt(const char *rname, int level, int id);
|
||||
int tfsMkdirRecurAt(const char *rname, int level, int id);
|
||||
int tfsMkdir(const char *rname);
|
||||
int tfsRmdir(const char *rname);
|
||||
int tfsRename(char *orname, char *nrname);
|
||||
|
||||
typedef struct TDIR TDIR;
|
||||
|
||||
TDIR * tfsOpendir(const char *rname);
|
||||
const TFILE *tfsReaddir(TDIR *tdir);
|
||||
void tfsClosedir(TDIR *tdir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -24,10 +24,13 @@ extern "C" {
|
|||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <float.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <regex.h>
|
||||
#include <sched.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
|
@ -44,6 +47,8 @@ extern "C" {
|
|||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <wordexp.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
|
|
@ -73,6 +73,12 @@ extern "C" {
|
|||
|
||||
#endif
|
||||
|
||||
#ifndef WINDOWS
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
|
||||
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
|
||||
|
||||
|
|
|
@ -259,31 +259,30 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0411)
|
||||
#define TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0420)
|
||||
#define TSDB_CODE_DND_MNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0421)
|
||||
#define TSDB_CODE_DND_MNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0422)
|
||||
#define TSDB_CODE_DND_MNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0423)
|
||||
#define TSDB_CODE_DND_MNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0424)
|
||||
#define TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0425)
|
||||
#define TSDB_CODE_DND_MNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0422)
|
||||
#define TSDB_CODE_DND_MNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0423)
|
||||
#define TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0424)
|
||||
#define TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0430)
|
||||
#define TSDB_CODE_DND_QNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0431)
|
||||
#define TSDB_CODE_DND_QNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0432)
|
||||
#define TSDB_CODE_DND_QNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0433)
|
||||
#define TSDB_CODE_DND_QNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0434)
|
||||
#define TSDB_CODE_DND_QNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0435)
|
||||
#define TSDB_CODE_DND_QNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0432)
|
||||
#define TSDB_CODE_DND_QNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0433)
|
||||
#define TSDB_CODE_DND_QNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0434)
|
||||
#define TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0440)
|
||||
#define TSDB_CODE_DND_SNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0441)
|
||||
#define TSDB_CODE_DND_SNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0442)
|
||||
#define TSDB_CODE_DND_SNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0443)
|
||||
#define TSDB_CODE_DND_SNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0444)
|
||||
#define TSDB_CODE_DND_SNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0445)
|
||||
#define TSDB_CODE_DND_SNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0442)
|
||||
#define TSDB_CODE_DND_SNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0443)
|
||||
#define TSDB_CODE_DND_SNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0444)
|
||||
#define TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0450)
|
||||
#define TSDB_CODE_DND_BNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0451)
|
||||
#define TSDB_CODE_DND_BNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0452)
|
||||
#define TSDB_CODE_DND_BNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0453)
|
||||
#define TSDB_CODE_DND_BNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0454)
|
||||
#define TSDB_CODE_DND_BNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0455)
|
||||
#define TSDB_CODE_DND_VNODE_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x0460)
|
||||
#define TSDB_CODE_DND_VNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0461)
|
||||
#define TSDB_CODE_DND_VNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0462)
|
||||
#define TSDB_CODE_DND_BNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0452)
|
||||
#define TSDB_CODE_DND_BNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0453)
|
||||
#define TSDB_CODE_DND_BNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0454)
|
||||
#define TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0460)
|
||||
#define TSDB_CODE_DND_VNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0461)
|
||||
#define TSDB_CODE_DND_VNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0462)
|
||||
#define TSDB_CODE_DND_VNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0463)
|
||||
#define TSDB_CODE_DND_VNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0464)
|
||||
#define TSDB_CODE_DND_VNODE_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x0465)
|
||||
|
||||
// vnode
|
||||
#define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) //"Action in progress")
|
||||
|
|
|
@ -124,6 +124,9 @@ int32_t taosHashGetSize(const SHashObj *pHashObj);
|
|||
*/
|
||||
int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size);
|
||||
|
||||
int32_t taosHashPutExt(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size, bool *newAdded);
|
||||
|
||||
|
||||
/**
|
||||
* return the payload data with the specified key
|
||||
*
|
||||
|
|
|
@ -44,7 +44,6 @@ extern int32_t tsdbDebugFlag;
|
|||
extern int32_t tqDebugFlag;
|
||||
extern int32_t cqDebugFlag;
|
||||
extern int32_t debugFlag;
|
||||
extern int32_t ctgDebugFlag;
|
||||
|
||||
#define DEBUG_FATAL 1U
|
||||
#define DEBUG_ERROR DEBUG_FATAL
|
||||
|
|
|
@ -51,6 +51,7 @@ void taosFreeQitem(void *pItem);
|
|||
int32_t taosWriteQitem(STaosQueue *queue, void *pItem);
|
||||
int32_t taosReadQitem(STaosQueue *queue, void **ppItem);
|
||||
bool taosQueueEmpty(STaosQueue *queue);
|
||||
int32_t taosQueueSize(STaosQueue *queue);
|
||||
|
||||
STaosQall *taosAllocateQall();
|
||||
void taosFreeQall(STaosQall *qall);
|
||||
|
|
|
@ -62,6 +62,7 @@ typedef struct SAppInstInfo {
|
|||
SList *pConnList; // STscObj linked list
|
||||
int64_t clusterId;
|
||||
void *pTransporter;
|
||||
SHeartBeatInfo hb;
|
||||
} SAppInstInfo;
|
||||
|
||||
typedef struct SAppInfo {
|
||||
|
@ -70,7 +71,7 @@ typedef struct SAppInfo {
|
|||
char *ep;
|
||||
int32_t pid;
|
||||
int32_t numOfThreads;
|
||||
SHeartBeatInfo hb;
|
||||
|
||||
SHashObj *pInstMap;
|
||||
} SAppInfo;
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj*
|
|||
(*pRequest)->sqlstr[sqlLen] = 0;
|
||||
(*pRequest)->sqlLen = sqlLen;
|
||||
|
||||
tscDebugL("0x%"PRIx64" SQL: %s, reqId:0x"PRIx64, (*pRequest)->self, (*pRequest)->sqlstr, (*pRequest)->requestId);
|
||||
tscDebugL("0x%"PRIx64" SQL: %s, reqId:0x%"PRIx64, (*pRequest)->self, (*pRequest)->sqlstr, (*pRequest)->requestId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) {
|
|||
if (pDcl->msgType == TDMT_VND_SHOW_TABLES) {
|
||||
SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
|
||||
if (pShowReqInfo->pArray == NULL) {
|
||||
pShowReqInfo->currentIndex = 0;
|
||||
pShowReqInfo->currentIndex = 0; // set the first vnode/ then iterate the next vnode
|
||||
pShowReqInfo->pArray = pDcl->pExtension;
|
||||
}
|
||||
}
|
||||
|
@ -291,10 +291,10 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
|||
|
||||
nPrintTsc("%s", sql)
|
||||
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQueryNode* pQuery = NULL;
|
||||
SQueryDag* pDag = NULL;
|
||||
void* pJob = NULL;
|
||||
SRequestObj *pRequest = NULL;
|
||||
SQueryNode *pQuery = NULL;
|
||||
SQueryDag *pDag = NULL;
|
||||
void *pJob = NULL;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
|
@ -395,13 +395,13 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj *pRequest) {
|
|||
}
|
||||
|
||||
pMsgSendInfo->msgType = TDMT_MND_CONNECT;
|
||||
pMsgSendInfo->msgInfo.len = sizeof(SConnectMsg);
|
||||
pMsgSendInfo->msgInfo.len = sizeof(SConnectReq);
|
||||
pMsgSendInfo->requestObjRefId = pRequest->self;
|
||||
pMsgSendInfo->requestId = pRequest->requestId;
|
||||
pMsgSendInfo->fp = handleRequestRspFp[TMSG_INDEX(pMsgSendInfo->msgType)];
|
||||
pMsgSendInfo->param = pRequest;
|
||||
|
||||
SConnectMsg *pConnect = calloc(1, sizeof(SConnectMsg));
|
||||
SConnectReq *pConnect = calloc(1, sizeof(SConnectReq));
|
||||
if (pConnect == NULL) {
|
||||
tfree(pMsgSendInfo);
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include "os.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "query.h"
|
||||
#include "tmsg.h"
|
||||
#include "tglobal.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "catalog.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
@ -46,6 +47,7 @@ void taos_cleanup(void) {
|
|||
taosCloseRef(id);
|
||||
|
||||
rpcCleanup();
|
||||
catalogDestroy();
|
||||
taosCloseLog();
|
||||
|
||||
tscInfo("all local resources released");
|
||||
|
|
|
@ -101,13 +101,13 @@ TEST(testCase, show_user_Test) {
|
|||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show users");
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
@ -134,13 +134,13 @@ TEST(testCase, show_db_Test) {
|
|||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show databases");
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
@ -228,29 +228,29 @@ TEST(testCase, use_db_test) {
|
|||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, drop_db_test) {
|
||||
//// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
//// assert(pConn != NULL);
|
||||
////
|
||||
//// showDB(pConn);
|
||||
////
|
||||
//// TAOS_RES* pRes = taos_query(pConn, "drop database abc1");
|
||||
//// if (taos_errno(pRes) != 0) {
|
||||
//// printf("failed to drop db, reason:%s\n", taos_errstr(pRes));
|
||||
//// }
|
||||
//// taos_free_result(pRes);
|
||||
////
|
||||
//// showDB(pConn);
|
||||
////
|
||||
//// pRes = taos_query(pConn, "create database abc1");
|
||||
//// if (taos_errno(pRes) != 0) {
|
||||
//// printf("create to drop db, reason:%s\n", taos_errstr(pRes));
|
||||
//// }
|
||||
//// taos_free_result(pRes);
|
||||
//// taos_close(pConn);
|
||||
// TEST(testCase, drop_db_test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// showDB(pConn);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "drop database abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to drop db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// showDB(pConn);
|
||||
//
|
||||
// pRes = taos_query(pConn, "create database abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("create to drop db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
|
||||
TEST(testCase, create_stable_Test) {
|
||||
TEST(testCase, create_stable_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
|
@ -281,128 +281,227 @@ TEST(testCase, use_db_test) {
|
|||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, create_table_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
TEST(testCase, create_table_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
//TEST(testCase, create_ctable_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "create table tm0 using st1 tags(1)");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
//
|
||||
//TEST(testCase, show_stable_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "show stables");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to show stables, reason:%s\n", taos_errstr(pRes));
|
||||
// taos_free_result(pRes);
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
//
|
||||
// TAOS_ROW pRow = NULL;
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
//TEST(testCase, show_vgroup_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "show vgroups");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes));
|
||||
// taos_free_result(pRes);
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
//
|
||||
// TAOS_ROW pRow = NULL;
|
||||
//
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)");
|
||||
taos_free_result(pRes);
|
||||
|
||||
//TEST(testCase, drop_stable_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("error in creating db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "use abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("error in using db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "drop stable st1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to drop stable, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, create_topic_Test) {
|
||||
TEST(testCase, create_ctable_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table tm0 using st1 tags(1)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, show_stable_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "show stables");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to show stables, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, show_vgroup_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "show vgroups");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_multiple_tables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
return;
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table t_2 using st1 tags(1)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
pRes = taos_query(pConn, "create table t_3 using st1 tags(2)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
for (int32_t i = 0; i < 20; ++i) {
|
||||
char sql[512] = {0};
|
||||
snprintf(sql, tListLen(sql),
|
||||
"create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5) t_x_%d using st1 tags(911)", i,
|
||||
(i + 1) * 30, (i + 2) * 40);
|
||||
TAOS_RES* pres = taos_query(pConn, sql);
|
||||
if (taos_errno(pres) != 0) {
|
||||
printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres));
|
||||
}
|
||||
taos_free_result(pres);
|
||||
}
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, show_table_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "show tables");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, drop_stable_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in creating db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in using db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "drop stable st1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to drop stable, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, generated_request_id_test) {
|
||||
SHashObj* phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
|
||||
for (int32_t i = 0; i < 50000; ++i) {
|
||||
uint64_t v = generateRequestId();
|
||||
void* result = taosHashGet(phash, &v, sizeof(v));
|
||||
if (result != nullptr) {
|
||||
printf("0x%lx, index:%d\n", v, i);
|
||||
}
|
||||
assert(result == nullptr);
|
||||
taosHashPut(phash, &v, sizeof(v), NULL, 0);
|
||||
}
|
||||
|
||||
taosHashCleanup(phash);
|
||||
}
|
||||
|
||||
// TEST(testCase, create_topic_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
|
@ -435,132 +534,55 @@ TEST(testCase, use_db_test) {
|
|||
// tmq_create_topic(pConn, "test_topic_1", sql, strlen(sql));
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
|
||||
//TEST(testCase, show_table_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "show tables");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes));
|
||||
// taos_free_result(pRes);
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
//
|
||||
// TAOS_ROW pRow = NULL;
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
|
||||
TEST(testCase, create_multiple_tables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
return;
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table t_2 using st1 tags(1)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
pRes = taos_query(pConn, "create table t_3 using st1 tags(2)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
for(int32_t i = 0; i < 200000; ++i) {
|
||||
char sql[512] = {0};
|
||||
snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i);
|
||||
TAOS_RES* pres = taos_query(pConn, sql);
|
||||
if (taos_errno(pres) != 0) {
|
||||
printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres));
|
||||
}
|
||||
|
||||
printf("%d\n", i);
|
||||
taos_free_result(pres);
|
||||
}
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, generated_request_id_test) {
|
||||
SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
|
||||
for(int32_t i = 0; i < 50000; ++i) {
|
||||
uint64_t v = generateRequestId();
|
||||
void* result = taosHashGet(phash, &v, sizeof(v));
|
||||
if (result != nullptr) {
|
||||
printf("0x%lx, index:%d\n", v, i);
|
||||
}
|
||||
assert(result == nullptr);
|
||||
taosHashPut(phash, &v, sizeof(v), NULL, 0);
|
||||
}
|
||||
|
||||
taosHashCleanup(phash);
|
||||
}
|
||||
|
||||
//TEST(testCase, projection_query_tables) {
|
||||
//TEST(testCase, insert_test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// ASSERT_EQ(pConn, nullptr);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "select * from t_2");
|
||||
// pRes = taos_query(pConn, "insert into t_2 values(now, 1)");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
// taos_free_result(pRes);
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
//
|
||||
// TAOS_ROW pRow = NULL;
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
//#endif
|
||||
|
||||
TEST(testCase, projection_query_tables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use test1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
return;
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "select * from tm0");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
|
|
@ -910,7 +910,7 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.option = "tsdbDebugFlag";
|
||||
cfg.ptr = &tsdbDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
|
|
|
@ -27,6 +27,64 @@
|
|||
#undef TD_MSG_SEG_CODE_
|
||||
#include "tmsgdef.h"
|
||||
|
||||
int tInitSubmitMsgIter(SSubmitMsg *pMsg, SSubmitMsgIter *pIter) {
|
||||
if (pMsg == NULL) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pIter->totalLen = pMsg->length;
|
||||
pIter->len = 0;
|
||||
pIter->pMsg = pMsg;
|
||||
if (pMsg->length <= sizeof(SSubmitMsg)) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tGetSubmitMsgNext(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock) {
|
||||
if (pIter->len == 0) {
|
||||
pIter->len += sizeof(SSubmitMsg);
|
||||
} else {
|
||||
SSubmitBlk *pSubmitBlk = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||
pIter->len += (sizeof(SSubmitBlk) + pSubmitBlk->dataLen + pSubmitBlk->schemaLen);
|
||||
}
|
||||
|
||||
if (pIter->len > pIter->totalLen) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
*pPBlock = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*pPBlock = (pIter->len == pIter->totalLen) ? NULL : (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter) {
|
||||
if (pBlock->dataLen <= 0) return -1;
|
||||
pIter->totalLen = pBlock->dataLen;
|
||||
pIter->len = 0;
|
||||
pIter->row = (SMemRow)(pBlock->data + pBlock->schemaLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SMemRow tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
|
||||
SMemRow row = pIter->row;
|
||||
|
||||
if (pIter->len >= pIter->totalLen) {
|
||||
return NULL;
|
||||
} else {
|
||||
pIter->len += memRowTLen(row);
|
||||
if (pIter->len < pIter->totalLen) {
|
||||
pIter->row = POINTER_SHIFT(row, memRowTLen(row));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
int tSerializeSClientHbReq(void **buf, const SClientHbReq *pReq) {
|
||||
int tlen = 0;
|
||||
tlen += taosEncodeSClientHbKey(buf, &pReq->connKey);
|
||||
|
|
|
@ -80,20 +80,20 @@ typedef struct {
|
|||
} SDnodeDir;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int32_t dropped;
|
||||
int64_t clusterId;
|
||||
int64_t rebootTime;
|
||||
int64_t updateTime;
|
||||
int8_t statusSent;
|
||||
SEpSet mnodeEpSet;
|
||||
char *file;
|
||||
SHashObj *dnodeHash;
|
||||
SDnodeEps *dnodeEps;
|
||||
pthread_t *threadId;
|
||||
SRWLatch latch;
|
||||
STaosQueue *pMgmtQ;
|
||||
SWorkerPool mgmtPool;
|
||||
int32_t dnodeId;
|
||||
int32_t dropped;
|
||||
int64_t clusterId;
|
||||
int64_t dver;
|
||||
int64_t rebootTime;
|
||||
int64_t updateTime;
|
||||
int8_t statusSent;
|
||||
SEpSet mnodeEpSet;
|
||||
char *file;
|
||||
SHashObj *dnodeHash;
|
||||
SDnodeEps *dnodeEps;
|
||||
pthread_t *threadId;
|
||||
SRWLatch latch;
|
||||
SDnodeWorker mgmtWorker;
|
||||
} SDnodeMgmt;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -29,12 +29,12 @@ void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
|||
void dndProcessVnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
|
||||
int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndBnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
|
@ -42,18 +42,13 @@ static SBnode *dndAcquireBnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndReleaseBnode(SDnode *pDnode, SBnode *pBnode) {
|
||||
if (pBnode == NULL) return;
|
||||
|
||||
SBnodeMgmt *pMgmt = &pDnode->bmgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pBnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
}
|
||||
int32_t refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pBnode != NULL) {
|
||||
dTrace("release bnode, refCount:%d", refCount);
|
||||
}
|
||||
dTrace("release bnode, refCount:%d", refCount);
|
||||
}
|
||||
|
||||
static int32_t dndReadBnodeFile(SDnode *pDnode) {
|
||||
|
@ -268,7 +263,7 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_BNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_BNODE_INVALID_OPTION;
|
||||
dError("failed to create bnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -281,7 +276,7 @@ int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_BNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_BNODE_INVALID_OPTION;
|
||||
dError("failed to drop bnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
|
|
|
@ -14,28 +14,25 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndBnode.h"
|
||||
#include "dndMnode.h"
|
||||
#include "dndQnode.h"
|
||||
#include "dndSnode.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndVnodes.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
static int32_t dndInitMgmtWorker(SDnode *pDnode);
|
||||
static void dndCleanupMgmtWorker(SDnode *pDnode);
|
||||
static int32_t dndAllocMgmtQueue(SDnode *pDnode);
|
||||
static void dndFreeMgmtQueue(SDnode *pDnode);
|
||||
static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
|
||||
static int32_t dndReadDnodes(SDnode *pDnode);
|
||||
static int32_t dndWriteDnodes(SDnode *pDnode);
|
||||
static void *dnodeThreadRoutine(void *param);
|
||||
|
||||
static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp);
|
||||
static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pRsp);
|
||||
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pRsp);
|
||||
|
||||
int32_t dndGetDnodeId(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
@ -80,13 +77,13 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
|||
taosRUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
tmsg_t msgType = pReq->msgType;
|
||||
|
||||
SEpSet epSet = {0};
|
||||
dndGetMnodeEpSet(pDnode, &epSet);
|
||||
|
||||
dDebug("RPC %p, msg:%s is redirected, num:%d use:%d", pMsg->handle, TMSG_INFO(msgType), epSet.numOfEps, epSet.inUse);
|
||||
dDebug("RPC %p, req:%s is redirected, num:%d use:%d", pReq->handle, TMSG_INFO(msgType), epSet.numOfEps, epSet.inUse);
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%u", i, epSet.fqdn[i], epSet.port[i]);
|
||||
if (strcmp(epSet.fqdn[i], pDnode->opt.localFqdn) == 0 && epSet.port[i] == pDnode->opt.serverPort) {
|
||||
|
@ -96,7 +93,7 @@ void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
epSet.port[i] = htons(epSet.port[i]);
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(pMsg->handle, &epSet);
|
||||
rpcSendRedirectRsp(pReq->handle, &epSet);
|
||||
}
|
||||
|
||||
static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
|
@ -350,14 +347,14 @@ static int32_t dndWriteDnodes(SDnode *pDnode) {
|
|||
terrno = 0;
|
||||
|
||||
pMgmt->updateTime = taosGetTimestampMs();
|
||||
dInfo("successed to write %s", pMgmt->file);
|
||||
dDebug("successed to write %s", pMgmt->file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndSendStatusReq(SDnode *pDnode) {
|
||||
int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||
int32_t contLen = sizeof(SStatusReq) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||
|
||||
SStatusMsg *pStatus = rpcMallocCont(contLen);
|
||||
SStatusReq *pStatus = rpcMallocCont(contLen);
|
||||
if (pStatus == NULL) {
|
||||
dError("failed to malloc status message");
|
||||
return;
|
||||
|
@ -366,6 +363,7 @@ void dndSendStatusReq(SDnode *pDnode) {
|
|||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
pStatus->sver = htonl(pDnode->opt.sver);
|
||||
pStatus->dver = htobe64(pMgmt->dver);
|
||||
pStatus->dnodeId = htonl(pMgmt->dnodeId);
|
||||
pStatus->clusterId = htobe64(pMgmt->clusterId);
|
||||
pStatus->rebootTime = htobe64(pMgmt->rebootTime);
|
||||
|
@ -385,12 +383,12 @@ void dndSendStatusReq(SDnode *pDnode) {
|
|||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads);
|
||||
contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad);
|
||||
contLen = sizeof(SStatusReq) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)9527};
|
||||
pMgmt->statusSent = 1;
|
||||
|
||||
dTrace("pDnode:%p, send status msg to mnode", pDnode);
|
||||
dTrace("pDnode:%p, send status req to mnode", pDnode);
|
||||
dndSendReqToMnode(pDnode, &rpcMsg);
|
||||
}
|
||||
|
||||
|
@ -426,12 +424,12 @@ static void dndUpdateDnodeEps(SDnode *pDnode, SDnodeEps *pDnodeEps) {
|
|||
taosWUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
if (pMsg->code != TSDB_CODE_SUCCESS) {
|
||||
if (pRsp->code != TSDB_CODE_SUCCESS) {
|
||||
pMgmt->statusSent = 0;
|
||||
if (pMsg->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->dropped && pMgmt->dnodeId > 0) {
|
||||
if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->dropped && pMgmt->dnodeId > 0) {
|
||||
dInfo("dnode:%d, set to dropped since not exist in mnode", pMgmt->dnodeId);
|
||||
pMgmt->dropped = 1;
|
||||
dndWriteDnodes(pDnode);
|
||||
|
@ -439,14 +437,16 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
return;
|
||||
}
|
||||
|
||||
SStatusRsp *pRsp = pMsg->pCont;
|
||||
if (pMsg->pCont != NULL && pMsg->contLen != 0) {
|
||||
SDnodeCfg *pCfg = &pRsp->dnodeCfg;
|
||||
if (pRsp->pCont != NULL && pRsp->contLen != 0) {
|
||||
SStatusRsp *pStatus = pRsp->pCont;
|
||||
pMgmt->dver = htobe64(pStatus->dver);
|
||||
|
||||
SDnodeCfg *pCfg = &pStatus->dnodeCfg;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
pCfg->clusterId = htobe64(pCfg->clusterId);
|
||||
dndUpdateDnodeCfg(pDnode, pCfg);
|
||||
|
||||
SDnodeEps *pDnodeEps = &pRsp->dnodeEps;
|
||||
SDnodeEps *pDnodeEps = &pStatus->dnodeEps;
|
||||
pDnodeEps->num = htonl(pDnodeEps->num);
|
||||
for (int32_t i = 0; i < pDnodeEps->num; ++i) {
|
||||
pDnodeEps->eps[i].id = htonl(pDnodeEps->eps[i].id);
|
||||
|
@ -458,26 +458,27 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
pMgmt->statusSent = 0;
|
||||
}
|
||||
|
||||
static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg) { assert(1); }
|
||||
static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pReq) { dError("auth rsp is received, but not supported yet"); }
|
||||
|
||||
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg) { assert(1); }
|
||||
|
||||
static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
dError("config msg is received, but not supported yet");
|
||||
SCfgDnodeMsg *pCfg = pMsg->pCont;
|
||||
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dError("grant rsp is received, but not supported yet");
|
||||
}
|
||||
|
||||
static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dError("config req is received, but not supported yet");
|
||||
SDCfgDnodeReq *pCfg = pReq->pCont;
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
dDebug("startup msg is received");
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dDebug("startup req is received");
|
||||
|
||||
SStartupMsg *pStartup = rpcMallocCont(sizeof(SStartupMsg));
|
||||
dndGetStartup(pDnode, pStartup);
|
||||
|
||||
dDebug("startup msg is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStartup, .contLen = sizeof(SStartupMsg)};
|
||||
SRpcMsg rpcRsp = {.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupMsg)};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
|
||||
|
@ -530,13 +531,8 @@ int32_t dndInitDnode(SDnode *pDnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitMgmtWorker(pDnode) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocMgmtQueue(pDnode) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (dndInitWorker(pDnode, &pMgmt->mgmtWorker, DND_WORKER_SINGLE, "dnode-mgmt", 1, 1, dndProcessMgmtQueue) != 0) {
|
||||
dError("failed to start dnode mgmt worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -547,15 +543,14 @@ int32_t dndInitDnode(SDnode *pDnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode-dnode is initialized");
|
||||
dInfo("dnode-mgmt is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndCleanupDnode(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
dndCleanupMgmtWorker(pDnode);
|
||||
dndFreeMgmtQueue(pDnode);
|
||||
dndCleanupWorker(&pMgmt->mgmtWorker);
|
||||
|
||||
if (pMgmt->threadId != NULL) {
|
||||
taosDestoryThread(pMgmt->threadId);
|
||||
|
@ -580,62 +575,22 @@ void dndCleanupDnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
dInfo("dnode-dnode is cleaned up");
|
||||
dInfo("dnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
static int32_t dndInitMgmtWorker(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
SWorkerPool *pPool = &pMgmt->mgmtPool;
|
||||
pPool->name = "dnode-mgmt";
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("dnode mgmt worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupMgmtWorker(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
tWorkerCleanup(&pMgmt->mgmtPool);
|
||||
dDebug("dnode mgmt worker is closed");
|
||||
}
|
||||
|
||||
static int32_t dndAllocMgmtQueue(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, pDnode, (FProcessItem)dndProcessMgmtQueue);
|
||||
if (pMgmt->pMgmtQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeMgmtQueue(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->mgmtPool, pMgmt->pMgmtQ);
|
||||
pMgmt->pMgmtQ = NULL;
|
||||
}
|
||||
|
||||
void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet) {
|
||||
void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
if (pEpSet && pEpSet->numOfEps > 0 && pRpcMsg->msgType == TDMT_MND_STATUS_RSP) {
|
||||
if (pEpSet && pEpSet->numOfEps > 0 && pMsg->msgType == TDMT_MND_STATUS_RSP) {
|
||||
dndUpdateMnodeEpSet(pDnode, pEpSet);
|
||||
}
|
||||
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg));
|
||||
if (pMsg != NULL) *pMsg = *pRpcMsg;
|
||||
|
||||
if (pMsg == NULL || taosWriteQitem(pMgmt->pMgmtQ, pMsg) != 0) {
|
||||
if (pRpcMsg->msgType & 1u) {
|
||||
SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_OUT_OF_MEMORY};
|
||||
if (dndWriteMsgToWorker(&pMgmt->mgmtWorker, pMsg, sizeof(SRpcMsg)) != 0) {
|
||||
if (pMsg->msgType & 1u) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = TSDB_CODE_OUT_OF_MEMORY};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
}
|
||||
|
@ -704,7 +659,7 @@ static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
default:
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
code = -1;
|
||||
dError("RPC %p, dnode req:%s not processed", pMsg->handle, TMSG_INFO(pMsg->msgType));
|
||||
dError("RPC %p, dnode msg:%s not processed", pMsg->handle, TMSG_INFO(pMsg->msgType));
|
||||
break;
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndMnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
|
@ -43,18 +43,13 @@ static SMnode *dndAcquireMnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode) {
|
||||
if (pMnode == NULL) return;
|
||||
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
}
|
||||
int32_t refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pMnode != NULL) {
|
||||
dTrace("release mnode, refCount:%d", refCount);
|
||||
}
|
||||
dTrace("release mnode, refCount:%d", refCount);
|
||||
}
|
||||
|
||||
static int32_t dndReadMnodeFile(SDnode *pDnode) {
|
||||
|
@ -305,25 +300,24 @@ static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
|||
memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
||||
}
|
||||
|
||||
static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SDCreateMnodeMsg *pMsg) {
|
||||
static int32_t dndBuildMnodeOptionFromReq(SDnode *pDnode, SMnodeOpt *pOption, SDCreateMnodeReq *pCreate) {
|
||||
dndInitMnodeOption(pDnode, pOption);
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
|
||||
pOption->replica = pMsg->replica;
|
||||
pOption->replica = pCreate->replica;
|
||||
pOption->selfIndex = -1;
|
||||
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
||||
for (int32_t i = 0; i < pCreate->replica; ++i) {
|
||||
SReplica *pReplica = &pOption->replicas[i];
|
||||
pReplica->id = pMsg->replicas[i].id;
|
||||
pReplica->port = pMsg->replicas[i].port;
|
||||
memcpy(pReplica->fqdn, pMsg->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||
pReplica->id = pCreate->replicas[i].id;
|
||||
pReplica->port = pCreate->replicas[i].port;
|
||||
memcpy(pReplica->fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||
if (pReplica->id == pOption->dnodeId) {
|
||||
pOption->selfIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (pOption->selfIndex == -1) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_NOT_FOUND;
|
||||
dError("failed to build mnode options since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -423,63 +417,97 @@ static int32_t dndDropMnode(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static SDCreateMnodeMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
|
||||
SDCreateMnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
||||
pMsg->replicas[i].id = htonl(pMsg->replicas[i].id);
|
||||
pMsg->replicas[i].port = htons(pMsg->replicas[i].port);
|
||||
static SDCreateMnodeReq *dndParseCreateMnodeReq(SRpcMsg *pReq) {
|
||||
SDCreateMnodeReq *pCreate = pReq->pCont;
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
for (int32_t i = 0; i < pCreate->replica; ++i) {
|
||||
pCreate->replicas[i].id = htonl(pCreate->replicas[i].id);
|
||||
pCreate->replicas[i].port = htons(pCreate->replicas[i].port);
|
||||
}
|
||||
|
||||
return pMsg;
|
||||
return pCreate;
|
||||
}
|
||||
|
||||
int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDCreateMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg);
|
||||
int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SDCreateMnodeReq *pCreate = dndParseCreateMnodeReq(pReq);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||
return -1;
|
||||
} else {
|
||||
SMnodeOpt option = {0};
|
||||
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dndOpenMnode(pDnode, &option);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDAlterMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||
if (pCreate->replica <= 1 || pCreate->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMnodeOpt option = {0};
|
||||
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
|
||||
if (dndBuildMnodeOptionFromReq(pDnode, &option, pCreate) != 0) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAlterMnode(pDnode, &option) != 0) {
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode != NULL) {
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
terrno = TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dndWriteMnodeFile(pDnode);
|
||||
dDebug("start to create mnode");
|
||||
return dndOpenMnode(pDnode, &option);
|
||||
}
|
||||
|
||||
int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDDropMnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SDAlterMnodeReq *pAlter = dndParseCreateMnodeReq(pReq);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||
if (pAlter->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to alter mnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndDropMnode(pDnode);
|
||||
}
|
||||
|
||||
SMnodeOpt option = {0};
|
||||
if (dndBuildMnodeOptionFromReq(pDnode, &option, pAlter) != 0) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to alter mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL) {
|
||||
terrno = TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
||||
dError("failed to alter mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("start to alter mnode");
|
||||
int32_t code = dndAlterMnode(pDnode, &option);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SDDropMnodeReq *pDrop = pReq->pCont;
|
||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||
|
||||
if (pDrop->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL) {
|
||||
terrno = TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("start to drop mnode");
|
||||
int32_t code = dndDropMnode(pDnode);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
|
@ -506,6 +534,7 @@ static void dndWriteMnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpc
|
|||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
code = dndWriteMsgToWorker(pWorker, pMsg, 0);
|
||||
if (code != 0) code = terrno;
|
||||
}
|
||||
|
||||
if (code != 0) {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndQnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
|
@ -42,18 +42,13 @@ static SQnode *dndAcquireQnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndReleaseQnode(SDnode *pDnode, SQnode *pQnode) {
|
||||
if (pQnode == NULL) return;
|
||||
|
||||
SQnodeMgmt *pMgmt = &pDnode->qmgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pQnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
}
|
||||
int32_t refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pQnode != NULL) {
|
||||
dTrace("release qnode, refCount:%d", refCount);
|
||||
}
|
||||
dTrace("release qnode, refCount:%d", refCount);
|
||||
}
|
||||
|
||||
static int32_t dndReadQnodeFile(SDnode *pDnode) {
|
||||
|
@ -274,7 +269,7 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_QNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_QNODE_INVALID_OPTION;
|
||||
dError("failed to create qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -287,7 +282,7 @@ int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_QNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_QNODE_INVALID_OPTION;
|
||||
dError("failed to drop qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndSnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
|
@ -42,18 +42,13 @@ static SSnode *dndAcquireSnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndReleaseSnode(SDnode *pDnode, SSnode *pSnode) {
|
||||
if (pSnode == NULL) return;
|
||||
|
||||
SSnodeMgmt *pMgmt = &pDnode->smgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pSnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
}
|
||||
int32_t refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pSnode != NULL) {
|
||||
dTrace("release snode, refCount:%d", refCount);
|
||||
}
|
||||
dTrace("release snode, refCount:%d", refCount);
|
||||
}
|
||||
|
||||
static int32_t dndReadSnodeFile(SDnode *pDnode) {
|
||||
|
@ -268,7 +263,7 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_SNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_SNODE_INVALID_OPTION;
|
||||
dError("failed to create snode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -281,7 +276,7 @@ int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_SNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_SNODE_INVALID_OPTION;
|
||||
dError("failed to drop snode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndTransport.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndMnode.h"
|
||||
#include "dndVnodes.h"
|
||||
|
||||
|
@ -143,26 +143,26 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES_FETCH)] = dndProcessVnodeFetchMsg;
|
||||
}
|
||||
|
||||
static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
static void dndProcessResponse(void *parent, SRpcMsg *pRsp, SEpSet *pEpSet) {
|
||||
SDnode *pDnode = parent;
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
tmsg_t msgType = pRsp->msgType;
|
||||
|
||||
if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) return;
|
||||
dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pMsg->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
if (pRsp == NULL || pRsp->pCont == NULL) return;
|
||||
dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pRsp->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pRsp->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, rsp:%s will be processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF);
|
||||
(*fp)(pDnode, pMsg, pEpSet);
|
||||
dTrace("RPC %p, rsp:%s will be processed, code:0x%x", pRsp->handle, TMSG_INFO(msgType), pRsp->code & 0XFFFF);
|
||||
(*fp)(pDnode, pRsp, pEpSet);
|
||||
} else {
|
||||
dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
dError("RPC %p, rsp:%s not processed", pRsp->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pRsp->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,48 +201,48 @@ static void dndCleanupClient(SDnode *pDnode) {
|
|||
}
|
||||
}
|
||||
|
||||
static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
static void dndProcessRequest(void *param, SRpcMsg *pReq, SEpSet *pEpSet) {
|
||||
SDnode *pDnode = param;
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
tmsg_t msgType = pReq->msgType;
|
||||
if (msgType == TDMT_DND_NETWORK_TEST) {
|
||||
dTrace("RPC %p, network test req, app:%p will be processed, code:0x%x", pMsg->handle, pMsg->ahandle, pMsg->code);
|
||||
dndProcessStartupReq(pDnode, pMsg);
|
||||
dTrace("RPC %p, network test req, app:%p will be processed, code:0x%x", pReq->handle, pReq->ahandle, pReq->code);
|
||||
dndProcessStartupReq(pDnode, pReq);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
|
||||
dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_OFFLINE};
|
||||
dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pReq->handle, TMSG_INFO(msgType), pReq->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pReq->handle, .code = TSDB_CODE_DND_OFFLINE};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
rpcFreeCont(pReq->pCont);
|
||||
return;
|
||||
} else if (dndGetStat(pDnode) != DND_STAT_RUNNING) {
|
||||
dError("RPC %p, req:%s app:%p is ignored since dnode not running", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY};
|
||||
dError("RPC %p, req:%s app:%p is ignored since dnode not running", pReq->handle, TMSG_INFO(msgType), pReq->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pReq->handle, .code = TSDB_CODE_APP_NOT_READY};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
rpcFreeCont(pReq->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pMsg->pCont == NULL) {
|
||||
dTrace("RPC %p, req:%s app:%p not processed since content is null", pMsg->handle, TMSG_INFO(msgType),
|
||||
pMsg->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN};
|
||||
if (pReq->pCont == NULL) {
|
||||
dTrace("RPC %p, req:%s app:%p not processed since content is null", pReq->handle, TMSG_INFO(msgType),
|
||||
pReq->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pReq->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN};
|
||||
rpcSendResponse(&rspMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, req:%s app:%p will be processed", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle);
|
||||
(*fp)(pDnode, pMsg, pEpSet);
|
||||
dTrace("RPC %p, req:%s app:%p will be processed", pReq->handle, TMSG_INFO(msgType), pReq->ahandle);
|
||||
(*fp)(pDnode, pReq, pEpSet);
|
||||
} else {
|
||||
dError("RPC %p, req:%s app:%p is not processed since no handle", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED};
|
||||
dError("RPC %p, req:%s app:%p is not processed since no handle", pReq->handle, TMSG_INFO(msgType), pReq->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pReq->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
rpcFreeCont(pReq->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ static void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pRpcMsg, SRpcMsg *pRp
|
|||
rpcSendRecv(pMgmt->clientRpc, &epSet, pRpcMsg, pRpcRsp);
|
||||
}
|
||||
|
||||
static int32_t dndAuthInternalMsg(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
static int32_t dndAuthInternalReq(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (strcmp(user, INTERNAL_USER) == 0) {
|
||||
// A simple temporary implementation
|
||||
char pass[TSDB_PASSWORD_LEN] = {0};
|
||||
|
@ -281,7 +281,7 @@ static int32_t dndAuthInternalMsg(SDnode *pDnode, char *user, char *spi, char *e
|
|||
static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
SDnode *pDnode = parent;
|
||||
|
||||
if (dndAuthInternalMsg(parent, user, spi, encrypt, secret, ckey) == 0) {
|
||||
if (dndAuthInternalReq(parent, user, spi, encrypt, secret, ckey) == 0) {
|
||||
// dTrace("get internal auth success");
|
||||
return 0;
|
||||
}
|
||||
|
@ -298,10 +298,10 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
|
|||
|
||||
// dDebug("user:%s, send auth msg to other mnodes", user);
|
||||
|
||||
SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg));
|
||||
tstrncpy(pMsg->user, user, TSDB_USER_LEN);
|
||||
SAuthReq *pReq = rpcMallocCont(sizeof(SAuthReq));
|
||||
tstrncpy(pReq->user, user, TSDB_USER_LEN);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pMsg, .contLen = sizeof(SAuthMsg), .msgType = TDMT_MND_AUTH};
|
||||
SRpcMsg rpcMsg = {.pCont = pReq, .contLen = sizeof(SAuthReq), .msgType = TDMT_MND_AUTH};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
|
||||
|
@ -381,19 +381,19 @@ void dndCleanupTrans(SDnode *pDnode) {
|
|||
dInfo("dnode-transport is cleaned up");
|
||||
}
|
||||
|
||||
int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_DND_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL);
|
||||
rpcSendRequest(pMgmt->clientRpc, pEpSet, pReq, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SEpSet epSet = {0};
|
||||
dndGetMnodeEpSet(pDnode, &epSet);
|
||||
return dndSendReqToDnode(pDnode, &epSet, pMsg);
|
||||
return dndSendReqToDnode(pDnode, &epSet, pReq);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ typedef struct {
|
|||
STaosQueue *pSyncQ;
|
||||
STaosQueue *pApplyQ;
|
||||
STaosQueue *pQueryQ;
|
||||
STaosQueue* pFetchQ;
|
||||
STaosQueue *pFetchQ;
|
||||
} SVnodeObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -53,22 +53,8 @@ typedef struct {
|
|||
SWrapperCfg *pCfgs;
|
||||
} SVnodeThread;
|
||||
|
||||
static int32_t dndInitVnodeReadWorker(SDnode *pDnode);
|
||||
static int32_t dndInitVnodeWriteWorker(SDnode *pDnode);
|
||||
static int32_t dndInitVnodeSyncWorker(SDnode *pDnode);
|
||||
static void dndCleanupVnodeReadWorker(SDnode *pDnode);
|
||||
static void dndCleanupVnodeWriteWorker(SDnode *pDnode);
|
||||
static void dndCleanupVnodeSyncWorker(SDnode *pDnode);
|
||||
static int32_t dndAllocVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
|
||||
static void dndProcessVnodeQueryQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
||||
static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
||||
|
@ -117,11 +103,9 @@ static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode) {
|
|||
if (pVnode == NULL) return;
|
||||
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
int32_t refCount = atomic_sub_fetch_32(&pVnode->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
dTrace("vgId:%d, release vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
}
|
||||
|
||||
|
@ -134,7 +118,7 @@ static int32_t dndOpenVnode(SDnode *pDnode, SWrapperCfg *pCfg, SVnode *pImpl) {
|
|||
}
|
||||
|
||||
pVnode->vgId = pCfg->vgId;
|
||||
pVnode->refCount = 1;
|
||||
pVnode->refCount = 0;
|
||||
pVnode->dropped = 0;
|
||||
pVnode->accessState = TSDB_VN_ALL_ACCCESS;
|
||||
pVnode->pImpl = pImpl;
|
||||
|
@ -148,23 +132,8 @@ static int32_t dndOpenVnode(SDnode *pDnode, SWrapperCfg *pCfg, SVnode *pImpl) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeQueryQueue(pDnode, pVnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeFetchQueue(pDnode, pVnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeWriteQueue(pDnode, pVnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeApplyQueue(pDnode, pVnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeSyncQueue(pDnode, pVnode) != 0) {
|
||||
if (dndAllocVnodeQueue(pDnode, pVnode) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -192,11 +161,10 @@ static void dndCloseVnode(SDnode *pDnode, SVnodeObj *pVnode) {
|
|||
while (!taosQueueEmpty(pVnode->pQueryQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(pVnode->pFetchQ)) taosMsleep(10);
|
||||
|
||||
dndFreeVnodeQueryQueue(pDnode, pVnode);
|
||||
dndFreeVnodeFetchQueue(pDnode, pVnode);
|
||||
dndFreeVnodeWriteQueue(pDnode, pVnode);
|
||||
dndFreeVnodeApplyQueue(pDnode, pVnode);
|
||||
dndFreeVnodeSyncQueue(pDnode, pVnode);
|
||||
dndFreeVnodeQueue(pDnode, pVnode);
|
||||
vnodeClose(pVnode->pImpl);
|
||||
pVnode->pImpl = NULL;
|
||||
|
||||
free(pVnode->path);
|
||||
free(pVnode->db);
|
||||
free(pVnode);
|
||||
|
@ -388,7 +356,7 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode) {
|
|||
free(pVnodes);
|
||||
}
|
||||
|
||||
dInfo("successed to write %s", file);
|
||||
dDebug("successed to write %s", realfile);
|
||||
return taosRenameFile(file, realfile);
|
||||
}
|
||||
|
||||
|
@ -408,7 +376,10 @@ static void *dnodeOpenVnodeFunc(void *param) {
|
|||
pMgmt->openVnodes, pMgmt->totalVnodes);
|
||||
dndReportStartup(pDnode, "open-vnodes", stepDesc);
|
||||
|
||||
SVnode *pImpl = vnodeOpen(pCfg->path, NULL);
|
||||
SVnodeCfg vnodeCfg = {0};
|
||||
vnodeCfg.vgId = pCfg->vgId;
|
||||
|
||||
SVnode *pImpl = vnodeOpen(pCfg->path, &vnodeCfg);
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to open vnode by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
|
@ -504,7 +475,6 @@ static void dndCloseVnodes(SDnode *pDnode) {
|
|||
SVnodeObj **pVnodes = dndGetVnodesFromHash(pDnode, &numOfVnodes);
|
||||
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
dndReleaseVnode(pDnode, pVnodes[i]);
|
||||
dndCloseVnode(pDnode, pVnodes[i]);
|
||||
}
|
||||
|
||||
|
@ -520,8 +490,8 @@ static void dndCloseVnodes(SDnode *pDnode) {
|
|||
dInfo("total vnodes:%d are all closed", numOfVnodes);
|
||||
}
|
||||
|
||||
static SCreateVnodeMsg *dndParseCreateVnodeReq(SRpcMsg *rpcMsg) {
|
||||
SCreateVnodeMsg *pCreate = rpcMsg->pCont;
|
||||
static SCreateVnodeReq *dndParseCreateVnodeReq(SRpcMsg *pReq) {
|
||||
SCreateVnodeReq *pCreate = pReq->pCont;
|
||||
pCreate->vgId = htonl(pCreate->vgId);
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
pCreate->dbUid = htobe64(pCreate->dbUid);
|
||||
|
@ -545,7 +515,8 @@ static SCreateVnodeMsg *dndParseCreateVnodeReq(SRpcMsg *rpcMsg) {
|
|||
return pCreate;
|
||||
}
|
||||
|
||||
static void dndGenerateVnodeCfg(SCreateVnodeMsg *pCreate, SVnodeCfg *pCfg) {
|
||||
static void dndGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
||||
pCfg->vgId = pCreate->vgId;
|
||||
pCfg->wsize = pCreate->cacheBlockSize;
|
||||
pCfg->ssize = pCreate->cacheBlockSize;
|
||||
pCfg->wsize = pCreate->cacheBlockSize;
|
||||
|
@ -554,7 +525,7 @@ static void dndGenerateVnodeCfg(SCreateVnodeMsg *pCreate, SVnodeCfg *pCfg) {
|
|||
pCfg->ttl = 4;
|
||||
pCfg->keep = pCreate->daysToKeep0;
|
||||
pCfg->isWeak = true;
|
||||
pCfg->tsdbCfg.keep0 = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.keep = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.keep1 = pCreate->daysToKeep2;
|
||||
pCfg->tsdbCfg.keep2 = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.lruCacheSize = pCreate->cacheBlockSize;
|
||||
|
@ -568,7 +539,7 @@ static void dndGenerateVnodeCfg(SCreateVnodeMsg *pCreate, SVnodeCfg *pCfg) {
|
|||
pCfg->walCfg.vgId = pCreate->vgId;
|
||||
}
|
||||
|
||||
static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeMsg *pCreate, SWrapperCfg *pCfg) {
|
||||
static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeReq *pCreate, SWrapperCfg *pCfg) {
|
||||
memcpy(pCfg->db, pCreate->db, TSDB_DB_FNAME_LEN);
|
||||
pCfg->dbUid = pCreate->dbUid;
|
||||
pCfg->dropped = 0;
|
||||
|
@ -577,20 +548,20 @@ static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeMsg *pCreate, SWra
|
|||
pCfg->vgVersion = pCreate->vgVersion;
|
||||
}
|
||||
|
||||
static SDropVnodeMsg *vnodeParseDropVnodeReq(SRpcMsg *rpcMsg) {
|
||||
SDropVnodeMsg *pDrop = rpcMsg->pCont;
|
||||
static SDropVnodeReq *vnodeParseDropVnodeReq(SRpcMsg *pReq) {
|
||||
SDropVnodeReq *pDrop = pReq->pCont;
|
||||
pDrop->vgId = htonl(pDrop->vgId);
|
||||
return pDrop;
|
||||
}
|
||||
|
||||
static SAuthVnodeMsg *vnodeParseAuthVnodeReq(SRpcMsg *rpcMsg) {
|
||||
SAuthVnodeMsg *pAuth = rpcMsg->pCont;
|
||||
static SAuthVnodeReq *vnodeParseAuthVnodeReq(SRpcMsg *pReq) {
|
||||
SAuthVnodeReq *pAuth = pReq->pCont;
|
||||
pAuth->vgId = htonl(pAuth->vgId);
|
||||
return pAuth;
|
||||
}
|
||||
|
||||
int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SCreateVnodeMsg *pCreate = dndParseCreateVnodeReq(rpcMsg);
|
||||
int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SCreateVnodeReq *pCreate = dndParseCreateVnodeReq(pReq);
|
||||
dDebug("vgId:%d, create vnode req is received", pCreate->vgId);
|
||||
|
||||
SVnodeCfg vnodeCfg = {0};
|
||||
|
@ -603,16 +574,19 @@ int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
if (pVnode != NULL) {
|
||||
dDebug("vgId:%d, already exist, return success", pCreate->vgId);
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
terrno = TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SVnode *pImpl = vnodeOpen(wrapperCfg.path, NULL /*pCfg*/);
|
||||
SVnode *pImpl = vnodeOpen(wrapperCfg.path, &vnodeCfg);
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to create vnode since %s", pCreate->vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = dndOpenVnode(pDnode, &wrapperCfg, pImpl);
|
||||
if (code != 0) {
|
||||
dError("vgId:%d, failed to open vnode since %s", pCreate->vgId, terrstr());
|
||||
vnodeClose(pImpl);
|
||||
vnodeDestroy(wrapperCfg.path);
|
||||
terrno = code;
|
||||
|
@ -630,23 +604,20 @@ int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SAlterVnodeMsg *pAlter = (SAlterVnodeMsg *)dndParseCreateVnodeReq(rpcMsg);
|
||||
int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SAlterVnodeReq *pAlter = (SAlterVnodeReq *)dndParseCreateVnodeReq(pReq);
|
||||
dDebug("vgId:%d, alter vnode req is received", pAlter->vgId);
|
||||
|
||||
SVnodeCfg vnodeCfg = {0};
|
||||
dndGenerateVnodeCfg(pAlter, &vnodeCfg);
|
||||
|
||||
SWrapperCfg wrapperCfg = {0};
|
||||
dndGenerateWrapperCfg(pDnode, pAlter, &wrapperCfg);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, pAlter->vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to alter vnode since %s", pAlter->vgId, terrstr());
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (wrapperCfg.vgVersion == pVnode->vgVersion) {
|
||||
if (pAlter->vgVersion == pVnode->vgVersion) {
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
dDebug("vgId:%d, no need to alter vnode cfg for version unchanged ", pAlter->vgId);
|
||||
return 0;
|
||||
|
@ -655,11 +626,11 @@ int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
if (vnodeAlter(pVnode->pImpl, &vnodeCfg) != 0) {
|
||||
dError("vgId:%d, failed to alter vnode since %s", pAlter->vgId, terrstr());
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t oldVersion = pVnode->vgVersion;
|
||||
pVnode->vgVersion = wrapperCfg.vgVersion;
|
||||
pVnode->vgVersion = pAlter->vgVersion;
|
||||
int32_t code = dndWriteVnodesToFile(pDnode);
|
||||
if (code != 0) {
|
||||
pVnode->vgVersion = oldVersion;
|
||||
|
@ -669,8 +640,8 @@ int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SDropVnodeMsg *pDrop = vnodeParseDropVnodeReq(rpcMsg);
|
||||
int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SDropVnodeReq *pDrop = vnodeParseDropVnodeReq(pReq);
|
||||
|
||||
int32_t vgId = pDrop->vgId;
|
||||
dDebug("vgId:%d, drop vnode req is received", vgId);
|
||||
|
@ -684,10 +655,10 @@ int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
pVnode->dropped = 1;
|
||||
if (dndWriteVnodesToFile(pDnode) != 0) {
|
||||
pVnode->dropped = 0;
|
||||
return terrno;
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
dndCloseVnode(pDnode, pVnode);
|
||||
vnodeClose(pVnode->pImpl);
|
||||
vnodeDestroy(pVnode->path);
|
||||
|
@ -696,17 +667,16 @@ int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SAuthVnodeMsg *pAuth = (SAuthVnodeMsg *)vnodeParseAuthVnodeReq(rpcMsg);
|
||||
int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SAuthVnodeReq *pAuth = (SAuthVnodeReq *)vnodeParseAuthVnodeReq(pReq);
|
||||
|
||||
int32_t code = 0;
|
||||
int32_t vgId = pAuth->vgId;
|
||||
dDebug("vgId:%d, auth vnode req is received", vgId);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to auth since %s", vgId, terrstr());
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pVnode->accessState = pAuth->accessState;
|
||||
|
@ -714,30 +684,30 @@ int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SAuthVnodeMsg *pAuth = (SAuthVnodeMsg *)vnodeParseAuthVnodeReq(rpcMsg);
|
||||
int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SSyncVnodeReq *pSync = (SSyncVnodeReq *)vnodeParseDropVnodeReq(pReq);
|
||||
|
||||
int32_t vgId = pAuth->vgId;
|
||||
dDebug("vgId:%d, auth vnode req is received", vgId);
|
||||
int32_t vgId = pSync->vgId;
|
||||
dDebug("vgId:%d, sync vnode req is received", vgId);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to auth since %s", vgId, terrstr());
|
||||
return terrno;
|
||||
dDebug("vgId:%d, failed to sync since %s", vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vnodeSync(pVnode->pImpl) != 0) {
|
||||
dError("vgId:%d, failed to auth vnode since %s", vgId, terrstr());
|
||||
dError("vgId:%d, failed to sync vnode since %s", vgId, terrstr());
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SCompactVnodeMsg *pCompact = (SCompactVnodeMsg *)vnodeParseDropVnodeReq(rpcMsg);
|
||||
int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SCompactVnodeReq *pCompact = (SCompactVnodeReq *)vnodeParseDropVnodeReq(pReq);
|
||||
|
||||
int32_t vgId = pCompact->vgId;
|
||||
dDebug("vgId:%d, compact vnode req is received", vgId);
|
||||
|
@ -745,13 +715,13 @@ int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to compact since %s", vgId, terrstr());
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vnodeCompact(pVnode->pImpl) != 0) {
|
||||
dError("vgId:%d, failed to compact vnode since %s", vgId, terrstr());
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
|
@ -810,6 +780,7 @@ static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, STaosQall *qall, int32_
|
|||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
|
||||
// todo
|
||||
SRpcMsg *pRsp = NULL;
|
||||
(void)vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp);
|
||||
}
|
||||
|
@ -821,6 +792,7 @@ static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, STaosQall *qall, int32_t
|
|||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
|
||||
// todo
|
||||
SRpcMsg *pRsp = NULL;
|
||||
(void)vnodeProcessSyncReq(pVnode->pImpl, pMsg, &pRsp);
|
||||
}
|
||||
|
@ -844,21 +816,25 @@ static int32_t dndWriteRpcMsgToVnodeQueue(STaosQueue *pQueue, SRpcMsg *pRpcMsg)
|
|||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
if (pRpcMsg->msgType & 1u) {
|
||||
SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static SVnodeObj *dndAcquireVnodeFromMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
SMsgHead *pHead = (SMsgHead *)pMsg->pCont;
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, pHead->vgId);
|
||||
if (pVnode == NULL) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = TSDB_CODE_VND_INVALID_VGROUP_ID};
|
||||
rpcSendResponse(&rsp);
|
||||
if (pMsg->msgType & 1u) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = TSDB_CODE_VND_INVALID_VGROUP_ID};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
|
@ -899,193 +875,96 @@ void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
|
||||
static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SRpcMsg *pMsg) {
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (pVnode == NULL) return -1;
|
||||
|
||||
int32_t code = taosWriteQitem(pVnode->pApplyQ, pMsg);
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pQueryQ = tWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FProcessItem)dndProcessVnodeQueryQueue);
|
||||
if (pVnode->pQueryQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
|
||||
pVnode->pQueryQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pFetchQ = tWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FProcessItem)dndProcessVnodeFetchQueue);
|
||||
if (pVnode->pFetchQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
|
||||
pVnode->pFetchQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitVnodeReadWorker(SDnode *pDnode) {
|
||||
static int32_t dndInitVnodeWorkers(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
||||
int32_t maxFetchThreads = 4;
|
||||
float threadsForQuery = MAX(pDnode->opt.numOfCores * pDnode->opt.ratioOfQueryCores, 1);
|
||||
int32_t minFetchThreads = MIN(maxFetchThreads, pDnode->opt.numOfCores);
|
||||
int32_t minQueryThreads = MAX((int32_t)(pDnode->opt.numOfCores * pDnode->opt.ratioOfQueryCores), 1);
|
||||
int32_t maxQueryThreads = minQueryThreads;
|
||||
int32_t maxWriteThreads = MAX(pDnode->opt.numOfCores, 1);
|
||||
int32_t maxSyncThreads = MAX(pDnode->opt.numOfCores / 2, 1);
|
||||
|
||||
SWorkerPool *pPool = &pMgmt->queryPool;
|
||||
pPool->name = "vnode-query";
|
||||
pPool->min = (int32_t)threadsForQuery;
|
||||
pPool->max = pPool->min;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pPool->min = minQueryThreads;
|
||||
pPool->max = maxQueryThreads;
|
||||
if (tWorkerInit(pPool) != 0) return -1;
|
||||
|
||||
pPool = &pMgmt->fetchPool;
|
||||
pPool->name = "vnode-fetch";
|
||||
pPool->min = MIN(maxFetchThreads, pDnode->opt.numOfCores);
|
||||
pPool->max = pPool->min;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pPool->min = minFetchThreads;
|
||||
pPool->max = maxFetchThreads;
|
||||
if (tWorkerInit(pPool) != 0) return -1;
|
||||
|
||||
dDebug("vnode read worker is initialized");
|
||||
SMWorkerPool *pMPool = &pMgmt->writePool;
|
||||
pMPool->name = "vnode-write";
|
||||
pMPool->max = maxWriteThreads;
|
||||
if (tMWorkerInit(pMPool) != 0) return -1;
|
||||
|
||||
pMPool = &pMgmt->syncPool;
|
||||
pMPool->name = "vnode-sync";
|
||||
pMPool->max = maxSyncThreads;
|
||||
if (tMWorkerInit(pMPool) != 0) return -1;
|
||||
|
||||
dDebug("vnode workers is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupVnodeReadWorker(SDnode *pDnode) {
|
||||
static void dndCleanupVnodeWorkers(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tWorkerCleanup(&pMgmt->fetchPool);
|
||||
tWorkerCleanup(&pMgmt->queryPool);
|
||||
dDebug("vnode close worker is initialized");
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pWriteQ = tMWorkerAllocQueue(&pMgmt->writePool, pVnode, (FProcessItems)dndProcessVnodeWriteQueue);
|
||||
if (pVnode->pWriteQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerFreeQueue(&pMgmt->writePool, pVnode->pWriteQ);
|
||||
pVnode->pWriteQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pApplyQ = tMWorkerAllocQueue(&pMgmt->writePool, pVnode, (FProcessItems)dndProcessVnodeApplyQueue);
|
||||
if (pVnode->pApplyQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerFreeQueue(&pMgmt->writePool, pVnode->pApplyQ);
|
||||
pVnode->pApplyQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
SMWorkerPool *pPool = &pMgmt->writePool;
|
||||
pPool->name = "vnode-write";
|
||||
pPool->max = pDnode->opt.numOfCores;
|
||||
if (tMWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("vnode write worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupVnodeWriteWorker(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerCleanup(&pMgmt->writePool);
|
||||
dDebug("vnode write worker is closed");
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pSyncQ = tMWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FProcessItems)dndProcessVnodeSyncQueue);
|
||||
if (pVnode->pSyncQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ);
|
||||
pVnode->pSyncQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitVnodeSyncWorker(SDnode *pDnode) {
|
||||
int32_t maxThreads = pDnode->opt.numOfCores / 2;
|
||||
if (maxThreads < 1) maxThreads = 1;
|
||||
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
SMWorkerPool *pPool = &pMgmt->syncPool;
|
||||
pPool->name = "vnode-sync";
|
||||
pPool->max = maxThreads;
|
||||
if (tMWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("vnode sync worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupVnodeSyncWorker(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerCleanup(&pMgmt->syncPool);
|
||||
dDebug("vnode sync worker is closed");
|
||||
dDebug("vnode workers is closed");
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
||||
pVnode->pWriteQ = tMWorkerAllocQueue(&pMgmt->writePool, pVnode, (FProcessItems)dndProcessVnodeWriteQueue);
|
||||
pVnode->pApplyQ = tMWorkerAllocQueue(&pMgmt->writePool, pVnode, (FProcessItems)dndProcessVnodeApplyQueue);
|
||||
pVnode->pSyncQ = tMWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FProcessItems)dndProcessVnodeSyncQueue);
|
||||
pVnode->pFetchQ = tWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FProcessItem)dndProcessVnodeFetchQueue);
|
||||
pVnode->pQueryQ = tWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FProcessItem)dndProcessVnodeQueryQueue);
|
||||
|
||||
if (pVnode->pApplyQ == NULL || pVnode->pWriteQ == NULL || pVnode->pSyncQ == NULL || pVnode->pFetchQ == NULL ||
|
||||
pVnode->pQueryQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
|
||||
tWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
|
||||
tMWorkerFreeQueue(&pMgmt->writePool, pVnode->pWriteQ);
|
||||
tMWorkerFreeQueue(&pMgmt->writePool, pVnode->pApplyQ);
|
||||
tMWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ);
|
||||
pVnode->pWriteQ = NULL;
|
||||
pVnode->pApplyQ = NULL;
|
||||
pVnode->pSyncQ = NULL;
|
||||
pVnode->pFetchQ = NULL;
|
||||
pVnode->pQueryQ = NULL;
|
||||
}
|
||||
|
||||
int32_t dndInitVnodes(SDnode *pDnode) {
|
||||
dInfo("dnode-vnodes start to init");
|
||||
|
||||
if (dndInitVnodeReadWorker(pDnode) != 0) {
|
||||
dError("failed to init vnodes read worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitVnodeWriteWorker(pDnode) != 0) {
|
||||
dError("failed to init vnodes write worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitVnodeSyncWorker(pDnode) != 0) {
|
||||
dError("failed to init vnodes sync worker since %s", terrstr());
|
||||
if (dndInitVnodeWorkers(pDnode) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
dError("failed to init vnode workers since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1101,9 +980,7 @@ int32_t dndInitVnodes(SDnode *pDnode) {
|
|||
void dndCleanupVnodes(SDnode *pDnode) {
|
||||
dInfo("dnode-vnodes start to clean up");
|
||||
dndCloseVnodes(pDnode);
|
||||
dndCleanupVnodeReadWorker(pDnode);
|
||||
dndCleanupVnodeWriteWorker(pDnode);
|
||||
dndCleanupVnodeSyncWorker(pDnode);
|
||||
dndCleanupVnodeWorkers(pDnode);
|
||||
dInfo("dnode-vnodes is cleaned up");
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,9 @@ int32_t dndWriteMsgToWorker(SDnodeWorker *pWorker, void *pCont, int32_t contLen)
|
|||
}
|
||||
|
||||
if (taosWriteQitem(pWorker->queue, pMsg) != 0) {
|
||||
taosFreeQitem(pMsg);
|
||||
if (contLen != 0) {
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndBnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndMnode.h"
|
||||
#include "dndQnode.h"
|
||||
#include "dndSnode.h"
|
||||
|
|
|
@ -3,18 +3,6 @@ enable_testing()
|
|||
add_subdirectory(qnode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(snode)
|
||||
|
||||
# add_subdirectory(auth)
|
||||
# add_subdirectory(balance)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(dnode)
|
||||
# add_subdirectory(func)
|
||||
add_subdirectory(mnode)
|
||||
add_subdirectory(profile)
|
||||
add_subdirectory(stb)
|
||||
# add_subdirectory(sync)
|
||||
# add_subdirectory(telem)
|
||||
# add_subdirectory(trans)
|
||||
add_subdirectory(vgroup)
|
||||
|
||||
add_subdirectory(vnode)
|
||||
add_subdirectory(sut)
|
||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(DndTestBnode, 01_Create_Bnode) {
|
|||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ID_INVALID);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ TEST_F(DndTestBnode, 01_Drop_Bnode) {
|
|||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ID_INVALID);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. DB_SRC)
|
||||
add_executable(dnode_test_db ${DB_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_db
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_db
|
||||
COMMAND dnode_test_db
|
||||
)
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. DTEST_SRC)
|
||||
add_executable(dnode_test_dnode ${DTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_dnode
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_dnode
|
||||
COMMAND dnode_test_dnode
|
||||
)
|
|
@ -1,261 +0,0 @@
|
|||
/**
|
||||
* @file dnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module dnode-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestDnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_dnode1", 9041);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9041";
|
||||
|
||||
server2.Start("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp);
|
||||
server3.Start("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
||||
server4.Start("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
||||
server5.Start("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
server3.Stop();
|
||||
server4.Stop();
|
||||
server5.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
static TestServer server3;
|
||||
static TestServer server4;
|
||||
static TestServer server5;
|
||||
};
|
||||
|
||||
Testbase DndTestDnode::test;
|
||||
TestServer DndTestDnode::server2;
|
||||
TestServer DndTestDnode::server3;
|
||||
TestServer DndTestDnode::server4;
|
||||
TestServer DndTestDnode::server5;
|
||||
|
||||
TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "support_vnodes");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
|
||||
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
|
||||
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 02_ConfigDnode) {
|
||||
int32_t contLen = sizeof(SCfgDnodeMsg);
|
||||
|
||||
SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->config, "ddebugflag 131");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONFIG_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9042);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
taosMsleep(1300);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9042", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDropDnodeMsg);
|
||||
|
||||
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9043);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9044);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9045);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
CheckInt16(5);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9043", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9044", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9045", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
|
||||
// restart
|
||||
uInfo("stop all server");
|
||||
test.Restart();
|
||||
server2.Restart();
|
||||
server3.Restart();
|
||||
server4.Restart();
|
||||
server5.Restart();
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
CheckInt16(5);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9043", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9044", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9045", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. MTEST_SRC)
|
||||
add_executable(dnode_test_mnode ${MTEST_SRC})
|
||||
aux_source_directory(. DMTEST_SRC)
|
||||
add_executable(dnode_test_mnode ${DMTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_mnode
|
||||
PUBLIC sut
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
/**
|
||||
* @file dmnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module mnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-07
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestMnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_mnode", 9113); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestMnode::test;
|
||||
|
||||
TEST_F(DndTestMnode, 01_Create_Mnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
||||
|
||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
||||
|
||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(2);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
||||
|
||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 2;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
pReq->replicas[1].id = htonl(1);
|
||||
pReq->replicas[1].port = htonl(9114);
|
||||
strcpy(pReq->replicas[1].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 02_Alter_Mnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||
|
||||
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||
|
||||
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(2);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||
|
||||
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 03_Drop_Mnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropMnodeReq);
|
||||
|
||||
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropMnodeReq);
|
||||
|
||||
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropMnodeReq);
|
||||
|
||||
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||
|
||||
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
||||
|
||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 2;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
|
@ -1,301 +0,0 @@
|
|||
/**
|
||||
* @file dnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module dnode-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestMnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_mnode1", 9061);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9061";
|
||||
|
||||
server2.Start("/tmp/dnode_test_mnode2", fqdn, 9062, firstEp);
|
||||
server3.Start("/tmp/dnode_test_mnode3", fqdn, 9063, firstEp);
|
||||
server4.Start("/tmp/dnode_test_mnode4", fqdn, 9064, firstEp);
|
||||
server5.Start("/tmp/dnode_test_mnode5", fqdn, 9065, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
server3.Stop();
|
||||
server4.Stop();
|
||||
server5.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
static TestServer server3;
|
||||
static TestServer server4;
|
||||
static TestServer server5;
|
||||
};
|
||||
|
||||
Testbase DndTestMnode::test;
|
||||
TestServer DndTestMnode::server2;
|
||||
TestServer DndTestMnode::server3;
|
||||
TestServer DndTestMnode::server4;
|
||||
TestServer DndTestMnode::server5;
|
||||
|
||||
TEST_F(DndTestMnode, 01_ShowDnode) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||
CHECK_META("show mnodes", 5);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, 12 + VARSTR_HEADER_SIZE, "role");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
CheckBinary("master", 12);
|
||||
CheckInt64(0);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateMnodeMsg);
|
||||
|
||||
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateMnodeMsg);
|
||||
|
||||
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 04_Create_Mnode) {
|
||||
{
|
||||
// create dnode
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9062);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
// create mnode
|
||||
int32_t contLen = sizeof(SMCreateMnodeMsg);
|
||||
|
||||
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9062", TSDB_EP_LEN);
|
||||
CheckBinary("master", 12);
|
||||
CheckBinary("slave", 12);
|
||||
CheckInt64(0);
|
||||
CheckInt64(0);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
// drop mnode
|
||||
int32_t contLen = sizeof(SMDropMnodeMsg);
|
||||
|
||||
SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
CheckBinary("master", 12);
|
||||
CheckInt64(0);
|
||||
CheckTimestamp();
|
||||
}
|
||||
}
|
||||
// {
|
||||
// int32_t contLen = sizeof(SDropDnodeMsg);
|
||||
|
||||
// SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
|
||||
// pReq->dnodeId = htonl(2);
|
||||
|
||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pRsp, nullptr);
|
||||
// ASSERT_EQ(pRsp->code, 0);
|
||||
// }
|
||||
|
||||
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// CHECK_META("show dnodes", 7);
|
||||
// test.SendShowRetrieveReq();
|
||||
// EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
// CheckInt16(1);
|
||||
// CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(1);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckTimestamp();
|
||||
// CheckBinary("", 24);
|
||||
|
||||
// {
|
||||
// int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
// strcpy(pReq->ep, "localhost:9063");
|
||||
|
||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pRsp, nullptr);
|
||||
// ASSERT_EQ(pRsp->code, 0);
|
||||
// }
|
||||
|
||||
// {
|
||||
// int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
// strcpy(pReq->ep, "localhost:9064");
|
||||
|
||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pRsp, nullptr);
|
||||
// ASSERT_EQ(pRsp->code, 0);
|
||||
// }
|
||||
|
||||
// {
|
||||
// int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
// strcpy(pReq->ep, "localhost:9065");
|
||||
|
||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pRsp, nullptr);
|
||||
// ASSERT_EQ(pRsp->code, 0);
|
||||
// }
|
||||
|
||||
// taosMsleep(1300);
|
||||
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// CHECK_META("show dnodes", 7);
|
||||
// test.SendShowRetrieveReq();
|
||||
// EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(3);
|
||||
// CheckInt16(4);
|
||||
// CheckInt16(5);
|
||||
// CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9063", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9065", TSDB_EP_LEN);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
|
||||
// // restart
|
||||
// uInfo("stop all server");
|
||||
// test.Restart();
|
||||
// server2.Restart();
|
||||
// server3.Restart();
|
||||
// server4.Restart();
|
||||
// server5.Restart();
|
||||
|
||||
// taosMsleep(1300);
|
||||
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// CHECK_META("show dnodes", 7);
|
||||
// test.SendShowRetrieveReq();
|
||||
// EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(3);
|
||||
// CheckInt16(4);
|
||||
// CheckInt16(5);
|
||||
// CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9063", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9065", TSDB_EP_LEN);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// }
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. PROFILE_SRC)
|
||||
add_executable(dnode_test_profile ${PROFILE_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_profile
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_profile
|
||||
COMMAND dnode_test_profile
|
||||
)
|
|
@ -34,7 +34,7 @@ TEST_F(DndTestQnode, 01_Create_Qnode) {
|
|||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ID_INVALID);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ TEST_F(DndTestQnode, 02_Drop_Qnode) {
|
|||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ID_INVALID);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(DndTestSnode, 01_Create_Snode) {
|
|||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ID_INVALID);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ TEST_F(DndTestSnode, 01_Drop_Snode) {
|
|||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ID_INVALID);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "sut.h"
|
||||
|
||||
void Testbase::InitLog(const char* path) {
|
||||
dDebugFlag = 0;
|
||||
dDebugFlag = 143;
|
||||
vDebugFlag = 0;
|
||||
mDebugFlag = 143;
|
||||
cDebugFlag = 0;
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. VGROUP_SRC)
|
||||
add_executable(dnode_test_vgroup ${VGROUP_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_vgroup
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_vgroup
|
||||
COMMAND dnode_test_vgroup
|
||||
)
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. VNODE_SRC)
|
||||
add_executable(dnode_test_vnode ${VNODE_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_vnode
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_vnode
|
||||
COMMAND dnode_test_vnode
|
||||
)
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestVgroup : public ::testing::Test {
|
||||
class DndTestVnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_vgroup", 9150); }
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_vnode", 9150); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
@ -23,14 +23,14 @@ class DndTestVgroup : public ::testing::Test {
|
|||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestVgroup::test;
|
||||
Testbase DndTestVnode::test;
|
||||
|
||||
TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
||||
TEST_F(DndTestVnode, 01_Create_Restart_Drop_Vnode) {
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
int32_t contLen = sizeof(SCreateVnodeMsg);
|
||||
int32_t contLen = sizeof(SCreateVnodeReq);
|
||||
|
||||
SCreateVnodeMsg* pReq = (SCreateVnodeMsg*)rpcMallocCont(contLen);
|
||||
SCreateVnodeReq* pReq = (SCreateVnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->vgId = htonl(2);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
|
@ -68,9 +68,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
|||
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
int32_t contLen = sizeof(SAlterVnodeMsg);
|
||||
int32_t contLen = sizeof(SAlterVnodeReq);
|
||||
|
||||
SAlterVnodeMsg* pReq = (SAlterVnodeMsg*)rpcMallocCont(contLen);
|
||||
SAlterVnodeReq* pReq = (SAlterVnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->vgId = htonl(2);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
|
@ -108,9 +108,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
|||
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
int32_t contLen = sizeof(SDropVnodeMsg);
|
||||
int32_t contLen = sizeof(SDropVnodeReq);
|
||||
|
||||
SDropVnodeMsg* pReq = (SDropVnodeMsg*)rpcMallocCont(contLen);
|
||||
SDropVnodeReq* pReq = (SDropVnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->vgId = htonl(2);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
|
@ -118,7 +118,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
|||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropVnodeMsg);
|
||||
rpcMsg.contLen = sizeof(SDropVnodeReq);
|
||||
rpcMsg.msgType = TDMT_DND_DROP_VNODE;
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_VNODE, pReq, contLen);
|
|
@ -31,8 +31,8 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
|||
SEpSet mndGetVgroupEpset(SMnode *pMnode, SVgObj *pVgroup);
|
||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
||||
|
||||
SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
SCreateVnodeReq *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
SDropVnodeReq *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -331,11 +331,11 @@ static int32_t mndSetCreateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SCreateVnodeMsg *pMsg = mndBuildCreateVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
SCreateVnodeReq *pMsg = mndBuildCreateVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
if (pMsg == NULL) return -1;
|
||||
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SCreateVnodeMsg);
|
||||
action.contLen = sizeof(SCreateVnodeReq);
|
||||
action.msgType = TDMT_DND_CREATE_VNODE;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
|
@ -360,11 +360,11 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SDropVnodeMsg *pMsg = mndBuildDropVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
SDropVnodeReq *pMsg = mndBuildDropVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
if (pMsg == NULL) return -1;
|
||||
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDropVnodeMsg);
|
||||
action.contLen = sizeof(SDropVnodeReq);
|
||||
action.msgType = TDMT_DND_DROP_VNODE;
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
|
@ -593,11 +593,11 @@ static int32_t mndBuildUpdateVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SAlterVnodeMsg *pMsg = (SAlterVnodeMsg *)mndBuildCreateVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
SAlterVnodeReq *pMsg = (SAlterVnodeReq *)mndBuildCreateVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
if (pMsg == NULL) return -1;
|
||||
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SAlterVnodeMsg);
|
||||
action.contLen = sizeof(SAlterVnodeReq);
|
||||
action.msgType = TDMT_DND_ALTER_VNODE;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
|
@ -757,11 +757,11 @@ static int32_t mndBuildDropVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *
|
|||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SDropVnodeMsg *pMsg = mndBuildDropVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
SDropVnodeReq *pMsg = mndBuildDropVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
if (pMsg == NULL) return -1;
|
||||
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SCreateVnodeMsg);
|
||||
action.contLen = sizeof(SCreateVnodeReq);
|
||||
action.msgType = TDMT_DND_DROP_VNODE;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
|
@ -917,6 +917,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
|
|||
}
|
||||
|
||||
memcpy(pRsp->db, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
pRsp->uid = htobe64(pDb->uid);
|
||||
pRsp->vgVersion = htonl(pDb->vgVersion);
|
||||
pRsp->vgNum = htonl(vindex);
|
||||
pRsp->hashMethod = pDb->hashMethod;
|
||||
|
|
|
@ -45,19 +45,19 @@ static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode);
|
|||
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode);
|
||||
static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode);
|
||||
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOldDnode, SDnodeObj *pNewDnode);
|
||||
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew);
|
||||
|
||||
static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropDnodeMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessConfigDnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessCreateDnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessDropDnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessConfigDnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessConfigDnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndProcessStatusReq(SMnodeMsg *pReq);
|
||||
|
||||
static int32_t mndGetConfigMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveConfigs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndGetConfigMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveConfigs(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextConfig(SMnode *pMnode, void *pIter);
|
||||
static int32_t mndGetDnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndGetDnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveDnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextDnode(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitDnode(SMnode *pMnode) {
|
||||
|
@ -70,11 +70,11 @@ int32_t mndInitDnode(SMnode *pMnode) {
|
|||
.updateFp = (SdbUpdateFp)mndDnodeActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndDnodeActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_DNODE, mndProcessCreateDnodeMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_DNODE, mndProcessDropDnodeMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_DNODE, mndProcessCreateDnodeReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_DNODE, mndProcessDropDnodeReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusReq);
|
||||
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndGetConfigMeta);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndRetrieveConfigs);
|
||||
|
@ -182,9 +182,9 @@ static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOldDnode, SDnodeObj *pNewDnode) {
|
||||
mTrace("dnode:%d, perform update action, old_row:%p new_row:%p", pOldDnode->id, pOldDnode, pNewDnode);
|
||||
pOldDnode->updateTime = pNewDnode->updateTime;
|
||||
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew) {
|
||||
mTrace("dnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -244,22 +244,22 @@ bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static void mndGetDnodeData(SMnode *pMnode, SDnodeEps *pEps, int32_t numOfEps) {
|
||||
static void mndGetDnodeData(SMnode *pMnode, SDnodeEps *pEps, int32_t maxEps) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
int32_t i = 0;
|
||||
int32_t numOfEps = 0;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
SDnodeObj *pDnode = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
|
||||
if (pIter == NULL) break;
|
||||
if (i >= numOfEps) {
|
||||
if (numOfEps >= maxEps) {
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pDnode);
|
||||
break;
|
||||
}
|
||||
|
||||
SDnodeEp *pEp = &pEps->eps[i];
|
||||
SDnodeEp *pEp = &pEps->eps[numOfEps];
|
||||
pEp->id = htonl(pDnode->id);
|
||||
pEp->port = htons(pDnode->port);
|
||||
memcpy(pEp->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
@ -267,11 +267,11 @@ static void mndGetDnodeData(SMnode *pMnode, SDnodeEps *pEps, int32_t numOfEps) {
|
|||
if (mndIsMnode(pMnode, pDnode->id)) {
|
||||
pEp->isMnode = 1;
|
||||
}
|
||||
i++;
|
||||
numOfEps++;
|
||||
sdbRelease(pSdb, pDnode);
|
||||
}
|
||||
|
||||
pEps->num = htonl(i);
|
||||
pEps->num = htonl(numOfEps);
|
||||
}
|
||||
|
||||
static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
|
||||
|
@ -299,8 +299,9 @@ static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void mndParseStatusMsg(SStatusMsg *pStatus) {
|
||||
static void mndParseStatusMsg(SStatusReq *pStatus) {
|
||||
pStatus->sver = htonl(pStatus->sver);
|
||||
pStatus->dver = htobe64(pStatus->dver);
|
||||
pStatus->dnodeId = htonl(pStatus->dnodeId);
|
||||
pStatus->clusterId = htobe64(pStatus->clusterId);
|
||||
pStatus->rebootTime = htobe64(pStatus->rebootTime);
|
||||
|
@ -309,11 +310,19 @@ static void mndParseStatusMsg(SStatusMsg *pStatus) {
|
|||
pStatus->numOfSupportVnodes = htonl(pStatus->numOfSupportVnodes);
|
||||
pStatus->clusterCfg.statusInterval = htonl(pStatus->clusterCfg.statusInterval);
|
||||
pStatus->clusterCfg.checkTime = htobe64(pStatus->clusterCfg.checkTime);
|
||||
for (int32_t v = 0; v < pStatus->vnodeLoads.num; ++v) {
|
||||
SVnodeLoad *pVload = &pStatus->vnodeLoads.data[v];
|
||||
pVload->vgId = htonl(pVload->vgId);
|
||||
pVload->totalStorage = htobe64(pVload->totalStorage);
|
||||
pVload->compStorage = htobe64(pVload->compStorage);
|
||||
pVload->pointsWritten = htobe64(pVload->pointsWritten);
|
||||
pVload->tablesNum = htobe64(pVload->tablesNum);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SStatusMsg *pStatus = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessStatusReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SStatusReq *pStatus = pReq->rpcMsg.pCont;
|
||||
SDnodeObj *pDnode = NULL;
|
||||
int32_t code = -1;
|
||||
|
||||
|
@ -341,9 +350,11 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
bool online = mndIsDnodeOnline(pMnode, pDnode, curMs);
|
||||
bool needCheckCfg = !(online && pDnode->rebootTime == pStatus->rebootTime);
|
||||
bool dnodeChanged = (pStatus->dver != sdbGetTableVer(pMnode->pSdb, SDB_DNODE));
|
||||
bool reboot = (pDnode->rebootTime != pStatus->rebootTime);
|
||||
bool needCheck = !online || dnodeChanged || reboot;
|
||||
|
||||
if (needCheckCfg) {
|
||||
if (needCheck) {
|
||||
if (pStatus->sver != pMnode->cfg.sver) {
|
||||
if (pDnode != NULL) {
|
||||
pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH;
|
||||
|
@ -379,7 +390,11 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
|
|||
goto PROCESS_STATUS_MSG_OVER;
|
||||
}
|
||||
|
||||
mInfo("dnode:%d, from offline to online", pDnode->id);
|
||||
if (!online) {
|
||||
mInfo("dnode:%d, from offline to online", pDnode->id);
|
||||
} else {
|
||||
mDebug("dnode:%d, send dnode eps", pDnode->id);
|
||||
}
|
||||
|
||||
pDnode->rebootTime = pStatus->rebootTime;
|
||||
pDnode->numOfCores = pStatus->numOfCores;
|
||||
|
@ -393,12 +408,13 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
|
|||
goto PROCESS_STATUS_MSG_OVER;
|
||||
}
|
||||
|
||||
pRsp->dver = htobe64(sdbGetTableVer(pMnode->pSdb, SDB_DNODE));
|
||||
pRsp->dnodeCfg.dnodeId = htonl(pDnode->id);
|
||||
pRsp->dnodeCfg.clusterId = htobe64(pMnode->clusterId);
|
||||
mndGetDnodeData(pMnode, &pRsp->dnodeEps, numOfEps);
|
||||
|
||||
pMsg->contLen = contLen;
|
||||
pMsg->pCont = pRsp;
|
||||
pReq->contLen = contLen;
|
||||
pReq->pCont = pRsp;
|
||||
}
|
||||
|
||||
pDnode->lastAccessTime = curMs;
|
||||
|
@ -409,7 +425,7 @@ PROCESS_STATUS_MSG_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg *pCreate) {
|
||||
static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pReq, SCreateDnodeReq *pCreate) {
|
||||
SDnodeObj dnodeObj = {0};
|
||||
dnodeObj.id = sdbGetMaxId(pMnode->pSdb, SDB_DNODE);
|
||||
dnodeObj.createdTime = taosGetTimestampMs();
|
||||
|
@ -418,7 +434,7 @@ static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg *
|
|||
memcpy(dnodeObj.fqdn, pCreate->fqdn, TSDB_FQDN_LEN);
|
||||
snprintf(dnodeObj.ep, TSDB_EP_LEN, "%s:%u", dnodeObj.fqdn, dnodeObj.port);
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("dnode:%s, failed to create since %s", dnodeObj.ep, terrstr());
|
||||
return -1;
|
||||
|
@ -443,9 +459,9 @@ static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessCreateDnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SCreateDnodeReq *pCreate = pReq->rpcMsg.pCont;
|
||||
pCreate->port = htonl(pCreate->port);
|
||||
mDebug("dnode:%s:%d, start to create", pCreate->fqdn, pCreate->port);
|
||||
|
||||
|
@ -465,7 +481,7 @@ static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndCreateDnode(pMnode, pMsg, pCreate);
|
||||
int32_t code = mndCreateDnode(pMnode, pReq, pCreate);
|
||||
|
||||
if (code != 0) {
|
||||
mError("dnode:%s:%d, failed to create since %s", pCreate->fqdn, pCreate->port, terrstr());
|
||||
|
@ -475,8 +491,8 @@ static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndDropDnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg);
|
||||
static int32_t mndDropDnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("dnode:%d, failed to drop since %s", pDnode->id, terrstr());
|
||||
return -1;
|
||||
|
@ -501,9 +517,9 @@ static int32_t mndDropDnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropDnodeMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SDropDnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessDropDnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SDropDnodeReq *pDrop = pReq->rpcMsg.pCont;
|
||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||
|
||||
mDebug("dnode:%d, start to drop", pDrop->dnodeId);
|
||||
|
@ -521,7 +537,7 @@ static int32_t mndProcessDropDnodeMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndDropDnode(pMnode, pMsg, pDnode);
|
||||
int32_t code = mndDropDnode(pMnode, pReq, pDnode);
|
||||
if (code != 0) {
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
mError("dnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
|
||||
|
@ -532,9 +548,9 @@ static int32_t mndProcessDropDnodeMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SCfgDnodeMsg *pCfg = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessConfigDnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SMCfgDnodeReq *pCfg = pReq->rpcMsg.pCont;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCfg->dnodeId);
|
||||
|
@ -547,14 +563,14 @@ static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg) {
|
|||
SEpSet epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SCfgDnodeMsg *pCfgDnode = rpcMallocCont(sizeof(SCfgDnodeMsg));
|
||||
SDCfgDnodeReq *pCfgDnode = rpcMallocCont(sizeof(SDCfgDnodeReq));
|
||||
pCfgDnode->dnodeId = htonl(pCfg->dnodeId);
|
||||
memcpy(pCfgDnode->config, pCfg->config, TSDB_DNODE_CONFIG_LEN);
|
||||
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE,
|
||||
.pCont = pCfgDnode,
|
||||
.contLen = sizeof(SCfgDnodeMsg),
|
||||
.ahandle = pMsg->rpcMsg.ahandle};
|
||||
.contLen = sizeof(SDCfgDnodeReq),
|
||||
.ahandle = pReq->rpcMsg.ahandle};
|
||||
|
||||
mInfo("dnode:%d, app:%p config:%s req send to dnode", pCfg->dnodeId, rpcMsg.ahandle, pCfg->config);
|
||||
mndSendReqToDnode(pMnode, &epSet, &rpcMsg);
|
||||
|
@ -562,11 +578,11 @@ static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessConfigDnodeRsp(SMnodeMsg *pMsg) {
|
||||
mInfo("app:%p config rsp from dnode", pMsg->rpcMsg.ahandle);
|
||||
static int32_t mndProcessConfigDnodeRsp(SMnodeMsg *pRsp) {
|
||||
mInfo("app:%p config rsp from dnode", pRsp->rpcMsg.ahandle);
|
||||
}
|
||||
|
||||
static int32_t mndGetConfigMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
static int32_t mndGetConfigMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->pSchema;
|
||||
|
||||
|
@ -597,8 +613,8 @@ static int32_t mndGetConfigMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveConfigs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveConfigs(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
int32_t numOfRows = 0;
|
||||
char *cfgOpts[TSDB_CONFIG_NUMBER] = {0};
|
||||
char cfgVals[TSDB_CONFIG_NUMBER][TSDB_CONIIG_VALUE_LEN + 1] = {0};
|
||||
|
@ -640,8 +656,8 @@ static int32_t mndRetrieveConfigs(SMnodeMsg *pMsg, SShowObj *pShow, char *data,
|
|||
|
||||
static void mndCancelGetNextConfig(SMnode *pMnode, void *pIter) {}
|
||||
|
||||
static int32_t mndGetDnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndGetDnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
int32_t cols = 0;
|
||||
|
@ -704,8 +720,8 @@ static int32_t mndGetDnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveDnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
|
|
|
@ -27,14 +27,14 @@ static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj);
|
|||
static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj);
|
||||
static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj);
|
||||
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode);
|
||||
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveMnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOld, SMnodeObj *pNew);
|
||||
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndGetMnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveMnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextMnode(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitMnode(SMnode *pMnode) {
|
||||
|
@ -65,7 +65,7 @@ void mndCleanupMnode(SMnode *pMnode) {}
|
|||
static SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SMnodeObj *pObj = sdbAcquire(pSdb, SDB_MNODE, &mnodeId);
|
||||
if (pObj == NULL) {
|
||||
if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
||||
terrno = TSDB_CODE_MND_MNODE_NOT_EXIST;
|
||||
}
|
||||
return pObj;
|
||||
|
@ -207,9 +207,9 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode) {
|
||||
mTrace("mnode:%d, perform update action, old_row:%p new_row:%p", pOldMnode->id, pOldMnode, pNewMnode);
|
||||
pOldMnode->updateTime = pNewMnode->updateTime;
|
||||
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOld, SMnodeObj *pNew) {
|
||||
mTrace("mnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -277,13 +277,13 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
|||
void *pIter = NULL;
|
||||
int32_t numOfReplicas = 0;
|
||||
|
||||
SDCreateMnodeMsg createMsg = {0};
|
||||
SDCreateMnodeReq createReq = {0};
|
||||
while (1) {
|
||||
SMnodeObj *pMObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SReplica *pReplica = &createMsg.replicas[numOfReplicas];
|
||||
SReplica *pReplica = &createReq.replicas[numOfReplicas];
|
||||
pReplica->id = htonl(pMObj->id);
|
||||
pReplica->port = htons(pMObj->pDnode->port);
|
||||
memcpy(pReplica->fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
@ -292,13 +292,13 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
|||
sdbRelease(pSdb, pMObj);
|
||||
}
|
||||
|
||||
SReplica *pReplica = &createMsg.replicas[numOfReplicas];
|
||||
SReplica *pReplica = &createReq.replicas[numOfReplicas];
|
||||
pReplica->id = htonl(pDnode->id);
|
||||
pReplica->port = htons(pDnode->port);
|
||||
memcpy(pReplica->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
numOfReplicas++;
|
||||
|
||||
createMsg.replica = numOfReplicas;
|
||||
createReq.replica = numOfReplicas;
|
||||
|
||||
while (1) {
|
||||
SMnodeObj *pMObj = NULL;
|
||||
|
@ -307,22 +307,23 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
|||
|
||||
STransAction action = {0};
|
||||
|
||||
SDAlterMnodeMsg *pMsg = malloc(sizeof(SDAlterMnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
SDAlterMnodeReq *pReq = malloc(sizeof(SDAlterMnodeReq));
|
||||
if (pReq == NULL) {
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pMObj);
|
||||
return -1;
|
||||
}
|
||||
memcpy(pMsg, &createMsg, sizeof(SDAlterMnodeMsg));
|
||||
memcpy(pReq, &createReq, sizeof(SDAlterMnodeReq));
|
||||
|
||||
pMsg->dnodeId = htonl(pMObj->id);
|
||||
pReq->dnodeId = htonl(pMObj->id);
|
||||
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDAlterMnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDAlterMnodeReq);
|
||||
action.msgType = TDMT_DND_ALTER_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pMObj);
|
||||
return -1;
|
||||
|
@ -335,17 +336,18 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
|||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
|
||||
SDCreateMnodeMsg *pMsg = malloc(sizeof(SDCreateMnodeMsg));
|
||||
if (pMsg == NULL) return -1;
|
||||
memcpy(pMsg, &createMsg, sizeof(SDAlterMnodeMsg));
|
||||
pMsg->dnodeId = htonl(pObj->id);
|
||||
SDCreateMnodeReq *pReq = malloc(sizeof(SDCreateMnodeReq));
|
||||
if (pReq == NULL) return -1;
|
||||
memcpy(pReq, &createReq, sizeof(SDAlterMnodeReq));
|
||||
pReq->dnodeId = htonl(pObj->id);
|
||||
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDCreateMnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDCreateMnodeReq);
|
||||
action.msgType = TDMT_DND_CREATE_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -353,39 +355,23 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateMnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateMnodeMsg *pCreate) {
|
||||
static int32_t mndCreateMnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateMnodeReq *pCreate) {
|
||||
int32_t code = -1;
|
||||
|
||||
SMnodeObj mnodeObj = {0};
|
||||
mnodeObj.id = pDnode->id;
|
||||
mnodeObj.createdTime = taosGetTimestampMs();
|
||||
mnodeObj.updateTime = mnodeObj.createdTime;
|
||||
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("mnode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||
goto CREATE_MNODE_OVER;
|
||||
}
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto CREATE_MNODE_OVER;
|
||||
|
||||
mDebug("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId);
|
||||
if (mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj) != 0) goto CREATE_MNODE_OVER;
|
||||
if (mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeObj) != 0) goto CREATE_MNODE_OVER;
|
||||
if (mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj) != 0) goto CREATE_MNODE_OVER;
|
||||
|
||||
if (mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_MNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeObj) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_MNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_MNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
goto CREATE_MNODE_OVER;
|
||||
}
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_MNODE_OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
@ -394,9 +380,9 @@ CREATE_MNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMCreateMnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SMCreateMnodeReq *pCreate = pReq->rpcMsg.pCont;
|
||||
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
|
||||
|
@ -408,6 +394,9 @@ static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
|
|||
mError("mnode:%d, mnode already exist", pObj->id);
|
||||
terrno = TSDB_CODE_MND_MNODE_ALREADY_EXIST;
|
||||
return -1;
|
||||
} else if (terrno != TSDB_CODE_MND_MNODE_NOT_EXIST) {
|
||||
mError("qnode:%d, failed to create mnode since %s", pCreate->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
|
||||
|
@ -417,7 +406,7 @@ static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndCreateMnode(pMnode, pMsg, pDnode, pCreate);
|
||||
int32_t code = mndCreateMnode(pMnode, pReq, pDnode, pCreate);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
if (code != 0) {
|
||||
|
@ -449,14 +438,14 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
|||
void *pIter = NULL;
|
||||
int32_t numOfReplicas = 0;
|
||||
|
||||
SDAlterMnodeMsg alterMsg = {0};
|
||||
SDAlterMnodeReq alterReq = {0};
|
||||
while (1) {
|
||||
SMnodeObj *pMObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (pMObj->id != pObj->id) {
|
||||
SReplica *pReplica = &alterMsg.replicas[numOfReplicas];
|
||||
SReplica *pReplica = &alterReq.replicas[numOfReplicas];
|
||||
pReplica->id = htonl(pMObj->id);
|
||||
pReplica->port = htons(pMObj->pDnode->port);
|
||||
memcpy(pReplica->fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
@ -466,7 +455,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
|||
sdbRelease(pSdb, pMObj);
|
||||
}
|
||||
|
||||
alterMsg.replica = numOfReplicas;
|
||||
alterReq.replica = numOfReplicas;
|
||||
|
||||
while (1) {
|
||||
SMnodeObj *pMObj = NULL;
|
||||
|
@ -475,22 +464,23 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
|||
if (pMObj->id != pObj->id) {
|
||||
STransAction action = {0};
|
||||
|
||||
SDAlterMnodeMsg *pMsg = malloc(sizeof(SDAlterMnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
SDAlterMnodeReq *pReq = malloc(sizeof(SDAlterMnodeReq));
|
||||
if (pReq == NULL) {
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pMObj);
|
||||
return -1;
|
||||
}
|
||||
memcpy(pMsg, &alterMsg, sizeof(SDAlterMnodeMsg));
|
||||
memcpy(pReq, &alterReq, sizeof(SDAlterMnodeReq));
|
||||
|
||||
pMsg->dnodeId = htonl(pMObj->id);
|
||||
pReq->dnodeId = htonl(pMObj->id);
|
||||
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDAlterMnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDAlterMnodeReq);
|
||||
action.msgType = TDMT_DND_ALTER_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pMObj);
|
||||
return -1;
|
||||
|
@ -504,19 +494,20 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
|||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
|
||||
SDDropMnodeMsg *pMsg = malloc(sizeof(SDDropMnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
SDDropMnodeReq *pReq = malloc(sizeof(SDDropMnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pMsg->dnodeId = htonl(pObj->id);
|
||||
pReq->dnodeId = htonl(pObj->id);
|
||||
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDDropMnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDDropMnodeReq);
|
||||
action.msgType = TDMT_DND_DROP_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -524,35 +515,18 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDropMnode(SMnode *pMnode, SMnodeMsg *pMsg, SMnodeObj *pObj) {
|
||||
static int32_t mndDropMnode(SMnode *pMnode, SMnodeMsg *pReq, SMnodeObj *pObj) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("mnode:%d, failed to drop since %s", pObj->id, terrstr());
|
||||
goto DROP_MNODE_OVER;
|
||||
}
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto DROP_MNODE_OVER;
|
||||
|
||||
mDebug("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
||||
|
||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto DROP_MNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto DROP_MNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto DROP_MNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
goto DROP_MNODE_OVER;
|
||||
}
|
||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) goto DROP_MNODE_OVER;
|
||||
if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) goto DROP_MNODE_OVER;
|
||||
if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj) != 0) goto DROP_MNODE_OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_MNODE_OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
@ -561,9 +535,9 @@ DROP_MNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMDropMnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SMDropMnodeReq *pDrop = pReq->rpcMsg.pCont;
|
||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||
|
||||
mDebug("mnode:%d, start to drop", pDrop->dnodeId);
|
||||
|
@ -577,12 +551,10 @@ static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
|
|||
SMnodeObj *pObj = mndAcquireMnode(pMnode, pDrop->dnodeId);
|
||||
if (pObj == NULL) {
|
||||
mError("mnode:%d, not exist", pDrop->dnodeId);
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndDropMnode(pMnode, pMsg, pObj);
|
||||
|
||||
int32_t code = mndDropMnode(pMnode, pReq, pObj);
|
||||
if (code != 0) {
|
||||
mError("mnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
||||
return -1;
|
||||
|
@ -592,23 +564,23 @@ static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransProcessRsp(pMsg);
|
||||
static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransProcessRsp(pMsg);
|
||||
static int32_t mndProcessAlterMnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransProcessRsp(pMsg);
|
||||
static int32_t mndProcessDropMnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndGetMnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
int32_t cols = 0;
|
||||
|
@ -660,8 +632,8 @@ static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveMnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveMnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
|
|
|
@ -47,14 +47,14 @@ static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId);
|
|||
static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn);
|
||||
static void *mndGetNextConn(SMnode *pMnode, void *pIter, SConnObj **pConn);
|
||||
static void mndCancelGetNextConn(SMnode *pMnode, void *pIter);
|
||||
static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessKillQueryMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessKillConnectionMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveConns(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveQueries(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessConnectReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessKillQueryReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessKillConnReq(SMnodeMsg *pReq);
|
||||
static int32_t mndGetConnsMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveConns(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndGetQueryMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveQueries(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitProfile(SMnode *pMnode) {
|
||||
|
@ -68,10 +68,10 @@ int32_t mndInitProfile(SMnode *pMnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_HEARTBEAT, mndProcessHeartBeatMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CONNECT, mndProcessConnectMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_KILL_QUERY, mndProcessKillQueryMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_KILL_CONN, mndProcessKillConnectionMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_HEARTBEAT, mndProcessHeartBeatReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CONNECT, mndProcessConnectReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_KILL_QUERY, mndProcessKillQueryReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_KILL_CONN, mndProcessKillConnReq);
|
||||
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndGetConnsMeta);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndRetrieveConns);
|
||||
|
@ -178,35 +178,35 @@ static void mndCancelGetNextConn(SMnode *pMnode, void *pIter) {
|
|||
taosHashCancelIterate(pMgmt->cache->pHashTable, pIter);
|
||||
}
|
||||
|
||||
static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SConnectMsg *pReq = pMsg->rpcMsg.pCont;
|
||||
pReq->pid = htonl(pReq->pid);
|
||||
pReq->startTime = htobe64(pReq->startTime);
|
||||
static int32_t mndProcessConnectReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SConnectReq *pConnReq = pReq->rpcMsg.pCont;
|
||||
pConnReq->pid = htonl(pConnReq->pid);
|
||||
pConnReq->startTime = htobe64(pConnReq->startTime);
|
||||
|
||||
SRpcConnInfo info = {0};
|
||||
if (rpcGetConnInfo(pMsg->rpcMsg.handle, &info) != 0) {
|
||||
mError("user:%s, failed to login while get connection info since %s", pMsg->user, terrstr());
|
||||
if (rpcGetConnInfo(pReq->rpcMsg.handle, &info) != 0) {
|
||||
mError("user:%s, failed to login while get connection info since %s", pReq->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
char ip[30];
|
||||
taosIp2String(info.clientIp, ip);
|
||||
|
||||
if (pReq->db[0]) {
|
||||
snprintf(pMsg->db, TSDB_DB_FNAME_LEN, "%d%s%s", pMsg->acctId, TS_PATH_DELIMITER, pReq->db);
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db);
|
||||
if (pConnReq->db[0]) {
|
||||
snprintf(pReq->db, TSDB_DB_FNAME_LEN, "%d%s%s", pReq->acctId, TS_PATH_DELIMITER, pConnReq->db);
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pReq->db);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB;
|
||||
mError("user:%s, failed to login from %s while use db:%s since %s", pMsg->user, ip, pReq->db, terrstr());
|
||||
mError("user:%s, failed to login from %s while use db:%s since %s", pReq->user, ip, pConnReq->db, terrstr());
|
||||
return -1;
|
||||
}
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
}
|
||||
|
||||
SConnObj *pConn = mndCreateConn(pMnode, &info, pReq->pid, pReq->app, pReq->startTime);
|
||||
SConnObj *pConn = mndCreateConn(pMnode, &info, pConnReq->pid, pConnReq->app, pConnReq->startTime);
|
||||
if (pConn == NULL) {
|
||||
mError("user:%s, failed to login from %s while create connection since %s", pMsg->user, ip, terrstr());
|
||||
mError("user:%s, failed to login from %s while create connection since %s", pReq->user, ip, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -214,11 +214,11 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) {
|
|||
if (pRsp == NULL) {
|
||||
mndReleaseConn(pMnode, pConn);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("user:%s, failed to login from %s while create rsp since %s", pMsg->user, ip, terrstr());
|
||||
mError("user:%s, failed to login from %s while create rsp since %s", pReq->user, ip, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pUser != NULL) {
|
||||
pRsp->acctId = htonl(pUser->acctId);
|
||||
pRsp->superUser = pUser->superUser;
|
||||
|
@ -230,16 +230,16 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) {
|
|||
mndGetMnodeEpSet(pMnode, &pRsp->epSet);
|
||||
mndReleaseConn(pMnode, pConn);
|
||||
|
||||
pMsg->contLen = sizeof(SConnectRsp);
|
||||
pMsg->pCont = pRsp;
|
||||
pReq->contLen = sizeof(SConnectRsp);
|
||||
pReq->pCont = pRsp;
|
||||
|
||||
mDebug("user:%s, login from %s, conn:%d, app:%s", info.user, ip, pConn->id, pReq->app);
|
||||
mDebug("user:%s, login from %s, conn:%d, app:%s", info.user, ip, pConn->id, pConnReq->app);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pMsg) {
|
||||
static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatReq *pReq) {
|
||||
pConn->numOfQueries = 0;
|
||||
int32_t numOfQueries = htonl(pMsg->numOfQueries);
|
||||
int32_t numOfQueries = htonl(pReq->numOfQueries);
|
||||
|
||||
if (numOfQueries > 0) {
|
||||
if (pConn->pQueries == NULL) {
|
||||
|
@ -250,38 +250,38 @@ static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pMsg) {
|
|||
|
||||
int32_t saveSize = pConn->numOfQueries * sizeof(SQueryDesc);
|
||||
if (saveSize > 0 && pConn->pQueries != NULL) {
|
||||
memcpy(pConn->pQueries, pMsg->pData, saveSize);
|
||||
memcpy(pConn->pQueries, pReq->pData, saveSize);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SHeartBeatMsg *pReq = pMsg->rpcMsg.pCont;
|
||||
pReq->connId = htonl(pReq->connId);
|
||||
pReq->pid = htonl(pReq->pid);
|
||||
SHeartBeatReq *pHeartbeat = pReq->rpcMsg.pCont;
|
||||
pHeartbeat->connId = htonl(pHeartbeat->connId);
|
||||
pHeartbeat->pid = htonl(pHeartbeat->pid);
|
||||
|
||||
SRpcConnInfo info = {0};
|
||||
if (rpcGetConnInfo(pMsg->rpcMsg.handle, &info) != 0) {
|
||||
mError("user:%s, connId:%d failed to process hb since %s", pMsg->user, pReq->connId, terrstr());
|
||||
if (rpcGetConnInfo(pReq->rpcMsg.handle, &info) != 0) {
|
||||
mError("user:%s, connId:%d failed to process hb since %s", pReq->user, pHeartbeat->connId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SConnObj *pConn = mndAcquireConn(pMnode, pReq->connId);
|
||||
SConnObj *pConn = mndAcquireConn(pMnode, pHeartbeat->connId);
|
||||
if (pConn == NULL) {
|
||||
pConn = mndCreateConn(pMnode, &info, pReq->pid, pReq->app, 0);
|
||||
pConn = mndCreateConn(pMnode, &info, pHeartbeat->pid, pHeartbeat->app, 0);
|
||||
if (pConn == NULL) {
|
||||
mError("user:%s, conn:%d is freed and failed to create new conn since %s", pMsg->user, pReq->connId, terrstr());
|
||||
mError("user:%s, conn:%d is freed and failed to create new since %s", pReq->user, pHeartbeat->connId, terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
mDebug("user:%s, conn:%d is freed and create a new conn:%d", pMsg->user, pReq->connId, pConn->id);
|
||||
mDebug("user:%s, conn:%d is freed and create a new conn:%d", pReq->user, pHeartbeat->connId, pConn->id);
|
||||
}
|
||||
} else if (pConn->killed) {
|
||||
mError("user:%s, conn:%d is already killed", pMsg->user, pConn->id);
|
||||
mError("user:%s, conn:%d is already killed", pReq->user, pConn->id);
|
||||
terrno = TSDB_CODE_MND_INVALID_CONNECTION;
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -304,11 +304,11 @@ static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
|||
if (pRsp == NULL) {
|
||||
mndReleaseConn(pMnode, pConn);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("user:%s, conn:%d failed to process hb while create rsp since %s", pMsg->user, pReq->connId, terrstr());
|
||||
mError("user:%s, conn:%d failed to process hb while since %s", pReq->user, pHeartbeat->connId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndSaveQueryStreamList(pConn, pReq);
|
||||
mndSaveQueryStreamList(pConn, pHeartbeat);
|
||||
if (pConn->killed != 0) {
|
||||
pRsp->killConnection = 1;
|
||||
}
|
||||
|
@ -324,16 +324,16 @@ static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
|||
mndGetMnodeEpSet(pMnode, &pRsp->epSet);
|
||||
mndReleaseConn(pMnode, pConn);
|
||||
|
||||
pMsg->contLen = sizeof(SConnectRsp);
|
||||
pMsg->pCont = pRsp;
|
||||
pReq->contLen = sizeof(SConnectRsp);
|
||||
pReq->pCont = pRsp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessKillQueryMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndProcessKillQueryReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
@ -342,7 +342,7 @@ static int32_t mndProcessKillQueryMsg(SMnodeMsg *pMsg) {
|
|||
}
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
||||
SKillQueryMsg *pKill = pMsg->rpcMsg.pCont;
|
||||
SKillQueryReq *pKill = pReq->rpcMsg.pCont;
|
||||
int32_t connId = htonl(pKill->connId);
|
||||
int32_t queryId = htonl(pKill->queryId);
|
||||
mInfo("kill query msg is received, queryId:%d", pKill->queryId);
|
||||
|
@ -353,18 +353,18 @@ static int32_t mndProcessKillQueryMsg(SMnodeMsg *pMsg) {
|
|||
terrno = TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
return -1;
|
||||
} else {
|
||||
mInfo("connId:%d, queryId:%d is killed by user:%s", connId, queryId, pMsg->user);
|
||||
mInfo("connId:%d, queryId:%d is killed by user:%s", connId, queryId, pReq->user);
|
||||
pConn->queryId = queryId;
|
||||
taosCacheRelease(pMgmt->cache, (void **)&pConn, false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndProcessKillConnectionMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndProcessKillConnReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
@ -373,7 +373,7 @@ static int32_t mndProcessKillConnectionMsg(SMnodeMsg *pMsg) {
|
|||
}
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
||||
SKillConnMsg *pKill = pMsg->rpcMsg.pCont;
|
||||
SKillConnReq *pKill = pReq->rpcMsg.pCont;
|
||||
int32_t connId = htonl(pKill->connId);
|
||||
|
||||
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->cache, &connId, sizeof(int32_t));
|
||||
|
@ -382,18 +382,18 @@ static int32_t mndProcessKillConnectionMsg(SMnodeMsg *pMsg) {
|
|||
terrno = TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
return -1;
|
||||
} else {
|
||||
mInfo("connId:%d, is killed by user:%s", connId, pMsg->user);
|
||||
mInfo("connId:%d, is killed by user:%s", connId, pReq->user);
|
||||
pConn->killed = 1;
|
||||
taosCacheRelease(pMgmt->cache, (void **)&pConn, false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndGetConnsMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
@ -464,8 +464,8 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveConns(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveConns(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
int32_t numOfRows = 0;
|
||||
SConnObj *pConn = NULL;
|
||||
int32_t cols = 0;
|
||||
|
@ -518,11 +518,11 @@ static int32_t mndRetrieveConns(SMnodeMsg *pMsg, SShowObj *pShow, char *data, in
|
|||
return numOfRows;
|
||||
}
|
||||
|
||||
static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndGetQueryMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
@ -633,8 +633,8 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveQueries(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveQueries(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
int32_t numOfRows = 0;
|
||||
SConnObj *pConn = NULL;
|
||||
int32_t cols = 0;
|
||||
|
|
|
@ -124,20 +124,20 @@ static int32_t mndProcessShowReq(SMnodeMsg *pReq) {
|
|||
|
||||
if (type <= TSDB_MGMT_TABLE_START || type >= TSDB_MGMT_TABLE_MAX) {
|
||||
terrno = TSDB_CODE_MND_INVALID_MSG_TYPE;
|
||||
mError("failed to process show msg since %s", terrstr());
|
||||
mError("failed to process show-meta req since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
ShowMetaFp metaFp = pMgmt->metaFps[type];
|
||||
if (metaFp == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_MSG_TYPE;
|
||||
mError("failed to process show-meta msg:%s since %s", mndShowStr(type), terrstr());
|
||||
mError("failed to process show-meta req:%s since %s", mndShowStr(type), terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SShowObj *pShow = mndCreateShowObj(pMnode, pShowReq);
|
||||
if (pShow == NULL) {
|
||||
mError("failed to process show-meta msg:%s since %s", mndShowStr(type), terrstr());
|
||||
mError("failed to process show-meta req:%s since %s", mndShowStr(type), terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ static int32_t mndProcessShowReq(SMnodeMsg *pReq) {
|
|||
if (pRsp == NULL) {
|
||||
mndReleaseShowObj(pShow, true);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("show:0x%" PRIx64 ", failed to process show-meta msg:%s since malloc rsp error", pShow->id,
|
||||
mError("show:0x%" PRIx64 ", failed to process show-meta req:%s since malloc rsp error", pShow->id,
|
||||
mndShowStr(type));
|
||||
return -1;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) {
|
|||
SShowObj *pShow = mndAcquireShowObj(pMnode, showId);
|
||||
if (pShow == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_SHOWOBJ;
|
||||
mError("failed to process show-retrieve msg:%p since %s", pShow, terrstr());
|
||||
mError("failed to process show-retrieve req:%p since %s", pShow, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -769,7 +769,8 @@ static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
|
|||
pMeta->tableType = TSDB_SUPER_TABLE;
|
||||
pMeta->update = pDb->cfg.update;
|
||||
pMeta->sversion = htonl(pStb->version);
|
||||
pMeta->suid = htonl(pStb->uid);
|
||||
pMeta->suid = htobe64(pStb->uid);
|
||||
pMeta->tuid = htobe64(pStb->uid);
|
||||
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pMeta->pSchema[i];
|
||||
|
|
|
@ -86,16 +86,16 @@ static int32_t mndRestoreWal(SMnode *pMnode) {
|
|||
|
||||
mndTransPullup(pMnode);
|
||||
|
||||
if (walBeginSnapshot(pWal, sdbVer) < 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
|
||||
if (sdbVer != lastSdbVer) {
|
||||
mInfo("sdb restored from %" PRId64 " to %" PRId64 ", write file", lastSdbVer, sdbVer);
|
||||
if (sdbWriteFile(pSdb) != 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
|
||||
if (walBeginSnapshot(pWal, sdbVer) < 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
|
||||
if (walEndSnapshot(pWal) < 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
|
|
|
@ -189,8 +189,8 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) {
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
SCreateVnodeMsg *pCreate = calloc(1, sizeof(SCreateVnodeMsg));
|
||||
SCreateVnodeReq *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
SCreateVnodeReq *pCreate = calloc(1, sizeof(SCreateVnodeReq));
|
||||
if (pCreate == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
|
@ -248,8 +248,8 @@ SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbOb
|
|||
return pCreate;
|
||||
}
|
||||
|
||||
SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
SDropVnodeMsg *pDrop = calloc(1, sizeof(SDropVnodeMsg));
|
||||
SDropVnodeReq *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
SDropVnodeReq *pDrop = calloc(1, sizeof(SDropVnodeReq));
|
||||
if (pDrop == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
|
|
|
@ -7,3 +7,8 @@ add_subdirectory(qnode)
|
|||
add_subdirectory(snode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(show)
|
||||
add_subdirectory(profile)
|
||||
add_subdirectory(dnode)
|
||||
add_subdirectory(mnode)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(stb)
|
||||
|
|
|
@ -96,9 +96,9 @@ TEST_F(MndTestBnode, 02_Create_Bnode) {
|
|||
|
||||
TEST_F(MndTestBnode, 03_Drop_Bnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9019);
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. DB_SRC)
|
||||
add_executable(mnode_test_db ${DB_SRC})
|
||||
target_link_libraries(
|
||||
mnode_test_db
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME mnode_test_db
|
||||
COMMAND mnode_test_db
|
||||
)
|
|
@ -1,19 +1,19 @@
|
|||
/**
|
||||
* @file db.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module db-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
* @brief MNODE module db tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-11
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestDb : public ::testing::Test {
|
||||
class MndTestDb : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_db", 9040); }
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_db", 9030); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
@ -23,9 +23,9 @@ class DndTestDb : public ::testing::Test {
|
|||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestDb::test;
|
||||
Testbase MndTestDb::test;
|
||||
|
||||
TEST_F(DndTestDb, 01_ShowDb) {
|
||||
TEST_F(MndTestDb, 01_ShowDb) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 18);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name");
|
||||
|
@ -51,7 +51,7 @@ TEST_F(DndTestDb, 01_ShowDb) {
|
|||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
||||
TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDbMsg);
|
||||
|
||||
|
@ -211,7 +211,7 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
|
||||
TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDbMsg);
|
||||
|
||||
|
@ -281,7 +281,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
|
|||
EXPECT_EQ(pInfo->numOfEps, 1);
|
||||
SEpAddrMsg* pAddr = &pInfo->epAddr[0];
|
||||
pAddr->port = htons(pAddr->port);
|
||||
EXPECT_EQ(pAddr->port, 9040);
|
||||
EXPECT_EQ(pAddr->port, 9030);
|
||||
EXPECT_STREQ(pAddr->fqdn, "localhost");
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
|
|||
EXPECT_EQ(pInfo->numOfEps, 1);
|
||||
SEpAddrMsg* pAddr = &pInfo->epAddr[0];
|
||||
pAddr->port = htons(pAddr->port);
|
||||
EXPECT_EQ(pAddr->port, 9040);
|
||||
EXPECT_EQ(pAddr->port, 9030);
|
||||
EXPECT_STREQ(pAddr->fqdn, "localhost");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. DTEST_SRC)
|
||||
add_executable(mnode_test_dnode ${DTEST_SRC})
|
||||
target_link_libraries(
|
||||
mnode_test_dnode
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME mnode_test_dnode
|
||||
COMMAND mnode_test_dnode
|
||||
)
|
|
@ -0,0 +1,350 @@
|
|||
/**
|
||||
* @file dnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief MNODE module dnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-06
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class MndTestDnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_dnode1", 9023);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9023";
|
||||
|
||||
server2.Start("/tmp/dnode_test_dnode2", fqdn, 9024, firstEp);
|
||||
server3.Start("/tmp/dnode_test_dnode3", fqdn, 9025, firstEp);
|
||||
server4.Start("/tmp/dnode_test_dnode4", fqdn, 9026, firstEp);
|
||||
server5.Start("/tmp/dnode_test_dnode5", fqdn, 9027, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
server3.Stop();
|
||||
server4.Stop();
|
||||
server5.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
static TestServer server3;
|
||||
static TestServer server4;
|
||||
static TestServer server5;
|
||||
};
|
||||
|
||||
Testbase MndTestDnode::test;
|
||||
TestServer MndTestDnode::server2;
|
||||
TestServer MndTestDnode::server3;
|
||||
TestServer MndTestDnode::server4;
|
||||
TestServer MndTestDnode::server5;
|
||||
|
||||
TEST_F(MndTestDnode, 01_ShowDnode) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "support_vnodes");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
|
||||
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
|
||||
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9023", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(MndTestDnode, 02_ConfigDnode) {
|
||||
int32_t contLen = sizeof(SMCfgDnodeReq);
|
||||
|
||||
SMCfgDnodeReq* pReq = (SMCfgDnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->config, "ddebugflag 131");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONFIG_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
TEST_F(MndTestDnode, 03_Create_Dnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "");
|
||||
pReq->port = htonl(9024);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DNODE_EP);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(-1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DNODE_EP);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(123456);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DNODE_EP);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9024);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9024);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_ALREADY_EXIST);
|
||||
}
|
||||
|
||||
taosMsleep(1300);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9023", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9024", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(MndTestDnode, 04_Drop_Dnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDropDnodeReq);
|
||||
|
||||
SDropDnodeReq* pReq = (SDropDnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(-3);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DNODE_ID);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDropDnodeReq);
|
||||
|
||||
SDropDnodeReq* pReq = (SDropDnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(5);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDropDnodeReq);
|
||||
|
||||
SDropDnodeReq* pReq = (SDropDnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDropDnodeReq);
|
||||
|
||||
SDropDnodeReq* pReq = (SDropDnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9023", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
|
||||
taosMsleep(2000);
|
||||
server2.Stop();
|
||||
server2.DoStart();
|
||||
}
|
||||
|
||||
TEST_F(MndTestDnode, 05_Create_Drop_Restart_Dnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9025);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9026);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9027);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
CheckInt16(5);
|
||||
CheckBinary("localhost:9023", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9025", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9026", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9027", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
|
||||
// restart
|
||||
uInfo("stop all server");
|
||||
test.Restart();
|
||||
server2.Restart();
|
||||
server3.Restart();
|
||||
server4.Restart();
|
||||
server5.Restart();
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
CheckInt16(5);
|
||||
CheckBinary("localhost:9023", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9025", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9026", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9027", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. MTEST_SRC)
|
||||
add_executable(mnode_test_mnode ${MTEST_SRC})
|
||||
target_link_libraries(
|
||||
mnode_test_mnode
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME mnode_test_mnode
|
||||
COMMAND mnode_test_mnode
|
||||
)
|
|
@ -0,0 +1,290 @@
|
|||
/**
|
||||
* @file mnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief MNODE module mnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-07
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class MndTestMnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_mnode1", 9028);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9028";
|
||||
|
||||
server2.Start("/tmp/mnode_test_mnode2", fqdn, 9029, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
};
|
||||
|
||||
Testbase MndTestMnode::test;
|
||||
TestServer MndTestMnode::server2;
|
||||
|
||||
TEST_F(MndTestMnode, 01_ShowDnode) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||
CHECK_META("show mnodes", 5);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, 12 + VARSTR_HEADER_SIZE, "role");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9028", TSDB_EP_LEN);
|
||||
CheckBinary("master", 12);
|
||||
CheckInt64(0);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
TEST_F(MndTestMnode, 02_Create_Mnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||
|
||||
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestMnode, 03_Create_Mnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||
|
||||
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestMnode, 04_Create_Mnode) {
|
||||
{
|
||||
// create dnode
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9029);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
// create mnode
|
||||
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||
|
||||
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9028", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9029", TSDB_EP_LEN);
|
||||
CheckBinary("master", 12);
|
||||
CheckBinary("slave", 12);
|
||||
CheckInt64(0);
|
||||
CheckInt64(0);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
// drop mnode
|
||||
int32_t contLen = sizeof(SMDropMnodeReq);
|
||||
|
||||
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9028", TSDB_EP_LEN);
|
||||
CheckBinary("master", 12);
|
||||
CheckInt64(0);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
// drop mnode
|
||||
int32_t contLen = sizeof(SMDropMnodeReq);
|
||||
|
||||
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
|
||||
{
|
||||
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||
|
||||
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, mnode is creating
|
||||
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||
|
||||
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, mnode is creating
|
||||
int32_t contLen = sizeof(SMDropMnodeReq);
|
||||
|
||||
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||
}
|
||||
|
||||
{
|
||||
// server start, wait until the rollback finished
|
||||
server2.DoStart();
|
||||
taosMsleep(1000);
|
||||
|
||||
int32_t retry = 0;
|
||||
int32_t retryMax = 20;
|
||||
|
||||
for (retry = 0; retry < retryMax; retry++) {
|
||||
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||
|
||||
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
if (pRsp->code == TSDB_CODE_MND_MNODE_ALREADY_EXIST) break;
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
ASSERT_NE(retry, retryMax);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
|
||||
{
|
||||
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||
int32_t contLen = sizeof(SMDropMnodeReq);
|
||||
|
||||
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, mnode is dropping
|
||||
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||
|
||||
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, mnode is dropping
|
||||
int32_t contLen = sizeof(SMDropMnodeReq);
|
||||
|
||||
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
|
||||
}
|
||||
|
||||
{
|
||||
// server start, wait until the rollback finished
|
||||
server2.DoStart();
|
||||
taosMsleep(1000);
|
||||
|
||||
int32_t retry = 0;
|
||||
int32_t retryMax = 20;
|
||||
|
||||
for (retry = 0; retry < retryMax; retry++) {
|
||||
int32_t contLen = sizeof(SMCreateMnodeReq);
|
||||
|
||||
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
if (pRsp->code == 0) break;
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
ASSERT_NE(retry, retryMax);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. PROFILE_SRC)
|
||||
add_executable(mnode_test_profile ${PROFILE_SRC})
|
||||
target_link_libraries(
|
||||
mnode_test_profile
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME mnode_test_profile
|
||||
COMMAND mnode_test_profile
|
||||
)
|
|
@ -1,19 +1,19 @@
|
|||
/**
|
||||
* @file profile.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module profile-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
* @brief MNODE module profile tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-06
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestProfile : public ::testing::Test {
|
||||
class MndTestProfile : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_profile", 9080); }
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_profile", 9022); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
@ -24,15 +24,15 @@ class DndTestProfile : public ::testing::Test {
|
|||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestProfile::test;
|
||||
int32_t DndTestProfile::connId;
|
||||
Testbase MndTestProfile::test;
|
||||
int32_t MndTestProfile::connId;
|
||||
|
||||
TEST_F(DndTestProfile, 01_ConnectMsg) {
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
TEST_F(MndTestProfile, 01_ConnectMsg) {
|
||||
int32_t contLen = sizeof(SConnectReq);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
SConnectReq* pReq = (SConnectReq*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->app, "mnode_test_profile");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
|
||||
|
@ -53,18 +53,18 @@ TEST_F(DndTestProfile, 01_ConnectMsg) {
|
|||
|
||||
EXPECT_EQ(pRsp->epSet.inUse, 0);
|
||||
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9080);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9022);
|
||||
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
|
||||
|
||||
connId = pRsp->connId;
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) {
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
TEST_F(MndTestProfile, 02_ConnectMsg_InvalidDB) {
|
||||
int32_t contLen = sizeof(SConnectReq);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
SConnectReq* pReq = (SConnectReq*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->app, "mnode_test_profile");
|
||||
strcpy(pReq->db, "invalid_db");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
|
||||
|
@ -73,7 +73,7 @@ TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) {
|
|||
ASSERT_EQ(pRsp->contLen, 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
|
||||
TEST_F(MndTestProfile, 03_ConnectMsg_Show) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, "");
|
||||
CHECK_META("show connections", 7);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "connId");
|
||||
|
@ -88,22 +88,22 @@ TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
|
|||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckInt32(1);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("dnode_test_profile", TSDB_APP_NAME_LEN);
|
||||
CheckBinary("mnode_test_profile", TSDB_APP_NAME_LEN);
|
||||
CheckInt32(1234);
|
||||
IgnoreBinary(TSDB_IPv4ADDR_LEN + 6);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 04_HeartBeatMsg) {
|
||||
int32_t contLen = sizeof(SHeartBeatMsg);
|
||||
TEST_F(MndTestProfile, 04_HeartBeatMsg) {
|
||||
int32_t contLen = sizeof(SHeartBeatReq);
|
||||
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen);
|
||||
SHeartBeatReq* pReq = (SHeartBeatReq*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->pid = htonl(1234);
|
||||
pReq->numOfQueries = htonl(0);
|
||||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->app, "mnode_test_profile");
|
||||
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
|
@ -127,15 +127,15 @@ TEST_F(DndTestProfile, 04_HeartBeatMsg) {
|
|||
|
||||
EXPECT_EQ(pRsp->epSet.inUse, 0);
|
||||
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9080);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9022);
|
||||
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 05_KillConnMsg) {
|
||||
TEST_F(MndTestProfile, 05_KillConnMsg) {
|
||||
{
|
||||
int32_t contLen = sizeof(SKillConnMsg);
|
||||
int32_t contLen = sizeof(SKillConnReq);
|
||||
|
||||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
|
||||
SKillConnReq* pReq = (SKillConnReq*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen);
|
||||
|
@ -144,14 +144,14 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
|
|||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SHeartBeatMsg);
|
||||
int32_t contLen = sizeof(SHeartBeatReq);
|
||||
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen);
|
||||
SHeartBeatReq* pReq = (SHeartBeatReq*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->pid = htonl(1234);
|
||||
pReq->numOfQueries = htonl(0);
|
||||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->app, "mnode_test_profile");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
|
@ -160,11 +160,11 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
|
|||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
int32_t contLen = sizeof(SConnectReq);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
SConnectReq* pReq = (SConnectReq*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->app, "mnode_test_profile");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
|
||||
|
@ -185,17 +185,17 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
|
|||
|
||||
EXPECT_EQ(pRsp->epSet.inUse, 0);
|
||||
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9080);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9022);
|
||||
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
|
||||
|
||||
connId = pRsp->connId;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) {
|
||||
int32_t contLen = sizeof(SKillConnMsg);
|
||||
TEST_F(MndTestProfile, 06_KillConnMsg_InvalidConn) {
|
||||
int32_t contLen = sizeof(SKillConnReq);
|
||||
|
||||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
|
||||
SKillConnReq* pReq = (SKillConnReq*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(2345);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen);
|
||||
|
@ -203,11 +203,11 @@ TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) {
|
|||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
||||
TEST_F(MndTestProfile, 07_KillQueryMsg) {
|
||||
{
|
||||
int32_t contLen = sizeof(SKillQueryMsg);
|
||||
int32_t contLen = sizeof(SKillQueryReq);
|
||||
|
||||
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(contLen);
|
||||
SKillQueryReq* pReq = (SKillQueryReq*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->queryId = htonl(1234);
|
||||
|
||||
|
@ -218,14 +218,14 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
|||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SHeartBeatMsg);
|
||||
int32_t contLen = sizeof(SHeartBeatReq);
|
||||
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen);
|
||||
SHeartBeatReq* pReq = (SHeartBeatReq*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->pid = htonl(1234);
|
||||
pReq->numOfQueries = htonl(0);
|
||||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->app, "mnode_test_profile");
|
||||
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
|
@ -249,15 +249,15 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
|||
|
||||
EXPECT_EQ(pRsp->epSet.inUse, 0);
|
||||
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9080);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9022);
|
||||
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) {
|
||||
int32_t contLen = sizeof(SKillQueryMsg);
|
||||
TEST_F(MndTestProfile, 08_KillQueryMsg_InvalidConn) {
|
||||
int32_t contLen = sizeof(SKillQueryReq);
|
||||
|
||||
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(contLen);
|
||||
SKillQueryReq* pReq = (SKillQueryReq*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(2345);
|
||||
pReq->queryId = htonl(1234);
|
||||
|
||||
|
@ -266,7 +266,7 @@ TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) {
|
|||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 09_KillQueryMsg) {
|
||||
TEST_F(MndTestProfile, 09_KillQueryMsg) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_QUERIES, "");
|
||||
CHECK_META("show queries", 14);
|
||||
|
|
@ -96,9 +96,9 @@ TEST_F(MndTestQnode, 02_Create_Qnode) {
|
|||
|
||||
TEST_F(MndTestQnode, 03_Drop_Qnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9015);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestShow : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9020); }
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9021); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
@ -50,9 +50,9 @@ TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) {
|
|||
}
|
||||
|
||||
TEST_F(MndTestShow, 03_ShowMsg_Conn) {
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
int32_t contLen = sizeof(SConnectReq);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
SConnectReq* pReq = (SConnectReq*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "mnode_test_show");
|
||||
strcpy(pReq->db, "");
|
||||
|
|
|
@ -96,9 +96,9 @@ TEST_F(MndTestSnode, 02_Create_Snode) {
|
|||
|
||||
TEST_F(MndTestSnode, 03_Drop_Snode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9017);
|
||||
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
/**
|
||||
* @file stb.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module db-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-17
|
||||
* @brief MNODE module stb tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-12
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestStb : public ::testing::Test {
|
||||
class MndTestStb : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_stb", 9101); }
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_stb", 9034); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
@ -23,9 +23,9 @@ class DndTestStb : public ::testing::Test {
|
|||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestStb::test;
|
||||
Testbase MndTestStb::test;
|
||||
|
||||
TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||
TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDbMsg);
|
||||
|
||||
|
@ -137,9 +137,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
pRsp->numOfColumns = htonl(pRsp->numOfColumns);
|
||||
pRsp->sversion = htonl(pRsp->sversion);
|
||||
pRsp->tversion = htonl(pRsp->tversion);
|
||||
pRsp->suid = htobe64(pRsp->suid);
|
||||
pRsp->tuid = htobe64(pRsp->tuid);
|
||||
pRsp->vgId = htobe64(pRsp->vgId);
|
||||
pRsp->suid = be64toh(pRsp->suid);
|
||||
pRsp->tuid = be64toh(pRsp->tuid);
|
||||
pRsp->vgId = be64toh(pRsp->vgId);
|
||||
for (int32_t i = 0; i < pRsp->numOfTags + pRsp->numOfColumns; ++i) {
|
||||
SSchema* pSchema = &pRsp->pSchema[i];
|
||||
pSchema->colId = htonl(pSchema->colId);
|
||||
|
@ -156,7 +156,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
EXPECT_EQ(pRsp->sversion, 1);
|
||||
EXPECT_EQ(pRsp->tversion, 0);
|
||||
EXPECT_GT(pRsp->suid, 0);
|
||||
EXPECT_EQ(pRsp->tuid, 0);
|
||||
EXPECT_GT(pRsp->tuid, 0);
|
||||
EXPECT_EQ(pRsp->vgId, 0);
|
||||
|
||||
{
|
|
@ -133,9 +133,9 @@ TEST_F(MndTestTrans, 02_Create_Qnode1_Crash) {
|
|||
|
||||
TEST_F(MndTestTrans, 03_Create_Qnode2_Crash) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
int32_t contLen = sizeof(SCreateDnodeReq);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
SCreateDnodeReq* pReq = (SCreateDnodeReq*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9020);
|
||||
|
||||
|
|
|
@ -429,3 +429,12 @@ int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type) {
|
|||
maxId = MAX(maxId, pSdb->maxId[type]);
|
||||
return maxId + 1;
|
||||
}
|
||||
|
||||
int64_t sdbGetTableVer(SSdb *pSdb, ESdbType type) {
|
||||
if (type >= SDB_MAX || type < 0) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return pSdb->tableVer[type];
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define vnodeShouldCommit vnodeBufPoolIsFull
|
||||
int vnodeSyncCommit(SVnode *pVnode);
|
||||
int vnodeAsyncCommit(SVnode *pVnode);
|
||||
int vnodeCommit(void *arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -15,10 +15,14 @@
|
|||
|
||||
#include "vnodeDef.h"
|
||||
|
||||
static int vnodeStartCommit(SVnode *pVnode);
|
||||
static int vnodeEndCommit(SVnode *pVnode);
|
||||
static int vnodeStartCommit(SVnode *pVnode);
|
||||
static int vnodeEndCommit(SVnode *pVnode);
|
||||
static int vnodeCommit(void *arg);
|
||||
static void vnodeWaitCommit(SVnode *pVnode);
|
||||
|
||||
int vnodeAsyncCommit(SVnode *pVnode) {
|
||||
vnodeWaitCommit(pVnode);
|
||||
|
||||
vnodeBufPoolSwitch(pVnode);
|
||||
SVnodeTask *pTask = (SVnodeTask *)malloc(sizeof(*pTask));
|
||||
|
||||
|
@ -33,7 +37,13 @@ int vnodeAsyncCommit(SVnode *pVnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int vnodeCommit(void *arg) {
|
||||
int vnodeSyncCommit(SVnode *pVnode) {
|
||||
vnodeAsyncCommit(pVnode);
|
||||
vnodeWaitCommit(pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vnodeCommit(void *arg) {
|
||||
SVnode *pVnode = (SVnode *)arg;
|
||||
|
||||
metaCommit(pVnode->pMeta);
|
||||
|
@ -42,7 +52,6 @@ int vnodeCommit(void *arg) {
|
|||
|
||||
vnodeBufPoolRecycle(pVnode);
|
||||
tsem_post(&(pVnode->canCommit));
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -54,4 +63,6 @@ static int vnodeStartCommit(SVnode *pVnode) {
|
|||
static int vnodeEndCommit(SVnode *pVnode) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE void vnodeWaitCommit(SVnode *pVnode) { tsem_wait(&pVnode->canCommit); }
|
|
@ -24,9 +24,9 @@ SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
|
|||
SVnode *pVnode = NULL;
|
||||
|
||||
// Set default options
|
||||
if (pVnodeCfg == NULL) {
|
||||
//if (pVnodeCfg == NULL) {
|
||||
pVnodeCfg = &defaultVnodeOptions;
|
||||
}
|
||||
//}
|
||||
|
||||
// Validate options
|
||||
if (vnodeValidateOptions(pVnodeCfg) < 0) {
|
||||
|
@ -137,6 +137,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
|
|||
}
|
||||
|
||||
static void vnodeCloseImpl(SVnode *pVnode) {
|
||||
// vnodeSyncCommit(pVnode);
|
||||
if (pVnode) {
|
||||
vnodeCloseBufPool(pVnode);
|
||||
metaClose(pVnode->pMeta);
|
||||
|
|
|
@ -105,6 +105,9 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
if (pTbCfg->type == META_CHILD_TABLE) {
|
||||
strcpy(pTbMetaMsg->stbFname, pStbCfg->name);
|
||||
pTbMetaMsg->suid = htobe64(pTbCfg->ctbCfg.suid);
|
||||
} else if (pTbCfg->type == META_SUPER_TABLE) {
|
||||
strcpy(pTbMetaMsg->stbFname, pTbCfg->name);
|
||||
pTbMetaMsg->suid = htobe64(uid);
|
||||
}
|
||||
pTbMetaMsg->numOfTags = htonl(nTagCols);
|
||||
pTbMetaMsg->numOfColumns = htonl(nCols);
|
||||
|
|
|
@ -92,7 +92,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
// }
|
||||
break;
|
||||
case TDMT_VND_SUBMIT:
|
||||
if (tsdbInsertData(pVnode->pTsdb, (SSubmitMsg *)ptr) < 0) {
|
||||
if (tsdbInsertData(pVnode->pTsdb, (SSubmitMsg *)ptr, NULL) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -19,11 +19,13 @@ add_library(meta STATIC ${META_SRC})
|
|||
target_include_directories(
|
||||
meta
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/vnode/meta"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/index"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
meta
|
||||
PUBLIC common
|
||||
PUBLIC index
|
||||
)
|
||||
|
||||
if(${META_DB_IMPL} STREQUAL "BDB")
|
||||
|
|
|
@ -13,9 +13,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "index.h"
|
||||
#include "metaDef.h"
|
||||
|
||||
struct SMetaIdx {
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
SIndex *pIdx;
|
||||
#endif
|
||||
/* data */
|
||||
};
|
||||
|
||||
|
@ -43,6 +47,13 @@ int metaOpenIdx(SMeta *pMeta) {
|
|||
rocksdb_options_destroy(options);
|
||||
#endif
|
||||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
SIndexOpts opts;
|
||||
if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -53,14 +64,47 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */
|
|||
pMeta->pIdx = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
SIndexOpts opts;
|
||||
if (indexClose(pMeta->pIdx->pIdx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions) {
|
||||
int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) {
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
if (pTbCfgs - type == META_CHILD_TABLE) {
|
||||
char buf[8] = {0};
|
||||
int16_t colId = (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId;
|
||||
sprintf(buf, "%d", colId); // colname
|
||||
|
||||
char *pTagVal = (char *)tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId);
|
||||
|
||||
tb_uid_t suid = pTbCfg->ctbCfg.suid; // super id
|
||||
tb_uid_t tuid = 0; // child table uid
|
||||
SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||
SIndexTerm * term =
|
||||
indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid);
|
||||
indexMultiTermAdd(terms, term);
|
||||
|
||||
int ret = indexPut(pMeta->pIdx->pIdx, terms);
|
||||
indexMultiTermDestroy(terms);
|
||||
return ret;
|
||||
} else {
|
||||
return DB_DONOTINDEX;
|
||||
}
|
||||
#endif
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid) {
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
|
||||
#endif
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,10 @@ int metaOpenUidGnrt(SMeta *pMeta) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */ }
|
||||
void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */
|
||||
}
|
||||
|
||||
tb_uid_t metaGenerateUid(SMeta *pMeta) {
|
||||
// Generate a new table UID
|
||||
return ++(pMeta->uidGnrt.nextUid);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ else(0)
|
|||
"src/tsdbMemTable.c"
|
||||
"src/tsdbOptions.c"
|
||||
"src/tsdbWrite.c"
|
||||
"src/tsdbReadImpl.c"
|
||||
"src/tsdbFile.c"
|
||||
"src/tsdbFS.c"
|
||||
)
|
||||
endif(0)
|
||||
|
||||
|
@ -25,4 +28,5 @@ target_link_libraries(
|
|||
PUBLIC util
|
||||
PUBLIC common
|
||||
PUBLIC tkv
|
||||
PUBLIC tfs
|
||||
)
|
|
@ -16,7 +16,6 @@
|
|||
#ifndef _TD_TSDB_COMMIT_H_
|
||||
#define _TD_TSDB_COMMIT_H_
|
||||
|
||||
#if 0
|
||||
typedef struct {
|
||||
int minFid;
|
||||
int midFid;
|
||||
|
@ -30,9 +29,19 @@ typedef struct {
|
|||
int64_t size;
|
||||
} SKVRecord;
|
||||
|
||||
void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn);
|
||||
|
||||
static FORCE_INLINE int TSDB_KEY_FID(TSKEY key, int32_t days, int8_t precision) {
|
||||
if (key < 0) {
|
||||
return (int)((key + 1) / tsTickPerDay[precision] / days - 1);
|
||||
} else {
|
||||
return (int)((key / tsTickPerDay[precision] / days));
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
#define TSDB_DEFAULT_BLOCK_ROWS(maxRows) ((maxRows)*4 / 5)
|
||||
|
||||
void tsdbGetRtnSnap(STsdbRepo *pRepo, SRtn *pRtn);
|
||||
int tsdbEncodeKVRecord(void **buf, SKVRecord *pRecord);
|
||||
void *tsdbDecodeKVRecord(void *buf, SKVRecord *pRecord);
|
||||
void *tsdbCommitData(STsdbRepo *pRepo);
|
||||
|
|
|
@ -17,27 +17,43 @@
|
|||
#define _TD_TSDB_DEF_H_
|
||||
|
||||
#include "mallocator.h"
|
||||
#include "tmsg.h"
|
||||
#include "tlist.h"
|
||||
#include "tcompression.h"
|
||||
#include "tglobal.h"
|
||||
#include "thash.h"
|
||||
#include "tlist.h"
|
||||
#include "tmsg.h"
|
||||
#include "tskiplist.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#include "tsdb.h"
|
||||
#include "tsdbCommit.h"
|
||||
#include "tsdbFS.h"
|
||||
#include "tsdbFile.h"
|
||||
#include "tsdbLog.h"
|
||||
#include "tsdbMemTable.h"
|
||||
#include "tsdbMemory.h"
|
||||
#include "tsdbOptions.h"
|
||||
#include "tsdbReadImpl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct STsdb {
|
||||
int32_t vgId;
|
||||
char * path;
|
||||
STsdbCfg options;
|
||||
STsdbCfg config;
|
||||
STsdbMemTable * mem;
|
||||
STsdbMemTable * imem;
|
||||
SRtn rtn;
|
||||
SMemAllocatorFactory *pmaf;
|
||||
STsdbFS fs;
|
||||
};
|
||||
|
||||
#define REPO_ID(r) 0
|
||||
#define REPO_CFG(r) (&(r)->config)
|
||||
#define REPO_FS(r) (&(r)->fs)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#ifndef _TD_TSDB_FS_H_
|
||||
#define _TD_TSDB_FS_H_
|
||||
|
||||
#if 0
|
||||
#include "tsdbFile.h"
|
||||
|
||||
#define TSDB_FS_VERSION 0
|
||||
|
||||
|
@ -39,19 +39,17 @@ typedef struct {
|
|||
// ==================
|
||||
typedef struct {
|
||||
STsdbFSMeta meta; // FS meta
|
||||
SMFile* pmf; // meta file pointer
|
||||
SMFile mf; // meta file
|
||||
SArray* df; // data file array
|
||||
SArray * df; // data file array
|
||||
} SFSStatus;
|
||||
|
||||
typedef struct {
|
||||
pthread_rwlock_t lock;
|
||||
|
||||
SFSStatus* cstatus; // current status
|
||||
SHashObj* metaCache; // meta cache
|
||||
SHashObj* metaCacheComp; // meta cache for compact
|
||||
SFSStatus *cstatus; // current status
|
||||
SHashObj * metaCache; // meta cache
|
||||
SHashObj * metaCacheComp; // meta cache for compact
|
||||
bool intxn;
|
||||
SFSStatus* nstatus; // new status
|
||||
SFSStatus *nstatus; // new status
|
||||
} STsdbFS;
|
||||
|
||||
#define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus)
|
||||
|
@ -63,10 +61,10 @@ typedef struct {
|
|||
typedef struct {
|
||||
int direction;
|
||||
uint64_t version; // current FS version
|
||||
STsdbFS* pfs;
|
||||
STsdbFS * pfs;
|
||||
int index; // used to position next fset when version the same
|
||||
int fid; // used to seek when version is changed
|
||||
SDFileSet* pSet;
|
||||
SDFileSet *pSet;
|
||||
} SFSIter;
|
||||
|
||||
#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC
|
||||
|
@ -74,21 +72,21 @@ typedef struct {
|
|||
|
||||
STsdbFS *tsdbNewFS(STsdbCfg *pCfg);
|
||||
void * tsdbFreeFS(STsdbFS *pfs);
|
||||
int tsdbOpenFS(STsdbRepo *pRepo);
|
||||
void tsdbCloseFS(STsdbRepo *pRepo);
|
||||
void tsdbStartFSTxn(STsdbRepo *pRepo, int64_t pointsAdd, int64_t storageAdd);
|
||||
int tsdbEndFSTxn(STsdbRepo *pRepo);
|
||||
int tsdbOpenFS(STsdb *pRepo);
|
||||
void tsdbCloseFS(STsdb *pRepo);
|
||||
void tsdbStartFSTxn(STsdb *pRepo, int64_t pointsAdd, int64_t storageAdd);
|
||||
int tsdbEndFSTxn(STsdb *pRepo);
|
||||
int tsdbEndFSTxnWithError(STsdbFS *pfs);
|
||||
void tsdbUpdateFSTxnMeta(STsdbFS *pfs, STsdbFSMeta *pMeta);
|
||||
void tsdbUpdateMFile(STsdbFS *pfs, const SMFile *pMFile);
|
||||
// void tsdbUpdateMFile(STsdbFS *pfs, const SMFile *pMFile);
|
||||
int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet);
|
||||
|
||||
void tsdbFSIterInit(SFSIter *pIter, STsdbFS *pfs, int direction);
|
||||
void tsdbFSIterSeek(SFSIter *pIter, int fid);
|
||||
SDFileSet *tsdbFSIterNext(SFSIter *pIter);
|
||||
int tsdbLoadMetaCache(STsdbRepo *pRepo, bool recoverMeta);
|
||||
int tsdbLoadMetaCache(STsdb *pRepo, bool recoverMeta);
|
||||
|
||||
static FORCE_INLINE int tsdbRLockFS(STsdbFS* pFs) {
|
||||
static FORCE_INLINE int tsdbRLockFS(STsdbFS *pFs) {
|
||||
int code = pthread_rwlock_rdlock(&(pFs->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -97,7 +95,7 @@ static FORCE_INLINE int tsdbRLockFS(STsdbFS* pFs) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int tsdbWLockFS(STsdbFS* pFs) {
|
||||
static FORCE_INLINE int tsdbWLockFS(STsdbFS *pFs) {
|
||||
int code = pthread_rwlock_wrlock(&(pFs->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -106,7 +104,7 @@ static FORCE_INLINE int tsdbWLockFS(STsdbFS* pFs) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int tsdbUnLockFS(STsdbFS* pFs) {
|
||||
static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) {
|
||||
int code = pthread_rwlock_unlock(&(pFs->lock));
|
||||
if (code != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
|
@ -115,6 +113,4 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS* pFs) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _TD_TSDB_FS_H_ */
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
#ifndef _TS_TSDB_FILE_H_
|
||||
#define _TS_TSDB_FILE_H_
|
||||
|
||||
#if 0
|
||||
#include "tchecksum.h"
|
||||
#include "tfs.h"
|
||||
|
||||
#define TSDB_FILE_HEAD_SIZE 512
|
||||
#define TSDB_FILE_DELIMITER 0xF00AFA0F
|
||||
|
@ -34,7 +35,7 @@
|
|||
#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_FD(f) = -1)
|
||||
#define TSDB_FILE_LEVEL(tf) TFILE_LEVEL(TSDB_FILE_F(tf))
|
||||
#define TSDB_FILE_ID(tf) TFILE_ID(TSDB_FILE_F(tf))
|
||||
#define TSDB_FILE_FSYNC(tf) taosFsync(TSDB_FILE_FD(tf))
|
||||
#define TSDB_FILE_FSYNC(tf) taosFsyncFile(TSDB_FILE_FD(tf))
|
||||
#define TSDB_FILE_STATE(tf) ((tf)->state)
|
||||
#define TSDB_FILE_SET_STATE(tf, s) ((tf)->state = (s))
|
||||
#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK)
|
||||
|
@ -42,6 +43,7 @@
|
|||
|
||||
typedef enum { TSDB_FILE_HEAD = 0, TSDB_FILE_DATA, TSDB_FILE_LAST, TSDB_FILE_MAX, TSDB_FILE_META } TSDB_FILE_T;
|
||||
|
||||
#if 0
|
||||
// =============== SMFile
|
||||
typedef struct {
|
||||
int64_t size;
|
||||
|
@ -68,7 +70,7 @@ int tsdbApplyMFileChange(SMFile* from, SMFile* to);
|
|||
int tsdbCreateMFile(SMFile* pMFile, bool updateHeader);
|
||||
int tsdbUpdateMFileHeader(SMFile* pMFile);
|
||||
int tsdbLoadMFileHeader(SMFile* pMFile, SMFInfo* pInfo);
|
||||
int tsdbScanAndTryFixMFile(STsdbRepo* pRepo);
|
||||
int tsdbScanAndTryFixMFile(STsdb* pRepo);
|
||||
int tsdbEncodeMFInfo(void** buf, SMFInfo* pInfo);
|
||||
void* tsdbDecodeMFInfo(void* buf, SMFInfo* pInfo);
|
||||
|
||||
|
@ -96,7 +98,7 @@ static FORCE_INLINE void tsdbCloseMFile(SMFile* pMFile) {
|
|||
static FORCE_INLINE int64_t tsdbSeekMFile(SMFile* pMFile, int64_t offset, int whence) {
|
||||
ASSERT(TSDB_FILE_OPENED(pMFile));
|
||||
|
||||
int64_t loffset = taosLSeek(TSDB_FILE_FD(pMFile), offset, whence);
|
||||
int64_t loffset = taosLSeekFile(TSDB_FILE_FD(pMFile), offset, whence);
|
||||
if (loffset < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
@ -108,7 +110,7 @@ static FORCE_INLINE int64_t tsdbSeekMFile(SMFile* pMFile, int64_t offset, int wh
|
|||
static FORCE_INLINE int64_t tsdbWriteMFile(SMFile* pMFile, void* buf, int64_t nbyte) {
|
||||
ASSERT(TSDB_FILE_OPENED(pMFile));
|
||||
|
||||
int64_t nwrite = taosWrite(pMFile->fd, buf, nbyte);
|
||||
int64_t nwrite = taosWriteFile(pMFile->fd, buf, nbyte);
|
||||
if (nwrite < nbyte) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
@ -150,7 +152,7 @@ static FORCE_INLINE int tsdbRemoveMFile(SMFile* pMFile) { return tfsremove(TSDB_
|
|||
static FORCE_INLINE int64_t tsdbReadMFile(SMFile* pMFile, void* buf, int64_t nbyte) {
|
||||
ASSERT(TSDB_FILE_OPENED(pMFile));
|
||||
|
||||
int64_t nread = taosRead(pMFile->fd, buf, nbyte);
|
||||
int64_t nread = taosReadFile(pMFile->fd, buf, nbyte);
|
||||
if (nread < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
@ -159,6 +161,8 @@ static FORCE_INLINE int64_t tsdbReadMFile(SMFile* pMFile, void* buf, int64_t nby
|
|||
return nread;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// =============== SDFile
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
|
@ -210,7 +214,7 @@ static FORCE_INLINE void tsdbCloseDFile(SDFile* pDFile) {
|
|||
static FORCE_INLINE int64_t tsdbSeekDFile(SDFile* pDFile, int64_t offset, int whence) {
|
||||
ASSERT(TSDB_FILE_OPENED(pDFile));
|
||||
|
||||
int64_t loffset = taosLSeek(TSDB_FILE_FD(pDFile), offset, whence);
|
||||
int64_t loffset = taosLSeekFile(TSDB_FILE_FD(pDFile), offset, whence);
|
||||
if (loffset < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
@ -222,7 +226,7 @@ static FORCE_INLINE int64_t tsdbSeekDFile(SDFile* pDFile, int64_t offset, int wh
|
|||
static FORCE_INLINE int64_t tsdbWriteDFile(SDFile* pDFile, void* buf, int64_t nbyte) {
|
||||
ASSERT(TSDB_FILE_OPENED(pDFile));
|
||||
|
||||
int64_t nwrite = taosWrite(pDFile->fd, buf, nbyte);
|
||||
int64_t nwrite = taosWriteFile(pDFile->fd, buf, nbyte);
|
||||
if (nwrite < nbyte) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
@ -264,7 +268,7 @@ static FORCE_INLINE int tsdbRemoveDFile(SDFile* pDFile) { return tfsremove(TSDB_
|
|||
static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nbyte) {
|
||||
ASSERT(TSDB_FILE_OPENED(pDFile));
|
||||
|
||||
int64_t nread = taosRead(pDFile->fd, buf, nbyte);
|
||||
int64_t nread = taosReadFile(pDFile->fd, buf, nbyte);
|
||||
if (nread < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
@ -316,7 +320,7 @@ void* tsdbDecodeDFileSetEx(void* buf, SDFileSet* pSet);
|
|||
int tsdbApplyDFileSetChange(SDFileSet* from, SDFileSet* to);
|
||||
int tsdbCreateDFileSet(SDFileSet* pSet, bool updateHeader);
|
||||
int tsdbUpdateDFileSetHeader(SDFileSet* pSet);
|
||||
int tsdbScanAndTryFixDFileSet(STsdbRepo *pRepo, SDFileSet* pSet);
|
||||
int tsdbScanAndTryFixDFileSet(STsdb* pRepo, SDFileSet* pSet);
|
||||
|
||||
static FORCE_INLINE void tsdbCloseDFileSet(SDFileSet* pSet) {
|
||||
for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) {
|
||||
|
@ -366,5 +370,4 @@ static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet* pSet) {
|
|||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* _TS_TSDB_FILE_H_ */
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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_TSDB_LOG_H_
|
||||
#define _TD_TSDB_LOG_H_
|
||||
|
||||
#include "tlog.h"
|
||||
|
||||
extern int32_t tsdbDebugFlag;
|
||||
|
||||
#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", 255, __VA_ARGS__); }} while(0)
|
||||
#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", 255, __VA_ARGS__); }} while(0)
|
||||
#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", 255, __VA_ARGS__); }} while(0)
|
||||
#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", 255, __VA_ARGS__); }} while(0)
|
||||
#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
||||
|
||||
#endif /* _TD_TSDB_LOG_H_ */
|
|
@ -24,9 +24,9 @@ extern "C" {
|
|||
|
||||
typedef struct STsdbMemTable STsdbMemTable;
|
||||
|
||||
STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF);
|
||||
void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable);
|
||||
int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg);
|
||||
STsdbMemTable *tsdbNewMemTable(STsdb *pTsdb);
|
||||
void tsdbFreeMemTable(STsdb *pTsdb, STsdbMemTable *pMemTable);
|
||||
int tsdbMemTableInsert(STsdb *pTsdb, STsdbMemTable *pMemTable, SSubmitMsg *pMsg, SShellSubmitRspMsg *pRsp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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_TSDB_MEMORY_H_
|
||||
#define _TD_TSDB_MEMORY_H_
|
||||
|
||||
static void * taosTMalloc(size_t size);
|
||||
static void * taosTCalloc(size_t nmemb, size_t size);
|
||||
static void * taosTRealloc(void *ptr, size_t size);
|
||||
static void * taosTZfree(void *ptr);
|
||||
static size_t taosTSizeof(void *ptr);
|
||||
static void taosTMemset(void *ptr, int c);
|
||||
|
||||
static FORCE_INLINE void *taosTMalloc(size_t size) {
|
||||
if (size <= 0) return NULL;
|
||||
|
||||
void *ret = malloc(size + sizeof(size_t));
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
*(size_t *)ret = size;
|
||||
|
||||
return (void *)((char *)ret + sizeof(size_t));
|
||||
}
|
||||
|
||||
static FORCE_INLINE void *taosTCalloc(size_t nmemb, size_t size) {
|
||||
size_t tsize = nmemb * size;
|
||||
void * ret = taosTMalloc(tsize);
|
||||
if (ret == NULL) return NULL;
|
||||
|
||||
taosTMemset(ret, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FORCE_INLINE size_t taosTSizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; }
|
||||
|
||||
static FORCE_INLINE void taosTMemset(void *ptr, int c) { memset(ptr, c, taosTSizeof(ptr)); }
|
||||
|
||||
static FORCE_INLINE void * taosTRealloc(void *ptr, size_t size) {
|
||||
if (ptr == NULL) return taosTMalloc(size);
|
||||
|
||||
if (size <= taosTSizeof(ptr)) return ptr;
|
||||
|
||||
void * tptr = (void *)((char *)ptr - sizeof(size_t));
|
||||
size_t tsize = size + sizeof(size_t);
|
||||
void* tptr1 = realloc(tptr, tsize);
|
||||
if (tptr1 == NULL) return NULL;
|
||||
tptr = tptr1;
|
||||
|
||||
*(size_t *)tptr = size;
|
||||
|
||||
return (void *)((char *)tptr + sizeof(size_t));
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* taosTZfree(void* ptr) {
|
||||
if (ptr) {
|
||||
free((void*)((char*)ptr - sizeof(size_t)));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
#endif /* _TD_TSDB_MEMORY_H_ */
|
|
@ -15,14 +15,14 @@
|
|||
|
||||
#ifndef _TD_TSDB_READ_IMPL_H_
|
||||
#define _TD_TSDB_READ_IMPL_H_
|
||||
#if 0
|
||||
|
||||
#include "os.h"
|
||||
#include "tfs.h"
|
||||
#include "tsdb.h"
|
||||
#include "os.h"
|
||||
#include "tsdbFile.h"
|
||||
#include "tskiplist.h"
|
||||
#include "tsdbMeta.h"
|
||||
#include "tsdbMemory.h"
|
||||
#include "common.h"
|
||||
|
||||
typedef struct SReadH SReadH;
|
||||
|
||||
|
@ -91,7 +91,7 @@ typedef struct {
|
|||
} SBlockData;
|
||||
|
||||
struct SReadH {
|
||||
STsdbRepo * pRepo;
|
||||
STsdb * pRepo;
|
||||
SDFileSet rSet; // FSET to read
|
||||
SArray * aBlkIdx; // SBlockIdx array
|
||||
STable * pTable; // table to read
|
||||
|
@ -116,7 +116,7 @@ struct SReadH {
|
|||
|
||||
#define TSDB_BLOCK_STATIS_SIZE(ncols) (sizeof(SBlockData) + sizeof(SBlockCol) * (ncols) + sizeof(TSCKSUM))
|
||||
|
||||
int tsdbInitReadH(SReadH *pReadh, STsdbRepo *pRepo);
|
||||
int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo);
|
||||
void tsdbDestroyReadH(SReadH *pReadh);
|
||||
int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet);
|
||||
void tsdbCloseAndUnsetFSet(SReadH *pReadh);
|
||||
|
@ -151,6 +151,4 @@ static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /*_TD_TSDB_READ_IMPL_H_*/
|
||||
|
|
|
@ -32,6 +32,23 @@ int tsdbCommit(STsdb *pTsdb) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) {
|
||||
STsdbCfg *pCfg = REPO_CFG(pRepo);
|
||||
TSKEY minKey, midKey, maxKey, now;
|
||||
|
||||
now = taosGetTimestamp(pCfg->precision);
|
||||
minKey = now - pCfg->keep * tsTickPerDay[pCfg->precision];
|
||||
midKey = now - pCfg->keep2 * tsTickPerDay[pCfg->precision];
|
||||
maxKey = now - pCfg->keep1 * tsTickPerDay[pCfg->precision];
|
||||
|
||||
pRtn->minKey = minKey;
|
||||
pRtn->minFid = (int)(TSDB_KEY_FID(minKey, pCfg->daysPerFile, pCfg->precision));
|
||||
pRtn->midFid = (int)(TSDB_KEY_FID(midKey, pCfg->daysPerFile, pCfg->precision));
|
||||
pRtn->maxFid = (int)(TSDB_KEY_FID(maxKey, pCfg->daysPerFile, pCfg->precision));
|
||||
tsdbDebug("vgId:%d now:%" PRId64 " minKey:%" PRId64 " minFid:%d, midFid:%d, maxFid:%d", REPO_ID(pRepo), now, minKey,
|
||||
pRtn->minFid, pRtn->midFid, pRtn->maxFid);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
|
@ -420,23 +437,6 @@ void *tsdbDecodeKVRecord(void *buf, SKVRecord *pRecord) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
void tsdbGetRtnSnap(STsdbRepo *pRepo, SRtn *pRtn) {
|
||||
STsdbCfg *pCfg = REPO_CFG(pRepo);
|
||||
TSKEY minKey, midKey, maxKey, now;
|
||||
|
||||
now = taosGetTimestamp(pCfg->precision);
|
||||
minKey = now - pCfg->keep * tsTickPerDay[pCfg->precision];
|
||||
midKey = now - pCfg->keep2 * tsTickPerDay[pCfg->precision];
|
||||
maxKey = now - pCfg->keep1 * tsTickPerDay[pCfg->precision];
|
||||
|
||||
pRtn->minKey = minKey;
|
||||
pRtn->minFid = (int)(TSDB_KEY_FID(minKey, pCfg->daysPerFile, pCfg->precision));
|
||||
pRtn->midFid = (int)(TSDB_KEY_FID(midKey, pCfg->daysPerFile, pCfg->precision));
|
||||
pRtn->maxFid = (int)(TSDB_KEY_FID(maxKey, pCfg->daysPerFile, pCfg->precision));
|
||||
tsdbDebug("vgId:%d now:%" PRId64 " minKey:%" PRId64 " minFid:%d, midFid:%d, maxFid:%d", REPO_ID(pRepo), now, minKey,
|
||||
pRtn->minFid, pRtn->midFid, pRtn->maxFid);
|
||||
}
|
||||
|
||||
static int tsdbUpdateMetaRecord(STsdbFS *pfs, SMFile *pMFile, uint64_t uid, void *cont, int contLen, bool compact) {
|
||||
char buf[64] = "\0";
|
||||
void * pBuf = buf;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue