TD-13120 merge 3.0
This commit is contained in:
commit
d7e304f00c
|
@ -701,7 +701,7 @@ SGlobalMerger* tscInitResObjForLocalQuery(int32_t numOfRes, int32_t rowLen, uint
|
|||
|
||||
// todo remove it
|
||||
int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize) {
|
||||
int32_t maxRowSize = MAX(rowSize, finalRowSize);
|
||||
int32_t maxRowSize = TMAX(rowSize, finalRowSize);
|
||||
char* pbuf = calloc(1, (size_t)(pOutput->num * maxRowSize));
|
||||
|
||||
size_t size = tscNumOfFields(pQueryInfo);
|
||||
|
@ -965,7 +965,7 @@ SSDataBlock* doGlobalAggregate(void* param, bool* newgroup) {
|
|||
w->ekey = *(int64_t*)(((char*)pInfoData->pData) + TSDB_KEYSIZE * (pRes->info.rows - 1));
|
||||
|
||||
if (pOperator->pRuntimeEnv->pQueryAttr->order.order == TSDB_ORDER_DESC) {
|
||||
SWAP(w->skey, w->ekey, TSKEY);
|
||||
TSWAP(w->skey, w->ekey, TSKEY);
|
||||
assert(w->skey <= w->ekey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ int compareSmlColKv(const void* p1, const void* p2) {
|
|||
TAOS_SML_KV* kv2 = (TAOS_SML_KV*)p2;
|
||||
int kvLen1 = (int)strlen(kv1->key);
|
||||
int kvLen2 = (int)strlen(kv2->key);
|
||||
int res = strncasecmp(kv1->key, kv2->key, MIN(kvLen1, kvLen2));
|
||||
int res = strncasecmp(kv1->key, kv2->key, TMIN(kvLen1, kvLen2));
|
||||
if (res != 0) {
|
||||
return res;
|
||||
} else {
|
||||
|
@ -123,7 +123,7 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra
|
|||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
pField->bytes = MAX(pField->bytes, bytes);
|
||||
pField->bytes = TMAX(pField->bytes, bytes);
|
||||
|
||||
} else {
|
||||
SSchema field = {0};
|
||||
|
|
|
@ -1785,7 +1785,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
|
|||
getNewResColId(pCmd), sizeof(double), false);
|
||||
|
||||
char* name = (pItem->aliasName != NULL)? pItem->aliasName:pItem->pNode->exprToken.z;
|
||||
size_t len = MIN(sizeof(pExpr->base.aliasName), pItem->pNode->exprToken.n + 1);
|
||||
size_t len = TMIN(sizeof(pExpr->base.aliasName), pItem->pNode->exprToken.n + 1);
|
||||
tstrncpy(pExpr->base.aliasName, name, len);
|
||||
|
||||
tExprNode* pNode = NULL;
|
||||
|
@ -2246,7 +2246,7 @@ SSchema tGetUserSpecifiedColumnSchema(SVariant* pVal, SStrToken* exprStr, const
|
|||
if (name != NULL) {
|
||||
tstrncpy(s.name, name, sizeof(s.name));
|
||||
} else {
|
||||
size_t tlen = MIN(sizeof(s.name), exprStr->n + 1);
|
||||
size_t tlen = TMIN(sizeof(s.name), exprStr->n + 1);
|
||||
tstrncpy(s.name, exprStr->z, tlen);
|
||||
strdequote(s.name);
|
||||
}
|
||||
|
@ -2419,7 +2419,7 @@ void setResultColName(char* name, tSqlExprItem* pItem, int32_t functionId, SStrT
|
|||
tstrncpy(name, pItem->aliasName, TSDB_COL_NAME_LEN);
|
||||
} else if (multiCols) {
|
||||
char uname[TSDB_COL_NAME_LEN] = {0};
|
||||
int32_t len = MIN(pToken->n + 1, TSDB_COL_NAME_LEN);
|
||||
int32_t len = TMIN(pToken->n + 1, TSDB_COL_NAME_LEN);
|
||||
tstrncpy(uname, pToken->z, len);
|
||||
|
||||
if (tsKeepOriginalColumnName) { // keep the original column name
|
||||
|
@ -2432,7 +2432,7 @@ void setResultColName(char* name, tSqlExprItem* pItem, int32_t functionId, SStrT
|
|||
tstrncpy(name, tmp, TSDB_COL_NAME_LEN);
|
||||
}
|
||||
} else { // use the user-input result column name
|
||||
int32_t len = MIN(pItem->pNode->exprToken.n + 1, TSDB_COL_NAME_LEN);
|
||||
int32_t len = TMIN(pItem->pNode->exprToken.n + 1, TSDB_COL_NAME_LEN);
|
||||
tstrncpy(name, pItem->pNode->exprToken.z, len);
|
||||
}
|
||||
}
|
||||
|
@ -4380,7 +4380,7 @@ static void exchangeExpr(tSqlExpr* pExpr) {
|
|||
}
|
||||
|
||||
pExpr->tokenId = optr;
|
||||
SWAP(pExpr->pLeft, pExpr->pRight, void*);
|
||||
TSWAP(pExpr->pLeft, pExpr->pRight, void*);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8089,7 +8089,7 @@ int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
|
|||
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||
}
|
||||
|
||||
int64_t timeRange = ABS(pQueryInfo->window.skey - pQueryInfo->window.ekey);
|
||||
int64_t timeRange = TABS(pQueryInfo->window.skey - pQueryInfo->window.ekey);
|
||||
|
||||
int64_t intervalRange = 0;
|
||||
if (pQueryInfo->interval.intervalUnit == 'n' || pQueryInfo->interval.intervalUnit == 'y') {
|
||||
|
|
|
@ -51,7 +51,7 @@ static bool validPassword(const char* passwd) {
|
|||
}
|
||||
|
||||
static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *auth, const char *db,
|
||||
uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, TAOS **taos) {
|
||||
void (*fp)(void *, TAOS_RES *, int), void *param, TAOS **taos) {
|
||||
if (taos_init()) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pa
|
|||
pObj->signature = pObj;
|
||||
pObj->pRpcObj = (SRpcObj *)pRpcObj;
|
||||
tstrncpy(pObj->user, user, sizeof(pObj->user));
|
||||
secretEncryptLen = MIN(secretEncryptLen, sizeof(pObj->pass));
|
||||
secretEncryptLen = TMIN(secretEncryptLen, sizeof(pObj->pass));
|
||||
memcpy(pObj->pass, secretEncrypt, secretEncryptLen);
|
||||
|
||||
if (db) {
|
||||
|
@ -186,7 +186,7 @@ static void syncConnCallback(void *param, TAOS_RES *tres, int code) {
|
|||
TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db,
|
||||
uint16_t port) {
|
||||
STscObj *pObj = NULL;
|
||||
SSqlObj *pSql = taosConnectImpl(ip, user, pass, auth, db, port, syncConnCallback, NULL, (void **)&pObj);
|
||||
SSqlObj *pSql = taosConnectImpl(ip, user, pass, auth, db, syncConnCallback, NULL, (void **)&pObj);
|
||||
if (pSql != NULL) {
|
||||
pSql->fp = syncConnCallback;
|
||||
pSql->param = pSql;
|
||||
|
@ -245,10 +245,10 @@ TAOS *taos_connect_c(const char *ip, uint8_t ipLen, const char *user, uint8_t us
|
|||
char userBuf[TSDB_USER_LEN] = {0};
|
||||
char passBuf[TSDB_KEY_LEN] = {0};
|
||||
char dbBuf[TSDB_DB_NAME_LEN] = {0};
|
||||
strncpy(ipBuf, ip, MIN(TSDB_EP_LEN - 1, ipLen));
|
||||
strncpy(userBuf, user, MIN(TSDB_USER_LEN - 1, userLen));
|
||||
strncpy(passBuf, pass, MIN(TSDB_KEY_LEN - 1, passLen));
|
||||
strncpy(dbBuf, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
|
||||
strncpy(ipBuf, ip, TMIN(TSDB_EP_LEN - 1, ipLen));
|
||||
strncpy(userBuf, user, TMIN(TSDB_USER_LEN - 1, userLen));
|
||||
strncpy(passBuf, pass, TMIN(TSDB_KEY_LEN - 1, passLen));
|
||||
strncpy(dbBuf, db, TMIN(TSDB_DB_NAME_LEN - 1, dbLen));
|
||||
return taos_connect(ipBuf, userBuf, passBuf, dbBuf, port);
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ static void asyncConnCallback(void *param, TAOS_RES *tres, int code) {
|
|||
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
|
||||
void *param, TAOS **taos) {
|
||||
STscObj *pObj = NULL;
|
||||
SSqlObj *pSql = taosConnectImpl(ip, user, pass, NULL, db, port, asyncConnCallback, param, (void **)&pObj);
|
||||
SSqlObj *pSql = taosConnectImpl(ip, user, pass, NULL, db, asyncConnCallback, param, (void **)&pObj);
|
||||
if (pSql == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -3396,7 +3396,7 @@ static void doBuildResFromSubqueries(SSqlObj* pSql) {
|
|||
}
|
||||
|
||||
int32_t remain = (int32_t)(pSub->res.numOfRows - pSub->res.row);
|
||||
numOfRes = (int32_t)(MIN(numOfRes, remain));
|
||||
numOfRes = (int32_t)(TMIN(numOfRes, remain));
|
||||
}
|
||||
|
||||
if (numOfRes == 0) { // no result any more, free all subquery objects
|
||||
|
|
|
@ -373,7 +373,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
|
|||
*interBytes = (int16_t)sizeof(SPercentileInfo);
|
||||
} else if (functionId == TSDB_FUNC_LEASTSQR) {
|
||||
*type = TSDB_DATA_TYPE_BINARY;
|
||||
*bytes = MAX(TSDB_AVG_FUNCTION_INTER_BUFFER_SIZE, sizeof(SLeastsquaresInfo)); // string
|
||||
*bytes = TMAX(TSDB_AVG_FUNCTION_INTER_BUFFER_SIZE, sizeof(SLeastsquaresInfo)); // string
|
||||
*interBytes = *bytes;
|
||||
} else if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_LAST_DST) {
|
||||
*type = TSDB_DATA_TYPE_BINARY;
|
||||
|
@ -1275,7 +1275,7 @@ static void max_func_merge(SQLFunctionCtx *pCtx) {
|
|||
continue; \
|
||||
} \
|
||||
(num) += 1; \
|
||||
(r) += POW2(((type *)d)[i] - (delta)); \
|
||||
(r) += TPOW2(((type *)d)[i] - (delta)); \
|
||||
}
|
||||
|
||||
static void stddev_function(SQLFunctionCtx *pCtx) {
|
||||
|
@ -1314,7 +1314,7 @@ static void stddev_function(SQLFunctionCtx *pCtx) {
|
|||
continue;
|
||||
}
|
||||
num += 1;
|
||||
*retVal += POW2(((int32_t *)pData)[i] - avg);
|
||||
*retVal += TPOW2(((int32_t *)pData)[i] - avg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1427,7 +1427,7 @@ static void stddev_dst_function(SQLFunctionCtx *pCtx) {
|
|||
continue;
|
||||
}
|
||||
num += 1;
|
||||
*retVal += POW2(((int32_t *)pData)[i] - avg);
|
||||
*retVal += TPOW2(((int32_t *)pData)[i] - avg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -4109,8 +4109,8 @@ static void mergeTableBlockDist(SResultRowCellInfo* pResInfo, const STableBlockD
|
|||
pDist->totalRows += pSrc->totalRows;
|
||||
|
||||
if (pResInfo->hasResult == DATA_SET_FLAG) {
|
||||
pDist->maxRows = MAX(pDist->maxRows, pSrc->maxRows);
|
||||
pDist->minRows = MIN(pDist->minRows, pSrc->minRows);
|
||||
pDist->maxRows = TMAX(pDist->maxRows, pSrc->maxRows);
|
||||
pDist->minRows = TMIN(pDist->minRows, pSrc->minRows);
|
||||
} else {
|
||||
pDist->maxRows = pSrc->maxRows;
|
||||
pDist->minRows = pSrc->minRows;
|
||||
|
|
|
@ -328,7 +328,7 @@ SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numO
|
|||
idata.info.bytes = pExpr[i].base.resBytes;
|
||||
idata.info.colId = pExpr[i].base.resColId;
|
||||
|
||||
int32_t size = MAX(idata.info.bytes * numOfRows, minSize);
|
||||
int32_t size = TMAX(idata.info.bytes * numOfRows, minSize);
|
||||
idata.pData = calloc(1, size); // at least to hold a pointer on x64 platform
|
||||
taosArrayPush(res->pDataBlock, &idata);
|
||||
}
|
||||
|
@ -2643,7 +2643,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
|
|||
|
||||
pQueryAttr->order.order = TSDB_ORDER_ASC;
|
||||
if (pQueryAttr->window.skey > pQueryAttr->window.ekey) {
|
||||
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
}
|
||||
|
||||
pQueryAttr->needReverseScan = false;
|
||||
|
@ -2653,7 +2653,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
|
|||
if (pQueryAttr->groupbyColumn && pQueryAttr->order.order == TSDB_ORDER_DESC) {
|
||||
pQueryAttr->order.order = TSDB_ORDER_ASC;
|
||||
if (pQueryAttr->window.skey > pQueryAttr->window.ekey) {
|
||||
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
}
|
||||
|
||||
pQueryAttr->needReverseScan = false;
|
||||
|
@ -2664,7 +2664,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
|
|||
if (pQueryAttr->pointInterpQuery && pQueryAttr->interval.interval == 0) {
|
||||
if (!QUERY_IS_ASC_QUERY(pQueryAttr)) {
|
||||
qDebug(msg, pQInfo->qId, "interp", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
|
||||
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
}
|
||||
|
||||
pQueryAttr->order.order = TSDB_ORDER_ASC;
|
||||
|
@ -2677,7 +2677,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
|
|||
qDebug(msg, pQInfo->qId, "only-first", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey,
|
||||
pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
|
||||
|
||||
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
doUpdateLastKey(pQueryAttr);
|
||||
}
|
||||
|
||||
|
@ -2688,7 +2688,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
|
|||
qDebug(msg, pQInfo->qId, "only-last", pQueryAttr->order.order, TSDB_ORDER_DESC, pQueryAttr->window.skey,
|
||||
pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
|
||||
|
||||
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
doUpdateLastKey(pQueryAttr);
|
||||
}
|
||||
|
||||
|
@ -2703,7 +2703,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
|
|||
qDebug(msg, pQInfo->qId, "only-first stable", pQueryAttr->order.order, TSDB_ORDER_ASC,
|
||||
pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
|
||||
|
||||
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
doUpdateLastKey(pQueryAttr);
|
||||
}
|
||||
|
||||
|
@ -2714,7 +2714,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
|
|||
qDebug(msg, pQInfo->qId, "only-last stable", pQueryAttr->order.order, TSDB_ORDER_DESC,
|
||||
pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
|
||||
|
||||
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
doUpdateLastKey(pQueryAttr);
|
||||
}
|
||||
|
||||
|
@ -2754,8 +2754,8 @@ static FORCE_INLINE bool doFilterByBlockStatistics(SQueryRuntimeEnv* pRuntimeEnv
|
|||
static bool overlapWithTimeWindow(SQueryAttr* pQueryAttr, SDataBlockInfo* pBlockInfo) {
|
||||
STimeWindow w = {0};
|
||||
|
||||
TSKEY sk = MIN(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
TSKEY ek = MAX(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
TSKEY sk = TMIN(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
TSKEY ek = TMAX(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
|
||||
if (QUERY_IS_ASC_QUERY(pQueryAttr)) {
|
||||
getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.skey, sk, ek, &w);
|
||||
|
@ -3523,7 +3523,7 @@ static void updateTableQueryInfoForReverseScan(STableQueryInfo *pTableQueryInfo)
|
|||
return;
|
||||
}
|
||||
|
||||
SWAP(pTableQueryInfo->win.skey, pTableQueryInfo->win.ekey, TSKEY);
|
||||
TSWAP(pTableQueryInfo->win.skey, pTableQueryInfo->win.ekey, TSKEY);
|
||||
pTableQueryInfo->lastKey = pTableQueryInfo->win.skey;
|
||||
|
||||
SWITCH_ORDER(pTableQueryInfo->cur.order);
|
||||
|
@ -3730,7 +3730,7 @@ static void setupEnvForReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo
|
|||
}
|
||||
|
||||
// reverse order time range
|
||||
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
TSWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
|
||||
|
||||
SET_REVERSE_SCAN_FLAG(pRuntimeEnv);
|
||||
setQueryStatus(pRuntimeEnv, QUERY_NOT_COMPLETED);
|
||||
|
@ -4109,8 +4109,8 @@ void setIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, TSKEY key) {
|
|||
*/
|
||||
STimeWindow w = TSWINDOW_INITIALIZER;
|
||||
|
||||
TSKEY sk = MIN(win.skey, win.ekey);
|
||||
TSKEY ek = MAX(win.skey, win.ekey);
|
||||
TSKEY sk = TMIN(win.skey, win.ekey);
|
||||
TSKEY ek = TMAX(win.skey, win.ekey);
|
||||
getAlignQueryTimeWindow(pQueryAttr, win.skey, sk, ek, &w);
|
||||
|
||||
// if (pResultRowInfo->prevSKey == TSKEY_INITIAL_VAL) {
|
||||
|
@ -4235,7 +4235,7 @@ static void updateNumOfRowsInResultRows(SQueryRuntimeEnv* pRuntimeEnv, SQLFuncti
|
|||
}
|
||||
|
||||
SResultRowCellInfo* pCell = getResultCell(pResult, j, rowCellInfoOffset);
|
||||
pResult->numOfRows = (uint16_t)(MAX(pResult->numOfRows, pCell->numOfRes));
|
||||
pResult->numOfRows = (uint16_t)(TMAX(pResult->numOfRows, pCell->numOfRes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6945,8 +6945,8 @@ SOperatorInfo* createFillOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorIn
|
|||
SFillColInfo* pColInfo = createFillColInfo(pExpr, numOfOutput, pQueryAttr->fillVal);
|
||||
STimeWindow w = TSWINDOW_INITIALIZER;
|
||||
|
||||
TSKEY sk = MIN(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
TSKEY ek = MAX(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
TSKEY sk = TMIN(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
TSKEY ek = TMAX(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
getAlignQueryTimeWindow(pQueryAttr, pQueryAttr->window.skey, sk, ek, &w);
|
||||
|
||||
pInfo->pFillInfo =
|
||||
|
|
|
@ -632,4 +632,6 @@ void exprSerializeTest2() {
|
|||
TEST(testCase, astTest) {
|
||||
// exprSerializeTest2();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -5,6 +5,7 @@
|
|||
#include "tsdb.h"
|
||||
#include "qExtbuffer.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
|
@ -121,4 +122,6 @@ TEST(testCase, columnsort_test) {
|
|||
printf("\n");
|
||||
|
||||
destroyColumnModel(pModel);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -6,6 +6,7 @@
|
|||
#include "taos.h"
|
||||
#include "qHistogram.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
|
||||
|
@ -140,3 +141,5 @@ TEST(testCase, heapsort) {
|
|||
//
|
||||
// free(pEntry);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -6,6 +6,7 @@
|
|||
#include "qAggMain.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
|
||||
|
@ -84,3 +85,5 @@ TEST(testCase, patternMatchTest) {
|
|||
ret = patternMatch("%9", str, 2, &info);
|
||||
EXPECT_EQ(ret, TSDB_PATTERN_MATCH);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "qPercentile.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
|
||||
|
@ -255,3 +256,5 @@ TEST(testCase, percentileTest) {
|
|||
unsignedDataTest();
|
||||
largeDataTest();
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "qFilter.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
|
||||
|
@ -365,3 +366,5 @@ TEST(testCase, rangeMergeTest) {
|
|||
intDataTest();
|
||||
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -6,6 +6,7 @@
|
|||
#include "taos.h"
|
||||
#include "tsdb.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
|
||||
|
@ -161,3 +162,5 @@ TEST(testCase, resultBufferTest) {
|
|||
writeDownTest();
|
||||
recyclePageTest();
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -9,6 +9,7 @@
|
|||
#include "ttoken.h"
|
||||
#include "tutil.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
|
||||
|
@ -513,3 +514,5 @@ TEST(testCase, tsBufTest) {
|
|||
mergeDiffVnodeBufferTest();
|
||||
mergeIdenticalVnodeBufferTest();
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -4,6 +4,7 @@
|
|||
#include "taos.h"
|
||||
#include "tsdb.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
|
@ -910,3 +911,4 @@ TEST(testCase, getTempFilePath_test) {
|
|||
printf("%s\n", path);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -10,8 +10,8 @@ set(CMAKE_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/cmake")
|
|||
set(CMAKE_CONTRIB_DIR "${CMAKE_SOURCE_DIR}/contrib")
|
||||
include(${CMAKE_SUPPORT_DIR}/cmake.options)
|
||||
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
||||
|
||||
# contrib
|
||||
add_subdirectory(contrib)
|
||||
|
|
|
@ -7,7 +7,7 @@ ExternalProject_Add(traft
|
|||
BINARY_DIR "${CMAKE_CONTRIB_DIR}/traft"
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
# https://answers.ros.org/question/333125/how-to-include-external-automakeautoconf-projects-into-ament_cmake/
|
||||
CONFIGURE_COMMAND COMMAND autoreconf -i COMMAND ./configure --enable-example
|
||||
CONFIGURE_COMMAND COMMAND autoreconf -i COMMAND ./configure
|
||||
BUILD_COMMAND "$(MAKE)"
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
|
|
|
@ -20,7 +20,7 @@ if(${BUILD_WITH_CRAFT})
|
|||
endif(${BUILD_WITH_CRAFT})
|
||||
|
||||
if(${BUILD_WITH_TRAFT})
|
||||
add_subdirectory(traft)
|
||||
# add_subdirectory(traft)
|
||||
endif(${BUILD_WITH_TRAFT})
|
||||
|
||||
add_subdirectory(tdev)
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
add_subdirectory(rebalance_leader)
|
||||
add_subdirectory(make_cluster)
|
||||
add_subdirectory(single_node)
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
all:
|
||||
gcc node10000.c -I ../../include/ ../../.libs/libraft.a -o node10000 -luv -llz4 -lpthread -g
|
||||
gcc node10001.c -I ../../include/ ../../.libs/libraft.a -o node10001 -luv -llz4 -lpthread -g
|
||||
gcc node10002.c -I ../../include/ ../../.libs/libraft.a -o node10002 -luv -llz4 -lpthread -g
|
||||
gcc node10000_restart.c -I ../../include/ ../../.libs/libraft.a -o node10000_restart -luv -llz4 -lpthread -g
|
||||
gcc node10001_restart.c -I ../../include/ ../../.libs/libraft.a -o node10001_restart -luv -llz4 -lpthread -g
|
||||
gcc node10002_restart.c -I ../../include/ ../../.libs/libraft.a -o node10002_restart -luv -llz4 -lpthread -g
|
||||
clean:
|
||||
rm -f node10000
|
||||
rm -f node10001
|
||||
rm -f node10002
|
||||
rm -f node10000_restart
|
||||
rm -f node10001_restart
|
||||
rm -f node10002_restart
|
||||
sh clear.sh
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
// printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 10000, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// add vgroup, id = 100, only has 3 replica.
|
||||
// array <peers, peersCount> gives the peer replica infomation.
|
||||
char peers[MAX_PEERS_COUNT][ADDRESS_LEN];
|
||||
memset(peers, 0, sizeof(peers));
|
||||
snprintf(peers[0], ADDRESS_LEN, "%s", "127.0.0.1:10001");
|
||||
snprintf(peers[1], ADDRESS_LEN, "%s", "127.0.0.1:10002");
|
||||
uint32_t peersCount = 2;
|
||||
r = addRaftVoter(&raftEnv, peers, peersCount, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit a value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
// printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 10000, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// add vgroup, id = 100, only has 3 replica.
|
||||
// here only add self.
|
||||
// peer replica information will restore from wal.
|
||||
r = addRaftVoter(&raftEnv, NULL, 0, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit a value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
// printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 10001, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// add vgroup, id = 100, only has 3 replica.
|
||||
// array <peers, peersCount> gives the peer replica infomation.
|
||||
char peers[MAX_PEERS_COUNT][ADDRESS_LEN];
|
||||
memset(peers, 0, sizeof(peers));
|
||||
snprintf(peers[0], ADDRESS_LEN, "%s", "127.0.0.1:10000");
|
||||
snprintf(peers[1], ADDRESS_LEN, "%s", "127.0.0.1:10002");
|
||||
uint32_t peersCount = 2;
|
||||
r = addRaftVoter(&raftEnv, peers, peersCount, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit a value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
// printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 10001, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// add vgroup, id = 100, only has 3 replica.
|
||||
// here only add self.
|
||||
// peer replica information will restore from wal.
|
||||
r = addRaftVoter(&raftEnv, NULL, 0, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit a value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
// printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 10002, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// add vgroup, id = 100, only has 3 replica.
|
||||
// array <peers, peersCount> gives the peer replica infomation.
|
||||
char peers[MAX_PEERS_COUNT][ADDRESS_LEN];
|
||||
memset(peers, 0, sizeof(peers));
|
||||
snprintf(peers[0], ADDRESS_LEN, "%s", "127.0.0.1:10000");
|
||||
snprintf(peers[1], ADDRESS_LEN, "%s", "127.0.0.1:10001");
|
||||
uint32_t peersCount = 2;
|
||||
r = addRaftVoter(&raftEnv, peers, peersCount, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit a value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
// printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 10002, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// add vgroup, id = 100, only has 3 replica.
|
||||
// here only add self.
|
||||
// peer replica information will restore from wal.
|
||||
r = addRaftVoter(&raftEnv, NULL, 0, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit a value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
all:
|
||||
gcc node_follower10000.c -I ../../include/ ../../.libs/libraft.a -o node_follower10000 -luv -llz4 -lpthread -g
|
||||
gcc node_follower10001.c -I ../../include/ ../../.libs/libraft.a -o node_follower10001 -luv -llz4 -lpthread -g
|
||||
gcc node_leader10002.c -I ../../include/ ../../.libs/libraft.a -o node_leader10002 -luv -llz4 -lpthread -g
|
||||
clean:
|
||||
rm -f node_follower10000
|
||||
rm -f node_follower10001
|
||||
rm -f node_leader10002
|
||||
sh clear.sh
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 10000, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// add one replica
|
||||
r = addRaftSpare(&raftEnv, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 10001, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// add one replica
|
||||
r = addRaftSpare(&raftEnv, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
void joinRaftPeerCb(struct raft_change *req, int status) {
|
||||
struct raft *r = req->data;
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "joinRaftPeerCb error: %s \n", raft_errmsg(r));
|
||||
} else {
|
||||
fprintf(stderr, "joinRaftPeerCb ok \n");
|
||||
}
|
||||
raft_free(req);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 10002, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// add one replica
|
||||
r = addRaftVoter(&raftEnv, NULL, 0, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
printRaftState(getRaft(&raftEnv, 100));
|
||||
|
||||
// wait for being leader
|
||||
while (1) {
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
if (r->state == RAFT_LEADER) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// join peers
|
||||
r = joinRaftPeer(&raftEnv, 100, "127.0.0.1", 10000, joinRaftPeerCb);
|
||||
assert(r == 0);
|
||||
|
||||
// wait for join over
|
||||
sleep(2);
|
||||
|
||||
r = joinRaftPeer(&raftEnv, 100, "127.0.0.1", 10001, joinRaftPeerCb);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
add_executable(makeCluster "")
|
||||
target_sources(makeCluster
|
||||
PRIVATE
|
||||
"raftMain.c"
|
||||
"raftServer.c"
|
||||
"config.c"
|
||||
"console.c"
|
||||
"simpleHash.c"
|
||||
"util.c"
|
||||
)
|
||||
target_link_libraries(makeCluster PUBLIC traft lz4 uv_a)
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef TRAFT_COMMON_H
|
||||
#define TRAFT_COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define COMMAND_LEN 512
|
||||
#define MAX_CMD_COUNT 10
|
||||
#define TOKEN_LEN 128
|
||||
#define MAX_PEERS_COUNT 19
|
||||
|
||||
#define HOST_LEN 64
|
||||
#define ADDRESS_LEN (HOST_LEN * 2)
|
||||
#define BASE_DIR_LEN 128
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,64 +0,0 @@
|
|||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void addrToString(const char *host, uint16_t port, char *addr, int len) { snprintf(addr, len, "%s:%hu", host, port); }
|
||||
|
||||
void parseAddr(const char *addr, char *host, int len, uint16_t *port) {
|
||||
char *tmp = (char *)malloc(strlen(addr) + 1);
|
||||
strcpy(tmp, addr);
|
||||
|
||||
char *context;
|
||||
char *separator = ":";
|
||||
char *token = strtok_r(tmp, separator, &context);
|
||||
if (token) {
|
||||
snprintf(host, len, "%s", token);
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (token) {
|
||||
sscanf(token, "%hu", port);
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
int parseConf(int argc, char **argv, RaftServerConfig *pConf) {
|
||||
memset(pConf, 0, sizeof(*pConf));
|
||||
|
||||
int option_index, option_value;
|
||||
option_index = 0;
|
||||
static struct option long_options[] = {{"help", no_argument, NULL, 'h'},
|
||||
{"addr", required_argument, NULL, 'a'},
|
||||
{"dir", required_argument, NULL, 'd'},
|
||||
{NULL, 0, NULL, 0}};
|
||||
|
||||
while ((option_value = getopt_long(argc, argv, "ha:d:", long_options, &option_index)) != -1) {
|
||||
switch (option_value) {
|
||||
case 'a': {
|
||||
parseAddr(optarg, pConf->me.host, sizeof(pConf->me.host), &pConf->me.port);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'd': {
|
||||
snprintf(pConf->baseDir, sizeof(pConf->baseDir), "%s", optarg);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h': {
|
||||
return -2;
|
||||
}
|
||||
|
||||
default: { return -2; }
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void printConf(RaftServerConfig *pConf) {
|
||||
printf("\n---printConf: \n");
|
||||
printf("me: [%s:%hu] \n", pConf->me.host, pConf->me.port);
|
||||
printf("dataDir: [%s] \n\n", pConf->baseDir);
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
#ifndef TRAFT_CONFIG_H
|
||||
#define TRAFT_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
typedef struct {
|
||||
char host[HOST_LEN];
|
||||
uint16_t port;
|
||||
} Addr;
|
||||
|
||||
typedef struct {
|
||||
Addr me;
|
||||
char baseDir[BASE_DIR_LEN];
|
||||
} RaftServerConfig;
|
||||
|
||||
void addrToString(const char *host, uint16_t port, char *addr, int len);
|
||||
void parseAddr(const char *addr, char *host, int len, uint16_t *port);
|
||||
int parseConf(int argc, char **argv, RaftServerConfig *pConf);
|
||||
void printConf(RaftServerConfig *pConf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,202 +0,0 @@
|
|||
#include "console.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "raftServer.h"
|
||||
#include "util.h"
|
||||
|
||||
void printHelp() {
|
||||
printf("---------------------\n");
|
||||
printf("help: \n\n");
|
||||
printf("create a vgroup with 3 replicas: \n");
|
||||
printf("create vnode voter vid 100 peers 127.0.0.1:10001 127.0.0.1:10002 \n");
|
||||
printf("create vnode voter vid 100 peers 127.0.0.1:10000 127.0.0.1:10002 \n");
|
||||
printf("create vnode voter vid 100 peers 127.0.0.1:10000 127.0.0.1:10001 \n");
|
||||
printf("\n");
|
||||
printf("create a vgroup with only one replica: \n");
|
||||
printf("create vnode voter vid 200 \n");
|
||||
printf("\n");
|
||||
printf("add vnode into vgroup: \n");
|
||||
printf("create vnode spare vid 100 ---- run at 127.0.0.1:10003\n");
|
||||
printf("join vnode vid 100 addr 127.0.0.1:10003 ---- run at leader of vgroup 100\n");
|
||||
printf("\n");
|
||||
printf("run \n");
|
||||
printf("put 0 key value \n");
|
||||
printf("get 0 key \n");
|
||||
printf("---------------------\n");
|
||||
}
|
||||
|
||||
void console(RaftServer *pRaftServer) {
|
||||
while (1) {
|
||||
int ret;
|
||||
char cmdBuf[COMMAND_LEN];
|
||||
memset(cmdBuf, 0, sizeof(cmdBuf));
|
||||
printf("(console)> ");
|
||||
char *retp = fgets(cmdBuf, COMMAND_LEN, stdin);
|
||||
if (!retp) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int pos = strlen(cmdBuf);
|
||||
if (cmdBuf[pos - 1] == '\n') {
|
||||
cmdBuf[pos - 1] = '\0';
|
||||
}
|
||||
|
||||
if (strncmp(cmdBuf, "", COMMAND_LEN) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char cmds[MAX_CMD_COUNT][TOKEN_LEN];
|
||||
memset(cmds, 0, sizeof(cmds));
|
||||
|
||||
int cmdCount;
|
||||
cmdCount = splitString(cmdBuf, " ", cmds, MAX_CMD_COUNT);
|
||||
|
||||
if (strcmp(cmds[0], "create") == 0 && strcmp(cmds[1], "vnode") == 0 && strcmp(cmds[3], "vid") == 0) {
|
||||
uint16_t vid;
|
||||
sscanf(cmds[4], "%hu", &vid);
|
||||
|
||||
if (strcmp(cmds[2], "voter") == 0) {
|
||||
char peers[MAX_PEERS_COUNT][ADDRESS_LEN];
|
||||
memset(peers, 0, sizeof(peers));
|
||||
uint32_t peersCount = 0;
|
||||
|
||||
if (strcmp(cmds[5], "peers") == 0 && cmdCount > 6) {
|
||||
// create vnode voter vid 100 peers 127.0.0.1:10001 127.0.0.1:10002
|
||||
for (int i = 6; i < cmdCount; ++i) {
|
||||
snprintf(peers[i - 6], ADDRESS_LEN, "%s", cmds[i]);
|
||||
peersCount++;
|
||||
}
|
||||
} else {
|
||||
// create vnode voter vid 200
|
||||
}
|
||||
ret = addRaftVoter(pRaftServer, peers, peersCount, vid);
|
||||
if (ret == 0) {
|
||||
printf("create vnode voter ok \n");
|
||||
} else {
|
||||
printf("create vnode voter error \n");
|
||||
}
|
||||
} else if (strcmp(cmds[2], "spare") == 0) {
|
||||
ret = addRaftSpare(pRaftServer, vid);
|
||||
if (ret == 0) {
|
||||
printf("create vnode spare ok \n");
|
||||
} else {
|
||||
printf("create vnode spare error \n");
|
||||
}
|
||||
} else {
|
||||
printHelp();
|
||||
}
|
||||
|
||||
} else if (strcmp(cmds[0], "join") == 0 && strcmp(cmds[1], "vnode") == 0 && strcmp(cmds[2], "vid") == 0 &&
|
||||
strcmp(cmds[4], "addr") == 0 && cmdCount == 6) {
|
||||
// join vnode vid 100 addr 127.0.0.1:10004
|
||||
|
||||
char * address = cmds[5];
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
parseAddr(address, host, sizeof(host), &port);
|
||||
|
||||
uint16_t vid;
|
||||
sscanf(cmds[3], "%hu", &vid);
|
||||
|
||||
HashNode **pp = pRaftServer->raftInstances.find(&pRaftServer->raftInstances, vid);
|
||||
if (*pp == NULL) {
|
||||
printf("vid:%hu not found \n", vid);
|
||||
break;
|
||||
}
|
||||
RaftInstance *pRaftInstance = (*pp)->data;
|
||||
|
||||
uint64_t destRaftId = encodeRaftId(host, port, vid);
|
||||
|
||||
struct raft_change *req = raft_malloc(sizeof(*req));
|
||||
RaftJoin * pRaftJoin = raft_malloc(sizeof(*pRaftJoin));
|
||||
pRaftJoin->r = &pRaftInstance->raft;
|
||||
pRaftJoin->joinId = destRaftId;
|
||||
req->data = pRaftJoin;
|
||||
ret = raft_add(&pRaftInstance->raft, req, destRaftId, address, raftChangeAddCb);
|
||||
if (ret != 0) {
|
||||
printf("raft_add error: %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
}
|
||||
|
||||
} else if (strcmp(cmds[0], "dropnode") == 0) {
|
||||
} else if (strcmp(cmds[0], "state") == 0) {
|
||||
pRaftServer->raftInstances.print(&pRaftServer->raftInstances);
|
||||
for (size_t i = 0; i < pRaftServer->raftInstances.length; ++i) {
|
||||
HashNode *ptr = pRaftServer->raftInstances.table[i];
|
||||
if (ptr != NULL) {
|
||||
while (ptr != NULL) {
|
||||
RaftInstance *pRaftInstance = ptr->data;
|
||||
printf("instance vid:%hu raftId:%llu \n", ptr->vgroupId, pRaftInstance->raftId);
|
||||
printRaftState(&pRaftInstance->raft);
|
||||
printf("\n");
|
||||
ptr = ptr->next;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (strcmp(cmds[0], "put") == 0 && cmdCount == 4) {
|
||||
uint16_t vid;
|
||||
sscanf(cmds[1], "%hu", &vid);
|
||||
char * key = cmds[2];
|
||||
char * value = cmds[3];
|
||||
HashNode **pp = pRaftServer->raftInstances.find(&pRaftServer->raftInstances, vid);
|
||||
if (*pp == NULL) {
|
||||
printf("vid:%hu not found \n", vid);
|
||||
break;
|
||||
}
|
||||
RaftInstance *pRaftInstance = (*pp)->data;
|
||||
|
||||
char *raftValue = malloc(TOKEN_LEN * 2 + 3);
|
||||
snprintf(raftValue, TOKEN_LEN * 2 + 3, "%s--%s", key, value);
|
||||
putValue(&pRaftInstance->raft, raftValue);
|
||||
free(raftValue);
|
||||
|
||||
} else if (strcmp(cmds[0], "run") == 0) {
|
||||
pthread_t tidRaftServer;
|
||||
pthread_create(&tidRaftServer, NULL, startServerFunc, pRaftServer);
|
||||
|
||||
} else if (strcmp(cmds[0], "get") == 0 && cmdCount == 3) {
|
||||
uint16_t vid;
|
||||
sscanf(cmds[1], "%hu", &vid);
|
||||
char * key = cmds[2];
|
||||
HashNode **pp = pRaftServer->raftInstances.find(&pRaftServer->raftInstances, vid);
|
||||
if (*pp == NULL) {
|
||||
printf("vid:%hu not found \n", vid);
|
||||
break;
|
||||
}
|
||||
RaftInstance * pRaftInstance = (*pp)->data;
|
||||
SimpleHash * pKV = pRaftInstance->fsm.data;
|
||||
SimpleHashNode **ppNode = pKV->find_cstr(pKV, key);
|
||||
if (*ppNode == NULL) {
|
||||
printf("key:%s not found \n", key);
|
||||
} else {
|
||||
printf("find key:%s value:%s \n", key, (char *)((*ppNode)->data));
|
||||
}
|
||||
|
||||
} else if (strcmp(cmds[0], "transfer") == 0) {
|
||||
} else if (strcmp(cmds[0], "state") == 0) {
|
||||
} else if (strcmp(cmds[0], "snapshot") == 0) {
|
||||
} else if (strcmp(cmds[0], "exit") == 0) {
|
||||
exit(0);
|
||||
|
||||
} else if (strcmp(cmds[0], "quit") == 0) {
|
||||
exit(0);
|
||||
|
||||
} else if (strcmp(cmds[0], "help") == 0) {
|
||||
printHelp();
|
||||
|
||||
} else {
|
||||
printf("unknown command: %s \n", cmdBuf);
|
||||
printHelp();
|
||||
}
|
||||
|
||||
/*
|
||||
printf("cmdBuf: [%s] \n", cmdBuf);
|
||||
printf("cmdCount : %d \n", cmdCount);
|
||||
for (int i = 0; i < MAX_CMD_COUNT; ++i) {
|
||||
printf("cmd%d : %s \n", i, cmds[i]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
#ifndef TRAFT_CONSOLE_H
|
||||
#define TRAFT_CONSOLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
#include "raftServer.h"
|
||||
|
||||
void console(RaftServer *pRaftServer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,81 +0,0 @@
|
|||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#include <pthread.h>
|
||||
#include <raft.h>
|
||||
#include <raft/uv.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "console.h"
|
||||
#include "raftServer.h"
|
||||
#include "simpleHash.h"
|
||||
#include "util.h"
|
||||
|
||||
const char *exe_name;
|
||||
|
||||
void *startConsoleFunc(void *param) {
|
||||
RaftServer *pRaftServer = (RaftServer *)param;
|
||||
console(pRaftServer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void usage() {
|
||||
printf("\nusage: \n");
|
||||
printf("%s --addr=127.0.0.1:10000 --dir=./data \n", exe_name);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
RaftServerConfig gConfig;
|
||||
RaftServer gRaftServer;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
srand(time(NULL));
|
||||
int32_t ret;
|
||||
|
||||
exe_name = argv[0];
|
||||
if (argc < 3) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
ret = parseConf(argc, argv, &gConfig);
|
||||
if (ret != 0) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
printConf(&gConfig);
|
||||
|
||||
if (!dirOK(gConfig.baseDir)) {
|
||||
ret = mkdir(gConfig.baseDir, 0775);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "mkdir error, %s \n", gConfig.baseDir);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
ret = raftServerInit(&gRaftServer, &gConfig);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raftServerInit error \n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
pthread_t tidRaftServer;
|
||||
pthread_create(&tidRaftServer, NULL, startServerFunc, &gRaftServer);
|
||||
*/
|
||||
|
||||
pthread_t tidConsole;
|
||||
pthread_create(&tidConsole, NULL, startConsoleFunc, &gRaftServer);
|
||||
|
||||
while (1) {
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,286 +0,0 @@
|
|||
#include "raftServer.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "common.h"
|
||||
#include "simpleHash.h"
|
||||
#include "util.h"
|
||||
|
||||
void *startServerFunc(void *param) {
|
||||
RaftServer *pRaftServer = (RaftServer *)param;
|
||||
int32_t r = raftServerStart(pRaftServer);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void raftChangeAssignCb(struct raft_change *req, int status) {
|
||||
struct raft *r = req->data;
|
||||
if (status != 0) {
|
||||
printf("raftChangeAssignCb error: %s \n", raft_errmsg(r));
|
||||
} else {
|
||||
printf("raftChangeAssignCb ok \n");
|
||||
}
|
||||
raft_free(req);
|
||||
}
|
||||
|
||||
void raftChangeAddCb(struct raft_change *req, int status) {
|
||||
RaftJoin *pRaftJoin = req->data;
|
||||
if (status != 0) {
|
||||
printf("raftChangeAddCb error: %s \n", raft_errmsg(pRaftJoin->r));
|
||||
} else {
|
||||
struct raft_change *req2 = raft_malloc(sizeof(*req2));
|
||||
req2->data = pRaftJoin->r;
|
||||
int ret = raft_assign(pRaftJoin->r, req2, pRaftJoin->joinId, RAFT_VOTER, raftChangeAssignCb);
|
||||
if (ret != 0) {
|
||||
printf("raftChangeAddCb error: %s \n", raft_errmsg(pRaftJoin->r));
|
||||
}
|
||||
}
|
||||
raft_free(req->data);
|
||||
raft_free(req);
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result) {
|
||||
// get fsm data
|
||||
SimpleHash *sh = pFsm->data;
|
||||
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: [%s] \n", msg);
|
||||
char arr[2][TOKEN_LEN];
|
||||
int r = splitString(msg, "--", arr, 2);
|
||||
assert(r == 2);
|
||||
|
||||
// do the value on fsm
|
||||
sh->insert_cstr(sh, arr[0], arr[1]);
|
||||
|
||||
raft_free(buf->base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
struct raft *r = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error: %s \n", raft_errmsg(r));
|
||||
} else {
|
||||
printf("putValueCb: %s \n", "ok");
|
||||
}
|
||||
raft_free(req);
|
||||
}
|
||||
|
||||
void putValue(struct raft *r, const char *value) {
|
||||
struct raft_buffer buf;
|
||||
|
||||
buf.len = strlen(value) + 1;
|
||||
buf.base = raft_malloc(buf.len);
|
||||
snprintf(buf.base, buf.len, "%s", value);
|
||||
|
||||
struct raft_apply *req = raft_malloc(sizeof(*req));
|
||||
req->data = r;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
const char *state2String(unsigned short state) {
|
||||
if (state == RAFT_UNAVAILABLE) {
|
||||
return "RAFT_UNAVAILABLE";
|
||||
|
||||
} else if (state == RAFT_FOLLOWER) {
|
||||
return "RAFT_FOLLOWER";
|
||||
|
||||
} else if (state == RAFT_CANDIDATE) {
|
||||
return "RAFT_CANDIDATE";
|
||||
|
||||
} else if (state == RAFT_LEADER) {
|
||||
return "RAFT_LEADER";
|
||||
}
|
||||
return "UNKNOWN_RAFT_STATE";
|
||||
}
|
||||
|
||||
void printRaftConfiguration(struct raft_configuration *c) {
|
||||
printf("configuration: \n");
|
||||
for (int i = 0; i < c->n; ++i) {
|
||||
printf("%llu -- %d -- %s\n", c->servers[i].id, c->servers[i].role, c->servers[i].address);
|
||||
}
|
||||
}
|
||||
|
||||
void printRaftState(struct raft *r) {
|
||||
printf("----Raft State: -----------\n");
|
||||
printf("mem_addr: %p \n", r);
|
||||
printf("my_id: %llu \n", r->id);
|
||||
printf("address: %s \n", r->address);
|
||||
printf("current_term: %llu \n", r->current_term);
|
||||
printf("voted_for: %llu \n", r->voted_for);
|
||||
printf("role: %s \n", state2String(r->state));
|
||||
printf("commit_index: %llu \n", r->commit_index);
|
||||
printf("last_applied: %llu \n", r->last_applied);
|
||||
printf("last_stored: %llu \n", r->last_stored);
|
||||
|
||||
printf("configuration_index: %llu \n", r->configuration_index);
|
||||
printf("configuration_uncommitted_index: %llu \n", r->configuration_uncommitted_index);
|
||||
printRaftConfiguration(&r->configuration);
|
||||
|
||||
printf("----------------------------\n");
|
||||
}
|
||||
|
||||
int32_t addRaftVoter(RaftServer *pRaftServer, char peers[][ADDRESS_LEN], uint32_t peersCount, uint16_t vid) {
|
||||
int ret;
|
||||
|
||||
RaftInstance *pRaftInstance = malloc(sizeof(*pRaftInstance));
|
||||
assert(pRaftInstance != NULL);
|
||||
|
||||
// init raftId
|
||||
pRaftInstance->raftId = encodeRaftId(pRaftServer->host, pRaftServer->port, vid);
|
||||
|
||||
// init dir
|
||||
snprintf(pRaftInstance->dir, sizeof(pRaftInstance->dir), "%s/%s_%hu_%hu_%llu", pRaftServer->baseDir,
|
||||
pRaftServer->host, pRaftServer->port, vid, pRaftInstance->raftId);
|
||||
|
||||
if (!dirOK(pRaftInstance->dir)) {
|
||||
ret = mkdir(pRaftInstance->dir, 0775);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "mkdir error, %s \n", pRaftInstance->dir);
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
// init fsm
|
||||
pRaftInstance->fsm.data = newSimpleHash(2);
|
||||
pRaftInstance->fsm.apply = fsmApplyCb;
|
||||
|
||||
// init io
|
||||
ret = raft_uv_init(&pRaftInstance->io, &pRaftServer->loop, pRaftInstance->dir, &pRaftServer->transport);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_uv_init error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft
|
||||
ret = raft_init(&pRaftInstance->raft, &pRaftInstance->io, &pRaftInstance->fsm, pRaftInstance->raftId,
|
||||
pRaftServer->address);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_init error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft_configuration
|
||||
struct raft_configuration conf;
|
||||
raft_configuration_init(&conf);
|
||||
raft_configuration_add(&conf, pRaftInstance->raftId, pRaftServer->address, RAFT_VOTER);
|
||||
for (int i = 0; i < peersCount; ++i) {
|
||||
char * peerAddress = peers[i];
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
parseAddr(peerAddress, host, sizeof(host), &port);
|
||||
uint64_t raftId = encodeRaftId(host, port, vid);
|
||||
raft_configuration_add(&conf, raftId, peers[i], RAFT_VOTER);
|
||||
}
|
||||
raft_bootstrap(&pRaftInstance->raft, &conf);
|
||||
|
||||
// start raft
|
||||
ret = raft_start(&pRaftInstance->raft);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_start error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// add raft instance into raft server
|
||||
pRaftServer->raftInstances.insert(&pRaftServer->raftInstances, vid, pRaftInstance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t addRaftSpare(RaftServer *pRaftServer, uint16_t vid) {
|
||||
int ret;
|
||||
|
||||
RaftInstance *pRaftInstance = malloc(sizeof(*pRaftInstance));
|
||||
assert(pRaftInstance != NULL);
|
||||
|
||||
// init raftId
|
||||
pRaftInstance->raftId = encodeRaftId(pRaftServer->host, pRaftServer->port, vid);
|
||||
|
||||
// init dir
|
||||
snprintf(pRaftInstance->dir, sizeof(pRaftInstance->dir), "%s/%s_%hu_%hu_%llu", pRaftServer->baseDir,
|
||||
pRaftServer->host, pRaftServer->port, vid, pRaftInstance->raftId);
|
||||
ret = mkdir(pRaftInstance->dir, 0775);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "mkdir error, %s \n", pRaftInstance->dir);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init fsm
|
||||
pRaftInstance->fsm.data = newSimpleHash(2);
|
||||
pRaftInstance->fsm.apply = fsmApplyCb;
|
||||
|
||||
// init io
|
||||
ret = raft_uv_init(&pRaftInstance->io, &pRaftServer->loop, pRaftInstance->dir, &pRaftServer->transport);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_uv_init error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft
|
||||
ret = raft_init(&pRaftInstance->raft, &pRaftInstance->io, &pRaftInstance->fsm, pRaftInstance->raftId,
|
||||
pRaftServer->address);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_init error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft_configuration
|
||||
struct raft_configuration conf;
|
||||
raft_configuration_init(&conf);
|
||||
raft_configuration_add(&conf, pRaftInstance->raftId, pRaftServer->address, RAFT_SPARE);
|
||||
raft_bootstrap(&pRaftInstance->raft, &conf);
|
||||
|
||||
// start raft
|
||||
ret = raft_start(&pRaftInstance->raft);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_start error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// add raft instance into raft server
|
||||
pRaftServer->raftInstances.insert(&pRaftServer->raftInstances, vid, pRaftInstance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t raftServerInit(RaftServer *pRaftServer, const RaftServerConfig *pConf) {
|
||||
int ret;
|
||||
|
||||
// init host, port, address, dir
|
||||
snprintf(pRaftServer->host, sizeof(pRaftServer->host), "%s", pConf->me.host);
|
||||
pRaftServer->port = pConf->me.port;
|
||||
snprintf(pRaftServer->address, sizeof(pRaftServer->address), "%s:%u", pRaftServer->host, pRaftServer->port);
|
||||
snprintf(pRaftServer->baseDir, sizeof(pRaftServer->baseDir), "%s", pConf->baseDir);
|
||||
|
||||
// init loop
|
||||
ret = uv_loop_init(&pRaftServer->loop);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "uv_loop_init error: %s \n", uv_strerror(ret));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init network
|
||||
ret = raft_uv_tcp_init(&pRaftServer->transport, &pRaftServer->loop);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_uv_tcp_init: error %d \n", ret);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft instance container
|
||||
initIdHash(&pRaftServer->raftInstances, 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t raftServerStart(RaftServer *pRaftServer) {
|
||||
// start loop
|
||||
uv_run(&pRaftServer->loop, UV_RUN_DEFAULT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void raftServerStop(RaftServer *pRaftServer) {}
|
|
@ -1,66 +0,0 @@
|
|||
#ifndef TDENGINE_RAFT_SERVER_H
|
||||
#define TDENGINE_RAFT_SERVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "raft.h"
|
||||
#include "raft/uv.h"
|
||||
#include "simpleHash.h"
|
||||
|
||||
typedef struct RaftJoin {
|
||||
struct raft *r;
|
||||
raft_id joinId;
|
||||
} RaftJoin;
|
||||
|
||||
typedef struct {
|
||||
raft_id raftId;
|
||||
char dir[BASE_DIR_LEN * 2];
|
||||
struct raft_fsm fsm;
|
||||
struct raft_io io;
|
||||
struct raft raft;
|
||||
} RaftInstance;
|
||||
|
||||
typedef struct {
|
||||
char host[HOST_LEN];
|
||||
uint16_t port;
|
||||
char address[ADDRESS_LEN]; /* Raft instance address */
|
||||
char baseDir[BASE_DIR_LEN]; /* Raft instance address */
|
||||
|
||||
struct uv_loop_s loop; /* UV loop */
|
||||
struct raft_uv_transport transport; /* UV I/O backend transport */
|
||||
|
||||
IdHash raftInstances; /* multi raft instances. traft use IdHash to manager multi vgroup inside, here we can use IdHash
|
||||
too. */
|
||||
} RaftServer;
|
||||
|
||||
void * startServerFunc(void *param);
|
||||
int32_t addRaftVoter(RaftServer *pRaftServer, char peers[][ADDRESS_LEN], uint32_t peersCount, uint16_t vid);
|
||||
int32_t addRaftSpare(RaftServer *pRaftServer, uint16_t vid);
|
||||
|
||||
int32_t raftServerInit(RaftServer *pRaftServer, const RaftServerConfig *pConf);
|
||||
int32_t raftServerStart(RaftServer *pRaftServer);
|
||||
void raftServerStop(RaftServer *pRaftServer);
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result);
|
||||
void putValueCb(struct raft_apply *req, int status, void *result);
|
||||
void putValue(struct raft *r, const char *value);
|
||||
|
||||
void raftChangeAddCb(struct raft_change *req, int status);
|
||||
|
||||
const char *state2String(unsigned short state);
|
||||
void printRaftConfiguration(struct raft_configuration *c);
|
||||
void printRaftState(struct raft *r);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_RAFT_SERVER_H
|
|
@ -1,218 +0,0 @@
|
|||
#include "simpleHash.h"
|
||||
|
||||
uint32_t mySimpleHash(const char* data, size_t n, uint32_t seed) {
|
||||
// Similar to murmur hash
|
||||
const uint32_t m = 0xc6a4a793;
|
||||
const uint32_t r = 24;
|
||||
const char* limit = data + n;
|
||||
uint32_t h = seed ^ (n * m);
|
||||
|
||||
// Pick up four bytes at a time
|
||||
while (data + 4 <= limit) {
|
||||
// uint32_t w = DecodeFixed32(data);
|
||||
uint32_t w;
|
||||
memcpy(&w, data, 4);
|
||||
|
||||
data += 4;
|
||||
h += w;
|
||||
h *= m;
|
||||
h ^= (h >> 16);
|
||||
}
|
||||
|
||||
// Pick up remaining bytes
|
||||
switch (limit - data) {
|
||||
case 3:
|
||||
h += (unsigned char)(data[2]) << 16;
|
||||
do {
|
||||
} while (0);
|
||||
case 2:
|
||||
h += (unsigned char)(data[1]) << 8;
|
||||
do {
|
||||
} while (0);
|
||||
case 1:
|
||||
h += (unsigned char)(data[0]);
|
||||
h *= m;
|
||||
h ^= (h >> r);
|
||||
break;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
int insertCStrSimpleHash(struct SimpleHash* ths, char* key, char* data) {
|
||||
return insertSimpleHash(ths, key, strlen(key) + 1, data, strlen(data) + 1);
|
||||
}
|
||||
|
||||
int removeCStrSimpleHash(struct SimpleHash* ths, char* key) { return removeSimpleHash(ths, key, strlen(key) + 1); }
|
||||
|
||||
SimpleHashNode** findCStrSimpleHash(struct SimpleHash* ths, char* key) {
|
||||
return findSimpleHash(ths, key, strlen(key) + 1);
|
||||
}
|
||||
|
||||
int insertSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen, char* data, size_t dataLen) {
|
||||
SimpleHashNode** pp = ths->find(ths, key, keyLen);
|
||||
if (*pp != NULL) {
|
||||
fprintf(stderr, "insertSimpleHash, already has key \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SimpleHashNode* node = malloc(sizeof(*node));
|
||||
node->hashCode = ths->hashFunc(key, keyLen);
|
||||
node->key = malloc(keyLen);
|
||||
node->keyLen = keyLen;
|
||||
memcpy(node->key, key, keyLen);
|
||||
node->data = malloc(dataLen);
|
||||
node->dataLen = dataLen;
|
||||
memcpy(node->data, data, dataLen);
|
||||
node->next = NULL;
|
||||
|
||||
// printf("insertSimpleHash: <%s, %ld, %s, %ld, %u> \n", node->key, node->keyLen, node->data, node->dataLen,
|
||||
// node->hashCode);
|
||||
|
||||
size_t index = node->hashCode & (ths->length - 1);
|
||||
|
||||
SimpleHashNode* ptr = ths->table[index];
|
||||
if (ptr != NULL) {
|
||||
node->next = ptr;
|
||||
ths->table[index] = node;
|
||||
|
||||
} else {
|
||||
ths->table[index] = node;
|
||||
}
|
||||
ths->elems++;
|
||||
if (ths->elems > 2 * ths->length) {
|
||||
ths->resize(ths);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int removeSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen) {
|
||||
SimpleHashNode** pp = ths->find(ths, key, keyLen);
|
||||
if (*pp == NULL) {
|
||||
fprintf(stderr, "removeSimpleHash, key not exist \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SimpleHashNode* del = *pp;
|
||||
*pp = del->next;
|
||||
free(del->key);
|
||||
free(del->data);
|
||||
free(del);
|
||||
ths->elems--;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SimpleHashNode** findSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen) {
|
||||
uint32_t hashCode = ths->hashFunc(key, keyLen);
|
||||
// size_t index = hashCode % ths->length;
|
||||
size_t index = hashCode & (ths->length - 1);
|
||||
|
||||
// printf("findSimpleHash: %s %ld %u \n", key, keyLen, hashCode);
|
||||
|
||||
SimpleHashNode** pp = &(ths->table[index]);
|
||||
while (*pp != NULL && ((*pp)->hashCode != hashCode || memcmp(key, (*pp)->key, keyLen) != 0)) {
|
||||
pp = &((*pp)->next);
|
||||
}
|
||||
|
||||
return pp;
|
||||
}
|
||||
|
||||
void printCStrSimpleHash(struct SimpleHash* ths) {
|
||||
printf("\n--- printCStrSimpleHash: elems:%d length:%d \n", ths->elems, ths->length);
|
||||
for (size_t i = 0; i < ths->length; ++i) {
|
||||
SimpleHashNode* ptr = ths->table[i];
|
||||
if (ptr != NULL) {
|
||||
printf("%zu: ", i);
|
||||
while (ptr != NULL) {
|
||||
printf("<%u, %s, %ld, %s, %ld> ", ptr->hashCode, (char*)ptr->key, ptr->keyLen, (char*)ptr->data, ptr->dataLen);
|
||||
ptr = ptr->next;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("---------------\n");
|
||||
}
|
||||
|
||||
void destroySimpleHash(struct SimpleHash* ths) {
|
||||
for (size_t i = 0; i < ths->length; ++i) {
|
||||
SimpleHashNode* ptr = ths->table[i];
|
||||
while (ptr != NULL) {
|
||||
SimpleHashNode* tmp = ptr;
|
||||
ptr = ptr->next;
|
||||
free(tmp->key);
|
||||
free(tmp->data);
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
ths->length = 0;
|
||||
ths->elems = 0;
|
||||
free(ths->table);
|
||||
free(ths);
|
||||
}
|
||||
|
||||
void resizeSimpleHash(struct SimpleHash* ths) {
|
||||
uint32_t new_length = ths->length;
|
||||
while (new_length < ths->elems) {
|
||||
new_length *= 2;
|
||||
}
|
||||
|
||||
printf("resizeSimpleHash: %p from %u to %u \n", ths, ths->length, new_length);
|
||||
|
||||
SimpleHashNode** new_table = malloc(new_length * sizeof(SimpleHashNode*));
|
||||
memset(new_table, 0, new_length * sizeof(SimpleHashNode*));
|
||||
|
||||
uint32_t count = 0;
|
||||
for (uint32_t i = 0; i < ths->length; i++) {
|
||||
if (ths->table[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SimpleHashNode* it = ths->table[i];
|
||||
while (it != NULL) {
|
||||
SimpleHashNode* move_node = it;
|
||||
it = it->next;
|
||||
|
||||
// move move_node
|
||||
move_node->next = NULL;
|
||||
size_t index = move_node->hashCode & (new_length - 1);
|
||||
|
||||
SimpleHashNode* ptr = new_table[index];
|
||||
if (ptr != NULL) {
|
||||
move_node->next = ptr;
|
||||
new_table[index] = move_node;
|
||||
} else {
|
||||
new_table[index] = move_node;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(ths->elems == count);
|
||||
free(ths->table);
|
||||
ths->table = new_table;
|
||||
ths->length = new_length;
|
||||
}
|
||||
|
||||
uint32_t simpleHashFunc(const char* key, size_t keyLen) { return mySimpleHash(key, keyLen, 1); }
|
||||
|
||||
struct SimpleHash* newSimpleHash(size_t length) {
|
||||
struct SimpleHash* ths = malloc(sizeof(*ths));
|
||||
|
||||
ths->length = length;
|
||||
ths->elems = 0;
|
||||
ths->table = malloc(length * sizeof(SimpleHashNode*));
|
||||
memset(ths->table, 0, length * sizeof(SimpleHashNode*));
|
||||
|
||||
ths->insert = insertSimpleHash;
|
||||
ths->remove = removeSimpleHash;
|
||||
ths->find = findSimpleHash;
|
||||
ths->insert_cstr = insertCStrSimpleHash;
|
||||
ths->remove_cstr = removeCStrSimpleHash;
|
||||
ths->find_cstr = findCStrSimpleHash;
|
||||
ths->print_cstr = printCStrSimpleHash;
|
||||
ths->destroy = destroySimpleHash;
|
||||
ths->resize = resizeSimpleHash;
|
||||
ths->hashFunc = simpleHashFunc;
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
#ifndef __SIMPLE_HASH_H__
|
||||
#define __SIMPLE_HASH_H__
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
uint32_t mySimpleHash(const char* data, size_t n, uint32_t seed);
|
||||
|
||||
typedef struct SimpleHashNode {
|
||||
uint32_t hashCode;
|
||||
void* key;
|
||||
size_t keyLen;
|
||||
void* data;
|
||||
size_t dataLen;
|
||||
struct SimpleHashNode* next;
|
||||
} SimpleHashNode;
|
||||
|
||||
typedef struct SimpleHash {
|
||||
// public:
|
||||
|
||||
int (*insert)(struct SimpleHash* ths, char* key, size_t keyLen, char* data, size_t dataLen);
|
||||
int (*remove)(struct SimpleHash* ths, char* key, size_t keyLen);
|
||||
SimpleHashNode** (*find)(struct SimpleHash* ths, char* key, size_t keyLen);
|
||||
|
||||
// wrapper
|
||||
int (*insert_cstr)(struct SimpleHash* ths, char* key, char* data);
|
||||
int (*remove_cstr)(struct SimpleHash* ths, char* key);
|
||||
SimpleHashNode** (*find_cstr)(struct SimpleHash* ths, char* key);
|
||||
|
||||
void (*print_cstr)(struct SimpleHash* ths);
|
||||
void (*destroy)(struct SimpleHash* ths);
|
||||
|
||||
uint32_t length;
|
||||
uint32_t elems;
|
||||
|
||||
// private:
|
||||
void (*resize)(struct SimpleHash* ths);
|
||||
uint32_t (*hashFunc)(const char* key, size_t keyLen);
|
||||
|
||||
SimpleHashNode** table;
|
||||
|
||||
} SimpleHash;
|
||||
|
||||
int insertCStrSimpleHash(struct SimpleHash* ths, char* key, char* data);
|
||||
int removeCStrSimpleHash(struct SimpleHash* ths, char* key);
|
||||
SimpleHashNode** findCStrSimpleHash(struct SimpleHash* ths, char* key);
|
||||
void printCStrSimpleHash(struct SimpleHash* ths);
|
||||
|
||||
int insertSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen, char* data, size_t dataLen);
|
||||
int removeSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen);
|
||||
SimpleHashNode** findSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen);
|
||||
void destroySimpleHash(struct SimpleHash* ths);
|
||||
void resizeSimpleHash(struct SimpleHash* ths);
|
||||
uint32_t simpleHashFunc(const char* key, size_t keyLen);
|
||||
|
||||
struct SimpleHash* newSimpleHash(size_t length);
|
||||
|
||||
#endif
|
|
@ -1,45 +0,0 @@
|
|||
#include "util.h"
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int dirOK(const char *path) {
|
||||
DIR *dir = opendir(path);
|
||||
if (dir != NULL) {
|
||||
closedir(dir);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int splitString(const char *str, char *separator, char (*arr)[TOKEN_LEN], int n_arr) {
|
||||
if (n_arr <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *tmp = (char *)malloc(strlen(str) + 1);
|
||||
strcpy(tmp, str);
|
||||
char *context;
|
||||
int n = 0;
|
||||
|
||||
char *token = strtok_r(tmp, separator, &context);
|
||||
if (!token) {
|
||||
goto ret;
|
||||
}
|
||||
strncpy(arr[n], token, TOKEN_LEN);
|
||||
n++;
|
||||
|
||||
while (1) {
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (!token || n >= n_arr) {
|
||||
goto ret;
|
||||
}
|
||||
strncpy(arr[n], token, TOKEN_LEN);
|
||||
n++;
|
||||
}
|
||||
|
||||
ret:
|
||||
free(tmp);
|
||||
return n;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef TRAFT_UTIL_H
|
||||
#define TRAFT_UTIL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
|
||||
int dirOK(const char *path);
|
||||
int splitString(const char *str, char *separator, char (*arr)[TOKEN_LEN], int n_arr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,7 +0,0 @@
|
|||
add_executable(rebalanceLeader "")
|
||||
target_sources(rebalanceLeader
|
||||
PRIVATE
|
||||
"raftMain.c"
|
||||
"raftServer.c"
|
||||
)
|
||||
target_link_libraries(rebalanceLeader PUBLIC traft lz4 uv_a)
|
|
@ -1,36 +0,0 @@
|
|||
#ifndef TDENGINE_COMMON_H
|
||||
#define TDENGINE_COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MAX_INSTANCE_NUM 100
|
||||
|
||||
#define MAX_PEERS 10
|
||||
#define COMMAND_LEN 1024
|
||||
#define TOKEN_LEN 128
|
||||
#define DIR_LEN 256
|
||||
#define HOST_LEN 64
|
||||
#define ADDRESS_LEN (HOST_LEN + 16)
|
||||
|
||||
typedef struct {
|
||||
char host[HOST_LEN];
|
||||
uint32_t port;
|
||||
} Addr;
|
||||
|
||||
typedef struct {
|
||||
Addr me;
|
||||
Addr peers[MAX_PEERS];
|
||||
int peersCount;
|
||||
char dir[DIR_LEN];
|
||||
char dataDir[DIR_LEN + HOST_LEN * 2];
|
||||
} SRaftServerConfig;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_COMMON_H
|
|
@ -1,678 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <raft.h>
|
||||
#include <raft/uv.h>
|
||||
#include "raftServer.h"
|
||||
#include "common.h"
|
||||
|
||||
const char *exe_name;
|
||||
|
||||
typedef struct LeaderState {
|
||||
char address[48];
|
||||
int leaderCount;
|
||||
|
||||
} LeaderState;
|
||||
|
||||
#define NODE_COUNT 3
|
||||
LeaderState leaderStates[NODE_COUNT];
|
||||
|
||||
void printLeaderCount() {
|
||||
for (int i = 0; i < NODE_COUNT; ++i) {
|
||||
printf("%s: leaderCount:%d \n", leaderStates[i].address, leaderStates[i].leaderCount);
|
||||
}
|
||||
}
|
||||
|
||||
void updateLeaderStates(SRaftServer *pRaftServer) {
|
||||
for (int i = 0; i < pRaftServer->instance[0].raft.configuration.n; ++i) {
|
||||
snprintf(leaderStates[i].address, sizeof(leaderStates[i].address), "%s", pRaftServer->instance[0].raft.configuration.servers[i].address);
|
||||
leaderStates[i].leaderCount = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||
struct raft *r = &pRaftServer->instance[i].raft;
|
||||
|
||||
char leaderAddress[128];
|
||||
memset(leaderAddress, 0, sizeof(leaderAddress));
|
||||
|
||||
if (r->state == RAFT_LEADER) {
|
||||
snprintf(leaderAddress, sizeof(leaderAddress), "%s", r->address);
|
||||
} else if (r->state == RAFT_FOLLOWER) {
|
||||
snprintf(leaderAddress, sizeof(leaderAddress), "%s", r->follower_state.current_leader.address);
|
||||
}
|
||||
|
||||
for (int j = 0; j < NODE_COUNT; j++) {
|
||||
if (strcmp(leaderAddress, leaderStates[j].address) == 0) {
|
||||
leaderStates[j].leaderCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void raftTransferCb(struct raft_transfer *req) {
|
||||
SRaftServer *pRaftServer = req->data;
|
||||
raft_free(req);
|
||||
|
||||
//printf("raftTransferCb: \n");
|
||||
updateLeaderStates(pRaftServer);
|
||||
//printLeaderCount();
|
||||
|
||||
int myLeaderCount;
|
||||
for (int i = 0; i < NODE_COUNT; ++i) {
|
||||
if (strcmp(pRaftServer->address, leaderStates[i].address) == 0) {
|
||||
myLeaderCount = leaderStates[i].leaderCount;
|
||||
}
|
||||
}
|
||||
|
||||
//printf("myLeaderCount:%d waterLevel:%d \n", myLeaderCount, pRaftServer->instanceCount / NODE_COUNT);
|
||||
if (myLeaderCount > pRaftServer->instanceCount / NODE_COUNT) {
|
||||
struct raft *r;
|
||||
for (int j = 0; j < pRaftServer->instanceCount; ++j) {
|
||||
if (pRaftServer->instance[j].raft.state == RAFT_LEADER) {
|
||||
r = &pRaftServer->instance[j].raft;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct raft_transfer *transfer = raft_malloc(sizeof(*transfer));
|
||||
transfer->data = pRaftServer;
|
||||
|
||||
uint64_t destRaftId;
|
||||
int minIndex = -1;
|
||||
int minLeaderCount = myLeaderCount;
|
||||
for (int j = 0; j < NODE_COUNT; ++j) {
|
||||
if (strcmp(leaderStates[j].address, pRaftServer->address) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (leaderStates[j].leaderCount <= minLeaderCount) {
|
||||
minLeaderCount = leaderStates[j].leaderCount;
|
||||
minIndex = j;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char myHost[48];
|
||||
uint16_t myPort;
|
||||
uint16_t myVid;
|
||||
decodeRaftId(r->id, myHost, sizeof(myHost), &myPort, &myVid);
|
||||
|
||||
|
||||
//printf("raftTransferCb transfer leader: vid[%u] choose: index:%d, leaderStates[%d].address:%s, leaderStates[%d].leaderCount:%d \n", minIndex, minIndex, leaderStates[minIndex].address, minIndex, leaderStates[minIndex].leaderCount);
|
||||
|
||||
char *destAddress = leaderStates[minIndex].address;
|
||||
|
||||
char tokens[MAX_PEERS][MAX_TOKEN_LEN];
|
||||
splitString(destAddress, ":", tokens, 2);
|
||||
char *destHost = tokens[0];
|
||||
uint16_t destPort = atoi(tokens[1]);
|
||||
destRaftId = encodeRaftId(destHost, destPort, myVid);
|
||||
|
||||
printf("\nraftTransferCb transfer leader: vgroupId:%u from:%s:%u --> to:%s:%u ", myVid, myHost, myPort, destHost, destPort);
|
||||
fflush(stdout);
|
||||
|
||||
raft_transfer(r, transfer, destRaftId, raftTransferCb);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void parseAddr(const char *addr, char *host, int len, uint32_t *port) {
|
||||
char* tmp = (char*)malloc(strlen(addr) + 1);
|
||||
strcpy(tmp, addr);
|
||||
|
||||
char* context;
|
||||
char* separator = ":";
|
||||
char* token = strtok_r(tmp, separator, &context);
|
||||
if (token) {
|
||||
snprintf(host, len, "%s", token);
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (token) {
|
||||
sscanf(token, "%u", port);
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
// only parse 3 tokens
|
||||
int parseCommand3(const char* str, char* token1, char* token2, char* token3, int len)
|
||||
{
|
||||
char* tmp = (char*)malloc(strlen(str) + 1);
|
||||
strcpy(tmp, str);
|
||||
|
||||
char* context;
|
||||
char* separator = " ";
|
||||
int n = 0;
|
||||
|
||||
char* token = strtok_r(tmp, separator, &context);
|
||||
if (!token) {
|
||||
goto ret;
|
||||
}
|
||||
if (strcmp(token, "") != 0) {
|
||||
strncpy(token1, token, len);
|
||||
n++;
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (!token) {
|
||||
goto ret;
|
||||
}
|
||||
if (strcmp(token, "") != 0) {
|
||||
strncpy(token2, token, len);
|
||||
n++;
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (!token) {
|
||||
goto ret;
|
||||
}
|
||||
if (strcmp(token, "") != 0) {
|
||||
strncpy(token3, token, len);
|
||||
n++;
|
||||
}
|
||||
|
||||
ret:
|
||||
return n;
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
// only parse 4 tokens
|
||||
int parseCommand4(const char* str, char* token1, char* token2, char* token3, char *token4, int len)
|
||||
{
|
||||
char* tmp = (char*)malloc(strlen(str) + 1);
|
||||
strcpy(tmp, str);
|
||||
|
||||
char* context;
|
||||
char* separator = " ";
|
||||
int n = 0;
|
||||
|
||||
char* token = strtok_r(tmp, separator, &context);
|
||||
if (!token) {
|
||||
goto ret;
|
||||
}
|
||||
if (strcmp(token, "") != 0) {
|
||||
strncpy(token1, token, len);
|
||||
n++;
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (!token) {
|
||||
goto ret;
|
||||
}
|
||||
if (strcmp(token, "") != 0) {
|
||||
strncpy(token2, token, len);
|
||||
n++;
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (!token) {
|
||||
goto ret;
|
||||
}
|
||||
if (strcmp(token, "") != 0) {
|
||||
strncpy(token3, token, len);
|
||||
n++;
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (!token) {
|
||||
goto ret;
|
||||
}
|
||||
if (strcmp(token, "") != 0) {
|
||||
strncpy(token4, token, len);
|
||||
n++;
|
||||
}
|
||||
|
||||
ret:
|
||||
return n;
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
void *startServerFunc(void *param) {
|
||||
SRaftServer *pServer = (SRaftServer*)param;
|
||||
int32_t r = raftServerStart(pServer);
|
||||
assert(r == 0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Console ---------------------------------
|
||||
const char* state2String(unsigned short state) {
|
||||
if (state == RAFT_UNAVAILABLE) {
|
||||
return "RAFT_UNAVAILABLE";
|
||||
|
||||
} else if (state == RAFT_FOLLOWER) {
|
||||
return "RAFT_FOLLOWER";
|
||||
|
||||
} else if (state == RAFT_CANDIDATE) {
|
||||
return "RAFT_CANDIDATE";
|
||||
|
||||
} else if (state == RAFT_LEADER) {
|
||||
return "RAFT_LEADER";
|
||||
|
||||
}
|
||||
return "UNKNOWN_RAFT_STATE";
|
||||
}
|
||||
|
||||
|
||||
void printRaftState2(struct raft *r) {
|
||||
char leaderAddress[128];
|
||||
memset(leaderAddress, 0, sizeof(leaderAddress));
|
||||
|
||||
if (r->state == RAFT_LEADER) {
|
||||
snprintf(leaderAddress, sizeof(leaderAddress), "%s", r->address);
|
||||
} else if (r->state == RAFT_FOLLOWER) {
|
||||
snprintf(leaderAddress, sizeof(leaderAddress), "%s", r->follower_state.current_leader.address);
|
||||
}
|
||||
|
||||
for (int i = 0; i < r->configuration.n; ++i) {
|
||||
char tmpAddress[128];
|
||||
snprintf(tmpAddress, sizeof(tmpAddress), "%s", r->configuration.servers[i].address);
|
||||
|
||||
uint64_t raftId = r->configuration.servers[i].id;
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
uint16_t vid;
|
||||
decodeRaftId(raftId, host, 128, &port, &vid);
|
||||
|
||||
char buf[512];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (strcmp(tmpAddress, leaderAddress) == 0) {
|
||||
snprintf(buf, sizeof(buf), "<%s:%u-%u-LEADER>\t", host, port, vid);
|
||||
} else {
|
||||
snprintf(buf, sizeof(buf), "<%s:%u-%u-FOLLOWER>\t", host, port, vid);
|
||||
}
|
||||
printf("%s", buf);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void printRaftConfiguration(struct raft_configuration *c) {
|
||||
printf("configuration: \n");
|
||||
for (int i = 0; i < c->n; ++i) {
|
||||
printf("%llu -- %d -- %s\n", c->servers[i].id, c->servers[i].role, c->servers[i].address);
|
||||
}
|
||||
}
|
||||
|
||||
void printRaftState(struct raft *r) {
|
||||
printf("----Raft State: -----------\n");
|
||||
printf("mem_addr: %p \n", r);
|
||||
printf("my_id: %llu \n", r->id);
|
||||
printf("address: %s \n", r->address);
|
||||
printf("current_term: %llu \n", r->current_term);
|
||||
printf("voted_for: %llu \n", r->voted_for);
|
||||
printf("role: %s \n", state2String(r->state));
|
||||
printf("commit_index: %llu \n", r->commit_index);
|
||||
printf("last_applied: %llu \n", r->last_applied);
|
||||
printf("last_stored: %llu \n", r->last_stored);
|
||||
|
||||
printf("configuration_index: %llu \n", r->configuration_index);
|
||||
printf("configuration_uncommitted_index: %llu \n", r->configuration_uncommitted_index);
|
||||
printRaftConfiguration(&r->configuration);
|
||||
|
||||
printf("----------------------------\n");
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
raft_free(req);
|
||||
struct raft *r = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb: %s \n", raft_errmsg(r));
|
||||
} else {
|
||||
printf("putValueCb: %s \n", "ok");
|
||||
}
|
||||
}
|
||||
|
||||
void putValue(struct raft *r, const char *value) {
|
||||
struct raft_buffer buf;
|
||||
|
||||
buf.len = TOKEN_LEN;;
|
||||
buf.base = raft_malloc(buf.len);
|
||||
snprintf(buf.base, buf.len, "%s", value);
|
||||
|
||||
struct raft_apply *req = raft_malloc(sizeof(struct raft_apply));
|
||||
req->data = r;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char*)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
void getValue(const char *key) {
|
||||
char *ptr = getKV(key);
|
||||
if (ptr) {
|
||||
printf("get value: [%s] \n", ptr);
|
||||
} else {
|
||||
printf("value not found for key: [%s] \n", key);
|
||||
}
|
||||
}
|
||||
|
||||
void console(SRaftServer *pRaftServer) {
|
||||
while (1) {
|
||||
char cmd_buf[COMMAND_LEN];
|
||||
memset(cmd_buf, 0, sizeof(cmd_buf));
|
||||
printf("(console)> ");
|
||||
char *ret = fgets(cmd_buf, COMMAND_LEN, stdin);
|
||||
if (!ret) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int pos = strlen(cmd_buf);
|
||||
if(cmd_buf[pos - 1] == '\n') {
|
||||
cmd_buf[pos - 1] = '\0';
|
||||
}
|
||||
|
||||
if (strncmp(cmd_buf, "", COMMAND_LEN) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char cmd[TOKEN_LEN];
|
||||
memset(cmd, 0, sizeof(cmd));
|
||||
|
||||
char param1[TOKEN_LEN];
|
||||
memset(param1, 0, sizeof(param1));
|
||||
|
||||
char param2[TOKEN_LEN];
|
||||
memset(param2, 0, sizeof(param2));
|
||||
|
||||
char param3[TOKEN_LEN];
|
||||
memset(param2, 0, sizeof(param2));
|
||||
|
||||
parseCommand4(cmd_buf, cmd, param1, param2, param3, TOKEN_LEN);
|
||||
if (strcmp(cmd, "addnode") == 0) {
|
||||
printf("not support \n");
|
||||
|
||||
/*
|
||||
char host[HOST_LEN];
|
||||
uint32_t port;
|
||||
parseAddr(param1, host, HOST_LEN, &port);
|
||||
uint64_t rid = raftId(host, port);
|
||||
|
||||
struct raft_change *req = raft_malloc(sizeof(*req));
|
||||
int r = raft_add(&pRaftServer->raft, req, rid, param1, NULL);
|
||||
if (r != 0) {
|
||||
printf("raft_add: %s \n", raft_errmsg(&pRaftServer->raft));
|
||||
}
|
||||
printf("add node: %lu %s \n", rid, param1);
|
||||
|
||||
struct raft_change *req2 = raft_malloc(sizeof(*req2));
|
||||
r = raft_assign(&pRaftServer->raft, req2, rid, RAFT_VOTER, NULL);
|
||||
if (r != 0) {
|
||||
printf("raft_assign: %s \n", raft_errmsg(&pRaftServer->raft));
|
||||
}
|
||||
*/
|
||||
|
||||
} else if (strcmp(cmd, "dropnode") == 0) {
|
||||
printf("not support \n");
|
||||
|
||||
} else if (strcmp(cmd, "quit") == 0 || strcmp(cmd, "exit") == 0) {
|
||||
exit(0);
|
||||
|
||||
} else if (strcmp(cmd, "rebalance") == 0 && strcmp(param1, "leader") == 0) {
|
||||
|
||||
/*
|
||||
updateLeaderStates(pRaftServer);
|
||||
|
||||
int myLeaderCount;
|
||||
for (int i = 0; i < NODE_COUNT; ++i) {
|
||||
if (strcmp(pRaftServer->address, leaderStates[i].address) == 0) {
|
||||
myLeaderCount = leaderStates[i].leaderCount;
|
||||
}
|
||||
}
|
||||
|
||||
while (myLeaderCount > pRaftServer->instanceCount / NODE_COUNT) {
|
||||
printf("myLeaderCount:%d waterLevel:%d \n", myLeaderCount, pRaftServer->instanceCount / NODE_COUNT);
|
||||
|
||||
struct raft *r;
|
||||
for (int j = 0; j < pRaftServer->instanceCount; ++j) {
|
||||
if (pRaftServer->instance[j].raft.state == RAFT_LEADER) {
|
||||
r = &pRaftServer->instance[j].raft;
|
||||
}
|
||||
}
|
||||
|
||||
struct raft_transfer *transfer = raft_malloc(sizeof(*transfer));
|
||||
transfer->data = pRaftServer;
|
||||
|
||||
uint64_t destRaftId;
|
||||
int minIndex = -1;
|
||||
int minLeaderCount = myLeaderCount;
|
||||
for (int j = 0; j < NODE_COUNT; ++j) {
|
||||
if (strcmp(leaderStates[j].address, pRaftServer->address) == 0) continue;
|
||||
|
||||
printf("-----leaderStates[%d].leaderCount:%d \n", j, leaderStates[j].leaderCount);
|
||||
if (leaderStates[j].leaderCount <= minLeaderCount) {
|
||||
minIndex = j;
|
||||
printf("++++ assign minIndex : %d \n", minIndex);
|
||||
}
|
||||
}
|
||||
|
||||
printf("minIndex:%d minLeaderCount:%d \n", minIndex, minLeaderCount);
|
||||
|
||||
char myHost[48];
|
||||
uint16_t myPort;
|
||||
uint16_t myVid;
|
||||
decodeRaftId(r->id, myHost, sizeof(myHost), &myPort, &myVid);
|
||||
|
||||
char *destAddress = leaderStates[minIndex].address;
|
||||
|
||||
char tokens[MAX_PEERS][MAX_TOKEN_LEN];
|
||||
splitString(destAddress, ":", tokens, 2);
|
||||
char *destHost = tokens[0];
|
||||
uint16_t destPort = atoi(tokens[1]);
|
||||
destRaftId = encodeRaftId(destHost, destPort, myVid);
|
||||
|
||||
printf("destHost:%s destPort:%u myVid:%u", destHost, destPort, myVid);
|
||||
raft_transfer(r, transfer, destRaftId, raftTransferCb);
|
||||
sleep(1);
|
||||
|
||||
for (int i = 0; i < NODE_COUNT; ++i) {
|
||||
if (strcmp(pRaftServer->address, leaderStates[i].address) == 0) {
|
||||
myLeaderCount = leaderStates[i].leaderCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
int leaderCount = 0;
|
||||
|
||||
struct raft *firstR;
|
||||
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||
struct raft *r = &pRaftServer->instance[i].raft;
|
||||
if (r->state == RAFT_LEADER) {
|
||||
leaderCount++;
|
||||
firstR = r;
|
||||
}
|
||||
}
|
||||
|
||||
if (leaderCount > pRaftServer->instanceCount / NODE_COUNT) {
|
||||
struct raft_transfer *transfer = raft_malloc(sizeof(*transfer));
|
||||
transfer->data = pRaftServer;
|
||||
raft_transfer(firstR, transfer, 0, raftTransferCb);
|
||||
}
|
||||
|
||||
|
||||
} else if (strcmp(cmd, "put") == 0) {
|
||||
char buf[256];
|
||||
uint16_t vid;
|
||||
sscanf(param1, "%hu", &vid);
|
||||
snprintf(buf, sizeof(buf), "%s--%s", param2, param3);
|
||||
putValue(&pRaftServer->instance[vid].raft, buf);
|
||||
|
||||
} else if (strcmp(cmd, "get") == 0) {
|
||||
getValue(param1);
|
||||
|
||||
} else if (strcmp(cmd, "transfer") == 0) {
|
||||
uint16_t vid;
|
||||
sscanf(param1, "%hu", &vid);
|
||||
|
||||
struct raft_transfer transfer;
|
||||
raft_transfer(&pRaftServer->instance[vid].raft, &transfer, 0, NULL);
|
||||
|
||||
|
||||
} else if (strcmp(cmd, "state") == 0) {
|
||||
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||
printf("instance %d: ", i);
|
||||
printRaftState(&pRaftServer->instance[i].raft);
|
||||
}
|
||||
|
||||
} else if (strcmp(cmd, "leader") == 0 && strcmp(param1, "state") == 0) {
|
||||
updateLeaderStates(pRaftServer);
|
||||
printf("\n--------------------------------------------\n");
|
||||
printLeaderCount();
|
||||
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||
printRaftState2(&pRaftServer->instance[i].raft);
|
||||
}
|
||||
printf("--------------------------------------------\n");
|
||||
|
||||
} else if (strcmp(cmd, "snapshot") == 0) {
|
||||
printf("not support \n");
|
||||
|
||||
} else if (strcmp(cmd, "help") == 0) {
|
||||
printf("addnode \"127.0.0.1:8888\" \n");
|
||||
printf("dropnode \"127.0.0.1:8888\" \n");
|
||||
printf("put key value \n");
|
||||
printf("get key \n");
|
||||
printf("state \n");
|
||||
|
||||
} else {
|
||||
printf("unknown command: [%s], type \"help\" to see help \n", cmd);
|
||||
}
|
||||
|
||||
//printf("cmd_buf: [%s] \n", cmd_buf);
|
||||
}
|
||||
}
|
||||
|
||||
void *startConsoleFunc(void *param) {
|
||||
SRaftServer *pServer = (SRaftServer*)param;
|
||||
console(pServer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Config ---------------------------------
|
||||
void usage() {
|
||||
printf("\nusage: \n");
|
||||
printf("%s --me=127.0.0.1:10000 --dir=./data \n", exe_name);
|
||||
printf("\n");
|
||||
printf("%s --me=127.0.0.1:10000 --peers=127.0.0.1:10001,127.0.0.1:10002 --dir=./data \n", exe_name);
|
||||
printf("%s --me=127.0.0.1:10001 --peers=127.0.0.1:10000,127.0.0.1:10002 --dir=./data \n", exe_name);
|
||||
printf("%s --me=127.0.0.1:10002 --peers=127.0.0.1:10000,127.0.0.1:10001 --dir=./data \n", exe_name);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void parseConf(int argc, char **argv, SRaftServerConfig *pConf) {
|
||||
memset(pConf, 0, sizeof(*pConf));
|
||||
|
||||
int option_index, option_value;
|
||||
option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"peers", required_argument, NULL, 'p'},
|
||||
{"me", required_argument, NULL, 'm'},
|
||||
{"dir", required_argument, NULL, 'd'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
while ((option_value = getopt_long(argc, argv, "hp:m:d:", long_options, &option_index)) != -1) {
|
||||
switch (option_value) {
|
||||
case 'm': {
|
||||
parseAddr(optarg, pConf->me.host, sizeof(pConf->me.host), &pConf->me.port);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'p': {
|
||||
char tokens[MAX_PEERS][MAX_TOKEN_LEN];
|
||||
int peerCount = splitString(optarg, ",", tokens, MAX_PEERS);
|
||||
pConf->peersCount = peerCount;
|
||||
for (int i = 0; i < peerCount; ++i) {
|
||||
Addr *pAddr = &pConf->peers[i];
|
||||
parseAddr(tokens[i], pAddr->host, sizeof(pAddr->host), &pAddr->port);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case 'd': {
|
||||
snprintf(pConf->dir, sizeof(pConf->dir), "%s", optarg);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h': {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
default: {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
snprintf(pConf->dataDir, sizeof(pConf->dataDir), "%s/%s_%u", pConf->dir, pConf->me.host, pConf->me.port);
|
||||
}
|
||||
|
||||
void printConf(SRaftServerConfig *pConf) {
|
||||
printf("\nconf: \n");
|
||||
printf("me: %s:%u \n", pConf->me.host, pConf->me.port);
|
||||
printf("peersCount: %d \n", pConf->peersCount);
|
||||
for (int i = 0; i < pConf->peersCount; ++i) {
|
||||
Addr *pAddr = &pConf->peers[i];
|
||||
printf("peer%d: %s:%u \n", i, pAddr->host, pAddr->port);
|
||||
}
|
||||
printf("dataDir: %s \n\n", pConf->dataDir);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
srand(time(NULL));
|
||||
int32_t ret;
|
||||
|
||||
exe_name = argv[0];
|
||||
if (argc < 3) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
SRaftServerConfig conf;
|
||||
parseConf(argc, argv, &conf);
|
||||
printConf(&conf);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
/*
|
||||
char cmd_buf[COMMAND_LEN];
|
||||
snprintf(cmd_buf, sizeof(cmd_buf), "mkdir -p %s", conf.dataDir);
|
||||
system(cmd_buf);
|
||||
*/
|
||||
|
||||
|
||||
struct raft_fsm fsm;
|
||||
initFsm(&fsm);
|
||||
|
||||
SRaftServer raftServer;
|
||||
ret = raftServerInit(&raftServer, &conf, &fsm);
|
||||
assert(ret == 0);
|
||||
|
||||
pthread_t tidRaftServer;
|
||||
pthread_create(&tidRaftServer, NULL, startServerFunc, &raftServer);
|
||||
|
||||
pthread_t tidConsole;
|
||||
pthread_create(&tidConsole, NULL, startConsoleFunc, &raftServer);
|
||||
|
||||
while (1) {
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
#include "raftServer.h"
|
||||
|
||||
//char *keys = malloc(MAX_RECORD_COUNT * MAX_KV_LEN);;
|
||||
//char *values = malloc(MAX_RECORD_COUNT * MAX_KV_LEN);
|
||||
|
||||
|
||||
char keys[MAX_KV_LEN][MAX_RECORD_COUNT];
|
||||
char values[MAX_KV_LEN][MAX_RECORD_COUNT];
|
||||
int writeIndex = 0;
|
||||
|
||||
void initStore() {
|
||||
}
|
||||
|
||||
void destroyStore() {
|
||||
//free(keys);
|
||||
//free(values);
|
||||
}
|
||||
|
||||
void putKV(const char *key, const char *value) {
|
||||
if (writeIndex < MAX_RECORD_COUNT) {
|
||||
strncpy(keys[writeIndex], key, MAX_KV_LEN);
|
||||
strncpy(values[writeIndex], value, MAX_KV_LEN);
|
||||
writeIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
char *getKV(const char *key) {
|
||||
for (int i = 0; i < MAX_RECORD_COUNT; ++i) {
|
||||
if (strcmp(keys[i], key) == 0) {
|
||||
return values[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int splitString(const char* str, char* separator, char (*arr)[MAX_TOKEN_LEN], int n_arr)
|
||||
{
|
||||
if (n_arr <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char* tmp = (char*)malloc(strlen(str) + 1);
|
||||
strcpy(tmp, str);
|
||||
char* context;
|
||||
int n = 0;
|
||||
|
||||
char* token = strtok_r(tmp, separator, &context);
|
||||
if (!token) {
|
||||
goto ret;
|
||||
}
|
||||
strncpy(arr[n], token, MAX_TOKEN_LEN);
|
||||
n++;
|
||||
|
||||
while (1) {
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (!token || n >= n_arr) {
|
||||
goto ret;
|
||||
}
|
||||
strncpy(arr[n], token, MAX_TOKEN_LEN);
|
||||
n++;
|
||||
}
|
||||
|
||||
ret:
|
||||
free(tmp);
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
uint64_t raftId(const char *host, uint32_t port) {
|
||||
uint32_t host_uint32 = (uint32_t)inet_addr(host);
|
||||
assert(host_uint32 != (uint32_t)-1);
|
||||
uint64_t code = ((uint64_t)host_uint32) << 32 | port;
|
||||
return code;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
uint64_t encodeRaftId(const char *host, uint16_t port, uint16_t vid) {
|
||||
uint64_t raftId;
|
||||
uint32_t host_uint32 = (uint32_t)inet_addr(host);
|
||||
assert(host_uint32 != (uint32_t)-1);
|
||||
|
||||
raftId = (((uint64_t)host_uint32) << 32) | (((uint32_t)port) << 16) | vid;
|
||||
return raftId;
|
||||
}
|
||||
|
||||
void decodeRaftId(uint64_t raftId, char *host, int32_t len, uint16_t *port, uint16_t *vid) {
|
||||
uint32_t host32 = (uint32_t)((raftId >> 32) & 0x00000000FFFFFFFF);
|
||||
|
||||
struct in_addr addr;
|
||||
addr.s_addr = host32;
|
||||
snprintf(host, len, "%s", inet_ntoa(addr));
|
||||
|
||||
*port = (uint16_t)((raftId & 0x00000000FFFF0000) >> 16);
|
||||
*vid = (uint16_t)(raftId & 0x000000000000FFFF);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
int32_t raftServerInit(SRaftServer *pRaftServer, const SRaftServerConfig *pConf, struct raft_fsm *pFsm) {
|
||||
int ret;
|
||||
|
||||
snprintf(pRaftServer->host, sizeof(pRaftServer->host), "%s", pConf->me.host);
|
||||
pRaftServer->port = pConf->me.port;
|
||||
snprintf(pRaftServer->address, sizeof(pRaftServer->address), "%s:%u", pRaftServer->host, pRaftServer->port);
|
||||
//strncpy(pRaftServer->dir, pConf->dataDir, sizeof(pRaftServer->dir));
|
||||
|
||||
ret = uv_loop_init(&pRaftServer->loop);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "uv_loop_init error: %s \n", uv_strerror(ret));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
ret = raft_uv_tcp_init(&pRaftServer->transport, &pRaftServer->loop);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_uv_tcp_init: error %d \n", ret);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
|
||||
uint16_t vid;
|
||||
pRaftServer->instanceCount = 20;
|
||||
|
||||
|
||||
for (int i = 0; i < pRaftServer->instanceCount; ++i)
|
||||
{
|
||||
//vid = 0;
|
||||
vid = i;
|
||||
|
||||
|
||||
pRaftServer->instance[vid].raftId = encodeRaftId(pRaftServer->host, pRaftServer->port, vid);
|
||||
snprintf(pRaftServer->instance[vid].dir, sizeof(pRaftServer->instance[vid].dir), "%s_%llu", pConf->dataDir, pRaftServer->instance[vid].raftId);
|
||||
|
||||
char cmd_buf[COMMAND_LEN];
|
||||
snprintf(cmd_buf, sizeof(cmd_buf), "mkdir -p %s", pRaftServer->instance[vid].dir);
|
||||
system(cmd_buf);
|
||||
sleep(1);
|
||||
|
||||
pRaftServer->instance[vid].fsm = pFsm;
|
||||
|
||||
ret = raft_uv_init(&pRaftServer->instance[vid].io, &pRaftServer->loop, pRaftServer->instance[vid].dir, &pRaftServer->transport);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->instance[vid].raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
ret = raft_init(&pRaftServer->instance[vid].raft, &pRaftServer->instance[vid].io, pRaftServer->instance[vid].fsm, pRaftServer->instance[vid].raftId, pRaftServer->address);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->instance[vid].raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
struct raft_configuration conf;
|
||||
raft_configuration_init(&conf);
|
||||
raft_configuration_add(&conf, pRaftServer->instance[vid].raftId, pRaftServer->address, RAFT_VOTER);
|
||||
printf("add myself: %llu - %s \n", pRaftServer->instance[vid].raftId, pRaftServer->address);
|
||||
for (int i = 0; i < pConf->peersCount; ++i) {
|
||||
const Addr *pAddr = &pConf->peers[i];
|
||||
|
||||
raft_id rid = encodeRaftId(pAddr->host, pAddr->port, vid);
|
||||
|
||||
char addrBuf[ADDRESS_LEN];
|
||||
snprintf(addrBuf, sizeof(addrBuf), "%s:%u", pAddr->host, pAddr->port);
|
||||
raft_configuration_add(&conf, rid, addrBuf, RAFT_VOTER);
|
||||
printf("add peers: %llu - %s \n", rid, addrBuf);
|
||||
}
|
||||
|
||||
raft_bootstrap(&pRaftServer->instance[vid].raft, &conf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t raftServerStart(SRaftServer *pRaftServer) {
|
||||
int ret;
|
||||
|
||||
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||
ret = raft_start(&pRaftServer->instance[i].raft);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->instance[i].raft));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
uv_run(&pRaftServer->loop, UV_RUN_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
void raftServerClose(SRaftServer *pRaftServer) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result) {
|
||||
char *msg = (char*)buf->base;
|
||||
printf("fsm apply: %s \n", msg);
|
||||
|
||||
char arr[2][MAX_TOKEN_LEN];
|
||||
splitString(msg, "--", arr, 2);
|
||||
putKV(arr[0], arr[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t initFsm(struct raft_fsm *fsm) {
|
||||
initStore();
|
||||
fsm->apply = fsmApplyCb;
|
||||
return 0;
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
#ifndef TDENGINE_RAFT_SERVER_H
|
||||
#define TDENGINE_RAFT_SERVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "raft.h"
|
||||
#include "raft/uv.h"
|
||||
#include "common.h"
|
||||
|
||||
|
||||
// simulate a db store, just for test
|
||||
#define MAX_KV_LEN 20
|
||||
#define MAX_RECORD_COUNT 16
|
||||
|
||||
|
||||
//char *keys;
|
||||
//char *values;
|
||||
//int writeIndex;
|
||||
|
||||
void initStore();
|
||||
void destroyStore();
|
||||
void putKV(const char *key, const char *value);
|
||||
char *getKV(const char *key);
|
||||
|
||||
typedef struct {
|
||||
char dir[DIR_LEN + HOST_LEN * 4]; /* Data dir of UV I/O backend */
|
||||
raft_id raftId; /* For vote */
|
||||
struct raft_fsm *fsm; /* Sample application FSM */
|
||||
struct raft raft; /* Raft instance */
|
||||
struct raft_io io; /* UV I/O backend */
|
||||
|
||||
} SInstance;
|
||||
|
||||
typedef struct {
|
||||
char host[HOST_LEN];
|
||||
uint32_t port;
|
||||
char address[ADDRESS_LEN]; /* Raft instance address */
|
||||
|
||||
struct uv_loop_s loop; /* UV loop */
|
||||
struct raft_uv_transport transport; /* UV I/O backend transport */
|
||||
|
||||
SInstance instance[MAX_INSTANCE_NUM];
|
||||
int32_t instanceCount;
|
||||
|
||||
} SRaftServer;
|
||||
|
||||
#define MAX_TOKEN_LEN 32
|
||||
int splitString(const char* str, char* separator, char (*arr)[MAX_TOKEN_LEN], int n_arr);
|
||||
|
||||
int32_t raftServerInit(SRaftServer *pRaftServer, const SRaftServerConfig *pConf, struct raft_fsm *pFsm);
|
||||
int32_t raftServerStart(SRaftServer *pRaftServer);
|
||||
void raftServerClose(SRaftServer *pRaftServer);
|
||||
|
||||
|
||||
int initFsm(struct raft_fsm *fsm);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_RAFT_SERVER_H
|
|
@ -0,0 +1,6 @@
|
|||
add_executable(singleNode "")
|
||||
target_sources(singleNode
|
||||
PRIVATE
|
||||
"singleNode.c"
|
||||
)
|
||||
target_link_libraries(singleNode PUBLIC traft lz4 uv_a)
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf 127.0.0.1*
|
||||
rm -rf ./data
|
|
@ -0,0 +1,6 @@
|
|||
all:
|
||||
gcc singleNode.c -I ../../include/ ../../.libs/libraft.a -o singleNode -luv -llz4 -lpthread -g
|
||||
clean:
|
||||
rm -f singleNode
|
||||
sh clear.sh
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
//#include <uv.h>
|
||||
|
||||
#include "raft.h"
|
||||
|
||||
SRaftEnv raftEnv;
|
||||
|
||||
typedef struct Tsdb {
|
||||
uint64_t lastApplyIndex;
|
||||
void *mem;
|
||||
void *imm;
|
||||
void *store;
|
||||
} Tsdb;
|
||||
|
||||
void tsdbWrite(Tsdb *t, char *msg) {}
|
||||
|
||||
void *startFunc(void *param) {
|
||||
SRaftEnv *pSRaftEnv = (SRaftEnv *)param;
|
||||
int32_t r = raftEnvStart(pSRaftEnv);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result, raft_index index) {
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: index:%llu value:%s \n", index, msg);
|
||||
|
||||
Tsdb *t = pFsm->data;
|
||||
if (index > t->lastApplyIndex) {
|
||||
// apply value into tsdb
|
||||
tsdbWrite(t, msg);
|
||||
|
||||
// update lastApplyIndex
|
||||
t->lastApplyIndex = index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
void *ptr = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error \n");
|
||||
} else {
|
||||
printf("putValueCb ok \n");
|
||||
}
|
||||
free(ptr);
|
||||
free(req);
|
||||
}
|
||||
|
||||
void submitValue() {
|
||||
// prepare value
|
||||
struct raft_buffer buf;
|
||||
buf.len = 32;
|
||||
void *ptr = malloc(buf.len);
|
||||
buf.base = ptr;
|
||||
snprintf(buf.base, buf.len, "%ld", time(NULL));
|
||||
|
||||
// get raft
|
||||
struct raft *r = getRaft(&raftEnv, 100);
|
||||
assert(r != NULL);
|
||||
// printRaftState(r);
|
||||
|
||||
// submit value
|
||||
struct raft_apply *req = malloc(sizeof(*req));
|
||||
req->data = ptr;
|
||||
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||
if (ret == 0) {
|
||||
printf("put %s \n", (char *)buf.base);
|
||||
} else {
|
||||
printf("put error: %s \n", raft_errmsg(r));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// init raft env
|
||||
int r = raftEnvInit(&raftEnv, "127.0.0.1", 38000, "./data");
|
||||
assert(r == 0);
|
||||
|
||||
// start raft env
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startFunc, &raftEnv);
|
||||
|
||||
// wait for start, just for simple
|
||||
while (raftEnv.isStart != 1) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// init fsm
|
||||
struct raft_fsm *pFsm = malloc(sizeof(*pFsm));
|
||||
pFsm->apply = fsmApplyCb;
|
||||
Tsdb *tsdb = malloc(sizeof(*tsdb));
|
||||
pFsm->data = tsdb;
|
||||
|
||||
// add vgroup, id = 100, only has one replica
|
||||
r = addRaftVoter(&raftEnv, NULL, 0, 100, pFsm);
|
||||
assert(r == 0);
|
||||
|
||||
// for test: submit a value every second
|
||||
while (1) {
|
||||
sleep(1);
|
||||
submitValue();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -192,9 +192,38 @@ DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr);
|
|||
|
||||
DLL_EXPORT int taos_load_table_info(TAOS *taos, const char* tableNameList);
|
||||
DLL_EXPORT TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision);
|
||||
typedef struct tmq_t tmq_t;
|
||||
typedef struct tmq_conf_t tmq_conf_t;
|
||||
typedef struct tmq_list_t tmq_list_t;
|
||||
|
||||
typedef struct tmq_message_t tmq_message_t;
|
||||
typedef struct tmq_message_topic_t tmq_message_topic_t;
|
||||
typedef struct tmq_message_tb_t tmq_message_tb_t;
|
||||
typedef struct tmq_tb_iter_t tmq_tb_iter_t;
|
||||
typedef struct tmq_message_col_t tmq_message_col_t;
|
||||
typedef struct tmq_col_iter_t tmq_col_iter_t;
|
||||
|
||||
DLL_EXPORT tmq_list_t* tmq_list_new();
|
||||
DLL_EXPORT int32_t tmq_list_append(tmq_list_t*, char*);
|
||||
|
||||
DLL_EXPORT tmq_conf_t* tmq_conf_new();
|
||||
|
||||
DLL_EXPORT int32_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value);
|
||||
|
||||
DLL_EXPORT TAOS_RES *taos_create_topic(TAOS* taos, const char* name, const char* sql, int sqlLen);
|
||||
|
||||
DLL_EXPORT tmq_t* taos_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errstrLen);
|
||||
|
||||
DLL_EXPORT TAOS_RES* tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list);
|
||||
|
||||
DLL_EXPORT tmq_message_t* tmq_consume_poll(tmq_t* tmq, int64_t blocking_time);
|
||||
|
||||
DLL_EXPORT int32_t tmq_topic_num(tmq_message_t* msg);
|
||||
DLL_EXPORT char* tmq_get_topic(tmq_message_topic_t* msg);
|
||||
DLL_EXPORT int32_t tmq_get_vgId(tmq_message_topic_t* msg);
|
||||
DLL_EXPORT tmq_message_tb_t* tmq_get_next_tb(tmq_message_topic_t* msg, tmq_tb_iter_t* iter);
|
||||
DLL_EXPORT tmq_message_col_t* tmq_get_next_col(tmq_message_tb_t* msg, tmq_col_iter_t* iter);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -136,7 +136,7 @@ typedef uint64_t TKEY;
|
|||
#define TKEY_IS_NEGATIVE(tkey) (((tkey)&TKEY_NEGATIVE_FLAG) != 0)
|
||||
#define TKEY_IS_DELETED(tkey) (((tkey)&TKEY_DELETE_FLAG) != 0)
|
||||
#define tdSetTKEYDeleted(tkey) ((tkey) | TKEY_DELETE_FLAG)
|
||||
#define tdGetTKEY(key) (((TKEY)ABS(key)) | (TKEY_NEGATIVE_FLAG & (TKEY)(key)))
|
||||
#define tdGetTKEY(key) (((TKEY)TABS(key)) | (TKEY_NEGATIVE_FLAG & (TKEY)(key)))
|
||||
#define tdGetKey(tkey) (((TSKEY)((tkey)&TKEY_VALUE_FILTER)) * (TKEY_IS_NEGATIVE(tkey) ? -1 : 1))
|
||||
|
||||
#define MIN_TS_KEY ((TSKEY)0x8000000000000001)
|
||||
|
|
|
@ -100,7 +100,7 @@ typedef enum _mgmt_table {
|
|||
TSDB_MGMT_TABLE_CLUSTER,
|
||||
TSDB_MGMT_TABLE_STREAMTABLES,
|
||||
TSDB_MGMT_TABLE_TP,
|
||||
TSDB_MGMT_TABLE_FUNCTION,
|
||||
TSDB_MGMT_TABLE_FUNC,
|
||||
TSDB_MGMT_TABLE_MAX,
|
||||
} EShowType;
|
||||
|
||||
|
@ -526,20 +526,21 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
int8_t igExists;
|
||||
int8_t funcType;
|
||||
int8_t scriptType;
|
||||
int8_t align;
|
||||
int8_t outputType;
|
||||
int32_t outputLen;
|
||||
int32_t bufSize;
|
||||
int64_t sigature;
|
||||
int64_t signature;
|
||||
int32_t commentSize;
|
||||
int32_t codeSize;
|
||||
char pCont[];
|
||||
} SCreateFuncReq;
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
int8_t igNotExists;
|
||||
} SDropFuncReq;
|
||||
|
||||
typedef struct {
|
||||
|
@ -549,13 +550,13 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
int8_t align;
|
||||
int8_t funcType;
|
||||
int8_t scriptType;
|
||||
int8_t align;
|
||||
int8_t outputType;
|
||||
int32_t outputLen;
|
||||
int32_t bufSize;
|
||||
int64_t sigature;
|
||||
int64_t signature;
|
||||
int32_t commentSize;
|
||||
int32_t codeSize;
|
||||
char pCont[];
|
||||
|
@ -696,13 +697,13 @@ typedef struct SVgroupInfo {
|
|||
uint32_t hashEnd;
|
||||
int8_t inUse;
|
||||
int8_t numOfEps;
|
||||
SEpAddr epAddr[TSDB_MAX_REPLICA];
|
||||
SEpAddr epAddr[TSDB_MAX_REPLICA];
|
||||
} SVgroupInfo;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int8_t numOfEps;
|
||||
SEpAddr epAddr[TSDB_MAX_REPLICA];
|
||||
SEpAddr epAddr[TSDB_MAX_REPLICA];
|
||||
} SVgroupMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -1518,88 +1519,126 @@ static FORCE_INLINE void* taosDecodeSMqMsg(void* buf, SMqHbMsg* pMsg) {
|
|||
}
|
||||
|
||||
typedef struct SMqSetCVgReq {
|
||||
int32_t vgId;
|
||||
int64_t consumerId;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
char cgroup[TSDB_CONSUMER_GROUP_LEN];
|
||||
char* sql;
|
||||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
SSubQueryMsg msg;
|
||||
int32_t vgId;
|
||||
int64_t oldConsumerId;
|
||||
int64_t newConsumerId;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
char cgroup[TSDB_CONSUMER_GROUP_LEN];
|
||||
char* sql;
|
||||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
uint32_t qmsgLen;
|
||||
void* qmsg;
|
||||
//SSubQueryMsg msg;
|
||||
} SMqSetCVgReq;
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSubQueryMsg(void** buf, const SSubQueryMsg* pMsg) {
|
||||
int32_t tlen = sizeof(SSubQueryMsg) + pMsg->contentLen;
|
||||
if (buf == NULL) return tlen;
|
||||
memcpy(*buf, pMsg, tlen);
|
||||
*buf = POINTER_SHIFT(*buf, tlen);
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedU64(buf, pMsg->sId);
|
||||
tlen += taosEncodeFixedU64(buf, pMsg->queryId);
|
||||
tlen += taosEncodeFixedU64(buf, pMsg->taskId);
|
||||
tlen += taosEncodeFixedU32(buf, pMsg->contentLen);
|
||||
//tlen += taosEncodeBinary(buf, pMsg->msg, pMsg->contentLen);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSSubQueryMsg(void* buf, SSubQueryMsg* pMsg) {
|
||||
int32_t tlen = sizeof(SSubQueryMsg) + ((SSubQueryMsg*)buf)->contentLen;
|
||||
memcpy(pMsg, buf, tlen);
|
||||
return POINTER_SHIFT(buf, tlen);
|
||||
buf = taosDecodeFixedU64(buf, &pMsg->sId);
|
||||
buf = taosDecodeFixedU64(buf, &pMsg->queryId);
|
||||
buf = taosDecodeFixedU64(buf, &pMsg->taskId);
|
||||
buf = taosDecodeFixedU32(buf, &pMsg->contentLen);
|
||||
//buf = taosDecodeBinaryTo(buf, pMsg->msg, pMsg->contentLen);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqSetCVgReq(void** buf, const SMqSetCVgReq* pReq) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI32(buf, pReq->vgId);
|
||||
tlen += taosEncodeFixedI64(buf, pReq->consumerId);
|
||||
tlen += taosEncodeFixedI64(buf, pReq->oldConsumerId);
|
||||
tlen += taosEncodeFixedI64(buf, pReq->newConsumerId);
|
||||
tlen += taosEncodeString(buf, pReq->topicName);
|
||||
tlen += taosEncodeString(buf, pReq->cgroup);
|
||||
tlen += taosEncodeString(buf, pReq->sql);
|
||||
tlen += taosEncodeString(buf, pReq->logicalPlan);
|
||||
tlen += taosEncodeString(buf, pReq->physicalPlan);
|
||||
tlen += tEncodeSSubQueryMsg(buf, &pReq->msg);
|
||||
tlen += taosEncodeFixedU32(buf, pReq->qmsgLen);
|
||||
tlen += taosEncodeBinary(buf, pReq->qmsg, pReq->qmsgLen);
|
||||
//tlen += tEncodeSSubQueryMsg(buf, &pReq->msg);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) {
|
||||
buf = taosDecodeFixedI32(buf, &pReq->vgId);
|
||||
buf = taosDecodeFixedI64(buf, &pReq->consumerId);
|
||||
buf = taosDecodeFixedI64(buf, &pReq->oldConsumerId);
|
||||
buf = taosDecodeFixedI64(buf, &pReq->newConsumerId);
|
||||
buf = taosDecodeStringTo(buf, pReq->topicName);
|
||||
buf = taosDecodeStringTo(buf, pReq->cgroup);
|
||||
buf = taosDecodeString(buf, &pReq->sql);
|
||||
buf = taosDecodeString(buf, &pReq->logicalPlan);
|
||||
buf = taosDecodeString(buf, &pReq->physicalPlan);
|
||||
buf = tDecodeSSubQueryMsg(buf, &pReq->msg);
|
||||
buf = taosDecodeFixedU32(buf, &pReq->qmsgLen);
|
||||
buf = taosDecodeBinary(buf, &pReq->qmsg, pReq->qmsgLen);
|
||||
//buf = tDecodeSSubQueryMsg(buf, &pReq->msg);
|
||||
return buf;
|
||||
}
|
||||
|
||||
typedef struct SMqSetCVgRsp {
|
||||
int32_t vgId;
|
||||
int64_t consumerId;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
char cGroup[TSDB_CONSUMER_GROUP_LEN];
|
||||
SMsgHead header;
|
||||
int32_t vgId;
|
||||
int64_t consumerId;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
char cGroup[TSDB_CONSUMER_GROUP_LEN];
|
||||
} SMqSetCVgRsp;
|
||||
|
||||
typedef struct SMqCVConsumeReq {
|
||||
int64_t reqId;
|
||||
int64_t offset;
|
||||
int64_t consumerId;
|
||||
int64_t blockingTime;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
char cgroup[TSDB_CONSUMER_GROUP_LEN];
|
||||
} SMqCVConsumeReq;
|
||||
typedef struct SMqColData {
|
||||
int16_t colId;
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
char data[];
|
||||
} SMqColData;
|
||||
|
||||
typedef struct SMqConsumeRspBlock {
|
||||
int32_t bodyLen;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
char body[];
|
||||
} SMqConsumeRspBlock;
|
||||
typedef struct SMqTbData {
|
||||
int64_t uid;
|
||||
int32_t numOfCols;
|
||||
int32_t numOfRows;
|
||||
SMqColData colData[];
|
||||
} SMqTbData;
|
||||
|
||||
typedef struct SMqTopicBlk {
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
int64_t committedOffset;
|
||||
int64_t reqOffset;
|
||||
int64_t rspOffset;
|
||||
int32_t skipLogNum;
|
||||
int32_t bodyLen;
|
||||
int32_t numOfTb;
|
||||
SMqTbData tbData[];
|
||||
} SMqTopicData;
|
||||
|
||||
typedef struct SMqConsumeRsp {
|
||||
int64_t reqId;
|
||||
int64_t consumerId;
|
||||
int32_t bodyLen;
|
||||
int32_t numOfTopics;
|
||||
SMqTopicData data[];
|
||||
} SMqConsumeRsp;
|
||||
|
||||
// one req for one vg+topic
|
||||
typedef struct SMqConsumeReq {
|
||||
//0: commit only, current offset
|
||||
//1: consume only, poll next offset
|
||||
//2: commit current and consume next offset
|
||||
int32_t reqType;
|
||||
|
||||
int64_t reqId;
|
||||
int64_t consumerId;
|
||||
int64_t blockingTime;
|
||||
char cgroup[TSDB_CONSUMER_GROUP_LEN];
|
||||
|
||||
int64_t offset;
|
||||
char topic[TSDB_TOPIC_FNAME_LEN];
|
||||
} SMqConsumeReq;
|
||||
|
||||
typedef struct SMqCVConsumeRsp {
|
||||
int64_t reqId;
|
||||
int64_t clientId;
|
||||
int64_t committedOffset;
|
||||
int64_t receiveOffset;
|
||||
int64_t rspOffset;
|
||||
int32_t skipLogNum;
|
||||
int32_t bodyLen;
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
SMqConsumeRspBlock blocks[];
|
||||
} SMqCvConsumeRsp;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -119,9 +119,9 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DB, "mnode-alter-db", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SYNC_DB, "mnode-sync-db", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_COMPACT_DB, "mnode-compact-db", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_FUNCTION, "mnode-create-function", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_RETRIEVE_FUNCTION, "mnode-retrieve-function", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_FUNCTION, "mnode-drop-function", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_FUNC, "mnode-create-func", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_RETRIEVE_FUNC, "mnode-retrieve-func", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_FUNC, "mnode-drop-func", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STB, "mnode-create-stb", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STB, "mnode-alter-stb", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_STB, "mnode-drop-stb", NULL, NULL)
|
||||
|
|
|
@ -29,21 +29,23 @@ struct SSubplan;
|
|||
/**
|
||||
* Create the exec task for streaming mode
|
||||
* @param pMsg
|
||||
* @param pStreamBlockReadHandle
|
||||
* @param streamReadHandle
|
||||
* @return
|
||||
*/
|
||||
qTaskInfo_t createStreamExecTaskInfo(SSubQueryMsg *pMsg, void* pStreamBlockReadHandle);
|
||||
qTaskInfo_t qCreateStreamExecTaskInfo(void *msg, void* streamReadHandle);
|
||||
|
||||
int32_t qSetStreamInput(qTaskInfo_t tinfo, void* input);
|
||||
|
||||
/**
|
||||
* Create the exec task object according to task json
|
||||
* @param tsdb
|
||||
* @param readHandle
|
||||
* @param vgId
|
||||
* @param pTaskInfoMsg
|
||||
* @param pTaskInfo
|
||||
* @param qId
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreateExecTask(void* tsdb, int32_t vgId, struct SSubplan* pPlan, qTaskInfo_t* pTaskInfo, DataSinkHandle* handle);
|
||||
int32_t qCreateExecTask(void* readHandle, int32_t vgId, struct SSubplan* pPlan, qTaskInfo_t* pTaskInfo, DataSinkHandle* handle);
|
||||
|
||||
/**
|
||||
* The main task execution function, including query on both table and multiple tables,
|
||||
|
@ -60,63 +62,63 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds);
|
|||
* this function will be blocked to wait for the query execution completed or paused,
|
||||
* in which case enough results have been produced already.
|
||||
*
|
||||
* @param qinfo
|
||||
* @param tinfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qRetrieveQueryResultInfo(qTaskInfo_t qinfo, bool* buildRes, void* pRspContext);
|
||||
int32_t qRetrieveQueryResultInfo(qTaskInfo_t tinfo, bool* buildRes, void* pRspContext);
|
||||
|
||||
/**
|
||||
*
|
||||
* Retrieve the actual results to fill the response message payload.
|
||||
* Note that this function must be executed after qRetrieveQueryResultInfo is invoked.
|
||||
*
|
||||
* @param qinfo qinfo object
|
||||
* @param tinfo tinfo object
|
||||
* @param pRsp response message
|
||||
* @param contLen payload length
|
||||
* @return
|
||||
*/
|
||||
//int32_t qDumpRetrieveResult(qTaskInfo_t qinfo, SRetrieveTableRsp** pRsp, int32_t* contLen, bool* continueExec);
|
||||
//int32_t qDumpRetrieveResult(qTaskInfo_t tinfo, SRetrieveTableRsp** pRsp, int32_t* contLen, bool* continueExec);
|
||||
|
||||
/**
|
||||
* return the transporter context (RPC)
|
||||
* @param qinfo
|
||||
* @param tinfo
|
||||
* @return
|
||||
*/
|
||||
void* qGetResultRetrieveMsg(qTaskInfo_t qinfo);
|
||||
void* qGetResultRetrieveMsg(qTaskInfo_t tinfo);
|
||||
|
||||
/**
|
||||
* kill the ongoing query and free the query handle and corresponding resources automatically
|
||||
* @param qinfo qhandle
|
||||
* @param tinfo qhandle
|
||||
* @return
|
||||
*/
|
||||
int32_t qKillTask(qTaskInfo_t qinfo);
|
||||
int32_t qKillTask(qTaskInfo_t tinfo);
|
||||
|
||||
/**
|
||||
* kill the ongoing query asynchronously
|
||||
* @param qinfo qhandle
|
||||
* @param tinfo qhandle
|
||||
* @return
|
||||
*/
|
||||
int32_t qAsyncKillTask(qTaskInfo_t qinfo);
|
||||
int32_t qAsyncKillTask(qTaskInfo_t tinfo);
|
||||
|
||||
/**
|
||||
* return whether query is completed or not
|
||||
* @param qinfo
|
||||
* @param tinfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qIsTaskCompleted(qTaskInfo_t qinfo);
|
||||
int32_t qIsTaskCompleted(qTaskInfo_t tinfo);
|
||||
|
||||
/**
|
||||
* destroy query info structure
|
||||
* @param qHandle
|
||||
*/
|
||||
void qDestroyTask(qTaskInfo_t qHandle);
|
||||
void qDestroyTask(qTaskInfo_t tinfo);
|
||||
|
||||
/**
|
||||
* Get the queried table uid
|
||||
* @param qHandle
|
||||
* @return
|
||||
*/
|
||||
int64_t qGetQueriedTableUid(qTaskInfo_t qHandle);
|
||||
int64_t qGetQueriedTableUid(qTaskInfo_t tinfo);
|
||||
|
||||
/**
|
||||
* Extract the qualified table id list, and than pass them to the TSDB driver to load the required table data blocks.
|
||||
|
@ -143,7 +145,7 @@ int32_t qGetQualifiedTableIdList(void* pTableList, const char* tagCond, int32_t
|
|||
* @param type operation type: ADD|DROP
|
||||
* @return
|
||||
*/
|
||||
int32_t qUpdateQueriedTableIdList(qTaskInfo_t qinfo, int64_t uid, int32_t type);
|
||||
int32_t qUpdateQueriedTableIdList(qTaskInfo_t tinfo, int64_t uid, int32_t type);
|
||||
|
||||
//================================================================================================
|
||||
// query handle management
|
||||
|
|
|
@ -74,6 +74,7 @@ void columnListCopy(SArray* dst, const SArray* src, uint64_t uid);
|
|||
void columnListDestroy(SArray* pColumnList);
|
||||
|
||||
void dropAllExprInfo(SArray** pExprInfo, int32_t numOfLevel);
|
||||
void dropOneLevelExprInfo(SArray* pExprInfo);
|
||||
|
||||
typedef struct SSourceParam {
|
||||
SArray *pExprNodeList; //Array<struct tExprNode*>
|
||||
|
|
|
@ -178,7 +178,7 @@ struct SQueryNode;
|
|||
* @param requestId
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag, uint64_t requestId);
|
||||
int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag, SSchema** pResSchema, int32_t* numOfCols, SArray* pNodeList, uint64_t requestId);
|
||||
|
||||
// Set datasource of this subplan, multiple calls may be made to a subplan.
|
||||
// @subplan subplan to be schedule
|
||||
|
|
|
@ -72,15 +72,15 @@ int32_t schedulerInit(SSchedulerCfg *cfg);
|
|||
* @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||
* @return
|
||||
*/
|
||||
int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, struct SSchJob** pJob, SQueryResult *pRes);
|
||||
int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, struct SSchJob** pJob, SQueryResult *pRes);
|
||||
|
||||
/**
|
||||
* Process the query job, generated according to the query physical plan.
|
||||
* This is a asynchronized API, and is also thread-safety.
|
||||
* @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||
* @param pNodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||
* @return
|
||||
*/
|
||||
int32_t scheduleAsyncExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, struct SSchJob** pJob);
|
||||
int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryDag* pDag, struct SSchJob** pJob);
|
||||
|
||||
/**
|
||||
* Fetch query result from the remote query executor
|
||||
|
@ -88,7 +88,7 @@ int32_t scheduleAsyncExecJob(void *transport, SArray *nodeList, SQueryDag* pDag,
|
|||
* @param data
|
||||
* @return
|
||||
*/
|
||||
int32_t scheduleFetchRows(struct SSchJob *pJob, void **data);
|
||||
int32_t schedulerFetchRows(struct SSchJob *pJob, void **data);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -102,7 +102,7 @@ int32_t scheduleFetchRows(struct SSchJob *pJob, void **data);
|
|||
* Free the query job
|
||||
* @param pJob
|
||||
*/
|
||||
void scheduleFreeJob(void *pJob);
|
||||
void schedulerFreeJob(void *pJob);
|
||||
|
||||
void schedulerDestroy(void);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
SDiskID did;
|
||||
char aname[TSDB_FILENAME_LEN]; // ABS name
|
||||
char aname[TSDB_FILENAME_LEN]; // TABS name
|
||||
char rname[TSDB_FILENAME_LEN]; // REL name
|
||||
STfs *pTfs;
|
||||
} STfsFile;
|
||||
|
|
|
@ -20,37 +20,37 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define POW2(x) ((x) * (x))
|
||||
#define ABS(x) ((x) > 0 ? (x) : -(x))
|
||||
#define TPOW2(x) ((x) * (x))
|
||||
#define TABS(x) ((x) > 0 ? (x) : -(x))
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
|
||||
#define SWAP(a, b, c) \
|
||||
#define TSWAP(a, b, c) \
|
||||
do { \
|
||||
c __tmp = (c)(a); \
|
||||
(a) = (c)(b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define TMAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define TMIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#else
|
||||
|
||||
#define SWAP(a, b, c) \
|
||||
#define TSWAP(a, b, c) \
|
||||
do { \
|
||||
typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#define MAX(a, b) \
|
||||
#define TMAX(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a > __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define MIN(a, b) \
|
||||
#define TMIN(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_UTIL_COMPARE_H
|
||||
#define _TD_UTIL_COMPARE_H
|
||||
#ifndef _TD_UTIL_COMPARE_H_
|
||||
#define _TD_UTIL_COMPARE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -35,67 +35,65 @@ extern "C" {
|
|||
#define FLT_GREATEREQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) > (_y)))
|
||||
#define FLT_LESSEQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) < (_y)))
|
||||
|
||||
#define PATTERN_COMPARE_INFO_INITIALIZER { '%', '_' }
|
||||
#define PATTERN_COMPARE_INFO_INITIALIZER \
|
||||
{ '%', '_' }
|
||||
|
||||
typedef struct SPatternCompareInfo {
|
||||
char matchAll; // symbol for match all wildcard, default: '%'
|
||||
char matchOne; // symbol for match one wildcard, default: '_'
|
||||
} SPatternCompareInfo;
|
||||
|
||||
int patternMatch(const char *pattern, const char *str, size_t size, const SPatternCompareInfo *pInfo);
|
||||
int32_t patternMatch(const char *pattern, const char *str, size_t size, const SPatternCompareInfo *pInfo);
|
||||
|
||||
int WCSPatternMatch(const wchar_t *pattern, const wchar_t *str, size_t size, const SPatternCompareInfo *pInfo);
|
||||
int32_t WCSPatternMatch(const wchar_t *pattern, const wchar_t *str, size_t size, const SPatternCompareInfo *pInfo);
|
||||
|
||||
|
||||
int32_t taosArrayCompareString(const void* a, const void* b);
|
||||
int32_t taosArrayCompareString(const void *a, const void *b);
|
||||
|
||||
int32_t setCompareBytes1(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t setCompareBytes2(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t setCompareBytes4(const void *pLeft, const void *pRight);
|
||||
int32_t setCompareBytes8(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareInt8Val(const void *pLeft, const void *pRight);
|
||||
int32_t compareInt16Val(const void *pLeft, const void *pRight);
|
||||
int32_t compareInt32Val(const void *pLeft, const void *pRight);
|
||||
int32_t compareInt64Val(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareInt16Val(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareInt8Val(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareUint8Val(const void *pLeft, const void *pRight);
|
||||
int32_t compareUint16Val(const void *pLeft, const void *pRight);
|
||||
int32_t compareUint32Val(const void *pLeft, const void *pRight);
|
||||
int32_t compareUint64Val(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareUint16Val(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareUint8Val(const void* pLeft, const void* pRight);
|
||||
|
||||
int32_t compareFloatVal(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareDoubleVal(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight);
|
||||
int32_t compareStrRegexComp(const void* pLeft, const void* pRight);
|
||||
int32_t compareStrRegexCompMatch(const void* pLeft, const void* pRight);
|
||||
int32_t compareStrRegexCompNMatch(const void* pLeft, const void* pRight);
|
||||
int32_t compareFindItemInSet(const void *pLeft, const void* pRight);
|
||||
|
||||
int32_t compareStrRegexComp(const void *pLeft, const void *pRight);
|
||||
int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight);
|
||||
int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareFindItemInSet(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareInt8ValDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareInt16ValDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareInt32ValDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareInt64ValDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareFloatValDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareDoubleValDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareUint8ValDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareUint16ValDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareUint32ValDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareUint64ValDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareLenPrefixedStrDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareLenPrefixedWStrDesc(const void* pLeft, const void* pRight);
|
||||
int32_t compareInt16ValDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareInt32ValDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareInt64ValDesc(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareFloatValDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareDoubleValDesc(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareUint8ValDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareUint16ValDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareUint32ValDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareUint64ValDesc(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_COMPARE_H*/
|
||||
#endif /*_TD_UTIL_COMPARE_H_*/
|
||||
|
|
|
@ -239,6 +239,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_INVALID_FUNC_COMMENT TAOS_DEF_ERROR_CODE(0, 0x03C4)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x03C5)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x03C6)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_RETRIEVE TAOS_DEF_ERROR_CODE(0, 0x03C7)
|
||||
|
||||
// mnode-trans
|
||||
#define TSDB_CODE_MND_TRANS_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03D0)
|
||||
|
@ -354,7 +355,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_QRY_SCH_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0710) //"Scheduler not exist")
|
||||
#define TSDB_CODE_QRY_TASK_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0711) //"Task not exist")
|
||||
#define TSDB_CODE_QRY_TASK_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0712) //"Task already exist")
|
||||
#define TSDB_CODE_QRY_RES_CACHE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0713) //"Task result cache not exist")
|
||||
#define TSDB_CODE_QRY_TASK_CTX_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0713) //"Task context not exist")
|
||||
#define TSDB_CODE_QRY_TASK_CANCELLED TAOS_DEF_ERROR_CODE(0, 0x0714) //"Task cancelled")
|
||||
#define TSDB_CODE_QRY_TASK_DROPPED TAOS_DEF_ERROR_CODE(0, 0x0715) //"Task dropped")
|
||||
#define TSDB_CODE_QRY_TASK_CANCELLING TAOS_DEF_ERROR_CODE(0, 0x0716) //"Task cancelling")
|
||||
|
|
|
@ -372,7 +372,7 @@ static FORCE_INLINE void *taosDecodeStringTo(void *buf, char *value) {
|
|||
}
|
||||
|
||||
// ---- binary
|
||||
static FORCE_INLINE int taosEncodeBinary(void **buf, const void *value, int valueLen) {
|
||||
static FORCE_INLINE int taosEncodeBinary(void **buf, const void *value, int32_t valueLen) {
|
||||
int tlen = 0;
|
||||
|
||||
if (buf != NULL) {
|
||||
|
@ -384,14 +384,19 @@ static FORCE_INLINE int taosEncodeBinary(void **buf, const void *value, int valu
|
|||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void *taosDecodeBinary(void *buf, void **value, int valueLen) {
|
||||
uint64_t size = 0;
|
||||
static FORCE_INLINE void *taosDecodeBinary(void *buf, void **value, int32_t valueLen) {
|
||||
|
||||
*value = malloc((size_t)valueLen);
|
||||
if (*value == NULL) return NULL;
|
||||
memcpy(*value, buf, (size_t)size);
|
||||
memcpy(*value, buf, (size_t)valueLen);
|
||||
|
||||
return POINTER_SHIFT(buf, size);
|
||||
return POINTER_SHIFT(buf, valueLen);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void *taosDecodeBinaryTo(void *buf, void *value, int32_t valueLen) {
|
||||
|
||||
memcpy(value, buf, (size_t)valueLen);
|
||||
return POINTER_SHIFT(buf, valueLen);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -173,6 +173,7 @@ do { \
|
|||
#define TSDB_FUNC_BUF_SIZE 512
|
||||
#define TSDB_FUNC_TYPE_SCALAR 1
|
||||
#define TSDB_FUNC_TYPE_AGGREGATE 2
|
||||
#define TSDB_FUNC_MAX_RETRIEVE 1024
|
||||
|
||||
#define TSDB_TYPE_STR_MAX_LEN 32
|
||||
#define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
|
|
|
@ -34,6 +34,7 @@ extern "C" {
|
|||
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
|
||||
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
|
||||
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
|
||||
#define TD_SLIST_NODE_NEXT_WITH_FIELD(sln, field) ((sln)->field.sl_next_)
|
||||
|
||||
#define TD_SLIST_INIT(sl) \
|
||||
do { \
|
||||
|
@ -48,12 +49,25 @@ extern "C" {
|
|||
TD_SLIST_NELES(sl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_SLIST_PUSH_WITH_FIELD(sl, sln, field) \
|
||||
do { \
|
||||
TD_SLIST_NODE_NEXT_WITH_FIELD(sln, field) = TD_SLIST_HEAD(sl); \
|
||||
TD_SLIST_HEAD(sl) = (sln); \
|
||||
TD_SLIST_NELES(sl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_SLIST_POP(sl) \
|
||||
do { \
|
||||
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \
|
||||
TD_SLIST_NELES(sl) -= 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_SLIST_POP_WITH_FIELD(sl, field) \
|
||||
do { \
|
||||
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT_WITH_FIELD(TD_SLIST_HEAD(sl), field); \
|
||||
TD_SLIST_NELES(sl) -= 1; \
|
||||
} while (0)
|
||||
|
||||
// Double linked list ================
|
||||
#define TD_DLIST_NODE(TYPE) \
|
||||
struct { \
|
||||
|
@ -70,6 +84,8 @@ extern "C" {
|
|||
|
||||
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
|
||||
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
|
||||
#define TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) ((dln)->field.dl_prev_)
|
||||
#define TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) ((dln)->field.dl_next_)
|
||||
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
|
||||
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
|
||||
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
|
||||
|
@ -94,6 +110,20 @@ extern "C" {
|
|||
TD_DLIST_NELES(dl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_DLIST_APPEND_WITH_FIELD(dl, dln, field) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == NULL) { \
|
||||
TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) = NULL; \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
|
||||
} else { \
|
||||
TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) = TD_DLIST_TAIL(dl); \
|
||||
TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) = NULL; \
|
||||
TD_DLIST_NODE_NEXT_WITH_FIELD(TD_DLIST_TAIL(dl), field) = (dln); \
|
||||
TD_DLIST_TAIL(dl) = (dln); \
|
||||
} \
|
||||
TD_DLIST_NELES(dl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_DLIST_PREPEND(dl, dln) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == NULL) { \
|
||||
|
@ -108,6 +138,20 @@ extern "C" {
|
|||
TD_DLIST_NELES(dl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_DLIST_PREPEND_WITH_FIELD(dl, dln, field) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == NULL) { \
|
||||
TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) = NULL; \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
|
||||
} else { \
|
||||
TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) = NULL; \
|
||||
TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) = TD_DLIST_HEAD(dl); \
|
||||
TD_DLIST_NODE_PREV_WITH_FIELD(TD_DLIST_HEAD(dl), field) = (dln); \
|
||||
TD_DLIST_HEAD(dl) = (dln); \
|
||||
} \
|
||||
TD_DLIST_NELES(dl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_DLIST_POP(dl, dln) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == (dln)) { \
|
||||
|
@ -126,6 +170,26 @@ extern "C" {
|
|||
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define TD_DLIST_POP_WITH_FIELD(dl, dln, field) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == (dln)) { \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field); \
|
||||
} \
|
||||
if (TD_DLIST_TAIL(dl) == (dln)) { \
|
||||
TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV_WITH_FIELD(dln, field); \
|
||||
} \
|
||||
if (TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) != NULL) { \
|
||||
TD_DLIST_NODE_NEXT_WITH_FIELD(TD_DLIST_NODE_PREV_WITH_FIELD(dln, field), field) = \
|
||||
TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field); \
|
||||
} \
|
||||
if (TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) != NULL) { \
|
||||
TD_DLIST_NODE_PREV_WITH_FIELD(TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field), field) = \
|
||||
TD_DLIST_NODE_PREV_WITH_FIELD(dln, field); \
|
||||
} \
|
||||
TD_DLIST_NELES(dl) -= 1; \
|
||||
TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) = TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) = NULL; \
|
||||
} while (0)
|
||||
|
||||
// General double linked list
|
||||
typedef enum { TD_LIST_FORWARD, TD_LIST_BACKWARD } TD_LIST_DIRECTION_T;
|
||||
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Generate the deb package for ubuntu, or rpm package for centos, or tar.gz package for other linux os
|
||||
|
||||
set -e
|
||||
#set -x
|
||||
|
||||
# set parameters by default value
|
||||
version="3.0.0.0"
|
||||
|
||||
curr_dir=$(pwd)
|
||||
|
||||
script_dir="$(dirname $(readlink -f $0))"
|
||||
top_dir="$(readlink -f ${script_dir}/..)"
|
||||
|
||||
echo "=======================new version number: ${verNumber}======================================"
|
||||
|
||||
build_time=$(date +"%F %R")
|
||||
|
||||
echo "top_dir: ${top_dir}"
|
||||
|
||||
cd ${top_dir}
|
||||
git pull || :
|
||||
|
||||
echo "curr_dir: ${curr_dir}"
|
||||
|
||||
# 2. cmake executable file
|
||||
compile_dir="${top_dir}/debug"
|
||||
if [ -d ${compile_dir} ]; then
|
||||
rm -rf ${compile_dir}
|
||||
fi
|
||||
|
||||
mkdir -p ${compile_dir}
|
||||
|
||||
cd ${compile_dir}
|
||||
|
||||
echo "compile_dir: ${compile_dir}"
|
||||
|
||||
cmake ..
|
||||
make -j32
|
||||
|
||||
release_dir="${top_dir}/release"
|
||||
if [ -d ${release_dir} ]; then
|
||||
rm -rf ${release_dir}
|
||||
fi
|
||||
|
||||
mkdir -p ${release_dir}
|
||||
cd ${release_dir}
|
||||
|
||||
install_dir="${release_dir}/TDengine-server-${version}"
|
||||
mkdir -p ${install_dir}
|
||||
mkdir -p ${install_dir}/lib
|
||||
|
||||
bin_files="${compile_dir}/source/dnode/mgmt/daemon/taosd ${compile_dir}/tools/shell/taos ${compile_dir}/tests/test/c/create_table"
|
||||
cp ${bin_files} ${install_dir}/ && chmod a+x ${install_dir}/* || :
|
||||
|
||||
|
||||
cp ${compile_dir}/source/client/libtaos.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/dnode/mnode/impl/libmnode.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/dnode/qnode/libqnode.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/dnode/snode/libsnode.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/dnode/bnode/libbnode.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/libs/wal/libwal.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/libs/scheduler/libscheduler.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/libs/planner/libplanner.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/libs/parser/libparser.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/libs/qcom/libqcom.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/libs/transport/libtransport.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/libs/function/libfunction.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/common/libcommon.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/os/libos.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/dnode/mnode/sdb/libsdb.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/libs/catalog/libcatalog.so ${install_dir}/lib/
|
||||
|
||||
pkg_name=${install_dir}-Linux-x64
|
||||
|
||||
tar -zcv -f "$(basename ${pkg_name}).tar.gz" $(basename ${install_dir}) --remove-files || :
|
||||
|
||||
|
|
@ -101,13 +101,13 @@ struct SAppInstInfo {
|
|||
};
|
||||
|
||||
typedef struct SAppInfo {
|
||||
int64_t startTime;
|
||||
char appName[TSDB_APP_NAME_LEN];
|
||||
char *ep;
|
||||
int32_t pid;
|
||||
int32_t numOfThreads;
|
||||
|
||||
SHashObj *pInstMap;
|
||||
int64_t startTime;
|
||||
char appName[TSDB_APP_NAME_LEN];
|
||||
char *ep;
|
||||
int32_t pid;
|
||||
int32_t numOfThreads;
|
||||
SHashObj *pInstMap;
|
||||
pthread_mutex_t mutex;
|
||||
} SAppInfo;
|
||||
|
||||
typedef struct STscObj {
|
||||
|
@ -136,6 +136,7 @@ typedef struct SReqResultInfo {
|
|||
TAOS_ROW row;
|
||||
char **pCol;
|
||||
uint32_t numOfRows;
|
||||
uint64_t totalRows;
|
||||
uint32_t current;
|
||||
bool completed;
|
||||
} SReqResultInfo;
|
||||
|
@ -191,7 +192,7 @@ uint64_t generateRequestId();
|
|||
void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type);
|
||||
void destroyRequest(SRequestObj* pRequest);
|
||||
|
||||
char *getConnectionDB(STscObj* pObj);
|
||||
char *getDbOfConnection(STscObj* pObj);
|
||||
void setConnectionDB(STscObj* pTscObj, const char* db);
|
||||
|
||||
void taos_init_imp(void);
|
||||
|
|
|
@ -67,7 +67,9 @@ static void deregisterRequest(SRequestObj* pRequest) {
|
|||
int32_t currentInst = atomic_sub_fetch_32(&pActivity->currentRequests, 1);
|
||||
int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1);
|
||||
|
||||
tscDebug("0x%"PRIx64" free Request from connObj: 0x%"PRIx64", current:%d, app current:%d", pRequest->self, pTscObj->id, num, currentInst);
|
||||
int64_t duration = taosGetTimestampMs() - pRequest->metric.start;
|
||||
tscDebug("0x%"PRIx64" free Request from connObj: 0x%"PRIx64", reqId:0x%"PRIx64" elapsed:%"PRIu64" ms, current:%d, app current:%d", pRequest->self, pTscObj->id,
|
||||
pRequest->requestId, duration, num, currentInst);
|
||||
taosReleaseRef(clientConnRefPool, pTscObj->id);
|
||||
}
|
||||
|
||||
|
@ -110,7 +112,7 @@ void* openTransporter(const char *user, const char *auth, int32_t numOfThread) {
|
|||
rpcInit.user = (char *)user;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.ckey = "key";
|
||||
// rpcInit.spi = 1;
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.secret = (char *)auth;
|
||||
|
||||
void* pDnodeConn = rpcOpen(&rpcInit);
|
||||
|
@ -196,6 +198,10 @@ static void doDestroyRequest(void* p) {
|
|||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
qDestroyQueryDag(pRequest->body.pDag);
|
||||
|
||||
if (pRequest->body.showInfo.pArray != NULL) {
|
||||
taosArrayDestroy(pRequest->body.showInfo.pArray);
|
||||
}
|
||||
|
||||
deregisterRequest(pRequest);
|
||||
tfree(pRequest);
|
||||
}
|
||||
|
@ -247,10 +253,11 @@ void taos_init_imp(void) {
|
|||
clientReqRefPool = taosOpenRef(40960, doDestroyRequest);
|
||||
|
||||
taosGetAppName(appInfo.appName, NULL);
|
||||
pthread_mutex_init(&appInfo.mutex, NULL);
|
||||
|
||||
appInfo.pid = taosGetPId();
|
||||
appInfo.startTime = taosGetTimestampMs();
|
||||
appInfo.pInstMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
|
||||
tscDebug("client is initialized successfully");
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
static int32_t initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet);
|
||||
static SMsgSendInfo* buildConnectMsg(SRequestObj *pRequest);
|
||||
static void destroySendMsgInfo(SMsgSendInfo* pMsgBody);
|
||||
static void setQueryResultByRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp);
|
||||
static void setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp);
|
||||
|
||||
static bool stringLengthCheck(const char* str, size_t maxsize) {
|
||||
static bool stringLengthCheck(const char* str, size_t maxsize) {
|
||||
if (str == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
@ -58,8 +58,8 @@ static char* getClusterKey(const char* user, const char* auth, const char* ip, i
|
|||
return strdup(key);
|
||||
}
|
||||
|
||||
static STscObj* taosConnectImpl(const char *user, const char *auth, const char *db, uint16_t port, __taos_async_fn_t fp, void *param, SAppInstInfo* pAppInfo);
|
||||
static void setResSchemaInfo(SReqResultInfo* pResInfo, const SDataBlockSchema* pDataBlockSchema);
|
||||
static STscObj* taosConnectImpl(const char *user, const char *auth, const char *db, __taos_async_fn_t fp, void *param, SAppInstInfo* pAppInfo);
|
||||
static void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols);
|
||||
|
||||
TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port) {
|
||||
if (taos_init() != TSDB_CODE_SUCCESS) {
|
||||
|
@ -110,9 +110,11 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
|
|||
}
|
||||
|
||||
char* key = getClusterKey(user, secretEncrypt, ip, port);
|
||||
SAppInstInfo** pInst = NULL;
|
||||
|
||||
// TODO: race condition here.
|
||||
SAppInstInfo** pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
||||
pthread_mutex_lock(&appInfo.mutex);
|
||||
|
||||
pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
||||
if (pInst == NULL) {
|
||||
SAppInstInfo* p = calloc(1, sizeof(struct SAppInstInfo));
|
||||
p->mgmtEp = epSet;
|
||||
|
@ -123,8 +125,10 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
|
|||
pInst = &p;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&appInfo.mutex);
|
||||
|
||||
tfree(key);
|
||||
return taosConnectImpl(user, &secretEncrypt[0], localDb, port, NULL, NULL, *pInst);
|
||||
return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst);
|
||||
}
|
||||
|
||||
int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj** pRequest) {
|
||||
|
@ -155,7 +159,7 @@ int32_t parseSql(SRequestObj* pRequest, SQueryNode** pQuery) {
|
|||
SParseContext cxt = {
|
||||
.requestId = pRequest->requestId,
|
||||
.acctId = pTscObj->acctId,
|
||||
.db = getConnectionDB(pTscObj),
|
||||
.db = getDbOfConnection(pTscObj),
|
||||
.pSql = pRequest->sqlstr,
|
||||
.sqlLen = pRequest->sqlLen,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
|
@ -202,52 +206,49 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQueryNode, SQueryDag** pDag) {
|
||||
int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQueryNode, SQueryDag** pDag, SArray* pNodeList) {
|
||||
pRequest->type = pQueryNode->type;
|
||||
|
||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
||||
int32_t code = qCreateQueryDag(pQueryNode, pDag, pRequest->requestId);
|
||||
SSchema* pSchema = NULL;
|
||||
int32_t numOfCols = 0;
|
||||
int32_t code = qCreateQueryDag(pQueryNode, pDag, &pSchema, &numOfCols, pNodeList, pRequest->requestId);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pQueryNode->type == TSDB_SQL_SELECT) {
|
||||
SArray* pa = taosArrayGetP((*pDag)->pSubplans, 0);
|
||||
|
||||
SSubplan* pPlan = taosArrayGetP(pa, 0);
|
||||
SDataBlockSchema* pDataBlockSchema = &(pPlan->pDataSink->schema);
|
||||
setResSchemaInfo(pResInfo, pDataBlockSchema);
|
||||
|
||||
setResSchemaInfo(&pRequest->body.resInfo, pSchema, numOfCols);
|
||||
tfree(pSchema);
|
||||
pRequest->type = TDMT_VND_QUERY;
|
||||
} else {
|
||||
tfree(pSchema);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void setResSchemaInfo(SReqResultInfo* pResInfo, const SDataBlockSchema* pDataBlockSchema) {
|
||||
assert(pDataBlockSchema != NULL && pDataBlockSchema->numOfCols > 0);
|
||||
void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols) {
|
||||
assert(pSchema != NULL && numOfCols > 0);
|
||||
|
||||
pResInfo->numOfCols = pDataBlockSchema->numOfCols;
|
||||
pResInfo->fields = calloc(pDataBlockSchema->numOfCols, sizeof(pDataBlockSchema->pSchema[0]));
|
||||
pResInfo->numOfCols = numOfCols;
|
||||
pResInfo->fields = calloc(numOfCols, sizeof(pSchema[0]));
|
||||
|
||||
for (int32_t i = 0; i < pResInfo->numOfCols; ++i) {
|
||||
SSchema* pSchema = &pDataBlockSchema->pSchema[i];
|
||||
pResInfo->fields[i].bytes = pSchema->bytes;
|
||||
pResInfo->fields[i].type = pSchema->type;
|
||||
tstrncpy(pResInfo->fields[i].name, pSchema->name, tListLen(pResInfo->fields[i].name));
|
||||
pResInfo->fields[i].bytes = pSchema[i].bytes;
|
||||
pResInfo->fields[i].type = pSchema[i].type;
|
||||
tstrncpy(pResInfo->fields[i].name, pSchema[i].name, tListLen(pResInfo->fields[i].name));
|
||||
}
|
||||
}
|
||||
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag) {
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, SArray* pNodeList) {
|
||||
if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) {
|
||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||
|
||||
int32_t code = scheduleExecJob(pRequest->pTscObj->pAppInfo->pTransporter, NULL, pDag, &pRequest->body.pQueryJob, &res);
|
||||
int32_t code = schedulerExecJob(pRequest->pTscObj->pAppInfo->pTransporter, NULL, pDag, &pRequest->body.pQueryJob, &res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
// handle error and retry
|
||||
} else {
|
||||
if (pRequest->body.pQueryJob != NULL) {
|
||||
scheduleFreeJob(pRequest->body.pQueryJob);
|
||||
schedulerFreeJob(pRequest->body.pQueryJob);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,24 +257,11 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag) {
|
|||
return pRequest->code;
|
||||
}
|
||||
|
||||
SArray *execNode = taosArrayInit(4, sizeof(SQueryNodeAddr));
|
||||
|
||||
SQueryNodeAddr addr = {.numOfEps = 1, .inUse = 0, .nodeId = 2};
|
||||
addr.epAddr[0].port = 7100;
|
||||
strcpy(addr.epAddr[0].fqdn, "localhost");
|
||||
|
||||
taosArrayPush(execNode, &addr);
|
||||
return scheduleAsyncExecJob(pRequest->pTscObj->pAppInfo->pTransporter, execNode, pDag, &pRequest->body.pQueryJob);
|
||||
return schedulerAsyncExecJob(pRequest->pTscObj->pAppInfo->pTransporter, pNodeList, pDag, &pRequest->body.pQueryJob);
|
||||
}
|
||||
|
||||
typedef struct tmq_t tmq_t;
|
||||
|
||||
typedef struct SMqClientTopic {
|
||||
// subscribe info
|
||||
int32_t sqlLen;
|
||||
char* sql;
|
||||
char* topicName;
|
||||
int64_t topicId;
|
||||
typedef struct SMqClientVg {
|
||||
// statistics
|
||||
int64_t consumeCnt;
|
||||
// offset
|
||||
|
@ -282,36 +270,175 @@ typedef struct SMqClientTopic {
|
|||
//connection info
|
||||
int32_t vgId;
|
||||
SEpSet epSet;
|
||||
} SMqClientVg;
|
||||
|
||||
typedef struct SMqClientTopic {
|
||||
// subscribe info
|
||||
int32_t sqlLen;
|
||||
char* sql;
|
||||
char* topicName;
|
||||
int64_t topicId;
|
||||
int32_t nextVgIdx;
|
||||
SArray* vgs; //SArray<SMqClientVg>
|
||||
} SMqClientTopic;
|
||||
|
||||
typedef struct tmq_resp_err_t {
|
||||
int32_t code;
|
||||
} tmq_resp_err_t;
|
||||
|
||||
typedef struct tmq_topic_vgroup_list_t {
|
||||
char* topicName;
|
||||
typedef struct tmq_topic_vgroup_t {
|
||||
char* topic;
|
||||
int32_t vgId;
|
||||
int64_t committedOffset;
|
||||
int64_t commitOffset;
|
||||
} tmq_topic_vgroup_t;
|
||||
|
||||
typedef struct tmq_topic_vgroup_list_t {
|
||||
int32_t cnt;
|
||||
int32_t size;
|
||||
tmq_topic_vgroup_t* elems;
|
||||
} tmq_topic_vgroup_list_t;
|
||||
|
||||
typedef void (tmq_commit_cb(tmq_t*, tmq_resp_err_t, tmq_topic_vgroup_list_t*, void* param));
|
||||
|
||||
typedef struct tmq_conf_t{
|
||||
char* clientId;
|
||||
char* groupId;
|
||||
struct tmq_conf_t {
|
||||
char clientId[256];
|
||||
char groupId[256];
|
||||
char* ip;
|
||||
uint16_t port;
|
||||
tmq_commit_cb* commit_cb;
|
||||
} tmq_conf_t;
|
||||
};
|
||||
|
||||
tmq_conf_t* tmq_conf_new() {
|
||||
tmq_conf_t* conf = calloc(1, sizeof(tmq_conf_t));
|
||||
return conf;
|
||||
}
|
||||
|
||||
int32_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value) {
|
||||
if (strcmp(key, "group.id") == 0) {
|
||||
strcpy(conf->groupId, value);
|
||||
}
|
||||
if (strcmp(key, "client.id") == 0) {
|
||||
strcpy(conf->clientId, value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct tmq_t {
|
||||
char groupId[256];
|
||||
char clientId[256];
|
||||
int64_t consumerId;
|
||||
int64_t status;
|
||||
STscObj* pTscObj;
|
||||
tmq_commit_cb* commit_cb;
|
||||
SArray* clientTopics; // SArray<SMqClientTopic>
|
||||
int32_t nextTopicIdx;
|
||||
SArray* clientTopics; //SArray<SMqClientTopic>
|
||||
};
|
||||
|
||||
tmq_t* taos_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
||||
tmq_t* pTmq = calloc(sizeof(tmq_t), 1);
|
||||
if (pTmq == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pTmq->pTscObj = (STscObj*)conn;
|
||||
pTmq->status = 0;
|
||||
strcpy(pTmq->clientId, conf->clientId);
|
||||
strcpy(pTmq->groupId, conf->groupId);
|
||||
pTmq->commit_cb = conf->commit_cb;
|
||||
pTmq->consumerId = generateRequestId() & ((uint64_t)-1 >> 1);
|
||||
return pTmq;
|
||||
}
|
||||
|
||||
struct tmq_list_t {
|
||||
int32_t cnt;
|
||||
int32_t tot;
|
||||
char* elems[];
|
||||
};
|
||||
tmq_list_t* tmq_list_new() {
|
||||
tmq_list_t *ptr = malloc(sizeof(tmq_list_t) + 8 * sizeof(char*));
|
||||
if (ptr == NULL) {
|
||||
return ptr;
|
||||
}
|
||||
ptr->cnt = 0;
|
||||
ptr->tot = 8;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int32_t tmq_list_append(tmq_list_t* ptr, char* src) {
|
||||
if (ptr->cnt >= ptr->tot-1) return -1;
|
||||
ptr->elems[ptr->cnt] = strdup(src);
|
||||
ptr->cnt++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
TAOS_RES* tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
||||
SRequestObj *pRequest = NULL;
|
||||
tmq->status = 1;
|
||||
int32_t sz = topic_list->cnt;
|
||||
tmq->clientTopics = taosArrayInit(sz, sizeof(void*));
|
||||
for (int i = 0; i < sz; i++) {
|
||||
char* topicName = topic_list->elems[i];
|
||||
|
||||
SName name = {0};
|
||||
char* dbName = getDbOfConnection(tmq->pTscObj);
|
||||
tNameSetDbName(&name, tmq->pTscObj->acctId, dbName, strlen(dbName));
|
||||
tNameFromString(&name, topicName, T_NAME_TABLE);
|
||||
|
||||
char* topicFname = calloc(1, TSDB_TOPIC_FNAME_LEN);
|
||||
if (topicFname == NULL) {
|
||||
|
||||
}
|
||||
tNameExtractFullName(&name, topicFname);
|
||||
tscDebug("subscribe topic: %s", topicFname);
|
||||
taosArrayPush(tmq->clientTopics, &topicFname);
|
||||
/*SMqClientTopic topic = {*/
|
||||
/*.*/
|
||||
/*};*/
|
||||
}
|
||||
SCMSubscribeReq req;
|
||||
req.topicNum = taosArrayGetSize(tmq->clientTopics);
|
||||
req.consumerId = tmq->consumerId;
|
||||
req.consumerGroup = strdup(tmq->groupId);
|
||||
req.topicNames = tmq->clientTopics;
|
||||
|
||||
int tlen = tSerializeSCMSubscribeReq(NULL, &req);
|
||||
void* buf = malloc(tlen);
|
||||
if(buf == NULL) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
void* abuf = buf;
|
||||
tSerializeSCMSubscribeReq(&abuf, &req);
|
||||
/*printf("formatted: %s\n", dagStr);*/
|
||||
|
||||
pRequest = createRequest(tmq->pTscObj, NULL, NULL, TSDB_SQL_SELECT);
|
||||
if (pRequest == NULL) {
|
||||
tscError("failed to malloc sqlObj");
|
||||
}
|
||||
|
||||
pRequest->body.requestMsg = (SDataBuf){ .pData = buf, .len = tlen };
|
||||
pRequest->type = TDMT_MND_SUBSCRIBE;
|
||||
|
||||
SMsgSendInfo* body = buildMsgInfoImpl(pRequest);
|
||||
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, body);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
|
||||
_return:
|
||||
if (body != NULL) {
|
||||
destroySendMsgInfo(body);
|
||||
}
|
||||
|
||||
if (pRequest != NULL && terrno != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = terrno;
|
||||
}
|
||||
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) {
|
||||
conf->commit_cb = cb;
|
||||
}
|
||||
|
@ -339,10 +466,10 @@ SArray* tmqGetConnInfo(SClientHbKey connKey, void* param) {
|
|||
int sz = taosArrayGetSize(clientTopics);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
SMqClientTopic* pCTopic = taosArrayGet(clientTopics, i);
|
||||
if (pCTopic->vgId == -1) {
|
||||
pMqHb->status = 1;
|
||||
break;
|
||||
}
|
||||
/*if (pCTopic->vgId == -1) {*/
|
||||
/*pMqHb->status = 1;*/
|
||||
/*break;*/
|
||||
/*}*/
|
||||
}
|
||||
kv.value = pMqHb;
|
||||
kv.valueLen = sizeof(SMqHbMsg);
|
||||
|
@ -399,7 +526,9 @@ TAOS_RES *taos_create_topic(TAOS* taos, const char* topicName, const char* sql,
|
|||
|
||||
// todo check for invalid sql statement and return with error code
|
||||
|
||||
CHECK_CODE_GOTO(qCreateQueryDag(pQueryNode, &pRequest->body.pDag, pRequest->requestId), _return);
|
||||
SSchema *schema = NULL;
|
||||
int32_t numOfCols = 0;
|
||||
CHECK_CODE_GOTO(qCreateQueryDag(pQueryNode, &pRequest->body.pDag, &schema, &numOfCols, NULL, pRequest->requestId), _return);
|
||||
|
||||
pStr = qDagToString(pRequest->body.pDag);
|
||||
if(pStr == NULL) {
|
||||
|
@ -421,7 +550,7 @@ TAOS_RES *taos_create_topic(TAOS* taos, const char* topicName, const char* sql,
|
|||
|
||||
SCMCreateTopicReq req = {
|
||||
.name = (char*) topicFname,
|
||||
.igExists = 0,
|
||||
.igExists = 1,
|
||||
.physicalPlan = (char*) pStr,
|
||||
.sql = (char*) sql,
|
||||
.logicalPlan = "no logic plan",
|
||||
|
@ -461,22 +590,63 @@ _return:
|
|||
return pRequest;
|
||||
}
|
||||
|
||||
typedef struct tmq_message_t {
|
||||
int32_t numOfRows;
|
||||
char* topicName;
|
||||
TAOS_ROW row[];
|
||||
} tmq_message_t;
|
||||
/*typedef SMqConsumeRsp tmq_message_t;*/
|
||||
|
||||
tmq_message_t* tmq_consume_poll(tmq_t* mq, int64_t blocking_time) {
|
||||
struct tmq_message_t {
|
||||
SMqConsumeRsp rsp;
|
||||
};
|
||||
|
||||
tmq_message_t* tmq_consume_poll(tmq_t* tmq, int64_t blocking_time) {
|
||||
if (tmq->clientTopics == NULL || taosArrayGetSize(tmq->clientTopics) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
SRequestObj *pRequest = NULL;
|
||||
SMqConsumeReq req = {0};
|
||||
req.reqType = 1;
|
||||
req.blockingTime = blocking_time;
|
||||
req.consumerId = tmq->consumerId;
|
||||
strcpy(req.cgroup, tmq->groupId);
|
||||
|
||||
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, tmq->nextTopicIdx);
|
||||
tmq->nextTopicIdx = (tmq->nextTopicIdx + 1) % taosArrayGetSize(tmq->clientTopics);
|
||||
strcpy(req.topic, pTopic->topicName);
|
||||
int32_t nextVgIdx = pTopic->nextVgIdx;
|
||||
pTopic->nextVgIdx = (nextVgIdx + 1) % taosArrayGetSize(pTopic->vgs);
|
||||
SMqClientVg* pVg = taosArrayGet(pTopic->vgs, nextVgIdx);
|
||||
req.offset = pVg->currentOffset;
|
||||
|
||||
pRequest->body.requestMsg = (SDataBuf){ .pData = &req, .len = sizeof(SMqConsumeReq) };
|
||||
pRequest->type = TDMT_VND_CONSUME;
|
||||
|
||||
SMsgSendInfo* body = buildMsgInfoImpl(pRequest);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, body);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
|
||||
return (tmq_message_t*)pRequest->body.resInfo.pData;
|
||||
|
||||
/*tsem_wait(&pRequest->body.rspSem);*/
|
||||
|
||||
/*if (body != NULL) {*/
|
||||
/*destroySendMsgInfo(body);*/
|
||||
/*}*/
|
||||
|
||||
/*if (pRequest != NULL && terrno != TSDB_CODE_SUCCESS) {*/
|
||||
/*pRequest->code = terrno;*/
|
||||
/*}*/
|
||||
|
||||
/*return pRequest;*/
|
||||
}
|
||||
|
||||
tmq_resp_err_t* tmq_commit(tmq_t* tmq, tmq_topic_vgroup_list_t* tmq_topic_vgroup_list, int32_t async) {
|
||||
SMqConsumeReq req = {0};
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmq_resp_err_t* tmq_commit(tmq_t* mq, void* callback, int32_t async) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tmq_message_destroy(tmq_message_t* mq_message) {
|
||||
|
||||
void tmq_message_destroy(tmq_message_t* tmq_message) {
|
||||
if (tmq_message == NULL) return;
|
||||
}
|
||||
|
||||
|
||||
|
@ -492,6 +662,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
|||
|
||||
SRequestObj *pRequest = NULL;
|
||||
SQueryNode *pQueryNode = NULL;
|
||||
SArray *pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr));
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
|
@ -500,12 +671,14 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
|||
if (qIsDdlQuery(pQueryNode)) {
|
||||
CHECK_CODE_GOTO(execDdlQuery(pRequest, pQueryNode), _return);
|
||||
} else {
|
||||
CHECK_CODE_GOTO(getPlan(pRequest, pQueryNode, &pRequest->body.pDag), _return);
|
||||
CHECK_CODE_GOTO(scheduleQuery(pRequest, pRequest->body.pDag), _return);
|
||||
|
||||
CHECK_CODE_GOTO(getPlan(pRequest, pQueryNode, &pRequest->body.pDag, pNodeList), _return);
|
||||
CHECK_CODE_GOTO(scheduleQuery(pRequest, pRequest->body.pDag, pNodeList), _return);
|
||||
pRequest->code = terrno;
|
||||
}
|
||||
|
||||
_return:
|
||||
taosArrayDestroy(pNodeList);
|
||||
qDestroyQuery(pQueryNode);
|
||||
if (NULL != pRequest && TSDB_CODE_SUCCESS != terrno) {
|
||||
pRequest->code = terrno;
|
||||
|
@ -550,7 +723,7 @@ int initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSe
|
|||
return 0;
|
||||
}
|
||||
|
||||
STscObj* taosConnectImpl(const char *user, const char *auth, const char *db, uint16_t port, __taos_async_fn_t fp, void *param, SAppInstInfo* pAppInfo) {
|
||||
STscObj* taosConnectImpl(const char *user, const char *auth, const char *db, __taos_async_fn_t fp, void *param, SAppInstInfo* pAppInfo) {
|
||||
STscObj *pTscObj = createTscObj(user, auth, db, pAppInfo);
|
||||
if (NULL == pTscObj) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -571,7 +744,7 @@ STscObj* taosConnectImpl(const char *user, const char *auth, const char *db, uin
|
|||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno);
|
||||
const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(pRequest->code);
|
||||
printf("failed to connect to server, reason: %s\n\n", errorMsg);
|
||||
|
||||
destroyRequest(pRequest);
|
||||
|
@ -608,7 +781,7 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj *pRequest) {
|
|||
|
||||
STscObj *pObj = pRequest->pTscObj;
|
||||
|
||||
char* db = getConnectionDB(pObj);
|
||||
char* db = getDbOfConnection(pObj);
|
||||
if (db != NULL) {
|
||||
tstrncpy(pConnect->db, db, sizeof(pConnect->db));
|
||||
}
|
||||
|
@ -699,10 +872,10 @@ TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, c
|
|||
char userStr[TSDB_USER_LEN] = {0};
|
||||
char passStr[TSDB_PASSWORD_LEN] = {0};
|
||||
|
||||
strncpy(ipStr, ip, MIN(TSDB_EP_LEN - 1, ipLen));
|
||||
strncpy(userStr, user, MIN(TSDB_USER_LEN - 1, userLen));
|
||||
strncpy(passStr, pass, MIN(TSDB_PASSWORD_LEN - 1, passLen));
|
||||
strncpy(dbStr, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
|
||||
strncpy(ipStr, ip, TMIN(TSDB_EP_LEN - 1, ipLen));
|
||||
strncpy(userStr, user, TMIN(TSDB_USER_LEN - 1, userLen));
|
||||
strncpy(passStr, pass, TMIN(TSDB_PASSWORD_LEN - 1, passLen));
|
||||
strncpy(dbStr, db, TMIN(TSDB_DB_NAME_LEN - 1, dbLen));
|
||||
return taos_connect(ipStr, userStr, passStr, dbStr, port);
|
||||
}
|
||||
|
||||
|
@ -719,13 +892,17 @@ void* doFetchRow(SRequestObj* pRequest) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32_t code = scheduleFetchRows(pRequest->body.pQueryJob, (void **)&pRequest->body.resInfo.pData);
|
||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
||||
int32_t code = schedulerFetchRows(pRequest->body.pQueryJob, (void **)&pResInfo->pData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
setQueryResultByRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pRequest->body.resInfo.pData);
|
||||
setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData);
|
||||
tscDebug("0x%"PRIx64 " fetch results, numOfRows:%d total Rows:%"PRId64", complete:%d, reqId:0x%"PRIx64, pRequest->self, pResInfo->numOfRows,
|
||||
pResInfo->totalRows, pResInfo->completed, pRequest->requestId);
|
||||
|
||||
if (pResultInfo->numOfRows == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -836,7 +1013,7 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t
|
|||
}
|
||||
}
|
||||
|
||||
char* getConnectionDB(STscObj* pObj) {
|
||||
char* getDbOfConnection(STscObj* pObj) {
|
||||
char *p = NULL;
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
size_t len = strlen(pObj->db);
|
||||
|
@ -855,7 +1032,7 @@ void setConnectionDB(STscObj* pTscObj, const char* db) {
|
|||
pthread_mutex_unlock(&pTscObj->mutex);
|
||||
}
|
||||
|
||||
void setQueryResultByRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp) {
|
||||
void setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp) {
|
||||
assert(pResultInfo != NULL && pRsp != NULL);
|
||||
|
||||
pResultInfo->pRspMsg = (const char*) pRsp;
|
||||
|
@ -864,5 +1041,6 @@ void setQueryResultByRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* p
|
|||
pResultInfo->current = 0;
|
||||
pResultInfo->completed = (pRsp->completed == 1);
|
||||
|
||||
pResultInfo->totalRows += pResultInfo->numOfRows;
|
||||
setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows);
|
||||
}
|
||||
|
|
|
@ -145,19 +145,23 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
pSchema = pMetaMsg->pSchema;
|
||||
TAOS_FIELD* pFields = calloc(pMetaMsg->numOfColumns, sizeof(TAOS_FIELD));
|
||||
for (int32_t i = 0; i < pMetaMsg->numOfColumns; ++i) {
|
||||
tstrncpy(pFields[i].name, pSchema[i].name, tListLen(pFields[i].name));
|
||||
pFields[i].type = pSchema[i].type;
|
||||
pFields[i].bytes = pSchema[i].bytes;
|
||||
}
|
||||
tfree(pRequest->body.resInfo.pRspMsg);
|
||||
|
||||
pRequest->body.resInfo.pRspMsg = pMsg->pData;
|
||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
||||
|
||||
pResInfo->fields = pFields;
|
||||
pResInfo->numOfCols = pMetaMsg->numOfColumns;
|
||||
if (pResInfo->fields == NULL) {
|
||||
TAOS_FIELD* pFields = calloc(pMetaMsg->numOfColumns, sizeof(TAOS_FIELD));
|
||||
for (int32_t i = 0; i < pMetaMsg->numOfColumns; ++i) {
|
||||
tstrncpy(pFields[i].name, pSchema[i].name, tListLen(pFields[i].name));
|
||||
pFields[i].type = pSchema[i].type;
|
||||
pFields[i].bytes = pSchema[i].bytes;
|
||||
}
|
||||
|
||||
pResInfo->fields = pFields;
|
||||
}
|
||||
|
||||
pResInfo->numOfCols = pMetaMsg->numOfColumns;
|
||||
pRequest->body.showInfo.execId = pShow->showId;
|
||||
|
||||
// todo
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -44,7 +44,7 @@ int32_t tsRpcTimer = 300;
|
|||
int32_t tsRpcMaxTime = 600; // seconds;
|
||||
int32_t tsRpcForceTcp = 1; // disable this, means query, show command use udp protocol as default
|
||||
int32_t tsMaxShellConns = 50000;
|
||||
int32_t tsMaxConnections = 5000;
|
||||
int32_t tsMaxConnections = 50000;
|
||||
int32_t tsShellActivityTimer = 3; // second
|
||||
float tsNumOfThreadsPerCore = 1.0f;
|
||||
int32_t tsNumOfCommitThreads = 4;
|
||||
|
|
|
@ -100,12 +100,12 @@ int32_t taosParseTime(const char* timestr, int64_t* time, int32_t len, int32_t t
|
|||
} else if (checkTzPresent(timestr, len)) {
|
||||
return parseTimeWithTz(timestr, time, timePrec, 0);
|
||||
} else {
|
||||
return (*parseLocaltimeFp[day_light])(timestr, time, timePrec);
|
||||
return (*parseLocaltimeFp[day_light])((char*)timestr, time, timePrec);
|
||||
}
|
||||
}
|
||||
|
||||
bool checkTzPresent(const char *str, int32_t len) {
|
||||
char *seg = forwardToTimeStringEnd(str);
|
||||
bool checkTzPresent(const char* str, int32_t len) {
|
||||
char* seg = forwardToTimeStringEnd((char*)str);
|
||||
int32_t seg_len = len - (int32_t)(seg - str);
|
||||
|
||||
char *c = &seg[seg_len - 1];
|
||||
|
@ -267,7 +267,7 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch
|
|||
#endif
|
||||
|
||||
int64_t fraction = 0;
|
||||
str = forwardToTimeStringEnd(timestr);
|
||||
str = forwardToTimeStringEnd((char*)timestr);
|
||||
|
||||
if ((str[0] == 'Z' || str[0] == 'z') && str[1] == '\0') {
|
||||
/* utc time, no millisecond, return directly*/
|
||||
|
|
|
@ -630,7 +630,7 @@ void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type) {
|
|||
}
|
||||
}
|
||||
|
||||
#define SWAP(a, b, c) \
|
||||
#define TSWAP(a, b, c) \
|
||||
do { \
|
||||
typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
|
@ -642,35 +642,35 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
|
|||
switch (type) {
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
SWAP(*(int32_t *)(pLeft), *(int32_t *)(pRight), int32_t);
|
||||
TSWAP(*(int32_t *)(pLeft), *(int32_t *)(pRight), int32_t);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
SWAP(*(int64_t *)(pLeft), *(int64_t *)(pRight), int64_t);
|
||||
TSWAP(*(int64_t *)(pLeft), *(int64_t *)(pRight), int64_t);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
SWAP(*(double *)(pLeft), *(double *)(pRight), double);
|
||||
TSWAP(*(double *)(pLeft), *(double *)(pRight), double);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
SWAP(*(int16_t *)(pLeft), *(int16_t *)(pRight), int16_t);
|
||||
TSWAP(*(int16_t *)(pLeft), *(int16_t *)(pRight), int16_t);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
SWAP(*(float *)(pLeft), *(float *)(pRight), float);
|
||||
TSWAP(*(float *)(pLeft), *(float *)(pRight), float);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT: {
|
||||
SWAP(*(int8_t *)(pLeft), *(int8_t *)(pRight), int8_t);
|
||||
TSWAP(*(int8_t *)(pLeft), *(int8_t *)(pRight), int8_t);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
|
||||
|
@ -94,3 +95,5 @@ TEST(testCase, toInteger_test) {
|
|||
ret = toInteger(s, strlen(s), 10, &val, &sign);
|
||||
ASSERT_EQ(ret, -1);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -621,5 +621,7 @@ int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *enc
|
|||
|
||||
int32_t code = mndRetriveAuth(pMnode, user, spi, encrypt, secret, ckey);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
|
||||
dTrace("user:%s, retrieve auth spi:%d encrypt:%d", user, *spi, *encrypt);
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -90,9 +90,9 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_DB)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SYNC_DB)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_COMPACT_DB)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_FUNCTION)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNCTION)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_FUNCTION)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_FUNC)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_RETRIEVE_FUNC)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_FUNC)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_STB)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_STB)] = dndProcessMnodeWriteMsg;
|
||||
|
@ -112,10 +112,14 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_TOPIC)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_ALTER_TOPIC)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_TOPIC)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SUBSCRIBE)] = dndProcessMnodeWriteMsg;
|
||||
/*pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SUBSCRIBE_RSP)] = dndProcessMnodeWriteMsg;*/
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_SET_CONN_RSP)] = dndProcessMnodeWriteMsg;
|
||||
|
||||
// Requests handled by VNODE
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SUBMIT)] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_QUERY)] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_QUERY_CONTINUE)] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_FETCH)] = dndProcessVnodeFetchMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_TABLE)] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_UPDATE_TAG_VAL)] = dndProcessVnodeWriteMsg;
|
||||
|
@ -141,6 +145,8 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_TABLE)] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES)] = dndProcessVnodeFetchMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES_FETCH)] = dndProcessVnodeFetchMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_SET_CONN)] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_SET_CUR)] = dndProcessVnodeFetchMsg;
|
||||
}
|
||||
|
||||
static void dndProcessResponse(void *parent, SRpcMsg *pRsp, SEpSet *pEpSet) {
|
||||
|
@ -171,7 +177,7 @@ static int32_t dndInitClient(SDnode *pDnode) {
|
|||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.label = "DND-C";
|
||||
rpcInit.label = "D-C";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = dndProcessResponse;
|
||||
rpcInit.sessions = 1024;
|
||||
|
@ -179,9 +185,13 @@ static int32_t dndInitClient(SDnode *pDnode) {
|
|||
rpcInit.idleTime = pDnode->cfg.shellActivityTimer * 1000;
|
||||
rpcInit.user = INTERNAL_USER;
|
||||
rpcInit.ckey = INTERNAL_CKEY;
|
||||
rpcInit.secret = INTERNAL_SECRET;
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.parent = pDnode;
|
||||
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
rpcInit.secret = pass;
|
||||
|
||||
pMgmt->clientRpc = rpcOpen(&rpcInit);
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
dError("failed to init rpc client");
|
||||
|
@ -256,20 +266,18 @@ static void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pRpcMsg, SRpcMsg *pRp
|
|||
|
||||
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};
|
||||
taosEncryptPass((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
memcpy(secret, pass, TSDB_PASSWORD_LEN);
|
||||
*spi = 0;
|
||||
*spi = 1;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
return 0;
|
||||
} else if (strcmp(user, TSDB_NETTEST_USER) == 0) {
|
||||
// A simple temporary implementation
|
||||
char pass[TSDB_PASSWORD_LEN] = {0};
|
||||
taosEncryptPass((uint8_t *)(TSDB_NETTEST_USER), strlen(TSDB_NETTEST_USER), pass);
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(TSDB_NETTEST_USER), strlen(TSDB_NETTEST_USER), pass);
|
||||
memcpy(secret, pass, TSDB_PASSWORD_LEN);
|
||||
*spi = 0;
|
||||
*spi = 1;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
return 0;
|
||||
|
@ -282,12 +290,12 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
|
|||
SDnode *pDnode = parent;
|
||||
|
||||
if (dndAuthInternalReq(parent, user, spi, encrypt, secret, ckey) == 0) {
|
||||
// dTrace("get internal auth success");
|
||||
dTrace("user:%s, get auth from internal mnode, spi:%d encrypt:%d", user, *spi, *encrypt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dndGetUserAuthFromMnode(pDnode, user, spi, encrypt, secret, ckey) == 0) {
|
||||
// dTrace("get auth from internal mnode");
|
||||
dTrace("user:%s, get auth from internal mnode, spi:%d encrypt:%d", user, *spi, *encrypt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -296,13 +304,12 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
|
|||
return -1;
|
||||
}
|
||||
|
||||
// dDebug("user:%s, send auth msg to other mnodes", user);
|
||||
|
||||
SAuthReq *pReq = rpcMallocCont(sizeof(SAuthReq));
|
||||
tstrncpy(pReq->user, user, TSDB_USER_LEN);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pReq, .contLen = sizeof(SAuthReq), .msgType = TDMT_MND_AUTH};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
dTrace("user:%s, send user auth req to other mnodes, spi:%d encrypt:%d", user, pReq->spi, pReq->encrypt);
|
||||
dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
|
||||
if (rpcRsp.code != 0) {
|
||||
|
@ -314,7 +321,7 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
|
|||
memcpy(ckey, pRsp->ckey, TSDB_PASSWORD_LEN);
|
||||
*spi = pRsp->spi;
|
||||
*encrypt = pRsp->encrypt;
|
||||
dDebug("user:%s, success to get user auth from other mnodes", user);
|
||||
dTrace("user:%s, success to get user auth from other mnodes, spi:%d encrypt:%d", user, pRsp->spi, pRsp->encrypt);
|
||||
}
|
||||
|
||||
rpcFreeCont(rpcRsp.pCont);
|
||||
|
@ -333,7 +340,7 @@ static int32_t dndInitServer(SDnode *pDnode) {
|
|||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = pDnode->cfg.serverPort;
|
||||
rpcInit.label = "DND-S";
|
||||
rpcInit.label = "D-S";
|
||||
rpcInit.numOfThreads = numOfThreads;
|
||||
rpcInit.cfp = dndProcessRequest;
|
||||
rpcInit.sessions = pDnode->cfg.maxShellConns;
|
||||
|
|
|
@ -892,7 +892,7 @@ int32_t dndPutReqToVQueryQ(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, pHead->vgId);
|
||||
if (pVnode == NULL) return -1;
|
||||
|
||||
int32_t code = dndWriteRpcMsgToVnodeQueue(pVnode->pFetchQ, pMsg, false);
|
||||
int32_t code = dndWriteRpcMsgToVnodeQueue(pVnode->pQueryQ, pMsg, false);
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return code;
|
||||
}
|
||||
|
@ -910,11 +910,11 @@ static int32_t dndInitVnodeWorkers(SDnode *pDnode) {
|
|||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
||||
int32_t maxFetchThreads = 4;
|
||||
int32_t minFetchThreads = MIN(maxFetchThreads, pDnode->env.numOfCores);
|
||||
int32_t minQueryThreads = MAX((int32_t)(pDnode->env.numOfCores * pDnode->cfg.ratioOfQueryCores), 1);
|
||||
int32_t minFetchThreads = TMIN(maxFetchThreads, pDnode->env.numOfCores);
|
||||
int32_t minQueryThreads = TMAX((int32_t)(pDnode->env.numOfCores * pDnode->cfg.ratioOfQueryCores), 1);
|
||||
int32_t maxQueryThreads = minQueryThreads;
|
||||
int32_t maxWriteThreads = MAX(pDnode->env.numOfCores, 1);
|
||||
int32_t maxSyncThreads = MAX(pDnode->env.numOfCores / 2, 1);
|
||||
int32_t maxWriteThreads = TMAX(pDnode->env.numOfCores, 1);
|
||||
int32_t maxSyncThreads = TMAX(pDnode->env.numOfCores / 2, 1);
|
||||
|
||||
SWorkerPool *pPool = &pMgmt->queryPool;
|
||||
pPool->name = "vnode-query";
|
||||
|
|
|
@ -96,6 +96,15 @@ class Testbase {
|
|||
#define CheckBinary(val, len) \
|
||||
{ EXPECT_STREQ(test.GetShowBinary(len), val); }
|
||||
|
||||
#define CheckBinaryByte(b, len) \
|
||||
{ \
|
||||
char* bytes = (char*)calloc(1, len); \
|
||||
for (int32_t i = 0; i < len - 1; ++i) { \
|
||||
bytes[i] = b; \
|
||||
} \
|
||||
EXPECT_STREQ(test.GetShowBinary(len), bytes); \
|
||||
}
|
||||
|
||||
#define CheckInt8(val) \
|
||||
{ EXPECT_EQ(test.GetShowInt8(), val); }
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ void TestClient::SetRpcRsp(SRpcMsg* pRsp) { this->pRsp = pRsp; };
|
|||
tsem_t* TestClient::GetSem() { return &sem; }
|
||||
|
||||
bool TestClient::Init(const char* user, const char* pass, const char* fqdn, uint16_t port) {
|
||||
char secretEncrypt[TSDB_PASSWORD_LEN] = {0};
|
||||
taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt);
|
||||
char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t*)pass, strlen(pass), secretEncrypt);
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
|
@ -42,7 +42,7 @@ bool TestClient::Init(const char* user, const char* pass, const char* fqdn, uint
|
|||
rpcInit.ckey = (char*)"key";
|
||||
rpcInit.parent = this;
|
||||
rpcInit.secret = (char*)secretEncrypt;
|
||||
// rpcInit.spi = 1;
|
||||
rpcInit.spi = 1;
|
||||
|
||||
clientRpc = rpcOpen(&rpcInit);
|
||||
ASSERT(clientRpc);
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
#include "os.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "scheduler.h"
|
||||
#include "sync.h"
|
||||
#include "tmsg.h"
|
||||
#include "thash.h"
|
||||
#include "tlist.h"
|
||||
#include "tlog.h"
|
||||
#include "tmsg.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimer.h"
|
||||
#include "scheduler.h"
|
||||
|
||||
#include "mnode.h"
|
||||
|
||||
|
@ -37,12 +37,42 @@ extern "C" {
|
|||
extern int32_t mDebugFlag;
|
||||
|
||||
// mnode log function
|
||||
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
|
||||
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
|
||||
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
|
||||
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }}
|
||||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
#define mFatal(...) \
|
||||
{ \
|
||||
if (mDebugFlag & DEBUG_FATAL) { \
|
||||
taosPrintLog("MND FATAL ", 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define mError(...) \
|
||||
{ \
|
||||
if (mDebugFlag & DEBUG_ERROR) { \
|
||||
taosPrintLog("MND ERROR ", 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define mWarn(...) \
|
||||
{ \
|
||||
if (mDebugFlag & DEBUG_WARN) { \
|
||||
taosPrintLog("MND WARN ", 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define mInfo(...) \
|
||||
{ \
|
||||
if (mDebugFlag & DEBUG_INFO) { \
|
||||
taosPrintLog("MND ", 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define mDebug(...) \
|
||||
{ \
|
||||
if (mDebugFlag & DEBUG_DEBUG) { \
|
||||
taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define mTrace(...) \
|
||||
{ \
|
||||
if (mDebugFlag & DEBUG_TRACE) { \
|
||||
taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
MND_AUTH_ACCT_START = 0,
|
||||
|
@ -96,13 +126,13 @@ typedef struct {
|
|||
ETrnPolicy policy;
|
||||
int32_t code;
|
||||
int32_t failedTimes;
|
||||
void *rpcHandle;
|
||||
void *rpcAHandle;
|
||||
SArray *redoLogs;
|
||||
SArray *undoLogs;
|
||||
SArray *commitLogs;
|
||||
SArray *redoActions;
|
||||
SArray *undoActions;
|
||||
void* rpcHandle;
|
||||
void* rpcAHandle;
|
||||
SArray* redoLogs;
|
||||
SArray* undoLogs;
|
||||
SArray* commitLogs;
|
||||
SArray* redoActions;
|
||||
SArray* undoActions;
|
||||
} STrans;
|
||||
|
||||
typedef struct {
|
||||
|
@ -135,28 +165,28 @@ typedef struct {
|
|||
ESyncState role;
|
||||
int32_t roleTerm;
|
||||
int64_t roleTime;
|
||||
SDnodeObj *pDnode;
|
||||
SDnodeObj* pDnode;
|
||||
} SMnodeObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
SDnodeObj *pDnode;
|
||||
SDnodeObj* pDnode;
|
||||
} SQnodeObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
SDnodeObj *pDnode;
|
||||
SDnodeObj* pDnode;
|
||||
} SSnodeObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
SDnodeObj *pDnode;
|
||||
SDnodeObj* pDnode;
|
||||
} SBnodeObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -201,7 +231,7 @@ typedef struct {
|
|||
int64_t updateTime;
|
||||
int8_t superUser;
|
||||
int32_t acctId;
|
||||
SHashObj *prohibitDbHash;
|
||||
SHashObj* prohibitDbHash;
|
||||
} SUserObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -226,15 +256,15 @@ typedef struct {
|
|||
} SDbCfg;
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_DB_FNAME_LEN];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
char name[TSDB_DB_FNAME_LEN];
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
uint64_t uid;
|
||||
int32_t cfgVersion;
|
||||
int32_t vgVersion;
|
||||
int8_t hashMethod; // default is 1
|
||||
SDbCfg cfg;
|
||||
int32_t cfgVersion;
|
||||
int32_t vgVersion;
|
||||
int8_t hashMethod; // default is 1
|
||||
SDbCfg cfg;
|
||||
} SDbObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -272,7 +302,7 @@ typedef struct {
|
|||
int32_t numOfColumns;
|
||||
int32_t numOfTags;
|
||||
SRWLatch lock;
|
||||
SSchema *pSchema;
|
||||
SSchema* pSchema;
|
||||
} SStbObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -284,11 +314,11 @@ typedef struct {
|
|||
int8_t outputType;
|
||||
int32_t outputLen;
|
||||
int32_t bufSize;
|
||||
int64_t sigature;
|
||||
int64_t signature;
|
||||
int32_t commentSize;
|
||||
int32_t codeSize;
|
||||
char *pComment;
|
||||
char *pCode;
|
||||
char* pComment;
|
||||
char* pCode;
|
||||
char pData[];
|
||||
} SFuncObj;
|
||||
|
||||
|
@ -301,8 +331,8 @@ typedef struct {
|
|||
int32_t numOfRows;
|
||||
int32_t numOfReads;
|
||||
int32_t payloadLen;
|
||||
void *pIter;
|
||||
SMnode *pMnode;
|
||||
void* pIter;
|
||||
SMnode* pMnode;
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
int16_t offset[TSDB_MAX_COLUMNS];
|
||||
int32_t bytes[TSDB_MAX_COLUMNS];
|
||||
|
@ -327,52 +357,61 @@ typedef struct SMqTopicConsumer {
|
|||
#endif
|
||||
|
||||
typedef struct SMqConsumerEp {
|
||||
int32_t vgId; // -1 for unassigned
|
||||
int32_t vgId; // -1 for unassigned
|
||||
int32_t status;
|
||||
SEpSet epSet;
|
||||
int64_t consumerId; // -1 for unassigned
|
||||
int64_t consumerId; // -1 for unassigned
|
||||
int64_t lastConsumerHbTs;
|
||||
int64_t lastVgHbTs;
|
||||
int32_t execLen;
|
||||
SSubQueryMsg qExec;
|
||||
uint32_t qmsgLen;
|
||||
char* qmsg;
|
||||
//SSubQueryMsg qExec;
|
||||
} SMqConsumerEp;
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqConsumerEp(void** buf, SMqConsumerEp* pConsumerEp) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI32(buf, pConsumerEp->vgId);
|
||||
tlen += taosEncodeFixedI32(buf, pConsumerEp->status);
|
||||
tlen += taosEncodeSEpSet(buf, &pConsumerEp->epSet);
|
||||
tlen += taosEncodeFixedI64(buf, pConsumerEp->consumerId);
|
||||
tlen += tEncodeSSubQueryMsg(buf, &pConsumerEp->qExec);
|
||||
//tlen += tEncodeSSubQueryMsg(buf, &pConsumerEp->qExec);
|
||||
tlen += taosEncodeFixedU32(buf, pConsumerEp->qmsgLen);
|
||||
tlen += taosEncodeBinary(buf, pConsumerEp->qmsg, pConsumerEp->qmsgLen);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqConsumerEp(void** buf, SMqConsumerEp* pConsumerEp) {
|
||||
buf = taosDecodeFixedI32(buf, &pConsumerEp->vgId);
|
||||
buf = taosDecodeFixedI32(buf, &pConsumerEp->status);
|
||||
buf = taosDecodeSEpSet(buf, &pConsumerEp->epSet);
|
||||
buf = taosDecodeFixedI64(buf, &pConsumerEp->consumerId);
|
||||
buf = tDecodeSSubQueryMsg(buf, &pConsumerEp->qExec);
|
||||
pConsumerEp->execLen = sizeof(SSubQueryMsg) + pConsumerEp->qExec.contentLen;
|
||||
//buf = tDecodeSSubQueryMsg(buf, &pConsumerEp->qExec);
|
||||
buf = taosDecodeFixedU32(buf, &pConsumerEp->qmsgLen);
|
||||
buf = taosDecodeBinary(buf, (void**)&pConsumerEp->qmsg, pConsumerEp->qmsgLen);
|
||||
return buf;
|
||||
}
|
||||
|
||||
//unit for rebalance
|
||||
// unit for rebalance
|
||||
typedef struct SMqSubscribeObj {
|
||||
char key[TSDB_SUBSCRIBE_KEY_LEN];
|
||||
int32_t epoch;
|
||||
//TODO: replace with priority queue
|
||||
// TODO: replace with priority queue
|
||||
int32_t nextConsumerIdx;
|
||||
SArray* availConsumer; // SArray<int64_t> (consumerId)
|
||||
SArray* assigned; // SArray<SMqConsumerEp>
|
||||
SArray* unassignedConsumer; // SArray<SMqConsumerEp>
|
||||
SArray* unassignedVg; // SArray<SMqConsumerEp>
|
||||
SArray* availConsumer; // SArray<int64_t> (consumerId)
|
||||
SArray* assigned; // SArray<SMqConsumerEp>
|
||||
SArray* idleConsumer; // SArray<SMqConsumerEp>
|
||||
SArray* lostConsumer; // SArray<SMqConsumerEp>
|
||||
SArray* unassignedVg; // SArray<SMqConsumerEp>
|
||||
} SMqSubscribeObj;
|
||||
|
||||
static FORCE_INLINE SMqSubscribeObj* tNewSubscribeObj() {
|
||||
SMqSubscribeObj* pSub = malloc(sizeof(SMqSubscribeObj));
|
||||
pSub->key[0] = 0;
|
||||
pSub->epoch = 0;
|
||||
if (pSub == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pSub->key[0] = 0;
|
||||
pSub->epoch = 0;
|
||||
|
||||
pSub->availConsumer = taosArrayInit(0, sizeof(int64_t));
|
||||
if (pSub->availConsumer == NULL) {
|
||||
free(pSub);
|
||||
|
@ -384,22 +423,22 @@ static FORCE_INLINE SMqSubscribeObj* tNewSubscribeObj() {
|
|||
free(pSub);
|
||||
return NULL;
|
||||
}
|
||||
pSub->unassignedConsumer = taosArrayInit(0, sizeof(SMqConsumerEp));
|
||||
pSub->idleConsumer = taosArrayInit(0, sizeof(SMqConsumerEp));
|
||||
if (pSub->assigned == NULL) {
|
||||
taosArrayDestroy(pSub->availConsumer);
|
||||
taosArrayDestroy(pSub->unassignedConsumer);
|
||||
taosArrayDestroy(pSub->idleConsumer);
|
||||
free(pSub);
|
||||
return NULL;
|
||||
}
|
||||
pSub->unassignedVg = taosArrayInit(0, sizeof(SMqConsumerEp));
|
||||
if (pSub->assigned == NULL) {
|
||||
taosArrayDestroy(pSub->availConsumer);
|
||||
taosArrayDestroy(pSub->unassignedConsumer);
|
||||
taosArrayDestroy(pSub->idleConsumer);
|
||||
taosArrayDestroy(pSub->unassignedVg);
|
||||
free(pSub);
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
return pSub;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSubscribeObj(void** buf, const SMqSubscribeObj* pSub) {
|
||||
|
@ -422,10 +461,10 @@ static FORCE_INLINE int32_t tEncodeSubscribeObj(void** buf, const SMqSubscribeOb
|
|||
tlen += tEncodeSMqConsumerEp(buf, pCEp);
|
||||
}
|
||||
|
||||
sz = taosArrayGetSize(pSub->unassignedConsumer);
|
||||
sz = taosArrayGetSize(pSub->idleConsumer);
|
||||
tlen += taosEncodeFixedI32(buf, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqConsumerEp* pCEp = taosArrayGet(pSub->unassignedConsumer, i);
|
||||
SMqConsumerEp* pCEp = taosArrayGet(pSub->idleConsumer, i);
|
||||
tlen += tEncodeSMqConsumerEp(buf, pCEp);
|
||||
}
|
||||
|
||||
|
@ -457,22 +496,22 @@ static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub)
|
|||
}
|
||||
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pSub->unassignedConsumer = taosArrayInit(sz, sizeof(SMqConsumerEp));
|
||||
if (pSub->unassignedConsumer == NULL) {
|
||||
pSub->idleConsumer = taosArrayInit(sz, sizeof(SMqConsumerEp));
|
||||
if (pSub->idleConsumer == NULL) {
|
||||
taosArrayDestroy(pSub->assigned);
|
||||
return NULL;
|
||||
}
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqConsumerEp cEp;
|
||||
buf = tDecodeSMqConsumerEp(buf, &cEp);
|
||||
taosArrayPush(pSub->unassignedConsumer, &cEp);
|
||||
taosArrayPush(pSub->idleConsumer, &cEp);
|
||||
}
|
||||
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pSub->unassignedVg = taosArrayInit(sz, sizeof(SMqConsumerEp));
|
||||
if (pSub->unassignedVg == NULL) {
|
||||
taosArrayDestroy(pSub->assigned);
|
||||
taosArrayDestroy(pSub->unassignedConsumer);
|
||||
taosArrayDestroy(pSub->idleConsumer);
|
||||
return NULL;
|
||||
}
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
|
@ -487,38 +526,37 @@ static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub)
|
|||
typedef struct SMqCGroup {
|
||||
char name[TSDB_CONSUMER_GROUP_LEN];
|
||||
int32_t status; // 0 - uninitialized, 1 - wait rebalance, 2- normal
|
||||
SList *consumerIds; // SList<int64_t>
|
||||
SList *idleVGroups; // SList<int32_t>
|
||||
SList* consumerIds; // SList<int64_t>
|
||||
SList* idleVGroups; // SList<int32_t>
|
||||
} SMqCGroup;
|
||||
|
||||
typedef struct SMqTopicObj {
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
int64_t createTime;
|
||||
int64_t updateTime;
|
||||
uint64_t uid;
|
||||
uint64_t dbUid;
|
||||
int32_t version;
|
||||
SRWLatch lock;
|
||||
int32_t sqlLen;
|
||||
char *sql;
|
||||
char *logicalPlan;
|
||||
char *physicalPlan;
|
||||
//SHashObj *cgroups; // SHashObj<SMqCGroup>
|
||||
//SHashObj *consumers; // SHashObj<SMqConsumerObj>
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
int64_t createTime;
|
||||
int64_t updateTime;
|
||||
uint64_t uid;
|
||||
uint64_t dbUid;
|
||||
int32_t version;
|
||||
SRWLatch lock;
|
||||
int32_t sqlLen;
|
||||
char* sql;
|
||||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
// SHashObj *cgroups; // SHashObj<SMqCGroup>
|
||||
// SHashObj *consumers; // SHashObj<SMqConsumerObj>
|
||||
} SMqTopicObj;
|
||||
|
||||
// TODO: add cache and change name to id
|
||||
typedef struct SMqConsumerTopic {
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
int32_t epoch;
|
||||
//TODO: replace with something with ep
|
||||
//SList *vgroups; // SList<int32_t>
|
||||
//vg assigned to the consumer on the topic
|
||||
SArray *pVgInfo; // SArray<int32_t>
|
||||
// vg assigned to the consumer on the topic
|
||||
SArray* pVgInfo; // SArray<int32_t>
|
||||
} SMqConsumerTopic;
|
||||
|
||||
static FORCE_INLINE SMqConsumerTopic* tNewConsumerTopic(int64_t consumerId, SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
||||
static FORCE_INLINE SMqConsumerTopic* tNewConsumerTopic(int64_t consumerId, SMqTopicObj* pTopic,
|
||||
SMqSubscribeObj* pSub) {
|
||||
SMqConsumerTopic* pCTopic = malloc(sizeof(SMqConsumerTopic));
|
||||
if (pCTopic == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -567,10 +605,11 @@ static FORCE_INLINE void* tDecodeSMqConsumerTopic(void* buf, SMqConsumerTopic* p
|
|||
|
||||
typedef struct SMqConsumerObj {
|
||||
int64_t consumerId;
|
||||
int64_t connId;
|
||||
SRWLatch lock;
|
||||
char cgroup[TSDB_CONSUMER_GROUP_LEN];
|
||||
SArray *topics; // SArray<SMqConsumerTopic>
|
||||
//SHashObj *topicHash; //SHashObj<SMqTopicObj>
|
||||
SArray* topics; // SArray<SMqConsumerTopic>
|
||||
// SHashObj *topicHash; //SHashObj<SMqTopicObj>
|
||||
} SMqConsumerObj;
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqConsumerObj(void** buf, const SMqConsumerObj* pConsumer) {
|
||||
|
@ -602,12 +641,12 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons
|
|||
|
||||
typedef struct SMqSubConsumerObj {
|
||||
int64_t consumerUid; // if -1, unassigned
|
||||
SList *vgId; // SList<int32_t>
|
||||
SList* vgId; // SList<int32_t>
|
||||
} SMqSubConsumerObj;
|
||||
|
||||
typedef struct SMqSubCGroupObj {
|
||||
char name[TSDB_CONSUMER_GROUP_LEN];
|
||||
SList *consumers; // SList<SMqConsumerObj>
|
||||
SList* consumers; // SList<SMqConsumerObj>
|
||||
} SMqSubCGroupObj;
|
||||
|
||||
typedef struct SMqSubTopicObj {
|
||||
|
@ -620,30 +659,30 @@ typedef struct SMqSubTopicObj {
|
|||
int32_t version;
|
||||
SRWLatch lock;
|
||||
int32_t sqlLen;
|
||||
char *sql;
|
||||
char *logicalPlan;
|
||||
char *physicalPlan;
|
||||
SList *cgroups; // SList<SMqSubCGroupObj>
|
||||
char* sql;
|
||||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
SList* cgroups; // SList<SMqSubCGroupObj>
|
||||
} SMqSubTopicObj;
|
||||
|
||||
typedef struct SMqConsumerSubObj {
|
||||
int64_t topicUid;
|
||||
SList *vgIds; // SList<int64_t>
|
||||
SList* vgIds; // SList<int64_t>
|
||||
} SMqConsumerSubObj;
|
||||
|
||||
typedef struct SMqConsumerHbObj {
|
||||
int64_t consumerId;
|
||||
SList *consumerSubs; // SList<SMqConsumerSubObj>
|
||||
SList* consumerSubs; // SList<SMqConsumerSubObj>
|
||||
} SMqConsumerHbObj;
|
||||
|
||||
typedef struct SMqVGroupSubObj {
|
||||
int64_t topicUid;
|
||||
SList *consumerIds; // SList<int64_t>
|
||||
SList* consumerIds; // SList<int64_t>
|
||||
} SMqVGroupSubObj;
|
||||
|
||||
typedef struct SMqVGroupHbObj {
|
||||
int64_t vgId;
|
||||
SList *vgSubs; // SList<SMqVGroupSubObj>
|
||||
SList* vgSubs; // SList<SMqVGroupSubObj>
|
||||
} SMqVGroupHbObj;
|
||||
|
||||
#if 0
|
||||
|
@ -663,11 +702,11 @@ typedef struct SMnodeMsg {
|
|||
char user[TSDB_USER_LEN];
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
int32_t acctId;
|
||||
SMnode *pMnode;
|
||||
SMnode* pMnode;
|
||||
int64_t createdTime;
|
||||
SRpcMsg rpcMsg;
|
||||
int32_t contLen;
|
||||
void *pCont;
|
||||
void* pCont;
|
||||
} SMnodeMsg;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mndAuth.h"
|
||||
#include "mndUser.h"
|
||||
|
||||
static int32_t mndProcessAuthReq(SMnodeMsg *pReq);
|
||||
|
||||
|
@ -25,9 +26,34 @@ int32_t mndInitAuth(SMnode *pMnode) {
|
|||
|
||||
void mndCleanupAuth(SMnode *pMnode) {}
|
||||
|
||||
int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { return 0; }
|
||||
int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, user);
|
||||
if (pUser == NULL) {
|
||||
*secret = 0;
|
||||
mError("user:%s, failed to auth user since %s", user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
*spi = 1;
|
||||
*encrypt = 0;
|
||||
*ckey = 0;
|
||||
|
||||
memcpy(secret, pUser->pass, TSDB_PASSWORD_LEN);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
||||
mDebug("user:%s, auth info is returned", user);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAuthReq(SMnodeMsg *pReq) {
|
||||
mDebug("user:%s, auth req is processed", pReq->user);
|
||||
return 0;
|
||||
SAuthReq *pAuth = pReq->rpcMsg.pCont;
|
||||
|
||||
int32_t contLen = sizeof(SAuthRsp);
|
||||
SAuthRsp *pRsp = rpcMallocCont(contLen);
|
||||
pReq->pCont = pRsp;
|
||||
pReq->contLen = contLen;
|
||||
|
||||
int32_t code = mndRetriveAuth(pReq->pMnode, pAuth->user, &pRsp->spi, &pRsp->encrypt, pRsp->secret, pRsp->ckey);
|
||||
mTrace("user:%s, auth req received, spi:%d encrypt:%d ruser:%s", pReq->user, pAuth->spi, pAuth->encrypt, pAuth->user);
|
||||
return code;
|
||||
}
|
|
@ -56,7 +56,9 @@ void mndCleanupConsumer(SMnode *pMnode) {}
|
|||
SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t tlen = tEncodeSMqConsumerObj(NULL, pConsumer);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_CONSUMER, MND_CONSUMER_VER_NUMBER, tlen);
|
||||
int32_t size = sizeof(int32_t) + tlen + MND_CONSUMER_RESERVE_SIZE;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_CONSUMER, MND_CONSUMER_VER_NUMBER, size);
|
||||
if (pRaw == NULL) goto CM_ENCODE_OVER;
|
||||
|
||||
void* buf = malloc(tlen);
|
||||
|
@ -68,34 +70,6 @@ SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) {
|
|||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, tlen, CM_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, buf, tlen, CM_ENCODE_OVER);
|
||||
|
||||
#if 0
|
||||
int32_t topicNum = taosArrayGetSize(pConsumer->topics);
|
||||
SDB_SET_INT64(pRaw, dataPos, pConsumer->consumerId, CM_ENCODE_OVER);
|
||||
int32_t len = strlen(pConsumer->cgroup);
|
||||
SDB_SET_INT32(pRaw, dataPos, len, CM_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pConsumer->cgroup, len, CM_ENCODE_OVER);
|
||||
SDB_SET_INT32(pRaw, dataPos, topicNum, CM_ENCODE_OVER);
|
||||
for (int i = 0; i < topicNum; i++) {
|
||||
int32_t len;
|
||||
SMqConsumerTopic *pConsumerTopic = taosArrayGet(pConsumer->topics, i);
|
||||
len = strlen(pConsumerTopic->name);
|
||||
SDB_SET_INT32(pRaw, dataPos, len, CM_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pConsumerTopic->name, len, CM_ENCODE_OVER);
|
||||
int vgSize;
|
||||
if (pConsumerTopic->vgroups == NULL) {
|
||||
vgSize = 0;
|
||||
} else {
|
||||
vgSize = listNEles(pConsumerTopic->vgroups);
|
||||
}
|
||||
SDB_SET_INT32(pRaw, dataPos, vgSize, CM_ENCODE_OVER);
|
||||
for (int j = 0; j < vgSize; j++) {
|
||||
// SList* head;
|
||||
/*SDB_SET_INT64(pRaw, dataPos, 0[> change to list item <]);*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE, CM_ENCODE_OVER);
|
||||
SDB_SET_DATALEN(pRaw, dataPos, CM_ENCODE_OVER);
|
||||
|
||||
|
@ -116,53 +90,35 @@ SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) {
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto CONSUME_DECODE_OVER;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto CM_DECODE_OVER;
|
||||
|
||||
if (sver != MND_CONSUMER_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto CONSUME_DECODE_OVER;
|
||||
goto CM_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SMqConsumerObj));
|
||||
if (pRow == NULL) goto CONSUME_DECODE_OVER;
|
||||
if (pRow == NULL) goto CM_DECODE_OVER;
|
||||
|
||||
SMqConsumerObj *pConsumer = sdbGetRowObj(pRow);
|
||||
if (pConsumer == NULL) goto CONSUME_DECODE_OVER;
|
||||
if (pConsumer == NULL) goto CM_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
int32_t len;
|
||||
SDB_GET_INT32(pRaw, dataPos, &len, CONSUME_DECODE_OVER);
|
||||
SDB_GET_INT32(pRaw, dataPos, &len, CM_DECODE_OVER);
|
||||
void* buf = malloc(len);
|
||||
if (buf == NULL) goto CONSUME_DECODE_OVER;
|
||||
|
||||
SDB_GET_BINARY(pRaw, dataPos, buf, len, CONSUME_DECODE_OVER);
|
||||
if (buf == NULL) goto CM_DECODE_OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, buf, len, CM_DECODE_OVER);
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE, CM_DECODE_OVER);
|
||||
|
||||
tDecodeSMqConsumerObj(buf, pConsumer);
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE, CONSUME_DECODE_OVER);
|
||||
if (tDecodeSMqConsumerObj(buf, pConsumer) == NULL) {
|
||||
goto CM_DECODE_OVER;
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
#if 0
|
||||
SDB_GET_INT32(pRaw, dataPos, &topicNum, CONSUME_DECODE_OVER);
|
||||
for (int i = 0; i < topicNum; i++) {
|
||||
int32_t topicLen;
|
||||
SMqConsumerTopic *pConsumerTopic = malloc(sizeof(SMqConsumerTopic));
|
||||
if (pConsumerTopic == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
/*pConsumerTopic->vgroups = taosArrayInit(topicNum, sizeof(SMqConsumerTopic));*/
|
||||
SDB_GET_INT32(pRaw, dataPos, &topicLen, CONSUME_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pConsumerTopic->name, topicLen, CONSUME_DECODE_OVER);
|
||||
int32_t vgSize;
|
||||
SDB_GET_INT32(pRaw, dataPos, &vgSize, CONSUME_DECODE_OVER);
|
||||
}
|
||||
#endif
|
||||
|
||||
CONSUME_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
CM_DECODE_OVER:
|
||||
if (terrno != TSDB_CODE_SUCCESS) {
|
||||
mError("consumer:%ld, failed to decode from raw:%p since %s", pConsumer->consumerId, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
|
|
|
@ -234,7 +234,7 @@ int32_t mndGetDnodeSize(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs) {
|
||||
int64_t interval = ABS(pDnode->lastAccessTime - curMs);
|
||||
int64_t interval = TABS(pDnode->lastAccessTime - curMs);
|
||||
if (interval > 3500 * pMnode->cfg.statusInterval) {
|
||||
if (pDnode->rebootTime > 0) {
|
||||
pDnode->offlineReason = DND_REASON_STATUS_MSG_TIMEOUT;
|
||||
|
|
|
@ -25,14 +25,14 @@ static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc);
|
|||
static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndFuncActionInsert(SSdb *pSdb, SFuncObj *pFunc);
|
||||
static int32_t mndFuncActionDelete(SSdb *pSdb, SFuncObj *pFunc);
|
||||
static int32_t mndFuncActionUpdate(SSdb *pSdb, SFuncObj *pOldFunc, SFuncObj *pNewFunc);
|
||||
static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pMsg, SCreateFuncReq *pCreate);
|
||||
static int32_t mndDropFunc(SMnode *pMnode, SMnodeMsg *pMsg, SFuncObj *pFunc);
|
||||
static int32_t mndProcessCreateFuncMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropFuncMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessRetrieveFuncMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetFuncMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaRsp *pMeta);
|
||||
static int32_t mndRetrieveFuncs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndFuncActionUpdate(SSdb *pSdb, SFuncObj *pOld, SFuncObj *pNew);
|
||||
static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pReq, SCreateFuncReq *pCreate);
|
||||
static int32_t mndDropFunc(SMnode *pMnode, SMnodeMsg *pReq, SFuncObj *pFunc);
|
||||
static int32_t mndProcessCreateFuncReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessDropFuncReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessRetrieveFuncReq(SMnodeMsg *pReq);
|
||||
static int32_t mndGetFuncMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta);
|
||||
static int32_t mndRetrieveFuncs(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextFunc(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitFunc(SMnode *pMnode) {
|
||||
|
@ -44,13 +44,13 @@ int32_t mndInitFunc(SMnode *pMnode) {
|
|||
.updateFp = (SdbUpdateFp)mndFuncActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndFuncActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_FUNCTION, mndProcessCreateFuncMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_FUNCTION, mndProcessDropFuncMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_RETRIEVE_FUNCTION, mndProcessRetrieveFuncMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_FUNC, mndProcessCreateFuncReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_FUNC, mndProcessDropFuncReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_RETRIEVE_FUNC, mndProcessRetrieveFuncReq);
|
||||
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_FUNCTION, mndGetFuncMeta);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_FUNCTION, mndRetrieveFuncs);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_FUNCTION, mndCancelGetNextFunc);
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_FUNC, mndGetFuncMeta);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_FUNC, mndRetrieveFuncs);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_FUNC, mndCancelGetNextFunc);
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) {
|
|||
SDB_SET_INT8(pRaw, dataPos, pFunc->outputType, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->outputLen, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->bufSize, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pFunc->sigature, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pFunc->signature, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize, FUNC_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, FUNC_ENCODE_OVER)
|
||||
|
@ -104,13 +104,11 @@ static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) {
|
|||
goto FUNC_DECODE_OVER;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SFuncObj) + TSDB_FUNC_COMMENT_LEN + TSDB_FUNC_CODE_LEN;
|
||||
SSdbRow *pRow = sdbAllocRow(size);
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SFuncObj));
|
||||
if (pRow == NULL) goto FUNC_DECODE_OVER;
|
||||
|
||||
SFuncObj *pFunc = sdbGetRowObj(pRow);
|
||||
if (pFunc == NULL) goto FUNC_DECODE_OVER;
|
||||
char *tmp = (char *)pFunc + sizeof(SFuncObj);
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, FUNC_DECODE_OVER)
|
||||
|
@ -121,12 +119,18 @@ static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT8(pRaw, dataPos, &pFunc->outputType, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pFunc->outputLen, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pFunc->bufSize, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pFunc->sigature, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pFunc->signature, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pFunc->commentSize, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pFunc->codeSize, FUNC_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pFunc->pData, pFunc->commentSize + pFunc->codeSize, FUNC_DECODE_OVER)
|
||||
pFunc->pComment = pFunc->pData;
|
||||
pFunc->pCode = (pFunc->pData + pFunc->commentSize);
|
||||
|
||||
pFunc->pComment = calloc(1, pFunc->commentSize);
|
||||
pFunc->pCode = calloc(1, pFunc->codeSize);
|
||||
if (pFunc->pComment == NULL || pFunc->pCode == NULL) {
|
||||
goto FUNC_DECODE_OVER;
|
||||
}
|
||||
|
||||
SDB_GET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, FUNC_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, FUNC_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
|
@ -148,136 +152,136 @@ static int32_t mndFuncActionInsert(SSdb *pSdb, SFuncObj *pFunc) {
|
|||
|
||||
static int32_t mndFuncActionDelete(SSdb *pSdb, SFuncObj *pFunc) {
|
||||
mTrace("func:%s, perform delete action, row:%p", pFunc->name, pFunc);
|
||||
tfree(pFunc->pCode);
|
||||
tfree(pFunc->pComment);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndFuncActionUpdate(SSdb *pSdb, SFuncObj *pOldFunc, SFuncObj *pNewFunc) {
|
||||
mTrace("func:%s, perform update action, old row:%p new row:%p", pOldFunc->name, pOldFunc, pNewFunc);
|
||||
static int32_t mndFuncActionUpdate(SSdb *pSdb, SFuncObj *pOld, SFuncObj *pNew) {
|
||||
mTrace("func:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pMsg, SCreateFuncReq *pCreate) {
|
||||
SFuncObj *pFunc = calloc(1, sizeof(SFuncObj) + pCreate->commentSize + pCreate->codeSize);
|
||||
pFunc->createdTime = taosGetTimestampMs();
|
||||
pFunc->funcType = pCreate->funcType;
|
||||
pFunc->scriptType = pCreate->scriptType;
|
||||
pFunc->outputType = pCreate->outputType;
|
||||
pFunc->outputLen = pCreate->outputLen;
|
||||
pFunc->bufSize = pCreate->bufSize;
|
||||
pFunc->sigature = pCreate->sigature;
|
||||
pFunc->commentSize = pCreate->commentSize;
|
||||
pFunc->codeSize = pCreate->codeSize;
|
||||
pFunc->pComment = pFunc->pData;
|
||||
memcpy(pFunc->pComment, pCreate->pCont, pCreate->commentSize);
|
||||
pFunc->pCode = pFunc->pData + pCreate->commentSize;
|
||||
memcpy(pFunc->pCode, pCreate->pCont + pCreate->commentSize, pFunc->codeSize);
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
free(pFunc);
|
||||
mError("func:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
static SFuncObj *mndAcquireFunc(SMnode *pMnode, char *funcName) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SFuncObj *pFunc = sdbAcquire(pSdb, SDB_FUNC, funcName);
|
||||
if (pFunc == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
||||
terrno = TSDB_CODE_MND_FUNC_NOT_EXIST;
|
||||
}
|
||||
return pFunc;
|
||||
}
|
||||
|
||||
static void mndReleaseFunc(SMnode *pMnode, SFuncObj *pFunc) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbRelease(pSdb, pFunc);
|
||||
}
|
||||
|
||||
static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pReq, SCreateFuncReq *pCreate) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
SFuncObj func = {0};
|
||||
memcpy(func.name, pCreate->name, TSDB_FUNC_NAME_LEN);
|
||||
func.createdTime = taosGetTimestampMs();
|
||||
func.funcType = pCreate->funcType;
|
||||
func.scriptType = pCreate->scriptType;
|
||||
func.outputType = pCreate->outputType;
|
||||
func.outputLen = pCreate->outputLen;
|
||||
func.bufSize = pCreate->bufSize;
|
||||
func.signature = pCreate->signature;
|
||||
func.commentSize = pCreate->commentSize;
|
||||
func.codeSize = pCreate->codeSize;
|
||||
func.pComment = malloc(func.commentSize);
|
||||
func.pCode = malloc(func.codeSize);
|
||||
if (func.pCode == NULL || func.pCode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto CREATE_FUNC_OVER;
|
||||
}
|
||||
|
||||
memcpy(func.pComment, pCreate->pCont, pCreate->commentSize);
|
||||
memcpy(func.pCode, pCreate->pCont + pCreate->commentSize, func.codeSize);
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto CREATE_FUNC_OVER;
|
||||
|
||||
mDebug("trans:%d, used to create func:%s", pTrans->id, pCreate->name);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndFuncActionEncode(pFunc);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
free(pFunc);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
||||
SSdbRaw *pRedoRaw = mndFuncActionEncode(&func);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) goto CREATE_FUNC_OVER;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) goto CREATE_FUNC_OVER;
|
||||
|
||||
SSdbRaw *pUndoRaw = mndFuncActionEncode(pFunc);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
free(pFunc);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
SSdbRaw *pUndoRaw = mndFuncActionEncode(&func);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) goto CREATE_FUNC_OVER;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) goto CREATE_FUNC_OVER;
|
||||
|
||||
SSdbRaw *pCommitRaw = mndFuncActionEncode(pFunc);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
free(pFunc);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
SSdbRaw *pCommitRaw = mndFuncActionEncode(&func);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) goto CREATE_FUNC_OVER;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) goto CREATE_FUNC_OVER;
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_FUNC_OVER;
|
||||
|
||||
free(pFunc);
|
||||
code = 0;
|
||||
|
||||
CREATE_FUNC_OVER:
|
||||
free(func.pCode);
|
||||
free(func.pComment);
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndDropFunc(SMnode *pMnode, SMnodeMsg *pMsg, SFuncObj *pFunc) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("func:%s, failed to drop since %s", pFunc->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
static int32_t mndDropFunc(SMnode *pMnode, SMnodeMsg *pReq, SFuncObj *pFunc) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto DROP_FUNC_OVER;
|
||||
|
||||
mDebug("trans:%d, used to drop user:%s", pTrans->id, pFunc->name);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndFuncActionEncode(pFunc);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) goto DROP_FUNC_OVER;
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndFuncActionEncode(pFunc);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) goto DROP_FUNC_OVER;
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndFuncActionEncode(pFunc);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) goto DROP_FUNC_OVER;
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_FUNC_OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
DROP_FUNC_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateFuncMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndProcessCreateFuncReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
|
||||
SCreateFuncReq *pCreate = pMsg->rpcMsg.pCont;
|
||||
SCreateFuncReq *pCreate = pReq->rpcMsg.pCont;
|
||||
pCreate->outputLen = htonl(pCreate->outputLen);
|
||||
pCreate->bufSize = htonl(pCreate->bufSize);
|
||||
pCreate->sigature = htobe64(pCreate->sigature);
|
||||
pCreate->signature = htobe64(pCreate->signature);
|
||||
pCreate->commentSize = htonl(pCreate->commentSize);
|
||||
pCreate->codeSize = htonl(pCreate->codeSize);
|
||||
|
||||
mDebug("func:%s, start to create", pCreate->name);
|
||||
|
||||
SFuncObj *pFunc = sdbAcquire(pMnode->pSdb, SDB_FUNC, pCreate->name);
|
||||
SFuncObj *pFunc = mndAcquireFunc(pMnode, pCreate->name);
|
||||
if (pFunc != NULL) {
|
||||
sdbRelease(pMnode->pSdb, pFunc);
|
||||
terrno = TSDB_CODE_MND_FUNC_ALREADY_EXIST;
|
||||
mError("func:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
mndReleaseFunc(pMnode, pFunc);
|
||||
if (pCreate->igExists) {
|
||||
mDebug("stb:%s, already exist, ignore exist is set", pCreate->name);
|
||||
return 0;
|
||||
} else {
|
||||
terrno = TSDB_CODE_MND_FUNC_ALREADY_EXIST;
|
||||
mError("func:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
} else if (terrno == TSDB_CODE_MND_FUNC_ALREADY_EXIST) {
|
||||
mError("stb:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -305,14 +309,13 @@ static int32_t mndProcessCreateFuncMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (pCreate->bufSize < 0 || pCreate->bufSize > TSDB_FUNC_BUF_SIZE) {
|
||||
if (pCreate->bufSize <= 0 || pCreate->bufSize > TSDB_FUNC_BUF_SIZE) {
|
||||
terrno = TSDB_CODE_MND_INVALID_FUNC_BUFSIZE;
|
||||
mError("func:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndCreateFunc(pMnode, pMsg, pCreate);
|
||||
|
||||
int32_t code = mndCreateFunc(pMnode, pReq, pCreate);
|
||||
if (code != 0) {
|
||||
mError("func:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
|
@ -321,9 +324,9 @@ static int32_t mndProcessCreateFuncMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropFuncMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SDropFuncReq *pDrop = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessDropFuncReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SDropFuncReq *pDrop = pReq->rpcMsg.pCont;
|
||||
|
||||
mDebug("func:%s, start to drop", pDrop->name);
|
||||
|
||||
|
@ -333,14 +336,20 @@ static int32_t mndProcessDropFuncMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SFuncObj *pFunc = sdbAcquire(pMnode->pSdb, SDB_FUNC, pDrop->name);
|
||||
SFuncObj *pFunc = mndAcquireFunc(pMnode, pDrop->name);
|
||||
if (pFunc == NULL) {
|
||||
terrno = TSDB_CODE_MND_FUNC_NOT_EXIST;
|
||||
mError("func:%s, failed to drop since %s", pDrop->name, terrstr());
|
||||
return -1;
|
||||
if (pDrop->igNotExists) {
|
||||
mDebug("func:%s, not exist, ignore not exist is set", pDrop->name);
|
||||
return 0;
|
||||
} else {
|
||||
terrno = TSDB_CODE_MND_FUNC_NOT_EXIST;
|
||||
mError("func:%s, failed to drop since %s", pDrop->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t code = mndDropFunc(pMnode, pMsg, pFunc);
|
||||
int32_t code = mndDropFunc(pMnode, pReq, pFunc);
|
||||
mndReleaseFunc(pMnode, pFunc);
|
||||
|
||||
if (code != 0) {
|
||||
mError("func:%s, failed to drop since %s", pDrop->name, terrstr());
|
||||
|
@ -350,15 +359,26 @@ static int32_t mndProcessDropFuncMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessRetrieveFuncMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndProcessRetrieveFuncReq(SMnodeMsg *pReq) {
|
||||
int32_t code = -1;
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
|
||||
SRetrieveFuncReq *pRetrieve = pMsg->rpcMsg.pCont;
|
||||
SRetrieveFuncReq *pRetrieve = pReq->rpcMsg.pCont;
|
||||
pRetrieve->numOfFuncs = htonl(pRetrieve->numOfFuncs);
|
||||
if (pRetrieve->numOfFuncs <= 0 || pRetrieve->numOfFuncs > TSDB_FUNC_MAX_RETRIEVE) {
|
||||
terrno = TSDB_CODE_MND_INVALID_FUNC_RETRIEVE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SRetrieveFuncRsp) + (sizeof(SFuncInfo) + TSDB_FUNC_CODE_LEN) * pRetrieve->numOfFuncs + 16384;
|
||||
int32_t fsize = sizeof(SFuncInfo) + TSDB_FUNC_CODE_LEN + TSDB_FUNC_COMMENT_LEN;
|
||||
int32_t size = sizeof(SRetrieveFuncRsp) + fsize * pRetrieve->numOfFuncs;
|
||||
|
||||
SRetrieveFuncRsp *pRetrieveRsp = rpcMallocCont(size);
|
||||
if (pRetrieveRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FUNC_RETRIEVE_OVER;
|
||||
}
|
||||
|
||||
pRetrieveRsp->numOfFuncs = htonl(pRetrieve->numOfFuncs);
|
||||
char *pOutput = pRetrieveRsp->pFuncInfos;
|
||||
|
||||
|
@ -366,37 +386,42 @@ static int32_t mndProcessRetrieveFuncMsg(SMnodeMsg *pMsg) {
|
|||
char funcName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
memcpy(funcName, pRetrieve->pFuncNames + i * TSDB_FUNC_NAME_LEN, TSDB_FUNC_NAME_LEN);
|
||||
|
||||
SFuncObj *pFunc = sdbAcquire(pMnode->pSdb, SDB_FUNC, funcName);
|
||||
SFuncObj *pFunc = mndAcquireFunc(pMnode, funcName);
|
||||
if (pFunc == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_FUNC;
|
||||
mError("func:%s, failed to retrieve since %s", funcName, terrstr());
|
||||
return -1;
|
||||
goto FUNC_RETRIEVE_OVER;
|
||||
}
|
||||
|
||||
SFuncInfo *pFuncInfo = (SFuncInfo *)pOutput;
|
||||
|
||||
strncpy(pFuncInfo->name, pFunc->name, TSDB_FUNC_NAME_LEN);
|
||||
memcpy(pFuncInfo->name, pFunc->name, TSDB_FUNC_NAME_LEN);
|
||||
pFuncInfo->funcType = pFunc->funcType;
|
||||
pFuncInfo->scriptType = pFunc->scriptType;
|
||||
pFuncInfo->outputType = pFunc->outputType;
|
||||
pFuncInfo->outputLen = htonl(pFunc->outputLen);
|
||||
pFuncInfo->bufSize = htonl(pFunc->bufSize);
|
||||
pFuncInfo->sigature = htobe64(pFunc->sigature);
|
||||
pFuncInfo->signature = htobe64(pFunc->signature);
|
||||
pFuncInfo->commentSize = htonl(pFunc->commentSize);
|
||||
pFuncInfo->codeSize = htonl(pFunc->codeSize);
|
||||
memcpy(pFuncInfo->pCont, pFunc->pCode, pFunc->commentSize + pFunc->codeSize);
|
||||
|
||||
pOutput += sizeof(SFuncInfo) + pFunc->commentSize + pFunc->codeSize;
|
||||
memcpy(pFuncInfo->pCont, pFunc->pComment, pFunc->commentSize);
|
||||
memcpy(pFuncInfo->pCont + pFunc->commentSize, pFunc->pCode, pFunc->codeSize);
|
||||
pOutput += (sizeof(SFuncInfo) + pFunc->commentSize + pFunc->codeSize);
|
||||
mndReleaseFunc(pMnode, pFunc);
|
||||
}
|
||||
|
||||
pMsg->pCont = pRetrieveRsp;
|
||||
pMsg->contLen = (int32_t)(pOutput - (char *)pRetrieveRsp);
|
||||
pReq->pCont = pRetrieveRsp;
|
||||
pReq->contLen = (int32_t)(pOutput - (char *)pRetrieveRsp);
|
||||
|
||||
return 0;
|
||||
code = 0;
|
||||
|
||||
FUNC_RETRIEVE_OVER:
|
||||
if (code != 0) rpcFreeCont(pRetrieveRsp);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndGetFuncMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaRsp *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndGetFuncMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
int32_t cols = 0;
|
||||
|
@ -454,7 +479,7 @@ static int32_t mndGetFuncMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaRsp *p
|
|||
|
||||
pShow->numOfRows = sdbGetSize(pSdb, SDB_FUNC);
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
strcpy(pMeta->tbFname, "show funcs");
|
||||
strcpy(pMeta->tbFname, mndShowStr(pShow->type));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -477,8 +502,8 @@ static void *mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int16_t le
|
|||
return tDataTypes[type].name;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveFuncs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveFuncs(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
SFuncObj *pFunc = NULL;
|
||||
|
|
|
@ -261,7 +261,7 @@ static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatReq *pReq) {
|
|||
pConn->pQueries = calloc(sizeof(SQueryDesc), QUERY_SAVE_SIZE);
|
||||
}
|
||||
|
||||
pConn->numOfQueries = MIN(QUERY_SAVE_SIZE, numOfQueries);
|
||||
pConn->numOfQueries = TMIN(QUERY_SAVE_SIZE, numOfQueries);
|
||||
|
||||
int32_t saveSize = pConn->numOfQueries * sizeof(SQueryDesc);
|
||||
if (saveSize > 0 && pConn->pQueries != NULL) {
|
||||
|
|
|
@ -296,7 +296,7 @@ char *mndShowStr(int32_t showType) {
|
|||
return "show streamtables";
|
||||
case TSDB_MGMT_TABLE_TP:
|
||||
return "show topics";
|
||||
case TSDB_MGMT_TABLE_FUNCTION:
|
||||
case TSDB_MGMT_TABLE_FUNC:
|
||||
return "show functions";
|
||||
default:
|
||||
return "undefined";
|
||||
|
|
|
@ -123,8 +123,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
goto STB_DECODE_OVER;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SStbObj) + TSDB_MAX_COLUMNS * sizeof(SSchema);
|
||||
SSdbRow *pRow = sdbAllocRow(size);
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SStbObj));
|
||||
if (pRow == NULL) goto STB_DECODE_OVER;
|
||||
|
||||
SStbObj *pStb = sdbGetRowObj(pRow);
|
||||
|
@ -143,6 +142,9 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
|
||||
int32_t totalCols = pStb->numOfColumns + pStb->numOfTags;
|
||||
pStb->pSchema = calloc(totalCols, sizeof(SSchema));
|
||||
if (pStb->pSchema == NULL) {
|
||||
goto STB_DECODE_OVER;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pStb->pSchema[i];
|
||||
|
@ -448,7 +450,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pReq, SMCreateStbReq *pCr
|
|||
stbObj.pSchema[i].colId = i + 1;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto CREATE_STB_OVER;
|
||||
|
||||
|
@ -481,7 +483,7 @@ static int32_t mndProcessMCreateStbReq(SMnodeMsg *pReq) {
|
|||
|
||||
SStbObj *pStb = mndAcquireStb(pMnode, pCreate->name);
|
||||
if (pStb != NULL) {
|
||||
sdbRelease(pMnode->pSdb, pStb);
|
||||
mndReleaseStb(pMnode, pStb);
|
||||
if (pCreate->igExists) {
|
||||
mDebug("stb:%s, already exist, ignore exist is set", pCreate->name);
|
||||
return 0;
|
||||
|
@ -492,6 +494,7 @@ static int32_t mndProcessMCreateStbReq(SMnodeMsg *pReq) {
|
|||
}
|
||||
} else if (terrno != TSDB_CODE_MND_STB_NOT_EXIST) {
|
||||
mError("stb:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// topic should have different name with stb
|
||||
|
@ -640,7 +643,7 @@ static int32_t mndDropStb(SMnode *pMnode, SMnodeMsg *pReq, SStbObj *pStb) {
|
|||
|
||||
DROP_STB_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessMDropStbReq(SMnodeMsg *pReq) {
|
||||
|
@ -665,7 +668,6 @@ static int32_t mndProcessMDropStbReq(SMnodeMsg *pReq) {
|
|||
mndReleaseStb(pMnode, pStb);
|
||||
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("stb:%s, failed to drop since %s", pDrop->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ int32_t mndInitSubscribe(SMnode *pMnode) {
|
|||
.deleteFp = (SdbDeleteFp)mndSubActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SUBSCRIBE, mndProcessSubscribeReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_SUBSCRIBE_RSP, mndProcessSubscribeInternalRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_MQ_SET_CONN_RSP, mndProcessSubscribeInternalRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_TIMER, mndProcessMqTimerMsg);
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
@ -96,24 +96,27 @@ static int32_t mndProcessMqTimerMsg(SMnodeMsg *pMsg) {
|
|||
pSub->nextConsumerIdx = (pSub->nextConsumerIdx + 1) % taosArrayGetSize(pSub->availConsumer);
|
||||
|
||||
// build msg
|
||||
SMqSetCVgReq req = {
|
||||
.vgId = pCEp->vgId,
|
||||
.consumerId = consumerId,
|
||||
};
|
||||
strcpy(req.cgroup, cgroup);
|
||||
strcpy(req.topicName, topic);
|
||||
strcpy(req.sql, pTopic->sql);
|
||||
strcpy(req.logicalPlan, pTopic->logicalPlan);
|
||||
strcpy(req.physicalPlan, pTopic->physicalPlan);
|
||||
memcpy(&req.msg, &pCEp->qExec, pCEp->execLen);
|
||||
int32_t tlen = tEncodeSMqSetCVgReq(NULL, &req);
|
||||
|
||||
SMqSetCVgReq* pReq = malloc(sizeof(SMqSetCVgReq) + pCEp->qmsgLen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
strcpy(pReq->cgroup, cgroup);
|
||||
strcpy(pReq->topicName, topic);
|
||||
pReq->sql = strdup(pTopic->sql);
|
||||
pReq->logicalPlan = strdup(pTopic->logicalPlan);
|
||||
pReq->physicalPlan = strdup(pTopic->physicalPlan);
|
||||
pReq->qmsgLen = pCEp->qmsgLen;
|
||||
memcpy(pReq->qmsg, pCEp->qmsg, pCEp->qmsgLen);
|
||||
int32_t tlen = tEncodeSMqSetCVgReq(NULL, pReq);
|
||||
void *reqStr = malloc(tlen);
|
||||
if (reqStr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
void *abuf = reqStr;
|
||||
tEncodeSMqSetCVgReq(abuf, &req);
|
||||
tEncodeSMqSetCVgReq(&abuf, pReq);
|
||||
|
||||
// persist msg
|
||||
STransAction action = {0};
|
||||
|
@ -127,6 +130,7 @@ static int32_t mndProcessMqTimerMsg(SMnodeMsg *pMsg) {
|
|||
SSdbRaw *pRaw = mndSubActionEncode(pSub);
|
||||
mndTransAppendRedolog(pTrans, pRaw);
|
||||
|
||||
free(pReq);
|
||||
tfree(topic);
|
||||
tfree(cgroup);
|
||||
}
|
||||
|
@ -145,6 +149,14 @@ static int mndInitUnassignedVg(SMnode *pMnode, SMqTopicObj *pTopic, SArray *unas
|
|||
//convert phyplan to dag
|
||||
SQueryDag *pDag = qStringToDag(pTopic->physicalPlan);
|
||||
SArray *pArray;
|
||||
SArray* inner = taosArrayGet(pDag->pSubplans, 0);
|
||||
SSubplan *plan = taosArrayGetP(inner, 0);
|
||||
plan->execNode.inUse = 0;
|
||||
strcpy(plan->execNode.epAddr[0].fqdn, "localhost");
|
||||
plan->execNode.epAddr[0].port = 6030;
|
||||
plan->execNode.nodeId = 2;
|
||||
plan->execNode.numOfEps = 1;
|
||||
|
||||
if (schedulerConvertDagToTaskList(pDag, &pArray) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -152,14 +164,22 @@ static int mndInitUnassignedVg(SMnode *pMnode, SMqTopicObj *pTopic, SArray *unas
|
|||
//convert dag to msg
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqConsumerEp CEp;
|
||||
CEp.status = 0;
|
||||
CEp.lastConsumerHbTs = CEp.lastVgHbTs = -1;
|
||||
STaskInfo* pTaskInfo = taosArrayGet(pArray, i);
|
||||
tConvertQueryAddrToEpSet(&CEp.epSet, &pTaskInfo->addr);
|
||||
/*mDebug("subscribe convert ep %d %s %s %s %s %s\n", CEp.epSet.numOfEps, CEp.epSet.fqdn[0], CEp.epSet.fqdn[1], CEp.epSet.fqdn[2], CEp.epSet.fqdn[3], CEp.epSet.fqdn[4]);*/
|
||||
CEp.vgId = pTaskInfo->addr.nodeId;
|
||||
CEp.qmsgLen = pTaskInfo->msg->contentLen;
|
||||
CEp.qmsg = malloc(CEp.qmsgLen);
|
||||
if (CEp.qmsg == NULL) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(CEp.qmsg, pTaskInfo->msg->msg, pTaskInfo->msg->contentLen);
|
||||
taosArrayPush(unassignedVg, &CEp);
|
||||
}
|
||||
|
||||
qDestroyQueryDag(pDag);
|
||||
/*qDestroyQueryDag(pDag);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -171,31 +191,38 @@ static int mndBuildMqSetConsumerVgReq(SMnode *pMnode, STrans *pTrans, SMqConsume
|
|||
SVgObj *pVgObj = mndAcquireVgroup(pMnode, vgId);
|
||||
SMqSetCVgReq req = {
|
||||
.vgId = vgId,
|
||||
.consumerId = pConsumer->consumerId,
|
||||
.oldConsumerId = -1,
|
||||
.newConsumerId = pConsumer->consumerId,
|
||||
};
|
||||
strcpy(req.cgroup, pConsumer->cgroup);
|
||||
strcpy(req.topicName, pTopic->name);
|
||||
strcpy(req.sql, pTopic->sql);
|
||||
strcpy(req.logicalPlan, pTopic->logicalPlan);
|
||||
strcpy(req.physicalPlan, pTopic->physicalPlan);
|
||||
req.sql = pTopic->sql;
|
||||
req.logicalPlan = pTopic->logicalPlan;
|
||||
req.physicalPlan = pTopic->physicalPlan;
|
||||
int32_t tlen = tEncodeSMqSetCVgReq(NULL, &req);
|
||||
void *reqStr = malloc(tlen);
|
||||
if (reqStr == NULL) {
|
||||
void *buf = malloc(sizeof(SMsgHead) + tlen);
|
||||
if (buf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
void *abuf = reqStr;
|
||||
|
||||
SMsgHead* pMsgHead = (SMsgHead*)buf;
|
||||
|
||||
pMsgHead->contLen = htonl(sizeof(SMsgHead) + tlen);
|
||||
pMsgHead->vgId = htonl(vgId);
|
||||
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
tEncodeSMqSetCVgReq(&abuf, &req);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgObj);
|
||||
action.pCont = reqStr;
|
||||
action.pCont = buf;
|
||||
action.contLen = tlen;
|
||||
action.msgType = TDMT_VND_MQ_SET_CONN;
|
||||
|
||||
mndReleaseVgroup(pMnode, pVgObj);
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(reqStr);
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -205,19 +232,18 @@ static int mndBuildMqSetConsumerVgReq(SMnode *pMnode, STrans *pTrans, SMqConsume
|
|||
void mndCleanupSubscribe(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *pSub) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t tlen = tEncodeSubscribeObj(NULL, pSub);
|
||||
int32_t size = tlen + MND_SUBSCRIBE_RESERVE_SIZE;
|
||||
int32_t size = sizeof(int32_t) + tlen + MND_SUBSCRIBE_RESERVE_SIZE;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_SUBSCRIBE, MND_SUBSCRIBE_VER_NUMBER, size);
|
||||
if (pRaw == NULL) goto SUB_ENCODE_OVER;
|
||||
|
||||
void *buf = malloc(tlen);
|
||||
if (buf == NULL) {
|
||||
goto SUB_ENCODE_OVER;
|
||||
}
|
||||
void *abuf = buf;
|
||||
if (buf == NULL) goto SUB_ENCODE_OVER;
|
||||
|
||||
tEncodeSubscribeObj(&buf, pSub);
|
||||
void *abuf = buf;
|
||||
tEncodeSubscribeObj(&abuf, pSub);
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, tlen, SUB_ENCODE_OVER);
|
||||
|
@ -225,6 +251,8 @@ static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *pSub) {
|
|||
SDB_SET_RESERVE(pRaw, dataPos, MND_SUBSCRIBE_RESERVE_SIZE, SUB_ENCODE_OVER);
|
||||
SDB_SET_DATALEN(pRaw, dataPos, SUB_ENCODE_OVER);
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
SUB_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("subscribe:%s, failed to encode to raw:%p since %s", pSub->key, pRaw, terrstr());
|
||||
|
@ -256,9 +284,9 @@ static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) {
|
|||
|
||||
int32_t dataPos = 0;
|
||||
int32_t tlen;
|
||||
SDB_GET_INT32(pRaw, dataPos, &tlen, SUB_DECODE_OVER);
|
||||
void *buf = malloc(tlen + 1);
|
||||
if (buf == NULL) goto SUB_DECODE_OVER;
|
||||
SDB_GET_INT32(pRaw, dataPos, &tlen, SUB_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, dataPos, buf, tlen, SUB_DECODE_OVER);
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_SUBSCRIBE_RESERVE_SIZE, SUB_DECODE_OVER);
|
||||
|
||||
|
@ -266,8 +294,10 @@ static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) {
|
|||
goto SUB_DECODE_OVER;
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
SUB_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
if (terrno != TSDB_CODE_SUCCESS) {
|
||||
mError("subscribe:%s, failed to decode from raw:%p since %s", pSub->key, pRaw, terrstr());
|
||||
// TODO free subscribeobj
|
||||
tfree(pRow);
|
||||
|
@ -376,10 +406,10 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
|
|||
oldTopicName = ((SMqConsumerTopic *)taosArrayGet(oldSub, j))->name;
|
||||
j++;
|
||||
} else if (j >= oldTopicNum) {
|
||||
newTopicName = taosArrayGet(newSub, i);
|
||||
newTopicName = taosArrayGetP(newSub, i);
|
||||
i++;
|
||||
} else {
|
||||
newTopicName = taosArrayGet(newSub, i);
|
||||
newTopicName = taosArrayGetP(newSub, i);
|
||||
oldTopicName = ((SMqConsumerTopic *)taosArrayGet(oldSub, j))->name;
|
||||
|
||||
int comp = compareLenPrefixedStr(newTopicName, oldTopicName);
|
||||
|
@ -451,27 +481,31 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
|
|||
|
||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, newTopicName);
|
||||
if (pTopic == NULL) {
|
||||
/*terrno = */
|
||||
mError("topic being subscribed not exist: %s", newTopicName);
|
||||
continue;
|
||||
}
|
||||
|
||||
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, consumerGroup, newTopicName);
|
||||
if (pSub == NULL) {
|
||||
mDebug("create new subscription, group: %s, topic %s", consumerGroup, newTopicName);
|
||||
pSub = tNewSubscribeObj();
|
||||
if (pSub == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
char* key = mndMakeSubscribeKey(consumerGroup, newTopicName);
|
||||
strcpy(pSub->key, key);
|
||||
// set unassigned vg
|
||||
mndInitUnassignedVg(pMnode, pTopic, pSub->unassignedVg);
|
||||
//TODO: disable alter
|
||||
}
|
||||
taosArrayPush(pSub->availConsumer, &consumerId);
|
||||
|
||||
// TODO: no need
|
||||
SMqConsumerTopic *pConsumerTopic = tNewConsumerTopic(consumerId, pTopic, pSub);
|
||||
taosArrayPush(pConsumer->topics, pConsumerTopic);
|
||||
|
||||
if (taosArrayGetSize(pConsumerTopic->pVgInfo) > 0) {
|
||||
ASSERT(taosArrayGetSize(pConsumerTopic->pVgInfo) == 1);
|
||||
int32_t vgId = *(int32_t *)taosArrayGetLast(pConsumerTopic->pVgInfo);
|
||||
// send setmsg to vnode
|
||||
if (mndBuildMqSetConsumerVgReq(pMnode, pTrans, pConsumer, pConsumerTopic, pTopic) < 0) {
|
||||
|
@ -479,10 +513,9 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(pConsumerTopic->pVgInfo);
|
||||
free(pConsumerTopic);
|
||||
|
||||
SSdbRaw *pRaw = mndSubActionEncode(pSub);
|
||||
/*sdbSetRawStatus(pRaw, SDB_STATUS_READY);*/
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
mndTransAppendRedolog(pTrans, pRaw);
|
||||
#if 0
|
||||
SMqCGroup *pGroup = taosHashGet(pTopic->cgroups, consumerGroup, cgroupLen);
|
||||
|
@ -515,8 +548,8 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
|
|||
mndTransAppendRedolog(pTrans, pTopicRaw);
|
||||
|
||||
#endif
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
/*mndReleaseTopic(pMnode, pTopic);*/
|
||||
/*mndReleaseSubscribe(pMnode, pSub);*/
|
||||
}
|
||||
}
|
||||
// part3. persist consumerObj
|
||||
|
@ -533,12 +566,12 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
|
|||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
if (newSub) taosArrayDestroy(newSub);
|
||||
mndTransDrop(pTrans);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: free memory
|
||||
if (newSub) taosArrayDestroy(newSub);
|
||||
mndTransDrop(pTrans);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
|
|
|
@ -56,7 +56,7 @@ static int32_t mndRestoreWal(SMnode *pMnode) {
|
|||
int64_t last = walGetLastVer(pWal);
|
||||
mDebug("start to restore sdb wal, sdb ver:%" PRId64 ", wal first:%" PRId64 " last:%" PRId64, lastSdbVer, first, last);
|
||||
|
||||
first = MAX(lastSdbVer + 1, first);
|
||||
first = TMAX(lastSdbVer + 1, first);
|
||||
for (int64_t ver = first; ver >= 0 && ver <= last; ++ver) {
|
||||
if (walReadWithHandle(pHandle, ver) < 0) {
|
||||
mError("failed to read by wal handle since %s, ver:%" PRId64, terrstr(), ver);
|
||||
|
|
|
@ -60,7 +60,9 @@ void mndCleanupTopic(SMnode *pMnode) {}
|
|||
SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size = sizeof(SMqTopicObj) + MND_TOPIC_RESERVE_SIZE;
|
||||
int32_t logicalPlanLen = strlen(pTopic->logicalPlan) + 1;
|
||||
int32_t physicalPlanLen = strlen(pTopic->physicalPlan) + 1;
|
||||
int32_t size = sizeof(SMqTopicObj) + logicalPlanLen + physicalPlanLen + pTopic->sqlLen + MND_TOPIC_RESERVE_SIZE;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size);
|
||||
if (pRaw == NULL) goto TOPIC_ENCODE_OVER;
|
||||
|
||||
|
@ -74,12 +76,10 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
|||
SDB_SET_INT32(pRaw, dataPos, pTopic->version, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_ENCODE_OVER);
|
||||
int32_t logicalPlanLen = strlen(pTopic->logicalPlan) + 1;
|
||||
SDB_SET_INT32(pRaw, dataPos, strlen(pTopic->logicalPlan)+1, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_INT32(pRaw, dataPos, logicalPlanLen, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->logicalPlan, logicalPlanLen, TOPIC_ENCODE_OVER);
|
||||
|
||||
int32_t physicalPlanLen = strlen(pTopic->physicalPlan) + 1;
|
||||
SDB_SET_INT32(pRaw, dataPos, strlen(pTopic->physicalPlan)+1, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_INT32(pRaw, dataPos, physicalPlanLen, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, physicalPlanLen, TOPIC_ENCODE_OVER);
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_ENCODE_OVER);
|
||||
|
@ -127,7 +127,7 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER);
|
||||
|
||||
pTopic->sql = calloc(pTopic->sqlLen + 1, sizeof(char));
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_DECODE_OVER);
|
||||
|
||||
SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER);
|
||||
pTopic->logicalPlan = calloc(len + 1, sizeof(char));
|
||||
|
@ -135,7 +135,7 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TOPIC_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->logicalPlan, len+1, TOPIC_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->logicalPlan, len, TOPIC_DECODE_OVER);
|
||||
|
||||
SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER);
|
||||
pTopic->physicalPlan = calloc(len + 1, sizeof(char));
|
||||
|
@ -144,7 +144,7 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TOPIC_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->physicalPlan, len+1, TOPIC_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->physicalPlan, len, TOPIC_DECODE_OVER);
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_DECODE_OVER);
|
||||
|
||||
|
@ -231,6 +231,7 @@ static int32_t mndCheckCreateTopicMsg(SCMCreateTopicReq *creattopReq) {
|
|||
}
|
||||
|
||||
static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pMsg, SCMCreateTopicReq *pCreate, SDbObj *pDb) {
|
||||
mDebug("topic:%s to create", pCreate->name);
|
||||
SMqTopicObj topicObj = {0};
|
||||
tstrncpy(topicObj.name, pCreate->name, TSDB_TOPIC_FNAME_LEN);
|
||||
tstrncpy(topicObj.db, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
|
@ -273,7 +274,7 @@ static int32_t mndProcessCreateTopicMsg(SMnodeMsg *pMsg) {
|
|||
return 0;
|
||||
} else {
|
||||
terrno = TSDB_CODE_MND_TOPIC_ALREADY_EXIST;
|
||||
mError("db:%s, failed to create since %s", createTopicReq.name, terrstr());
|
||||
mError("topic:%s, failed to create since already exists", createTopicReq.name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -390,9 +390,11 @@ static void mndTransDropActions(SArray *pArray) {
|
|||
}
|
||||
|
||||
void mndTransDrop(STrans *pTrans) {
|
||||
mndTransDropData(pTrans);
|
||||
mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans);
|
||||
tfree(pTrans);
|
||||
if (pTrans != NULL) {
|
||||
mndTransDropData(pTrans);
|
||||
mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans);
|
||||
tfree(pTrans);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw) {
|
||||
|
|
|
@ -60,9 +60,9 @@ void mndCleanupUser(SMnode *pMnode) {}
|
|||
|
||||
static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char *pass) {
|
||||
SUserObj userObj = {0};
|
||||
taosEncryptPass_c((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = userObj.createdTime;
|
||||
|
||||
|
@ -202,7 +202,7 @@ SUserObj *mndAcquireUser(SMnode *pMnode, char *userName) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
SUserObj *pUser = sdbAcquire(pSdb, SDB_USER, userName);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
|
||||
}
|
||||
return pUser;
|
||||
}
|
||||
|
@ -214,9 +214,9 @@ void mndReleaseUser(SMnode *pMnode, SUserObj *pUser) {
|
|||
|
||||
static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pReq) {
|
||||
SUserObj userObj = {0};
|
||||
taosEncryptPass_c((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.superUser = 0;
|
||||
|
@ -351,8 +351,9 @@ static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq) {
|
|||
|
||||
SUserObj newUser = {0};
|
||||
memcpy(&newUser, pUser, sizeof(SUserObj));
|
||||
memset(pUser->pass, 0, sizeof(pUser->pass));
|
||||
taosEncryptPass((uint8_t *)pAlter->pass, strlen(pAlter->pass), pUser->pass);
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)pAlter->pass, strlen(pAlter->pass), pass);
|
||||
memcpy(pUser->pass, pass, TSDB_PASSWORD_LEN);
|
||||
newUser.updateTime = taosGetTimestampMs();
|
||||
|
||||
int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pReq);
|
||||
|
|
|
@ -459,7 +459,7 @@ static bool mndGetVgroupMaxReplicaFp(SMnode *pMnode, void *pObj, void *p1, void
|
|||
int32_t *pNumOfVgroups = p3;
|
||||
|
||||
if (pVgroup->dbUid == uid) {
|
||||
*pReplica = MAX(*pReplica, pVgroup->replica);
|
||||
*pReplica = TMAX(*pReplica, pVgroup->replica);
|
||||
(*pNumOfVgroups)++;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,3 +12,4 @@ add_subdirectory(dnode)
|
|||
add_subdirectory(mnode)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(stb)
|
||||
add_subdirectory(func)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue