Merge branch 'develop' into hotfix/test
This commit is contained in:
commit
88c11ce773
|
@ -162,7 +162,6 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
|
|||
pDnode->openVnodes, pDnode->diskAvailable, pDnode->alternativeRole);
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
if (mnodeGetOnlineDnodesNum() == 0) {
|
||||
return TSDB_CODE_MND_NOT_READY;
|
||||
|
@ -377,15 +376,13 @@ static bool balanceMonitorBalance() {
|
|||
srcScore, pDestDnode->score, destScore);
|
||||
balanceAddVnode(pVgroup, pSrcDnode, pDestDnode);
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
sdbFreeIter(pIter);
|
||||
mnodeCancelGetNextVgroup(pIter);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -413,8 +410,6 @@ void balanceReset() {
|
|||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
tsAccessSquence = 0;
|
||||
}
|
||||
|
||||
|
@ -443,12 +438,11 @@ static int32_t balanceMonitorVgroups() {
|
|||
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
mnodeCancelGetNextVgroup(pIter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
return hasUpdatingVgroup;
|
||||
}
|
||||
|
||||
|
@ -465,11 +459,12 @@ static bool balanceMonitorDnodeDropping(SDnodeObj *pDnode) {
|
|||
hasThisDnode = balanceCheckDnodeInVgroup(pDnode, pVgroup);
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
|
||||
if (hasThisDnode) break;
|
||||
if (hasThisDnode) {
|
||||
mnodeCancelGetNextVgroup(pIter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
if (!hasThisDnode) {
|
||||
mInfo("dnode:%d, dropped for all vnodes are moving to other dnodes", pDnode->dnodeId);
|
||||
mnodeDropDnode(pDnode, NULL);
|
||||
|
@ -499,20 +494,18 @@ static bool balanceMontiorDropping() {
|
|||
pDnode->status = TAOS_DN_STATUS_DROPPING;
|
||||
mnodeUpdateDnode(pDnode);
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
sdbFreeIter(pIter);
|
||||
mnodeCancelGetNextDnode(pIter);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pDnode->status == TAOS_DN_STATUS_DROPPING) {
|
||||
bool ret = balanceMonitorDnodeDropping(pDnode);
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
sdbFreeIter(pIter);
|
||||
mnodeCancelGetNextDnode(pIter);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -556,8 +549,6 @@ static void balanceSetVgroupOffline(SDnodeObj* pDnode) {
|
|||
}
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
}
|
||||
|
||||
static void balanceCheckDnodeAccess() {
|
||||
|
@ -578,8 +569,6 @@ static void balanceCheckDnodeAccess() {
|
|||
}
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
}
|
||||
|
||||
static void balanceProcessBalanceTimer(void *handle, void *tmrId) {
|
||||
|
@ -630,6 +619,7 @@ void balanceAsyncNotify() {
|
|||
int32_t balanceInit() {
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_SCORES, balanceGetScoresMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_SCORES, balanceRetrieveScores);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_SCORES, mnodeCancelGetNextDnode);
|
||||
|
||||
pthread_mutex_init(&tsBalanceMutex, NULL);
|
||||
balanceInitDnodeList();
|
||||
|
@ -667,8 +657,6 @@ int32_t balanceDropDnode(SDnodeObj *pDnode) {
|
|||
mnodeDecDnodeRef(pTempDnode);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
if (pDnode->openVnodes > totalFreeVnodes) {
|
||||
mError("dnode:%d, openVnodes:%d totalFreeVnodes:%d no enough dnodes", pDnode->dnodeId, pDnode->openVnodes, totalFreeVnodes);
|
||||
return TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
|
@ -780,8 +768,12 @@ void balanceAccquireDnodeList() {
|
|||
SDnodeObj *pDnode = NULL;
|
||||
int32_t dnodeIndex = 0;
|
||||
|
||||
while (1) {
|
||||
if (dnodeIndex >= dnodesNum) break;
|
||||
while (1) {
|
||||
if (dnodeIndex >= dnodesNum) {
|
||||
mnodeCancelGetNextDnode(pIter);
|
||||
break;
|
||||
}
|
||||
|
||||
pIter = mnodeGetNextDnode(pIter, &pDnode);
|
||||
if (pDnode == NULL) break;
|
||||
if (pDnode->status == TAOS_DN_STATUS_OFFLINE) {
|
||||
|
@ -802,8 +794,6 @@ void balanceAccquireDnodeList() {
|
|||
dnodeIndex++;
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
tsBalanceDnodeListSize = dnodeIndex;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ typedef struct SLocalReducer {
|
|||
tFilePage * pTempBuffer;
|
||||
struct SQLFunctionCtx *pCtx;
|
||||
int32_t rowSize; // size of each intermediate result.
|
||||
int32_t finalRowSize; // final result row size
|
||||
int32_t status; // denote it is in reduce process, in reduce process, it
|
||||
bool hasPrevRow; // cannot be released
|
||||
bool hasUnprocessedRow;
|
||||
|
|
|
@ -64,13 +64,13 @@
|
|||
} \
|
||||
} while (0);
|
||||
|
||||
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
|
||||
do {\
|
||||
for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) { \
|
||||
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[i]; \
|
||||
aAggs[TSDB_FUNC_TAG].xFunction(__ctx); \
|
||||
} \
|
||||
} while(0);
|
||||
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
|
||||
do { \
|
||||
for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) { \
|
||||
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[i]; \
|
||||
aAggs[TSDB_FUNC_TAG].xFunction(__ctx); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
void noop1(SQLFunctionCtx *UNUSED_PARAM(pCtx)) {}
|
||||
void noop2(SQLFunctionCtx *UNUSED_PARAM(pCtx), int32_t UNUSED_PARAM(index)) {}
|
||||
|
@ -3624,52 +3624,147 @@ static bool twa_function_setup(SQLFunctionCtx *pCtx) {
|
|||
return false;
|
||||
}
|
||||
|
||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); //->aOutputBuf + pCtx->outputBytes;
|
||||
STwaInfo * pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
pInfo->lastKey = INT64_MIN;
|
||||
pInfo->type = pCtx->inputType;
|
||||
|
||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||
|
||||
STwaInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
pInfo->lastKey = INT64_MIN;
|
||||
pInfo->win = TSWINDOW_INITIALIZER;
|
||||
return true;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void setTWALastVal(SQLFunctionCtx *pCtx, const char *data, int32_t i, STwaInfo *pInfo) {
|
||||
switch (pCtx->inputType) {
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
pInfo->iLastValue = GET_INT32_VAL(data + pCtx->inputBytes * i);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
pInfo->iLastValue = GET_INT8_VAL(data + pCtx->inputBytes * i);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
pInfo->iLastValue = GET_INT16_VAL(data + pCtx->inputBytes * i);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
pInfo->iLastValue = GET_INT64_VAL(data + pCtx->inputBytes * i);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
pInfo->dLastValue = GET_FLOAT_VAL(data + pCtx->inputBytes * i);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
pInfo->dLastValue = GET_DOUBLE_VAL(data + pCtx->inputBytes * i);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
static int32_t twa_function_impl(SQLFunctionCtx* pCtx, int32_t index, int32_t size) {
|
||||
int32_t notNullElems = 0;
|
||||
TSKEY *primaryKey = pCtx->ptsList;
|
||||
|
||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||
|
||||
STwaInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
int32_t i = index;
|
||||
|
||||
if (pCtx->start.key != INT64_MIN) {
|
||||
assert(pCtx->start.key < primaryKey[index] && pInfo->lastKey == INT64_MIN);
|
||||
|
||||
pInfo->lastKey = primaryKey[index];
|
||||
GET_TYPED_DATA(pInfo->lastValue, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, 0));
|
||||
|
||||
pInfo->dOutput += ((pInfo->lastValue + pCtx->start.val) / 2) * (pInfo->lastKey - pCtx->start.key);
|
||||
|
||||
pInfo->hasResult = DATA_SET_FLAG;
|
||||
pInfo->win.skey = pCtx->start.key;
|
||||
notNullElems++;
|
||||
i += 1;
|
||||
} else if (pInfo->lastKey == INT64_MIN) {
|
||||
pInfo->lastKey = primaryKey[index];
|
||||
GET_TYPED_DATA(pInfo->lastValue, double, pCtx->inputType, GET_INPUT_CHAR_INDEX(pCtx, 0));
|
||||
|
||||
pInfo->hasResult = DATA_SET_FLAG;
|
||||
pInfo->win.skey = pInfo->lastKey;
|
||||
notNullElems++;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
// calculate the value of
|
||||
switch(pCtx->inputType) {
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
int8_t *val = (int8_t*) GET_INPUT_CHAR_INDEX(pCtx, index);
|
||||
for (; i < size; i++) {
|
||||
if (pCtx->hasNull && isNull((const char*) &val[i], pCtx->inputType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i] - pInfo->lastKey);
|
||||
pInfo->lastValue = val[i];
|
||||
pInfo->lastKey = primaryKey[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
int16_t *val = (int16_t*) GET_INPUT_CHAR_INDEX(pCtx, index);
|
||||
for (; i < size; i++) {
|
||||
if (pCtx->hasNull && isNull((const char*) &val[i], pCtx->inputType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i] - pInfo->lastKey);
|
||||
pInfo->lastValue = val[i];
|
||||
pInfo->lastKey = primaryKey[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
int32_t *val = (int32_t*) GET_INPUT_CHAR_INDEX(pCtx, index);
|
||||
for (; i < size; i++) {
|
||||
if (pCtx->hasNull && isNull((const char*) &val[i], pCtx->inputType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i] - pInfo->lastKey);
|
||||
pInfo->lastValue = val[i];
|
||||
pInfo->lastKey = primaryKey[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
int64_t *val = (int64_t*) GET_INPUT_CHAR_INDEX(pCtx, index);
|
||||
for (; i < size; i++) {
|
||||
if (pCtx->hasNull && isNull((const char*) &val[i], pCtx->inputType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i] - pInfo->lastKey);
|
||||
pInfo->lastValue = (double) val[i];
|
||||
pInfo->lastKey = primaryKey[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float *val = (float*) GET_INPUT_CHAR_INDEX(pCtx, index);
|
||||
for (; i < size; i++) {
|
||||
if (pCtx->hasNull && isNull((const char*) &val[i], pCtx->inputType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i] - pInfo->lastKey);
|
||||
pInfo->lastValue = val[i];
|
||||
pInfo->lastKey = primaryKey[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double *val = (double*) GET_INPUT_CHAR_INDEX(pCtx, index);
|
||||
for (; i < size; i++) {
|
||||
if (pCtx->hasNull && isNull((const char*) &val[i], pCtx->inputType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pInfo->dOutput += ((val[i] + pInfo->lastValue) / 2) * (primaryKey[i] - pInfo->lastKey);
|
||||
pInfo->lastValue = val[i];
|
||||
pInfo->lastKey = primaryKey[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
|
||||
// the last interpolated time window value
|
||||
if (pCtx->end.key != INT64_MIN) {
|
||||
pInfo->dOutput += ((pInfo->lastValue + pCtx->end.val) / 2) * (pCtx->end.key - pInfo->lastKey);
|
||||
pInfo->lastValue = pCtx->end.val;
|
||||
pInfo->lastKey = pCtx->end.key;
|
||||
}
|
||||
|
||||
pInfo->win.ekey = pInfo->lastKey;
|
||||
return notNullElems;
|
||||
}
|
||||
|
||||
static void twa_function(SQLFunctionCtx *pCtx) {
|
||||
void * data = GET_INPUT_CHAR(pCtx);
|
||||
TSKEY *primaryKey = pCtx->ptsList;
|
||||
|
||||
int32_t notNullElems = 0;
|
||||
|
||||
|
||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||
STwaInfo * pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
int32_t i = 0;
|
||||
|
||||
// skip null value
|
||||
int32_t i = 0;
|
||||
while (pCtx->hasNull && i < pCtx->size && isNull((char *)data + pCtx->inputBytes * i, pCtx->inputType)) {
|
||||
i++;
|
||||
}
|
||||
|
@ -3678,40 +3773,7 @@ static void twa_function(SQLFunctionCtx *pCtx) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (pInfo->lastKey == INT64_MIN) {
|
||||
pInfo->lastKey = pCtx->nStartQueryTimestamp;
|
||||
setTWALastVal(pCtx, data, i, pInfo);
|
||||
|
||||
pInfo->hasResult = DATA_SET_FLAG;
|
||||
}
|
||||
|
||||
notNullElems++;
|
||||
|
||||
if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT || pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) {
|
||||
pInfo->dOutput += pInfo->dLastValue * (primaryKey[i] - pInfo->lastKey);
|
||||
} else {
|
||||
pInfo->iOutput += pInfo->iLastValue * (primaryKey[i] - pInfo->lastKey);
|
||||
}
|
||||
|
||||
pInfo->lastKey = primaryKey[i];
|
||||
setTWALastVal(pCtx, data, i, pInfo);
|
||||
|
||||
for (++i; i < pCtx->size; i++) {
|
||||
if (pCtx->hasNull && isNull((char *)data + pCtx->inputBytes * i, pCtx->inputType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
notNullElems++;
|
||||
if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT || pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) {
|
||||
pInfo->dOutput += pInfo->dLastValue * (primaryKey[i] - pInfo->lastKey);
|
||||
} else {
|
||||
pInfo->iOutput += pInfo->iLastValue * (primaryKey[i] - pInfo->lastKey);
|
||||
}
|
||||
|
||||
pInfo->lastKey = primaryKey[i];
|
||||
setTWALastVal(pCtx, data, i, pInfo);
|
||||
}
|
||||
|
||||
int32_t notNullElems = twa_function_impl(pCtx, pCtx->startOffset, pCtx->size);
|
||||
SET_VAL(pCtx, notNullElems, 1);
|
||||
|
||||
if (notNullElems > 0) {
|
||||
|
@ -3721,8 +3783,6 @@ static void twa_function(SQLFunctionCtx *pCtx) {
|
|||
if (pCtx->stableQuery) {
|
||||
memcpy(pCtx->aOutputBuf, pInfo, sizeof(STwaInfo));
|
||||
}
|
||||
|
||||
// pCtx->numOfIteratedElems += notNullElems;
|
||||
}
|
||||
|
||||
static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||
|
@ -3730,35 +3790,12 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
|||
if (pCtx->hasNull && isNull(pData, pCtx->inputType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SET_VAL(pCtx, 1, 1);
|
||||
|
||||
TSKEY *primaryKey = pCtx->ptsList;
|
||||
|
||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||
STwaInfo *pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
if (pInfo->lastKey == INT64_MIN) {
|
||||
pInfo->lastKey = pCtx->nStartQueryTimestamp;
|
||||
setTWALastVal(pCtx, pData, 0, pInfo);
|
||||
|
||||
pInfo->hasResult = DATA_SET_FLAG;
|
||||
}
|
||||
|
||||
if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT || pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) {
|
||||
pInfo->dOutput += pInfo->dLastValue * (primaryKey[index] - pInfo->lastKey);
|
||||
} else {
|
||||
pInfo->iOutput += pInfo->iLastValue * (primaryKey[index] - pInfo->lastKey);
|
||||
}
|
||||
|
||||
// record the last key/value
|
||||
pInfo->lastKey = primaryKey[index];
|
||||
setTWALastVal(pCtx, pData, 0, pInfo);
|
||||
|
||||
// pCtx->numOfIteratedElems += 1;
|
||||
pResInfo->hasResult = DATA_SET_FLAG;
|
||||
|
||||
|
||||
int32_t notNullElems = twa_function_impl(pCtx, index, 1);
|
||||
SET_VAL(pCtx, notNullElems, 1);
|
||||
|
||||
if (pCtx->stableQuery) {
|
||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||
memcpy(pCtx->aOutputBuf, GET_ROWCELL_INTERBUF(pResInfo), sizeof(STwaInfo));
|
||||
}
|
||||
}
|
||||
|
@ -3778,16 +3815,10 @@ static void twa_func_merge(SQLFunctionCtx *pCtx) {
|
|||
}
|
||||
|
||||
numOfNotNull++;
|
||||
if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) {
|
||||
pBuf->iOutput += pInput->iOutput;
|
||||
} else {
|
||||
pBuf->dOutput += pInput->dOutput;
|
||||
}
|
||||
|
||||
pBuf->SKey = pInput->SKey;
|
||||
pBuf->EKey = pInput->EKey;
|
||||
pBuf->dOutput += pInput->dOutput;
|
||||
|
||||
pBuf->win = pInput->win;
|
||||
pBuf->lastKey = pInput->lastKey;
|
||||
pBuf->iLastValue = pInput->iLastValue;
|
||||
}
|
||||
|
||||
SET_VAL(pCtx, numOfNotNull, 1);
|
||||
|
@ -3814,21 +3845,17 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) {
|
|||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||
|
||||
STwaInfo *pInfo = (STwaInfo *)GET_ROWCELL_INTERBUF(pResInfo);
|
||||
assert(pInfo->EKey >= pInfo->lastKey && pInfo->hasResult == pResInfo->hasResult);
|
||||
assert(pInfo->win.ekey == pInfo->lastKey && pInfo->hasResult == pResInfo->hasResult);
|
||||
|
||||
if (pInfo->hasResult != DATA_SET_FLAG) {
|
||||
setNull(pCtx->aOutputBuf, TSDB_DATA_TYPE_DOUBLE, sizeof(double));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pInfo->SKey == pInfo->EKey) {
|
||||
*(double *)pCtx->aOutputBuf = 0;
|
||||
} else if (pInfo->type >= TSDB_DATA_TYPE_TINYINT && pInfo->type <= TSDB_DATA_TYPE_BIGINT) {
|
||||
pInfo->iOutput += pInfo->iLastValue * (pInfo->EKey - pInfo->lastKey);
|
||||
*(double *)pCtx->aOutputBuf = pInfo->iOutput / (double)(pInfo->EKey - pInfo->SKey);
|
||||
if (pInfo->win.ekey == pInfo->win.skey) {
|
||||
*(double *)pCtx->aOutputBuf = pInfo->lastValue;
|
||||
} else {
|
||||
pInfo->dOutput += pInfo->dLastValue * (pInfo->EKey - pInfo->lastKey);
|
||||
*(double *)pCtx->aOutputBuf = pInfo->dOutput / (pInfo->EKey - pInfo->SKey);
|
||||
*(double *)pCtx->aOutputBuf = pInfo->dOutput / (pInfo->win.ekey - pInfo->win.skey);
|
||||
}
|
||||
|
||||
GET_RES_INFO(pCtx)->numOfRes = 1;
|
||||
|
|
|
@ -198,6 +198,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
|
||||
if (numOfFlush == 0 || numOfBuffer == 0) {
|
||||
tscLocalReducerEnvDestroy(pMemBuffer, pDesc, finalmodel, pFFModel, numOfBuffer);
|
||||
pCmd->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT; // no result, set the result empty
|
||||
tscDebug("%p retrieved no data", pSql);
|
||||
return;
|
||||
}
|
||||
|
@ -330,22 +331,19 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
|||
pReducer->nResultBufSize = pMemBuffer[0]->pageSize * 16;
|
||||
pReducer->pResultBuf = (tFilePage *)calloc(1, pReducer->nResultBufSize + sizeof(tFilePage));
|
||||
|
||||
pReducer->finalRowSize = tscGetResRowLength(pQueryInfo->exprList);
|
||||
pReducer->resColModel = finalmodel;
|
||||
pReducer->resColModel->capacity = pReducer->nResultBufSize;
|
||||
|
||||
pReducer->finalModel = pFFModel;
|
||||
|
||||
assert(pReducer->finalRowSize > 0);
|
||||
if (pReducer->finalRowSize > 0) {
|
||||
pReducer->resColModel->capacity /= pReducer->finalRowSize;
|
||||
if (finalmodel->rowSize > 0) {
|
||||
pReducer->resColModel->capacity /= finalmodel->rowSize;
|
||||
}
|
||||
assert(pReducer->finalRowSize <= pReducer->rowSize);
|
||||
|
||||
assert(finalmodel->rowSize > 0 && finalmodel->rowSize <= pReducer->rowSize);
|
||||
pReducer->pFinalRes = calloc(1, pReducer->rowSize * pReducer->resColModel->capacity);
|
||||
|
||||
if (pReducer->pTempBuffer == NULL || pReducer->discardData == NULL || pReducer->pResultBuf == NULL ||
|
||||
/*pReducer->pBufForInterpo == NULL || */pReducer->pFinalRes == NULL || pReducer->prevRowOfInput == NULL) {
|
||||
pReducer->pFinalRes == NULL || pReducer->prevRowOfInput == NULL) {
|
||||
tfree(pReducer->pTempBuffer);
|
||||
tfree(pReducer->discardData);
|
||||
tfree(pReducer->pResultBuf);
|
||||
|
@ -920,7 +918,7 @@ static void genFinalResWithoutFill(SSqlRes* pRes, SLocalReducer *pLocalReducer,
|
|||
savePrevRecordAndSetupFillInfo(pLocalReducer, pQueryInfo, pLocalReducer->pFillInfo);
|
||||
}
|
||||
|
||||
memcpy(pRes->data, pBeforeFillData->data, (size_t)(pRes->numOfRows * pLocalReducer->finalRowSize));
|
||||
memcpy(pRes->data, pBeforeFillData->data, (size_t)(pRes->numOfRows * pLocalReducer->finalModel->rowSize));
|
||||
|
||||
pRes->numOfClauseTotal += pRes->numOfRows;
|
||||
pBeforeFillData->num = 0;
|
||||
|
@ -1256,7 +1254,7 @@ bool genFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool noMoreCur
|
|||
tColModelCompact(pModel, pResBuf, pModel->capacity);
|
||||
|
||||
if (tscIsSecondStageQuery(pQueryInfo)) {
|
||||
pLocalReducer->finalRowSize = doArithmeticCalculate(pQueryInfo, pResBuf, pModel->rowSize, pLocalReducer->finalRowSize);
|
||||
doArithmeticCalculate(pQueryInfo, pResBuf, pModel->rowSize, pLocalReducer->finalModel->rowSize);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG_VIEW
|
||||
|
@ -1627,7 +1625,8 @@ void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen)
|
|||
}
|
||||
|
||||
int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_t rowSize, int32_t finalRowSize) {
|
||||
char* pbuf = calloc(1, pOutput->num * rowSize);
|
||||
int32_t maxRowSize = MAX(rowSize, finalRowSize);
|
||||
char* pbuf = calloc(1, pOutput->num * maxRowSize);
|
||||
|
||||
size_t size = tscNumOfFields(pQueryInfo);
|
||||
SArithmeticSupport arithSup = {0};
|
||||
|
@ -1660,7 +1659,6 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_
|
|||
offset += pSup->field.bytes;
|
||||
}
|
||||
|
||||
assert(finalRowSize <= rowSize);
|
||||
memcpy(pOutput->data, pbuf, pOutput->num * offset);
|
||||
|
||||
tfree(pbuf);
|
||||
|
|
|
@ -4248,7 +4248,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
|
|||
tExprTreeDestroy(&p, NULL);
|
||||
|
||||
taosArrayDestroy(colList);
|
||||
if (taosArrayGetSize(pQueryInfo->tagCond.pCond) > 0 && !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||
if (pQueryInfo->tagCond.pCond != NULL && taosArrayGetSize(pQueryInfo->tagCond.pCond) > 0 && !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "filter on tag not supported for normal table");
|
||||
}
|
||||
}
|
||||
|
@ -4256,6 +4256,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
|
|||
pCondExpr->pTagCond = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql) {
|
||||
if (pExpr == NULL) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -6648,7 +6649,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
return TSDB_CODE_TSC_INVALID_SQL;
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "not support filter expression");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
@ -200,7 +200,7 @@ int32_t tsNumOfLogLines = 10000000;
|
|||
int32_t mDebugFlag = 135;
|
||||
int32_t sdbDebugFlag = 135;
|
||||
int32_t dDebugFlag = 135;
|
||||
int32_t vDebugFlag = 131;
|
||||
int32_t vDebugFlag = 135;
|
||||
int32_t cDebugFlag = 131;
|
||||
int32_t jniDebugFlag = 131;
|
||||
int32_t odbcDebugFlag = 131;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 050667e5b4d0eafa5387e4283e713559b421203f
|
||||
Subproject commit 8c58c512b6acda8bcdfa48fdc7140227b5221766
|
|
@ -1 +1 @@
|
|||
Subproject commit ec77d9049a719dabfd1a7c1122a209e201861944
|
||||
Subproject commit d598db167eb256fe67409b7bb3d0eb7fffc3ff8c
|
|
@ -19,6 +19,7 @@
|
|||
#include "tutil.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tfile.h"
|
||||
#include "twal.h"
|
||||
#include "trpc.h"
|
||||
#include "dnode.h"
|
||||
|
@ -55,6 +56,7 @@ typedef struct {
|
|||
} SDnodeComponent;
|
||||
|
||||
static const SDnodeComponent tsDnodeComponents[] = {
|
||||
{"tfile", tfInit, tfCleanup},
|
||||
{"rpc", rpcInit, rpcCleanup},
|
||||
{"storage", dnodeInitStorage, dnodeCleanupStorage},
|
||||
{"dnodecfg", dnodeInitCfg, dnodeCleanupCfg},
|
||||
|
|
|
@ -444,12 +444,12 @@ static int32_t dnodeProcessCreateMnodeMsg(SRpcMsg *pMsg) {
|
|||
SCreateMnodeMsg *pCfg = pMsg->pCont;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
if (pCfg->dnodeId != dnodeGetDnodeId()) {
|
||||
dError("dnodeId:%d, in create mnode msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId());
|
||||
dDebug("dnodeId:%d, in create mnode msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId());
|
||||
return TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
if (strcmp(pCfg->dnodeEp, tsLocalEp) != 0) {
|
||||
dError("dnodeEp:%s, in create mnode msg is not equal with saved dnodeEp:%s", pCfg->dnodeEp, tsLocalEp);
|
||||
dDebug("dnodeEp:%s, in create mnode msg is not equal with saved dnodeEp:%s", pCfg->dnodeEp, tsLocalEp);
|
||||
return TSDB_CODE_MND_DNODE_EP_NOT_CONFIGURED;
|
||||
}
|
||||
|
||||
|
|
|
@ -261,6 +261,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CONFIG, 0, 0x0900, "Invalid Sy
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_ENABLED, 0, 0x0901, "Sync module not enabled")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_VERSION, 0, 0x0902, "Invalid Sync version")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_CONFIRM_EXPIRED, 0, 0x0903, "Sync confirm expired")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_VND_COMMITING, 0, 0x0904, "Vnode is commiting")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_FILE_CHNAGED, 0, 0x0905, "Vnode file is changed")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_APP_ERROR, 0, 0x1000, "Unexpected generic error in sync")
|
||||
|
||||
// wal
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "Unexpected generic error in wal")
|
||||
|
@ -367,6 +370,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_TAG_VALUE_TOO_LONG, 0, 0x11A4, "tag value
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_VALUE_NULL, 0, 0x11A5, "value not find")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_HTTP_OP_VALUE_TYPE, 0, 0x11A6, "value type should be boolean, number or string")
|
||||
|
||||
// odbc
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_OOM, 0, 0x2100, "out of memory")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_CHAR_NOT_NUM, 0, 0x2101, "convertion not a valid literal input")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_UNDEF, 0, 0x2102, "convertion undefined")
|
||||
|
@ -390,7 +394,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_BAD_SEQ, 0, 0x2113, "src bad se
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_INCOMPLETE, 0, 0x2114, "src incomplete")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_ODBC_CONV_SRC_GENERAL, 0, 0x2115, "src general")
|
||||
|
||||
|
||||
#ifdef TAOS_ERROR_C
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -85,6 +85,9 @@ typedef void (*FNotifyFlowCtrl)(int32_t vgId, int32_t level);
|
|||
// when data file is synced successfully, notity app
|
||||
typedef int32_t (*FNotifyFileSynced)(int32_t vgId, uint64_t fversion);
|
||||
|
||||
// get file version
|
||||
typedef int32_t (*FGetFileVersion)(int32_t vgId, uint64_t *fver);
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId; // vgroup ID
|
||||
uint64_t version; // initial version
|
||||
|
@ -97,6 +100,7 @@ typedef struct {
|
|||
FNotifyRole notifyRole;
|
||||
FNotifyFlowCtrl notifyFlowCtrl;
|
||||
FNotifyFileSynced notifyFileSynced;
|
||||
FGetFileVersion getFileVersion;
|
||||
} SSyncInfo;
|
||||
|
||||
typedef void *tsync_h;
|
||||
|
|
|
@ -51,9 +51,8 @@ typedef struct {
|
|||
typedef void * twalh; // WAL HANDLE
|
||||
typedef int32_t FWalWrite(void *ahandle, void *pHead, int32_t qtype, void *pMsg);
|
||||
|
||||
int32_t walInit();
|
||||
void walCleanUp();
|
||||
|
||||
int32_t walInit();
|
||||
void walCleanUp();
|
||||
twalh walOpen(char *path, SWalCfg *pCfg);
|
||||
int32_t walAlter(twalh pWal, SWalCfg *pCfg);
|
||||
void walStop(twalh);
|
||||
|
|
|
@ -27,6 +27,7 @@ void mnodeCleanupAccts();
|
|||
void mnodeGetStatOfAllAcct(SAcctInfo* pAcctInfo);
|
||||
void * mnodeGetAcct(char *acctName);
|
||||
void * mnodeGetNextAcct(void *pIter, SAcctObj **pAcct);
|
||||
void mnodeCancelGetNextAcct(void *pIter);
|
||||
void mnodeIncAcctRef(SAcctObj *pAcct);
|
||||
void mnodeDecAcctRef(SAcctObj *pAcct);
|
||||
void mnodeAddDbToAcct(SAcctObj *pAcct, SDbObj *pDb);
|
||||
|
|
|
@ -34,6 +34,7 @@ int64_t mnodeGetDbNum();
|
|||
SDbObj *mnodeGetDb(char *db);
|
||||
SDbObj *mnodeGetDbByTableId(char *db);
|
||||
void * mnodeGetNextDb(void *pIter, SDbObj **pDb);
|
||||
void mnodeCancelGetNextDb(void *pIter);
|
||||
void mnodeIncDbRef(SDbObj *pDb);
|
||||
void mnodeDecDbRef(SDbObj *pDb);
|
||||
bool mnodeCheckIsMonitorDB(char *db, char *monitordb);
|
||||
|
|
|
@ -65,6 +65,7 @@ int32_t mnodeGetDnodesNum();
|
|||
int32_t mnodeGetOnlinDnodesCpuCoreNum();
|
||||
int32_t mnodeGetOnlineDnodesNum();
|
||||
void * mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode);
|
||||
void mnodeCancelGetNextDnode(void *pIter);
|
||||
void mnodeIncDnodeRef(SDnodeObj *pDnode);
|
||||
void mnodeDecDnodeRef(SDnodeObj *pDnode);
|
||||
void * mnodeGetDnode(int32_t dnodeId);
|
||||
|
|
|
@ -38,6 +38,7 @@ void mnodeDropMnodeLocal(int32_t dnodeId);
|
|||
void * mnodeGetMnode(int32_t mnodeId);
|
||||
int32_t mnodeGetMnodesNum();
|
||||
void * mnodeGetNextMnode(void *pIter, struct SMnodeObj **pMnode);
|
||||
void mnodeCancelGetNextMnode(void *pIter);
|
||||
void mnodeIncMnodeRef(struct SMnodeObj *pMnode);
|
||||
void mnodeDecMnodeRef(struct SMnodeObj *pMnode);
|
||||
|
||||
|
|
|
@ -79,10 +79,13 @@ typedef struct {
|
|||
int32_t (*fpRestored)();
|
||||
} SSdbTableDesc;
|
||||
|
||||
int32_t sdbInitRef();
|
||||
void sdbCleanUpRef();
|
||||
int32_t sdbInit();
|
||||
void sdbCleanUp();
|
||||
void * sdbOpenTable(SSdbTableDesc *desc);
|
||||
void sdbCloseTable(void *handle);
|
||||
int64_t sdbOpenTable(SSdbTableDesc *desc);
|
||||
void sdbCloseTable(int64_t rid);
|
||||
void* sdbGetTableByRid(int64_t rid);
|
||||
bool sdbIsMaster();
|
||||
bool sdbIsServing();
|
||||
void sdbUpdateMnodeRoles();
|
||||
|
@ -92,9 +95,9 @@ int32_t sdbDeleteRow(SSdbRow *pRow);
|
|||
int32_t sdbUpdateRow(SSdbRow *pRow);
|
||||
int32_t sdbInsertRowToQueue(SSdbRow *pRow);
|
||||
|
||||
void *sdbGetRow(void *pTable, void *key);
|
||||
void *sdbFetchRow(void *pTable, void *pIter, void **ppRow);
|
||||
void sdbFreeIter(void *pIter);
|
||||
void * sdbGetRow(void *pTable, void *key);
|
||||
void * sdbFetchRow(void *pTable, void *pIter, void **ppRow);
|
||||
void sdbFreeIter(void *pTable, void *pIter);
|
||||
void sdbIncRef(void *pTable, void *pRow);
|
||||
void sdbDecRef(void *pTable, void *pRow);
|
||||
int64_t sdbGetNumOfRows(void *pTable);
|
||||
|
|
|
@ -26,8 +26,10 @@ void mnodeCleanUpShow();
|
|||
|
||||
typedef int32_t (*SShowMetaFp)(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
typedef void (*SShowFreeIterFp)(void *pIter);
|
||||
void mnodeAddShowMetaHandle(uint8_t showType, SShowMetaFp fp);
|
||||
void mnodeAddShowRetrieveHandle(uint8_t showType, SShowRetrieveFp fp);
|
||||
void mnodeAddShowFreeIterHandle(uint8_t msgType, SShowFreeIterFp fp);
|
||||
void mnodeVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -31,6 +31,8 @@ void mnodeIncTableRef(void *pTable);
|
|||
void mnodeDecTableRef(void *pTable);
|
||||
void * mnodeGetNextChildTable(void *pIter, SCTableObj **pTable);
|
||||
void * mnodeGetNextSuperTable(void *pIter, SSTableObj **pTable);
|
||||
void mnodeCancelGetNextChildTable(void *pIter);
|
||||
void mnodeCancelGetNextSuperTable(void *pIter);
|
||||
void mnodeDropAllChildTables(SDbObj *pDropDb);
|
||||
void mnodeDropAllSuperTables(SDbObj *pDropDb);
|
||||
void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup);
|
||||
|
|
|
@ -25,6 +25,7 @@ int32_t mnodeInitUsers();
|
|||
void mnodeCleanupUsers();
|
||||
SUserObj *mnodeGetUser(char *name);
|
||||
void * mnodeGetNextUser(void *pIter, SUserObj **pUser);
|
||||
void mnodeCancelGetNextUser(void *pIter);
|
||||
void mnodeIncUserRef(SUserObj *pUser);
|
||||
void mnodeDecUserRef(SUserObj *pUser);
|
||||
SUserObj *mnodeGetUserFromConn(void *pConn);
|
||||
|
|
|
@ -34,6 +34,7 @@ void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode);
|
|||
//void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb);
|
||||
|
||||
void * mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup);
|
||||
void mnodeCancelGetNextVgroup(void *pIter);
|
||||
void mnodeUpdateVgroup(SVgObj *pVgroup);
|
||||
void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload);
|
||||
void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t openVnodes);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
|
||||
int64_t tsAcctRid = -1;
|
||||
void * tsAcctSdb = NULL;
|
||||
static int32_t tsAcctUpdateSize;
|
||||
static int32_t mnodeCreateRootAcct();
|
||||
|
@ -114,7 +115,8 @@ int32_t mnodeInitAccts() {
|
|||
.fpRestored = mnodeAcctActionRestored
|
||||
};
|
||||
|
||||
tsAcctSdb = sdbOpenTable(&desc);
|
||||
tsAcctRid = sdbOpenTable(&desc);
|
||||
tsAcctSdb = sdbGetTableByRid(tsAcctRid);
|
||||
if (tsAcctSdb == NULL) {
|
||||
mError("table:%s, failed to create hash", desc.name);
|
||||
return -1;
|
||||
|
@ -126,7 +128,7 @@ int32_t mnodeInitAccts() {
|
|||
|
||||
void mnodeCleanupAccts() {
|
||||
acctCleanUp();
|
||||
sdbCloseTable(tsAcctSdb);
|
||||
sdbCloseTable(tsAcctRid);
|
||||
tsAcctSdb = NULL;
|
||||
}
|
||||
|
||||
|
@ -144,7 +146,6 @@ void mnodeGetStatOfAllAcct(SAcctInfo* pAcctInfo) {
|
|||
pAcctInfo->numOfTimeSeries += pAcct->acctInfo.numOfTimeSeries;
|
||||
mnodeDecAcctRef(pAcct);
|
||||
}
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
SVgObj *pVgroup = NULL;
|
||||
pIter = NULL;
|
||||
|
@ -158,7 +159,6 @@ void mnodeGetStatOfAllAcct(SAcctInfo* pAcctInfo) {
|
|||
pAcctInfo->totalPoints += pVgroup->pointsWritten;
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
sdbFreeIter(pIter);
|
||||
}
|
||||
|
||||
void *mnodeGetAcct(char *name) {
|
||||
|
@ -169,6 +169,10 @@ void *mnodeGetNextAcct(void *pIter, SAcctObj **pAcct) {
|
|||
return sdbFetchRow(tsAcctSdb, pIter, (void **)pAcct);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextAcct(void *pIter) {
|
||||
sdbFreeIter(tsAcctSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeIncAcctRef(SAcctObj *pAcct) {
|
||||
sdbIncRef(tsAcctSdb, pAcct);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "mnodeShow.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
int64_t tsClusterRid = -1;
|
||||
static void * tsClusterSdb = NULL;
|
||||
static int32_t tsClusterUpdateSize;
|
||||
static char tsClusterId[TSDB_CLUSTER_ID_LEN];
|
||||
|
@ -31,6 +32,7 @@ static int32_t mnodeCreateCluster();
|
|||
|
||||
static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static void mnodeCancelGetNextCluster(void *pIter);
|
||||
|
||||
static int32_t mnodeClusterActionDestroy(SSdbRow *pRow) {
|
||||
tfree(pRow->pObj);
|
||||
|
@ -100,21 +102,23 @@ int32_t mnodeInitCluster() {
|
|||
.fpRestored = mnodeClusterActionRestored
|
||||
};
|
||||
|
||||
tsClusterSdb = sdbOpenTable(&desc);
|
||||
tsClusterRid = sdbOpenTable(&desc);
|
||||
tsClusterSdb = sdbGetTableByRid(tsClusterRid);
|
||||
if (tsClusterSdb == NULL) {
|
||||
mError("table:%s, failed to create hash", desc.name);
|
||||
mError("table:%s, rid:%" PRId64 ", failed to create hash", desc.name, tsClusterRid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeGetClusterMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeRetrieveClusters);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeCancelGetNextCluster);
|
||||
|
||||
mDebug("table:%s, hash is created", desc.name);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void mnodeCleanupCluster() {
|
||||
sdbCloseTable(tsClusterSdb);
|
||||
sdbCloseTable(tsClusterRid);
|
||||
tsClusterSdb = NULL;
|
||||
}
|
||||
|
||||
|
@ -122,6 +126,10 @@ void *mnodeGetNextCluster(void *pIter, SClusterObj **pCluster) {
|
|||
return sdbFetchRow(tsClusterSdb, pIter, (void **)pCluster);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextCluster(void *pIter) {
|
||||
sdbFreeIter(tsClusterSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeIncClusterRef(SClusterObj *pCluster) {
|
||||
sdbIncRef(tsClusterSdb, pCluster);
|
||||
}
|
||||
|
@ -167,7 +175,7 @@ void mnodeUpdateClusterId() {
|
|||
}
|
||||
|
||||
mnodeDecClusterRef(pCluster);
|
||||
sdbFreeIter(pIter);
|
||||
mnodeCancelGetNextCluster(pIter);
|
||||
}
|
||||
|
||||
static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "mnodeVgroup.h"
|
||||
|
||||
#define VG_LIST_SIZE 8
|
||||
int64_t tsDbRid = -1;
|
||||
static void * tsDbSdb = NULL;
|
||||
static int32_t tsDbUpdateSize;
|
||||
|
||||
|
@ -160,7 +161,8 @@ int32_t mnodeInitDbs() {
|
|||
.fpRestored = mnodeDbActionRestored
|
||||
};
|
||||
|
||||
tsDbSdb = sdbOpenTable(&desc);
|
||||
tsDbRid = sdbOpenTable(&desc);
|
||||
tsDbSdb = sdbGetTableByRid(tsDbRid);
|
||||
if (tsDbSdb == NULL) {
|
||||
mError("failed to init db data");
|
||||
return -1;
|
||||
|
@ -171,6 +173,7 @@ int32_t mnodeInitDbs() {
|
|||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_DB, mnodeProcessDropDbMsg);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_DB, mnodeGetDbMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_DB, mnodeRetrieveDbs);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_DB, mnodeCancelGetNextDb);
|
||||
|
||||
mDebug("table:dbs table is created");
|
||||
return 0;
|
||||
|
@ -180,6 +183,10 @@ void *mnodeGetNextDb(void *pIter, SDbObj **pDb) {
|
|||
return sdbFetchRow(tsDbSdb, pIter, (void **)pDb);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextDb(void *pIter) {
|
||||
sdbFreeIter(tsDbSdb, pIter);
|
||||
}
|
||||
|
||||
SDbObj *mnodeGetDb(char *db) {
|
||||
return (SDbObj *)sdbGetRow(tsDbSdb, db);
|
||||
}
|
||||
|
@ -491,7 +498,7 @@ void mnodeRemoveVgroupFromDb(SVgObj *pVgroup) {
|
|||
}
|
||||
|
||||
void mnodeCleanupDbs() {
|
||||
sdbCloseTable(tsDbSdb);
|
||||
sdbCloseTable(tsDbRid);
|
||||
tsDbSdb = NULL;
|
||||
}
|
||||
|
||||
|
@ -986,8 +993,8 @@ static int32_t mnodeAlterDbCb(SMnodeMsg *pMsg, int32_t code) {
|
|||
SDbObj *pDb = pMsg->pDb;
|
||||
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
SVgObj *pVgroup = NULL;
|
||||
while (1) {
|
||||
pIter = mnodeGetNextVgroup(pIter, &pVgroup);
|
||||
if (pVgroup == NULL) break;
|
||||
if (pVgroup->pDb == pDb) {
|
||||
|
@ -995,7 +1002,6 @@ static int32_t mnodeAlterDbCb(SMnodeMsg *pMsg, int32_t code) {
|
|||
}
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mDebug("db:%s, all vgroups is altered", pDb->name);
|
||||
mLInfo("db:%s, is alterd by %s", pDb->name, mnodeGetUserFromMsg(pMsg));
|
||||
|
@ -1146,7 +1152,5 @@ void mnodeDropAllDbs(SAcctObj *pAcct) {
|
|||
mnodeDecDbRef(pDb);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mInfo("acct:%s, all dbs:%d is dropped from sdb", pAcct->user, numOfDbs);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "mnodeCluster.h"
|
||||
|
||||
int32_t tsAccessSquence = 0;
|
||||
int64_t tsDnodeRid = -1;
|
||||
static void * tsDnodeSdb = NULL;
|
||||
static int32_t tsDnodeUpdateSize = 0;
|
||||
extern void * tsMnodeSdb;
|
||||
|
@ -187,7 +188,8 @@ int32_t mnodeInitDnodes() {
|
|||
.fpRestored = mnodeDnodeActionRestored
|
||||
};
|
||||
|
||||
tsDnodeSdb = sdbOpenTable(&desc);
|
||||
tsDnodeRid = sdbOpenTable(&desc);
|
||||
tsDnodeSdb = sdbGetTableByRid(tsDnodeRid);
|
||||
if (tsDnodeSdb == NULL) {
|
||||
mError("failed to init dnodes data");
|
||||
return -1;
|
||||
|
@ -206,13 +208,14 @@ int32_t mnodeInitDnodes() {
|
|||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VNODES, mnodeRetrieveVnodes);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_DNODE, mnodeGetDnodeMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_DNODE, mnodeRetrieveDnodes);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_DNODE, mnodeCancelGetNextDnode);
|
||||
|
||||
mDebug("table:dnodes table is created");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mnodeCleanupDnodes() {
|
||||
sdbCloseTable(tsDnodeSdb);
|
||||
sdbCloseTable(tsDnodeRid);
|
||||
pthread_mutex_destroy(&tsDnodeEpsMutex);
|
||||
free(tsDnodeEps);
|
||||
tsDnodeEps = NULL;
|
||||
|
@ -223,6 +226,10 @@ void *mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode) {
|
|||
return sdbFetchRow(tsDnodeSdb, pIter, (void **)pDnode);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextDnode(void *pIter) {
|
||||
sdbFreeIter(tsDnodeSdb, pIter);
|
||||
}
|
||||
|
||||
int32_t mnodeGetDnodesNum() {
|
||||
return sdbGetNumOfRows(tsDnodeSdb);
|
||||
}
|
||||
|
@ -241,8 +248,6 @@ int32_t mnodeGetOnlinDnodesCpuCoreNum() {
|
|||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
if (cpuCores < 2) cpuCores = 2;
|
||||
return cpuCores;
|
||||
}
|
||||
|
@ -259,8 +264,6 @@ int32_t mnodeGetOnlineDnodesNum() {
|
|||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
return onlineDnodes;
|
||||
}
|
||||
|
||||
|
@ -276,13 +279,12 @@ void *mnodeGetDnodeByEp(char *ep) {
|
|||
pIter = mnodeGetNextDnode(pIter, &pDnode);
|
||||
if (pDnode == NULL) break;
|
||||
if (strcmp(ep, pDnode->dnodeEp) == 0) {
|
||||
sdbFreeIter(pIter);
|
||||
mnodeCancelGetNextDnode(pIter);
|
||||
return pDnode;
|
||||
}
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -464,7 +466,10 @@ static void mnodeUpdateDnodeEps() {
|
|||
while (1) {
|
||||
pIter = mnodeGetNextDnode(pIter, &pDnode);
|
||||
if (pDnode == NULL) break;
|
||||
if (dnodesNum >= totalDnodes) break;
|
||||
if (dnodesNum >= totalDnodes) {
|
||||
mnodeCancelGetNextDnode(pIter);
|
||||
break;
|
||||
}
|
||||
|
||||
SDnodeEp *pEp = &tsDnodeEps->dnodeEps[dnodesNum];
|
||||
dnodesNum++;
|
||||
|
@ -474,7 +479,6 @@ static void mnodeUpdateDnodeEps() {
|
|||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
pthread_mutex_unlock(&tsDnodeEpsMutex);
|
||||
}
|
||||
|
||||
|
@ -1100,7 +1104,7 @@ static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
|
|||
pDnode = mnodeGetDnodeByEp(pShow->payload);
|
||||
} else {
|
||||
void *pIter = mnodeGetNextDnode(NULL, (SDnodeObj **)&pDnode);
|
||||
sdbFreeIter(pIter);
|
||||
mnodeCancelGetNextDnode(pIter);
|
||||
}
|
||||
|
||||
if (pDnode != NULL) {
|
||||
|
@ -1148,7 +1152,6 @@ static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, vo
|
|||
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
sdbFreeIter(pIter);
|
||||
} else {
|
||||
numOfRows = 0;
|
||||
}
|
||||
|
@ -1217,8 +1220,6 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
|
|||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
if (pSelDnode == NULL) {
|
||||
mError("failed to alloc vnode to vgroup");
|
||||
return TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
|
|
|
@ -47,6 +47,7 @@ void *tsMnodeTmr = NULL;
|
|||
static bool tsMgmtIsRunning = false;
|
||||
|
||||
static const SMnodeComponent tsMnodeComponents[] = {
|
||||
{"sdbref", sdbInitRef, sdbCleanUpRef},
|
||||
{"profile", mnodeInitProfile, mnodeCleanupProfile},
|
||||
{"cluster", mnodeInitCluster, mnodeCleanupCluster},
|
||||
{"accts", mnodeInitAccts, mnodeCleanupAccts},
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "mnodeUser.h"
|
||||
#include "mnodeVgroup.h"
|
||||
|
||||
int64_t tsMnodeRid = -1;
|
||||
static void * tsMnodeSdb = NULL;
|
||||
static int32_t tsMnodeUpdateSize = 0;
|
||||
static SRpcEpSet tsMnodeEpSetForShell;
|
||||
|
@ -123,7 +124,7 @@ static int32_t mnodeMnodeActionRestored() {
|
|||
pMnode->role = TAOS_SYNC_ROLE_MASTER;
|
||||
mnodeDecMnodeRef(pMnode);
|
||||
}
|
||||
sdbFreeIter(pIter);
|
||||
mnodeCancelGetNextMnode(pIter);
|
||||
}
|
||||
|
||||
mnodeUpdateMnodeEpSet();
|
||||
|
@ -153,7 +154,8 @@ int32_t mnodeInitMnodes() {
|
|||
.fpRestored = mnodeMnodeActionRestored
|
||||
};
|
||||
|
||||
tsMnodeSdb = sdbOpenTable(&desc);
|
||||
tsMnodeRid = sdbOpenTable(&desc);
|
||||
tsMnodeSdb = sdbGetTableByRid(tsMnodeRid);
|
||||
if (tsMnodeSdb == NULL) {
|
||||
mError("failed to init mnodes data");
|
||||
return -1;
|
||||
|
@ -161,13 +163,14 @@ int32_t mnodeInitMnodes() {
|
|||
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_MNODE, mnodeGetMnodeMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_MNODE, mnodeRetrieveMnodes);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_MNODE, mnodeCancelGetNextMnode);
|
||||
|
||||
mDebug("table:mnodes table is created");
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void mnodeCleanupMnodes() {
|
||||
sdbCloseTable(tsMnodeSdb);
|
||||
sdbCloseTable(tsMnodeRid);
|
||||
tsMnodeSdb = NULL;
|
||||
mnodeMnodeDestroyLock();
|
||||
}
|
||||
|
@ -192,6 +195,10 @@ void *mnodeGetNextMnode(void *pIter, SMnodeObj **pMnode) {
|
|||
return sdbFetchRow(tsMnodeSdb, pIter, (void **)pMnode);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextMnode(void *pIter) {
|
||||
sdbFreeIter(tsMnodeSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeUpdateMnodeEpSet() {
|
||||
mInfo("update mnodes epSet, numOfEps:%d ", mnodeGetMnodesNum());
|
||||
|
||||
|
@ -239,8 +246,6 @@ void mnodeUpdateMnodeEpSet() {
|
|||
tsMnodeEpSetForShell.numOfEps = index;
|
||||
tsMnodeEpSetForPeer.numOfEps = index;
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mnodeMnodeUnLock();
|
||||
}
|
||||
|
||||
|
@ -248,12 +253,30 @@ void mnodeGetMnodeEpSetForPeer(SRpcEpSet *epSet) {
|
|||
mnodeMnodeRdLock();
|
||||
*epSet = tsMnodeEpSetForPeer;
|
||||
mnodeMnodeUnLock();
|
||||
|
||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||
if (strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort + TSDB_PORT_DNODEDNODE) {
|
||||
epSet->inUse = (i + 1) % epSet->numOfEps;
|
||||
mTrace("mnode:%d, for peer ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
||||
} else {
|
||||
mTrace("mpeer:%d, for peer ep:%s:%u", i, epSet->fqdn[i], htons(epSet->port[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mnodeGetMnodeEpSetForShell(SRpcEpSet *epSet) {
|
||||
mnodeMnodeRdLock();
|
||||
*epSet = tsMnodeEpSetForShell;
|
||||
mnodeMnodeUnLock();
|
||||
|
||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||
if (strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort) {
|
||||
epSet->inUse = (i + 1) % epSet->numOfEps;
|
||||
mTrace("mnode:%d, for shell ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
||||
} else {
|
||||
mTrace("mnode:%d, for shell ep:%s:%u", i, epSet->fqdn[i], htons(epSet->port[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* mnodeGetMnodeMasterEp() {
|
||||
|
|
|
@ -58,16 +58,8 @@ int32_t mnodeProcessPeerReq(SMnodeMsg *pMsg) {
|
|||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SRpcEpSet);
|
||||
|
||||
mDebug("msg:%p, ahandle:%p type:%s in mpeer queue will be redirected, numOfEps:%d inUse:%d", pMsg,
|
||||
pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType], epSet->numOfEps, epSet->inUse);
|
||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||
if (strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort + TSDB_PORT_DNODEDNODE) {
|
||||
epSet->inUse = (i + 1) % epSet->numOfEps;
|
||||
mDebug("mpeer:%d ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
||||
} else {
|
||||
mDebug("mpeer:%d ep:%s:%u", i, epSet->fqdn[i], htons(epSet->port[i]));
|
||||
}
|
||||
}
|
||||
mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
return TSDB_CODE_RPC_REDIRECT;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#define QUERY_ID_SIZE 20
|
||||
#define QUERY_STREAM_SAVE_SIZE 20
|
||||
|
||||
extern void *tsMnodeTmr;
|
||||
static SCacheObj *tsMnodeConnCache = NULL;
|
||||
static int32_t tsConnIndex = 0;
|
||||
|
||||
|
@ -42,6 +41,7 @@ static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
|
|||
static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static void mnodeCancelGetNextConn(void *pIter);
|
||||
static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
static void mnodeFreeConn(void *data);
|
||||
|
@ -52,10 +52,13 @@ static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg);
|
|||
int32_t mnodeInitProfile() {
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_QUERIES, mnodeGetQueryMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_QUERIES, mnodeRetrieveQueries);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_QUERIES, mnodeCancelGetNextConn);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CONNS, mnodeGetConnsMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CONNS, mnodeRetrieveConns);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_CONNS, mnodeCancelGetNextConn);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_STREAMS, mnodeGetStreamMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_STREAMS, mnodeRetrieveStreams);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_STREAMS, mnodeCancelGetNextConn);
|
||||
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_QUERY, mnodeProcessKillQueryMsg);
|
||||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_KILL_STREAM, mnodeProcessKillStreamMsg);
|
||||
|
@ -137,21 +140,15 @@ static void mnodeFreeConn(void *data) {
|
|||
mDebug("connId:%d, is destroyed", pConn->connId);
|
||||
}
|
||||
|
||||
static void *mnodeGetNextConn(SHashMutableIterator *pIter, SConnObj **pConn) {
|
||||
static void *mnodeGetNextConn(void *pIter, SConnObj **pConn) {
|
||||
*pConn = NULL;
|
||||
|
||||
if (pIter == NULL) {
|
||||
pIter = taosHashCreateIter(tsMnodeConnCache->pHashTable);
|
||||
}
|
||||
pIter = taosHashIterate(tsMnodeConnCache->pHashTable, pIter);
|
||||
if (pIter == NULL) return NULL;
|
||||
|
||||
if (!taosHashIterNext(pIter)) {
|
||||
taosHashDestroyIter(pIter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SCacheDataNode **pNode = taosHashIterGet(pIter);
|
||||
SCacheDataNode **pNode = pIter;
|
||||
if (pNode == NULL || *pNode == NULL) {
|
||||
taosHashDestroyIter(pIter);
|
||||
taosHashCancelIterate(tsMnodeConnCache->pHashTable, pIter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -159,6 +156,10 @@ static void *mnodeGetNextConn(SHashMutableIterator *pIter, SConnObj **pConn) {
|
|||
return pIter;
|
||||
}
|
||||
|
||||
static void mnodeCancelGetNextConn(void *pIter) {
|
||||
taosHashCancelIterate(tsMnodeConnCache->pHashTable, pIter);
|
||||
}
|
||||
|
||||
static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
SUserObj *pUser = mnodeGetUserFromConn(pConn);
|
||||
if (pUser == NULL) return 0;
|
||||
|
|
|
@ -51,21 +51,12 @@ int32_t mnodeProcessRead(SMnodeMsg *pMsg) {
|
|||
SMnodeRsp *rpcRsp = &pMsg->rpcRsp;
|
||||
SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet));
|
||||
mnodeGetMnodeEpSetForShell(epSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in mread queue will be redirected, numOfEps:%d inUse:%d", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType], epSet->numOfEps, epSet->inUse);
|
||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||
if (strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort) {
|
||||
epSet->inUse = (i + 1) % epSet->numOfEps;
|
||||
mDebug("mnode index:%d ep:%s:%u, set inUse to %d", i, epSet->fqdn[i], htons(epSet->port[i]), epSet->inUse);
|
||||
} else {
|
||||
mDebug("mnode index:%d ep:%s:%u", i, epSet->fqdn[i], htons(epSet->port[i]));
|
||||
}
|
||||
}
|
||||
|
||||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SRpcEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
return TSDB_CODE_RPC_REDIRECT;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "taoserror.h"
|
||||
#include "hash.h"
|
||||
#include "tutil.h"
|
||||
#include "tref.h"
|
||||
#include "tbalance.h"
|
||||
#include "tqueue.h"
|
||||
#include "twal.h"
|
||||
|
@ -98,6 +99,7 @@ typedef struct {
|
|||
SSdbWorker *worker;
|
||||
} SSdbWorkerPool;
|
||||
|
||||
int32_t tsSdbRid;
|
||||
extern void * tsMnodeTmr;
|
||||
static void * tsSdbTmr;
|
||||
static SSdbMgmt tsSdbMgmt = {0};
|
||||
|
@ -118,6 +120,7 @@ static void sdbFreeQueue();
|
|||
static int32_t sdbInsertHash(SSdbTable *pTable, SSdbRow *pRow);
|
||||
static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbRow *pRow);
|
||||
static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbRow *pRow);
|
||||
static void sdbCloseTableObj(void *handle);
|
||||
|
||||
int32_t sdbGetId(void *pTable) {
|
||||
return ((SSdbTable *)pTable)->autoIndex;
|
||||
|
@ -325,7 +328,6 @@ void sdbUpdateSync(void *pMnodes) {
|
|||
mnodeDecDnodeRef(pDnode);
|
||||
mnodeDecMnodeRef(pMnode);
|
||||
}
|
||||
sdbFreeIter(pIter);
|
||||
syncCfg.replica = index;
|
||||
mDebug("vgId:1, mnodes info not input, use infos in sdb, numOfMnodes:%d", syncCfg.replica);
|
||||
} else {
|
||||
|
@ -386,6 +388,17 @@ void sdbUpdateSync(void *pMnodes) {
|
|||
sdbUpdateMnodeRoles();
|
||||
}
|
||||
|
||||
int32_t sdbInitRef() {
|
||||
tsSdbRid = taosOpenRef(10, sdbCloseTableObj);
|
||||
if (tsSdbRid <= 0) {
|
||||
sdbError("failed to init sdb ref");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sdbCleanUpRef() { taosCloseRef(tsSdbRid); }
|
||||
|
||||
int32_t sdbInit() {
|
||||
pthread_mutex_init(&tsSdbMgmt.mutex, NULL);
|
||||
|
||||
|
@ -424,7 +437,7 @@ void sdbCleanUp() {
|
|||
walClose(tsSdbMgmt.wal);
|
||||
tsSdbMgmt.wal = NULL;
|
||||
}
|
||||
|
||||
|
||||
pthread_mutex_destroy(&tsSdbMgmt.mutex);
|
||||
}
|
||||
|
||||
|
@ -507,7 +520,7 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbRow *pRow) {
|
|||
atomic_add_fetch_32(&pTable->autoIndex, 1);
|
||||
}
|
||||
|
||||
sdbDebug("vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%" PRId64 ", msg:%p", pTable->name,
|
||||
sdbTrace("vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%" PRId64 ", msg:%p", pTable->name,
|
||||
sdbGetRowStr(pTable, pRow->pObj), pRow->rowSize, pTable->numOfRows, pRow->pMsg);
|
||||
|
||||
int32_t code = (*pTable->fpInsert)(pRow);
|
||||
|
@ -543,7 +556,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbRow *pRow) {
|
|||
|
||||
atomic_sub_fetch_32(&pTable->numOfRows, 1);
|
||||
|
||||
sdbDebug("vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->name,
|
||||
sdbTrace("vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->name,
|
||||
sdbGetRowStr(pTable, pRow->pObj), pTable->numOfRows, pRow->pMsg);
|
||||
|
||||
sdbDecRef(pTable, pRow->pObj);
|
||||
|
@ -552,7 +565,7 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbRow *pRow) {
|
|||
}
|
||||
|
||||
static int32_t sdbUpdateHash(SSdbTable *pTable, SSdbRow *pRow) {
|
||||
sdbDebug("vgId:1, sdb:%s, update key:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->name,
|
||||
sdbTrace("vgId:1, sdb:%s, update key:%s in hash, numOfRows:%" PRId64 ", msg:%p", pTable->name,
|
||||
sdbGetRowStr(pTable, pRow->pObj), pTable->numOfRows, pRow->pMsg);
|
||||
|
||||
(*pTable->fpUpdate)(pRow);
|
||||
|
@ -650,7 +663,7 @@ static int32_t sdbProcessWrite(void *wparam, void *hparam, int32_t qtype, void *
|
|||
return syncCode;
|
||||
}
|
||||
|
||||
sdbDebug("vgId:1, sdb:%s, record from wal/fwd is disposed, action:%s key:%s hver:%" PRIu64, pTable->name,
|
||||
sdbTrace("vgId:1, sdb:%s, record from %s is disposed, action:%s key:%s hver:%" PRIu64, pTable->name, qtypeStr[qtype],
|
||||
actStr[action], sdbGetKeyStr(pTable, pHead->cont), pHead->version);
|
||||
|
||||
// even it is WAL/FWD, it shall be called to update version in sync
|
||||
|
@ -775,24 +788,17 @@ int32_t sdbUpdateRow(SSdbRow *pRow) {
|
|||
}
|
||||
}
|
||||
|
||||
void *sdbFetchRow(void *tparam, void *pNode, void **ppRow) {
|
||||
void *sdbFetchRow(void *tparam, void *pIter, void **ppRow) {
|
||||
SSdbTable *pTable = tparam;
|
||||
*ppRow = NULL;
|
||||
if (pTable == NULL) return NULL;
|
||||
|
||||
SHashMutableIterator *pIter = pNode;
|
||||
if (pIter == NULL) {
|
||||
pIter = taosHashCreateIter(pTable->iHandle);
|
||||
}
|
||||
pIter = taosHashIterate(pTable->iHandle, pIter);
|
||||
if (pIter == NULL) return NULL;
|
||||
|
||||
if (!taosHashIterNext(pIter)) {
|
||||
taosHashDestroyIter(pIter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void **ppMetaRow = taosHashIterGet(pIter);
|
||||
void **ppMetaRow = pIter;
|
||||
if (ppMetaRow == NULL) {
|
||||
taosHashDestroyIter(pIter);
|
||||
taosHashCancelIterate(pTable->iHandle, pIter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -802,16 +808,17 @@ void *sdbFetchRow(void *tparam, void *pNode, void **ppRow) {
|
|||
return pIter;
|
||||
}
|
||||
|
||||
void sdbFreeIter(void *pIter) {
|
||||
if (pIter != NULL) {
|
||||
taosHashDestroyIter(pIter);
|
||||
}
|
||||
void sdbFreeIter(void *tparam, void *pIter) {
|
||||
SSdbTable *pTable = tparam;
|
||||
if (pTable == NULL || pIter == NULL) return;
|
||||
|
||||
taosHashCancelIterate(pTable->iHandle, pIter);
|
||||
}
|
||||
|
||||
void *sdbOpenTable(SSdbTableDesc *pDesc) {
|
||||
int64_t sdbOpenTable(SSdbTableDesc *pDesc) {
|
||||
SSdbTable *pTable = (SSdbTable *)calloc(1, sizeof(SSdbTable));
|
||||
|
||||
if (pTable == NULL) return NULL;
|
||||
if (pTable == NULL) return -1;
|
||||
|
||||
pthread_mutex_init(&pTable->mutex, NULL);
|
||||
tstrncpy(pTable->name, pDesc->name, SDB_TABLE_LEN);
|
||||
|
@ -836,19 +843,31 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) {
|
|||
|
||||
tsSdbMgmt.numOfTables++;
|
||||
tsSdbMgmt.tableList[pTable->id] = pTable;
|
||||
return pTable;
|
||||
|
||||
return taosAddRef(tsSdbRid, pTable);
|
||||
}
|
||||
|
||||
void sdbCloseTable(void *handle) {
|
||||
void sdbCloseTable(int64_t rid) {
|
||||
taosRemoveRef(tsSdbRid, rid);
|
||||
}
|
||||
|
||||
void *sdbGetTableByRid(int64_t rid) {
|
||||
void *handle = taosAcquireRef(tsSdbRid, rid);
|
||||
taosReleaseRef(tsSdbRid, rid);
|
||||
return handle;
|
||||
}
|
||||
|
||||
static void sdbCloseTableObj(void *handle) {
|
||||
SSdbTable *pTable = (SSdbTable *)handle;
|
||||
if (pTable == NULL) return;
|
||||
|
||||
tsSdbMgmt.numOfTables--;
|
||||
tsSdbMgmt.tableList[pTable->id] = NULL;
|
||||
|
||||
SHashMutableIterator *pIter = taosHashCreateIter(pTable->iHandle);
|
||||
while (taosHashIterNext(pIter)) {
|
||||
void **ppRow = taosHashIterGet(pIter);
|
||||
void *pIter = taosHashIterate(pTable->iHandle, NULL);
|
||||
while (pIter) {
|
||||
void **ppRow = pIter;
|
||||
pIter = taosHashIterate(pTable->iHandle, pIter);
|
||||
if (ppRow == NULL) continue;
|
||||
|
||||
SSdbRow row = {
|
||||
|
@ -859,8 +878,9 @@ void sdbCloseTable(void *handle) {
|
|||
(*pTable->fpDestroy)(&row);
|
||||
}
|
||||
|
||||
taosHashDestroyIter(pIter);
|
||||
taosHashCancelIterate(pTable->iHandle, pIter);
|
||||
taosHashCleanup(pTable->iHandle);
|
||||
pTable->iHandle = NULL;
|
||||
pthread_mutex_destroy(&pTable->mutex);
|
||||
|
||||
sdbDebug("vgId:1, sdb:%s, is closed, numOfTables:%d", pTable->name, tsSdbMgmt.numOfTables);
|
||||
|
|
|
@ -52,11 +52,11 @@ static bool mnodeCheckShowFinished(SShowObj *pShow);
|
|||
static void *mnodePutShowObj(SShowObj *pShow);
|
||||
static void mnodeReleaseShowObj(SShowObj *pShow, bool forceRemove);
|
||||
|
||||
extern void *tsMnodeTmr;
|
||||
static void *tsMnodeShowCache = NULL;
|
||||
static int32_t tsShowObjIndex = 0;
|
||||
static SShowMetaFp tsMnodeShowMetaFp[TSDB_MGMT_TABLE_MAX] = {0};
|
||||
static SShowRetrieveFp tsMnodeShowRetrieveFp[TSDB_MGMT_TABLE_MAX] = {0};
|
||||
static SShowFreeIterFp tsMnodeShowFreeIterFp[TSDB_MGMT_TABLE_MAX] = {0};
|
||||
|
||||
int32_t mnodeInitShow() {
|
||||
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_SHOW, mnodeProcessShowMsg);
|
||||
|
@ -85,6 +85,10 @@ void mnodeAddShowRetrieveHandle(uint8_t msgType, SShowRetrieveFp fp) {
|
|||
tsMnodeShowRetrieveFp[msgType] = fp;
|
||||
}
|
||||
|
||||
void mnodeAddShowFreeIterHandle(uint8_t msgType, SShowFreeIterFp fp) {
|
||||
tsMnodeShowFreeIterFp[msgType] = fp;
|
||||
}
|
||||
|
||||
static char *mnodeGetShowType(int32_t showType) {
|
||||
switch (showType) {
|
||||
case TSDB_MGMT_TABLE_ACCT: return "show accounts";
|
||||
|
@ -412,7 +416,9 @@ static void* mnodePutShowObj(SShowObj *pShow) {
|
|||
|
||||
static void mnodeFreeShowObj(void *data) {
|
||||
SShowObj *pShow = *(SShowObj **)data;
|
||||
sdbFreeIter(pShow->pIter);
|
||||
if (tsMnodeShowFreeIterFp[pShow->type] != NULL && pShow->pIter != NULL) {
|
||||
(*tsMnodeShowFreeIterFp[pShow->type])(pShow->pIter);
|
||||
}
|
||||
|
||||
mDebug("%p, show is destroyed, data:%p index:%d", pShow, data, pShow->index);
|
||||
tfree(pShow);
|
||||
|
|
|
@ -49,7 +49,9 @@
|
|||
#define CREATE_CTABLE_RETRY_TIMES 10
|
||||
#define CREATE_CTABLE_RETRY_SEC 14
|
||||
|
||||
int64_t tsCTableRid = -1;
|
||||
static void * tsChildTableSdb;
|
||||
int64_t tsSTableRid = -1;
|
||||
static void * tsSuperTableSdb;
|
||||
static int32_t tsChildTableUpdateSize;
|
||||
static int32_t tsSuperTableUpdateSize;
|
||||
|
@ -342,8 +344,7 @@ static int32_t mnodeChildTableActionRestored() {
|
|||
mnodeDecTableRef(pTable);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mnodeCancelGetNextChildTable(pIter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -351,7 +352,7 @@ static int32_t mnodeInitChildTables() {
|
|||
SCTableObj tObj;
|
||||
tsChildTableUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj.info.type;
|
||||
|
||||
SSdbTableDesc tableDesc = {
|
||||
SSdbTableDesc desc = {
|
||||
.id = SDB_TABLE_CTABLE,
|
||||
.name = "ctables",
|
||||
.hashSessions = TSDB_DEFAULT_CTABLES_HASH_SIZE,
|
||||
|
@ -367,7 +368,8 @@ static int32_t mnodeInitChildTables() {
|
|||
.fpRestored = mnodeChildTableActionRestored
|
||||
};
|
||||
|
||||
tsChildTableSdb = sdbOpenTable(&tableDesc);
|
||||
tsCTableRid = sdbOpenTable(&desc);
|
||||
tsChildTableSdb = sdbGetTableByRid(tsCTableRid);
|
||||
if (tsChildTableSdb == NULL) {
|
||||
mError("failed to init child table data");
|
||||
return -1;
|
||||
|
@ -378,7 +380,7 @@ static int32_t mnodeInitChildTables() {
|
|||
}
|
||||
|
||||
static void mnodeCleanupChildTables() {
|
||||
sdbCloseTable(tsChildTableSdb);
|
||||
sdbCloseTable(tsCTableRid);
|
||||
tsChildTableSdb = NULL;
|
||||
}
|
||||
|
||||
|
@ -544,7 +546,7 @@ static int32_t mnodeInitSuperTables() {
|
|||
SSTableObj tObj;
|
||||
tsSuperTableUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj.info.type;
|
||||
|
||||
SSdbTableDesc tableDesc = {
|
||||
SSdbTableDesc desc = {
|
||||
.id = SDB_TABLE_STABLE,
|
||||
.name = "stables",
|
||||
.hashSessions = TSDB_DEFAULT_STABLES_HASH_SIZE,
|
||||
|
@ -560,7 +562,8 @@ static int32_t mnodeInitSuperTables() {
|
|||
.fpRestored = mnodeSuperTableActionRestored
|
||||
};
|
||||
|
||||
tsSuperTableSdb = sdbOpenTable(&tableDesc);
|
||||
tsSTableRid = sdbOpenTable(&desc);
|
||||
tsSuperTableSdb = sdbGetTableByRid(tsSTableRid);
|
||||
if (tsSuperTableSdb == NULL) {
|
||||
mError("failed to init stables data");
|
||||
return -1;
|
||||
|
@ -571,7 +574,7 @@ static int32_t mnodeInitSuperTables() {
|
|||
}
|
||||
|
||||
static void mnodeCleanupSuperTables() {
|
||||
sdbCloseTable(tsSuperTableSdb);
|
||||
sdbCloseTable(tsSTableRid);
|
||||
tsSuperTableSdb = NULL;
|
||||
}
|
||||
|
||||
|
@ -602,10 +605,13 @@ int32_t mnodeInitTables() {
|
|||
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_TABLE, mnodeGetShowTableMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_TABLE, mnodeRetrieveShowTables);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_TABLE, mnodeCancelGetNextChildTable);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_METRIC, mnodeGetShowSuperTableMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_METRIC, mnodeRetrieveShowSuperTables);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_METRIC, mnodeCancelGetNextSuperTable);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_STREAMTABLES, mnodeGetStreamTableMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_STREAMTABLES, mnodeRetrieveStreamTables);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_STREAMTABLES, mnodeCancelGetNextChildTable);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -626,14 +632,12 @@ static void *mnodeGetSuperTableByUid(uint64_t uid) {
|
|||
pIter = mnodeGetNextSuperTable(pIter, &pStable);
|
||||
if (pStable == NULL) break;
|
||||
if (pStable->uid == uid) {
|
||||
sdbFreeIter(pIter);
|
||||
mnodeCancelGetNextSuperTable(pIter);
|
||||
return pStable;
|
||||
}
|
||||
mnodeDecTableRef(pStable);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -655,10 +659,18 @@ void *mnodeGetNextChildTable(void *pIter, SCTableObj **pTable) {
|
|||
return sdbFetchRow(tsChildTableSdb, pIter, (void **)pTable);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextChildTable(void *pIter) {
|
||||
sdbFreeIter(tsChildTableSdb, pIter);
|
||||
}
|
||||
|
||||
void *mnodeGetNextSuperTable(void *pIter, SSTableObj **pTable) {
|
||||
return sdbFetchRow(tsSuperTableSdb, pIter, (void **)pTable);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextSuperTable(void *pIter) {
|
||||
sdbFreeIter(tsSuperTableSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeIncTableRef(void *p1) {
|
||||
STableObj *pTable = (STableObj *)p1;
|
||||
if (pTable->type == TSDB_SUPER_TABLE) {
|
||||
|
@ -914,10 +926,10 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
SSTableObj *pStable = (SSTableObj *)pMsg->pTable;
|
||||
if (pStable->vgHash != NULL /*pStable->numOfTables != 0*/) {
|
||||
SHashMutableIterator *pIter = taosHashCreateIter(pStable->vgHash);
|
||||
while (taosHashIterNext(pIter)) {
|
||||
int32_t *pVgId = taosHashIterGet(pIter);
|
||||
int32_t *pVgId = taosHashIterate(pStable->vgHash, NULL);
|
||||
while (pVgId) {
|
||||
SVgObj *pVgroup = mnodeGetVgroup(*pVgId);
|
||||
pVgId = taosHashIterate(pStable->vgHash, pVgId);
|
||||
if (pVgroup == NULL) break;
|
||||
|
||||
SDropSTableMsg *pDrop = rpcMallocCont(sizeof(SDropSTableMsg));
|
||||
|
@ -933,7 +945,8 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
|
|||
dnodeSendMsgToDnode(&epSet, &rpcMsg);
|
||||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
taosHashDestroyIter(pIter);
|
||||
|
||||
taosHashCancelIterate(pStable->vgHash, pVgId);
|
||||
|
||||
mnodeDropAllChildTablesInStable(pStable);
|
||||
}
|
||||
|
@ -1430,8 +1443,6 @@ void mnodeDropAllSuperTables(SDbObj *pDropDb) {
|
|||
mnodeDecTableRef(pTable);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mInfo("db:%s, all super tables:%d is dropped from sdb", pDropDb->name, numOfTables);
|
||||
}
|
||||
|
||||
|
@ -1523,11 +1534,11 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
|
|||
} else {
|
||||
SVgroupsMsg *pVgroupMsg = (SVgroupsMsg *)msg;
|
||||
|
||||
SHashMutableIterator *pIter = taosHashCreateIter(pTable->vgHash);
|
||||
int32_t vgSize = 0;
|
||||
while (taosHashIterNext(pIter)) {
|
||||
int32_t *pVgId = taosHashIterGet(pIter);
|
||||
SVgObj * pVgroup = mnodeGetVgroup(*pVgId);
|
||||
int32_t *pVgId = taosHashIterate(pTable->vgHash, NULL);
|
||||
int32_t vgSize = 0;
|
||||
while (pVgId) {
|
||||
SVgObj *pVgroup = mnodeGetVgroup(*pVgId);
|
||||
pVgId = taosHashIterate(pTable->vgHash, pVgId);
|
||||
if (pVgroup == NULL) continue;
|
||||
|
||||
pVgroupMsg->vgroups[vgSize].vgId = htonl(pVgroup->vgId);
|
||||
|
@ -1547,7 +1558,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
|
|||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
|
||||
taosHashDestroyIter(pIter);
|
||||
taosHashCancelIterate(pTable->vgHash, pVgId);
|
||||
mnodeDecTableRef(pTable);
|
||||
|
||||
pVgroupMsg->numOfVgroups = htonl(vgSize);
|
||||
|
@ -2230,8 +2241,6 @@ void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup) {
|
|||
mnodeDecTableRef(pTable);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mInfo("vgId:%d, all child tables is dropped from sdb", pVgroup->vgId);
|
||||
}
|
||||
|
||||
|
@ -2263,8 +2272,6 @@ void mnodeDropAllChildTables(SDbObj *pDropDb) {
|
|||
mnodeDecTableRef(pTable);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mInfo("db:%s, all child tables:%d is dropped from sdb", pDropDb->name, numOfTables);
|
||||
}
|
||||
|
||||
|
@ -2293,8 +2300,6 @@ static void mnodeDropAllChildTablesInStable(SSTableObj *pStable) {
|
|||
mnodeDecTableRef(pTable);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mInfo("stable:%s, all child tables:%d is dropped from sdb", pStable->info.tableId, numOfTables);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "mnodeWrite.h"
|
||||
#include "mnodePeer.h"
|
||||
|
||||
int64_t tsUserRid = -1;
|
||||
static void * tsUserSdb = NULL;
|
||||
static int32_t tsUserUpdateSize = 0;
|
||||
static int32_t mnodeGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
|
@ -123,7 +124,6 @@ static void mnodePrintUserAuth() {
|
|||
}
|
||||
|
||||
fflush(fp);
|
||||
sdbFreeIter(pIter);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,8 @@ int32_t mnodeInitUsers() {
|
|||
.fpRestored = mnodeUserActionRestored
|
||||
};
|
||||
|
||||
tsUserSdb = sdbOpenTable(&desc);
|
||||
tsUserRid = sdbOpenTable(&desc);
|
||||
tsUserSdb = sdbGetTableByRid(tsUserRid);
|
||||
if (tsUserSdb == NULL) {
|
||||
mError("table:%s, failed to create hash", desc.name);
|
||||
return -1;
|
||||
|
@ -177,6 +178,8 @@ int32_t mnodeInitUsers() {
|
|||
mnodeAddWriteMsgHandle(TSDB_MSG_TYPE_CM_DROP_USER, mnodeProcessDropUserMsg);
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_USER, mnodeGetUserMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_USER, mnodeRetrieveUsers);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_USER, mnodeCancelGetNextUser);
|
||||
|
||||
mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_AUTH, mnodeProcessAuthMsg);
|
||||
|
||||
mDebug("table:%s, hash is created", desc.name);
|
||||
|
@ -184,7 +187,7 @@ int32_t mnodeInitUsers() {
|
|||
}
|
||||
|
||||
void mnodeCleanupUsers() {
|
||||
sdbCloseTable(tsUserSdb);
|
||||
sdbCloseTable(tsUserRid);
|
||||
tsUserSdb = NULL;
|
||||
}
|
||||
|
||||
|
@ -196,6 +199,10 @@ void *mnodeGetNextUser(void *pIter, SUserObj **pUser) {
|
|||
return sdbFetchRow(tsUserSdb, pIter, (void **)pUser);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextUser(void *pIter) {
|
||||
sdbFreeIter(tsUserSdb, pIter);
|
||||
}
|
||||
|
||||
void mnodeIncUserRef(SUserObj *pUser) {
|
||||
return sdbIncRef(tsUserSdb, pUser);
|
||||
}
|
||||
|
@ -574,8 +581,6 @@ void mnodeDropAllUsers(SAcctObj *pAcct) {
|
|||
mnodeDecUserRef(pUser);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mDebug("acct:%s, all users:%d is dropped from sdb", pAcct->user, numOfUsers);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ char* vgroupStatus[] = {
|
|||
"updating"
|
||||
};
|
||||
|
||||
int64_t tsVgroupRid = -1;
|
||||
static void *tsVgroupSdb = NULL;
|
||||
static int32_t tsVgUpdateSize = 0;
|
||||
|
||||
|
@ -222,7 +223,8 @@ int32_t mnodeInitVgroups() {
|
|||
.fpRestored = mnodeVgroupActionRestored,
|
||||
};
|
||||
|
||||
tsVgroupSdb = sdbOpenTable(&desc);
|
||||
tsVgroupRid = sdbOpenTable(&desc);
|
||||
tsVgroupSdb = sdbGetTableByRid(tsVgroupRid);
|
||||
if (tsVgroupSdb == NULL) {
|
||||
mError("failed to init vgroups data");
|
||||
return -1;
|
||||
|
@ -230,6 +232,7 @@ int32_t mnodeInitVgroups() {
|
|||
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_VGROUP, mnodeGetVgroupMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VGROUP, mnodeRetrieveVgroups);
|
||||
mnodeAddShowFreeIterHandle(TSDB_MGMT_TABLE_VGROUP, mnodeCancelGetNextVgroup);
|
||||
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP, mnodeProcessCreateVnodeRsp);
|
||||
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP, mnodeProcessAlterVnodeRsp);
|
||||
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_DROP_VNODE_RSP, mnodeProcessDropVnodeRsp);
|
||||
|
@ -304,7 +307,7 @@ void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t o
|
|||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
mnodeCancelGetNextVgroup(pIter);
|
||||
}
|
||||
|
||||
void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload) {
|
||||
|
@ -491,6 +494,10 @@ void *mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup) {
|
|||
return sdbFetchRow(tsVgroupSdb, pIter, (void **)pVgroup);
|
||||
}
|
||||
|
||||
void mnodeCancelGetNextVgroup(void *pIter) {
|
||||
sdbFreeIter(tsVgroupSdb, pIter);
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateVgroupFp(SMnodeMsg *pMsg) {
|
||||
SVgObj *pVgroup = pMsg->pVgroup;
|
||||
SDbObj *pDb = pMsg->pDb;
|
||||
|
@ -605,7 +612,7 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) {
|
|||
}
|
||||
|
||||
void mnodeCleanupVgroups() {
|
||||
sdbCloseTable(tsVgroupSdb);
|
||||
sdbCloseTable(tsVgroupRid);
|
||||
tsVgroupSdb = NULL;
|
||||
}
|
||||
|
||||
|
@ -1095,8 +1102,6 @@ void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
|
|||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mInfo("dnode:%d, all vgroups:%d is dropped from sdb", pDropDnode->dnodeId, numOfVgroups);
|
||||
}
|
||||
|
||||
|
@ -1118,8 +1123,6 @@ void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb) {
|
|||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mInfo("db:%s, all vgroups is updated in sdb", pAlterDb->name);
|
||||
}
|
||||
#endif
|
||||
|
@ -1147,8 +1150,6 @@ void mnodeDropAllDbVgroups(SDbObj *pDropDb) {
|
|||
mnodeDecVgroupRef(pVgroup);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mInfo("db:%s, all vgroups:%d is dropped from sdb", pDropDb->name, numOfVgroups);
|
||||
}
|
||||
|
||||
|
@ -1170,7 +1171,5 @@ void mnodeSendDropAllDbVgroupsMsg(SDbObj *pDropDb) {
|
|||
numOfVgroups++;
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
mInfo("db:%s, all vgroups:%d drop msg is sent to dnode", pDropDb->name, numOfVgroups);
|
||||
}
|
||||
|
|
|
@ -54,18 +54,8 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) {
|
|||
rpcRsp->rsp = epSet;
|
||||
rpcRsp->len = sizeof(SRpcEpSet);
|
||||
|
||||
mDebug("msg:%p, app:%p type:%s in write queue, will be redirected, numOfEps:%d inUse:%d", pMsg, pMsg->rpcMsg.ahandle,
|
||||
taosMsg[pMsg->rpcMsg.msgType], epSet->numOfEps, epSet->inUse);
|
||||
for (int32_t i = 0; i < epSet->numOfEps; ++i) {
|
||||
if (strcmp(epSet->fqdn[i], tsLocalFqdn) == 0 && htons(epSet->port[i]) == tsServerPort) {
|
||||
epSet->inUse = (i + 1) % epSet->numOfEps;
|
||||
mDebug("msg:%p, app:%p mnode index:%d ep:%s:%d, set inUse to %d", pMsg, pMsg->rpcMsg.ahandle, i, epSet->fqdn[i],
|
||||
htons(epSet->port[i]), epSet->inUse);
|
||||
} else {
|
||||
mDebug("msg:%p, app:%p mnode index:%d ep:%s:%d", pMsg, pMsg->rpcMsg.ahandle, i, epSet->fqdn[i],
|
||||
htons(epSet->port[i]));
|
||||
}
|
||||
}
|
||||
mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg,
|
||||
pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType], epSet->numOfEps, epSet->inUse);
|
||||
|
||||
return TSDB_CODE_RPC_REDIRECT;
|
||||
}
|
||||
|
|
|
@ -20,17 +20,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define tread(fd, buf, count) read(fd, buf, count)
|
||||
#define twrite(fd, buf, count) write(fd, buf, count)
|
||||
#define tlseek(fd, offset, whence) lseek(fd, offset, whence)
|
||||
#define tclose(fd) \
|
||||
{ \
|
||||
if (FD_VALID(fd)) { \
|
||||
close(fd); \
|
||||
fd = FD_INITIALIZER; \
|
||||
} \
|
||||
}
|
||||
|
||||
int64_t taosReadImp(int32_t fd, void *buf, int64_t count);
|
||||
int64_t taosWriteImp(int32_t fd, void *buf, int64_t count);
|
||||
int64_t taosLSeekImp(int32_t fd, int64_t offset, int32_t whence);
|
||||
|
@ -39,7 +28,13 @@ int32_t taosRenameFile(char *fullPath, char *suffix, char delimiter, char **dstP
|
|||
#define taosRead(fd, buf, count) taosReadImp(fd, buf, count)
|
||||
#define taosWrite(fd, buf, count) taosWriteImp(fd, buf, count)
|
||||
#define taosLSeek(fd, offset, whence) taosLSeekImp(fd, offset, whence)
|
||||
#define taosClose(x) tclose(x)
|
||||
#define taosClose(fd) \
|
||||
{ \
|
||||
if (FD_VALID(fd)) { \
|
||||
close(fd); \
|
||||
fd = FD_INITIALIZER; \
|
||||
} \
|
||||
}
|
||||
|
||||
// TAOS_OS_FUNC_FILE_SENDIFLE
|
||||
int64_t taosSendFile(int32_t dfd, int32_t sfd, int64_t *offset, int64_t size);
|
||||
|
|
|
@ -116,7 +116,7 @@ int64_t taosWriteImp(int32_t fd, void *buf, int64_t n) {
|
|||
}
|
||||
|
||||
int64_t taosLSeekImp(int32_t fd, int64_t offset, int32_t whence) {
|
||||
return (int64_t)tlseek(fd, (long)offset, whence);
|
||||
return (int64_t)lseek(fd, (long)offset, whence);
|
||||
}
|
||||
|
||||
#ifndef TAOS_OS_FUNC_FILE_SENDIFLE
|
||||
|
|
|
@ -63,9 +63,11 @@ typedef struct SSqlGroupbyExpr {
|
|||
|
||||
typedef struct SResultRow {
|
||||
int32_t pageId; // pageId & rowId is the position of current result in disk-based output buffer
|
||||
int32_t rowId:15;
|
||||
bool closed:1; // this result status: closed or opened
|
||||
uint16_t numOfRows; // number of rows of current time window
|
||||
int32_t rowId:29; // row index in buffer page
|
||||
bool startInterp; // the time window start timestamp has done the interpolation already.
|
||||
bool endInterp; // the time window end timestamp has done the interpolation already.
|
||||
bool closed; // this result status: closed or opened
|
||||
uint32_t numOfRows; // number of rows of current time window
|
||||
SResultRowCellInfo* pCellInfo; // For each result column, there is a resultInfo
|
||||
union {STimeWindow win; char* key;}; // start key of current time window
|
||||
} SResultRow;
|
||||
|
@ -187,6 +189,7 @@ typedef struct SQueryRuntimeEnv {
|
|||
bool topBotQuery; // false
|
||||
bool groupbyNormalCol; // denote if this is a groupby normal column query
|
||||
bool hasTagResults; // if there are tag values in final result or not
|
||||
bool timeWindowInterpo;// if the time window start/end required interpolation
|
||||
int32_t interBufSize; // intermediate buffer sizse
|
||||
int32_t prevGroupId; // previous executed group id
|
||||
SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||
|
@ -195,6 +198,8 @@ typedef struct SQueryRuntimeEnv {
|
|||
SResultRowPool* pool; // window result object pool
|
||||
|
||||
int32_t* rowCellInfoOffset;// offset value for each row result cell info
|
||||
char** prevRow;
|
||||
char** nextRow;
|
||||
} SQueryRuntimeEnv;
|
||||
|
||||
enum {
|
||||
|
|
|
@ -152,6 +152,11 @@ typedef struct SResultRowCellInfo {
|
|||
uint32_t numOfRes; // num of output result in current buffer
|
||||
} SResultRowCellInfo;
|
||||
|
||||
typedef struct SPoint1 {
|
||||
int64_t key;
|
||||
double val;
|
||||
} SPoint1;
|
||||
|
||||
#define GET_ROWCELL_INTERBUF(_c) ((void*) ((char*)(_c) + sizeof(SResultRowCellInfo)))
|
||||
|
||||
struct SQLFunctionCtx;
|
||||
|
@ -194,6 +199,8 @@ typedef struct SQLFunctionCtx {
|
|||
SResultRowCellInfo *resultInfo;
|
||||
|
||||
SExtTagsInfo tagInfo;
|
||||
SPoint1 start;
|
||||
SPoint1 end;
|
||||
} SQLFunctionCtx;
|
||||
|
||||
typedef struct SQLAggFuncElem {
|
||||
|
@ -243,21 +250,11 @@ enum {
|
|||
};
|
||||
|
||||
typedef struct STwaInfo {
|
||||
TSKEY lastKey;
|
||||
int8_t hasResult; // flag to denote has value
|
||||
int16_t type; // source data type
|
||||
TSKEY SKey;
|
||||
TSKEY EKey;
|
||||
|
||||
union {
|
||||
double dOutput;
|
||||
int64_t iOutput;
|
||||
};
|
||||
|
||||
union {
|
||||
double dLastValue;
|
||||
int64_t iLastValue;
|
||||
};
|
||||
TSKEY lastKey;
|
||||
int8_t hasResult; // flag to denote has value
|
||||
double dOutput;
|
||||
double lastValue;
|
||||
STimeWindow win;
|
||||
} STwaInfo;
|
||||
|
||||
/* global sql function array */
|
||||
|
@ -276,8 +273,6 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha
|
|||
(_r)->initialized = false; \
|
||||
} while (0)
|
||||
|
||||
//void setResultInfoBuf(SResultRowCellInfo *pResInfo, char* buf);
|
||||
|
||||
static FORCE_INLINE void initResultInfo(SResultRowCellInfo *pResInfo, uint32_t bufLen) {
|
||||
pResInfo->initialized = true; // the this struct has been initialized flag
|
||||
|
||||
|
|
|
@ -370,6 +370,66 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
|
|||
#endif
|
||||
}
|
||||
|
||||
static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOfRows) {
|
||||
switch(type) {
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
int8_t* p = (int8_t*) dest;
|
||||
int8_t* pSrc = (int8_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
int16_t* p = (int16_t*) dest;
|
||||
int16_t* pSrc = (int16_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
int32_t* p = (int32_t*) dest;
|
||||
int32_t* pSrc = (int32_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
int64_t* p = (int64_t*) dest;
|
||||
int64_t* pSrc = (int64_t*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) dest;
|
||||
float* pSrc = (float*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) dest;
|
||||
double* pSrc = (double*) src;
|
||||
|
||||
for(int32_t i = 0; i < numOfRows; ++i) {
|
||||
p[i] = pSrc[numOfRows - i - 1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
|
||||
char *(*getSourceDataBlock)(void *, const char*, int32_t)) {
|
||||
if (pExprs == NULL) {
|
||||
|
@ -387,6 +447,8 @@ void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
|
|||
|
||||
/* the right output has result from the right child syntax tree */
|
||||
char *pRightOutput = malloc(sizeof(int64_t) * numOfRows);
|
||||
char *pdata = malloc(sizeof(int64_t) * numOfRows);
|
||||
|
||||
if (pRight->nodeType == TSQL_NODE_EXPR) {
|
||||
tExprTreeCalcTraverse(pRight, numOfRows, pRightOutput, param, order, getSourceDataBlock);
|
||||
}
|
||||
|
@ -398,52 +460,75 @@ void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
|
|||
* the type of returned value of one expression is always double float precious
|
||||
*/
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_DOUBLE, pExprs->_node.optr);
|
||||
fp(pLeftOutput, pRightOutput, numOfRows, numOfRows, pOutput, order);
|
||||
fp(pLeftOutput, pRightOutput, numOfRows, numOfRows, pOutput, TSDB_ORDER_ASC);
|
||||
|
||||
} else if (pRight->nodeType == TSQL_NODE_COL) { // exprLeft + columnRight
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(TSDB_DATA_TYPE_DOUBLE, pRight->pSchema->type, pExprs->_node.optr);
|
||||
|
||||
// set input buffer
|
||||
char *pInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
|
||||
fp(pLeftOutput, pInputData, numOfRows, numOfRows, pOutput, order);
|
||||
if (order == TSDB_ORDER_DESC) {
|
||||
reverseCopy(pdata, pInputData, pRight->pSchema->type, numOfRows);
|
||||
fp(pLeftOutput, pdata, numOfRows, numOfRows, pOutput, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
fp(pLeftOutput, pInputData, numOfRows, numOfRows, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
|
||||
} else if (pRight->nodeType == TSQL_NODE_VALUE) { // exprLeft + 12
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(TSDB_DATA_TYPE_DOUBLE, pRight->pVal->nType, pExprs->_node.optr);
|
||||
fp(pLeftOutput, &pRight->pVal->i64Key, numOfRows, 1, pOutput, order);
|
||||
fp(pLeftOutput, &pRight->pVal->i64Key, numOfRows, 1, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
} else if (pLeft->nodeType == TSQL_NODE_COL) {
|
||||
// column data specified on left-hand-side
|
||||
char *pLeftInputData = getSourceDataBlock(param, pLeft->pSchema->name, pLeft->pSchema->colId);
|
||||
if (pRight->nodeType == TSQL_NODE_EXPR) { // columnLeft + expr2
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(pLeft->pSchema->type, TSDB_DATA_TYPE_DOUBLE, pExprs->_node.optr);
|
||||
fp(pLeftInputData, pRightOutput, numOfRows, numOfRows, pOutput, order);
|
||||
|
||||
if (order == TSDB_ORDER_DESC) {
|
||||
reverseCopy(pdata, pLeftInputData, pLeft->pSchema->type, numOfRows);
|
||||
fp(pdata, pRightOutput, numOfRows, numOfRows, pOutput, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
fp(pLeftInputData, pRightOutput, numOfRows, numOfRows, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
|
||||
} else if (pRight->nodeType == TSQL_NODE_COL) { // columnLeft + columnRight
|
||||
// column data specified on right-hand-side
|
||||
char *pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
|
||||
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(pLeft->pSchema->type, pRight->pSchema->type, pExprs->_node.optr);
|
||||
fp(pLeftInputData, pRightInputData, numOfRows, numOfRows, pOutput, order);
|
||||
|
||||
// both columns are descending order, do not reverse the source data
|
||||
fp(pLeftInputData, pRightInputData, numOfRows, numOfRows, pOutput, order);
|
||||
} else if (pRight->nodeType == TSQL_NODE_VALUE) { // columnLeft + 12
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(pLeft->pSchema->type, pRight->pVal->nType, pExprs->_node.optr);
|
||||
fp(pLeftInputData, &pRight->pVal->i64Key, numOfRows, 1, pOutput, order);
|
||||
|
||||
if (order == TSDB_ORDER_DESC) {
|
||||
reverseCopy(pdata, pLeftInputData, pLeft->pSchema->type, numOfRows);
|
||||
fp(pdata, &pRight->pVal->i64Key, numOfRows, 1, pOutput, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
fp(pLeftInputData, &pRight->pVal->i64Key, numOfRows, 1, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// column data specified on left-hand-side
|
||||
if (pRight->nodeType == TSQL_NODE_EXPR) { // 12 + expr2
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(pLeft->pVal->nType, TSDB_DATA_TYPE_DOUBLE, pExprs->_node.optr);
|
||||
fp(&pLeft->pVal->i64Key, pRightOutput, 1, numOfRows, pOutput, order);
|
||||
fp(&pLeft->pVal->i64Key, pRightOutput, 1, numOfRows, pOutput, TSDB_ORDER_ASC);
|
||||
|
||||
} else if (pRight->nodeType == TSQL_NODE_COL) { // 12 + columnRight
|
||||
// column data specified on right-hand-side
|
||||
char *pRightInputData = getSourceDataBlock(param, pRight->pSchema->name, pRight->pSchema->colId);
|
||||
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(pLeft->pVal->nType, pRight->pSchema->type, pExprs->_node.optr);
|
||||
fp(&pLeft->pVal->i64Key, pRightInputData, 1, numOfRows, pOutput, order);
|
||||
|
||||
if (order == TSDB_ORDER_DESC) {
|
||||
reverseCopy(pdata, pRightInputData, pRight->pSchema->type, numOfRows);
|
||||
fp(&pLeft->pVal->i64Key, pdata, numOfRows, 1, pOutput, TSDB_ORDER_ASC);
|
||||
} else {
|
||||
fp(&pLeft->pVal->i64Key, pRightInputData, 1, numOfRows, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
|
||||
} else if (pRight->nodeType == TSQL_NODE_VALUE) { // 12 + 12
|
||||
_bi_consumer_fn_t fp = tGetBiConsumerFn(pLeft->pVal->nType, pRight->pVal->nType, pExprs->_node.optr);
|
||||
fp(&pLeft->pVal->i64Key, &pRight->pVal->i64Key, 1, 1, pOutput, order);
|
||||
fp(&pLeft->pVal->i64Key, &pRight->pVal->i64Key, 1, 1, pOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "query.h"
|
||||
#include "queryLog.h"
|
||||
#include "tlosertree.h"
|
||||
#include "ttype.h"
|
||||
|
||||
#define MAX_ROWS_PER_RESBUF_PAGE ((1u<<12) - 1)
|
||||
|
||||
|
@ -194,6 +195,7 @@ static int32_t setAdditionalInfo(SQInfo *pQInfo, void *pTable, STableQueryInfo *
|
|||
static int32_t flushFromResultBuf(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo* pGroupResInfo);
|
||||
static int32_t checkForQueryBuf(size_t numOfTables);
|
||||
static void releaseQueryBuf(size_t numOfTables);
|
||||
static int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order);
|
||||
|
||||
bool doFilterData(SQuery *pQuery, int32_t elemPos) {
|
||||
for (int32_t k = 0; k < pQuery->numOfFilterCols; ++k) {
|
||||
|
@ -400,6 +402,17 @@ static bool isTopBottomQuery(SQuery *pQuery) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool timeWindowInterpoRequired(SQuery *pQuery) {
|
||||
for(int32_t i = 0; i < pQuery->numOfOutput; ++i) {
|
||||
int32_t functionId = pQuery->pExpr1[i].base.functionId;
|
||||
if (functionId == TSDB_FUNC_TWA) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool hasTagValOutput(SQuery* pQuery) {
|
||||
SExprInfo *pExprInfo = &pQuery->pExpr1[0];
|
||||
if (pQuery->numOfOutput == 1 && pExprInfo->base.functionId == TSDB_FUNC_TS_COMP) {
|
||||
|
@ -457,6 +470,7 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SWin
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// TODO refactor
|
||||
// more than the capacity, reallocate the resources
|
||||
if (pWindowResInfo->size >= pWindowResInfo->capacity) {
|
||||
int64_t newCapacity = 0;
|
||||
|
@ -595,14 +609,17 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
|
|||
}
|
||||
|
||||
static int32_t setWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWindowResInfo, SDataBlockInfo* pBockInfo,
|
||||
STimeWindow *win, bool masterscan, bool* newWind) {
|
||||
STimeWindow *win, bool masterscan, bool* newWind, SResultRow** pResult) {
|
||||
assert(win->skey <= win->ekey);
|
||||
SDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
||||
|
||||
SResultRow *pResultRow = doPrepareResultRowFromKey(pRuntimeEnv, pWindowResInfo, (char *)&win->skey, TSDB_KEYSIZE, masterscan, pBockInfo->uid);
|
||||
// todo refactor
|
||||
int64_t uid = getResultInfoUId(pRuntimeEnv);
|
||||
SResultRow *pResultRow = doPrepareResultRowFromKey(pRuntimeEnv, pWindowResInfo, (char *)&win->skey, TSDB_KEYSIZE, masterscan, uid);
|
||||
if (pResultRow == NULL) {
|
||||
*newWind = false;
|
||||
|
||||
// no master scan, no result generated means error occurs
|
||||
return masterscan? -1:0;
|
||||
}
|
||||
|
||||
|
@ -618,15 +635,40 @@ static int32_t setWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SWindowRes
|
|||
|
||||
// set time window for current result
|
||||
pResultRow->win = (*win);
|
||||
*pResult = pResultRow;
|
||||
setResultRowOutputBufInitCtx(pRuntimeEnv, pResultRow);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool getTimeWindowResStatus(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
||||
static bool getResultRowStatus(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
||||
assert(slot >= 0 && slot < pWindowResInfo->size);
|
||||
return pWindowResInfo->pResult[slot]->closed;
|
||||
}
|
||||
|
||||
typedef enum SResultTsInterpType {
|
||||
RESULT_ROW_START_INTERP = 1,
|
||||
RESULT_ROW_END_INTERP = 2,
|
||||
} SResultTsInterpType;
|
||||
|
||||
static void setResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) {
|
||||
assert(pResult != NULL && (type == RESULT_ROW_START_INTERP || type == RESULT_ROW_END_INTERP));
|
||||
if (type == RESULT_ROW_START_INTERP) {
|
||||
pResult->startInterp = true;
|
||||
} else {
|
||||
pResult->endInterp = true;
|
||||
}
|
||||
}
|
||||
|
||||
static bool isResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) {
|
||||
assert(pResult != NULL && (type == RESULT_ROW_START_INTERP || type == RESULT_ROW_END_INTERP));
|
||||
if (type == RESULT_ROW_START_INTERP) {
|
||||
return pResult->startInterp == true;
|
||||
} else {
|
||||
return pResult->endInterp == true;
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn_t searchFn, TSKEY ekey, int16_t pos,
|
||||
int16_t order, int64_t *pData) {
|
||||
int32_t forwardStep = 0;
|
||||
|
@ -990,6 +1032,113 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas
|
|||
return dataBlock;
|
||||
}
|
||||
|
||||
// window start key interpolation
|
||||
static bool setTimeWindowInterpolationStartTs(SQueryRuntimeEnv* pRuntimeEnv, int32_t pos, SArray* pDataBlock, TSKEY* tsCols, STimeWindow* win) {
|
||||
SQuery* pQuery = pRuntimeEnv->pQuery;
|
||||
|
||||
TSKEY start = tsCols[pos];
|
||||
TSKEY lastTs = *(TSKEY *) pRuntimeEnv->prevRow[0];
|
||||
TSKEY prevTs = (pos == 0)? lastTs : tsCols[pos - 1];
|
||||
|
||||
// if lastTs == INT64_MIN, it is the first block, no need to do the start time interpolation
|
||||
if (((lastTs != INT64_MIN && pos >= 0) || (lastTs == INT64_MIN && pos > 0)) && win->skey > lastTs &&
|
||||
win->skey < start) {
|
||||
|
||||
for (int32_t k = 0; k < pQuery->numOfCols; ++k) {
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, k);
|
||||
if (k == 0 && pColInfo->info.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
||||
assert(pColInfo->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v1 = 0, v2 = 0, v = 0;
|
||||
|
||||
char *prevVal = pos == 0 ? pRuntimeEnv->prevRow[k] : ((char*)pColInfo->pData) + (pos - 1) * pColInfo->info.bytes;
|
||||
|
||||
GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)prevVal);
|
||||
GET_TYPED_DATA(v2, double, pColInfo->info.type, (char *)pColInfo->pData + pos * pColInfo->info.bytes);
|
||||
|
||||
SPoint point1 = (SPoint){.key = prevTs, .val = &v1};
|
||||
SPoint point2 = (SPoint){.key = start, .val = &v2};
|
||||
SPoint point = (SPoint){.key = win->skey, .val = &v};
|
||||
taosGetLinearInterpolationVal(TSDB_DATA_TYPE_DOUBLE, &point1, &point2, &point);
|
||||
pRuntimeEnv->pCtx[k].start.key = point.key;
|
||||
pRuntimeEnv->pCtx[k].start.val = v;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
for (int32_t k = 0; k < pQuery->numOfCols; ++k) {
|
||||
pRuntimeEnv->pCtx[k].start.key = INT64_MIN;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool setTimeWindowInterpolationEndTs(SQueryRuntimeEnv* pRuntimeEnv, int32_t pos, SArray* pDataBlock, TSKEY* tsCols, TSKEY ekey, STimeWindow* win) {
|
||||
SQuery* pQuery = pRuntimeEnv->pQuery;
|
||||
TSKEY trueEndKey = tsCols[pos];
|
||||
|
||||
if (win->ekey < ekey && win->ekey != trueEndKey) {
|
||||
int32_t nextIndex = pos + 1;
|
||||
TSKEY next = tsCols[nextIndex];
|
||||
|
||||
for (int32_t k = 0; k < pQuery->numOfCols; ++k) {
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, k);
|
||||
if (k == 0 && pColInfo->info.type == TSDB_DATA_TYPE_TIMESTAMP &&
|
||||
pColInfo->info.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double v1 = 0, v2 = 0, v = 0;
|
||||
GET_TYPED_DATA(v1, double, pColInfo->info.type, (char *)pColInfo->pData + pos * pColInfo->info.bytes);
|
||||
GET_TYPED_DATA(v2, double, pColInfo->info.type, (char *)pColInfo->pData + nextIndex * pColInfo->info.bytes);
|
||||
|
||||
SPoint point1 = (SPoint){.key = trueEndKey, .val = &v1};
|
||||
SPoint point2 = (SPoint){.key = next, .val = &v2};
|
||||
SPoint point = (SPoint){.key = win->ekey, .val = &v};
|
||||
taosGetLinearInterpolationVal(TSDB_DATA_TYPE_DOUBLE, &point1, &point2, &point);
|
||||
pRuntimeEnv->pCtx[k].end.key = point.key;
|
||||
pRuntimeEnv->pCtx[k].end.val = v;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else { // current time window does not ended in current data block, do nothing
|
||||
for (int32_t k = 0; k < pQuery->numOfCols; ++k) {
|
||||
pRuntimeEnv->pCtx[k].end.key = INT64_MIN;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void saveDataBlockLastRow(SQueryRuntimeEnv* pRuntimeEnv, SDataBlockInfo* pDataBlockInfo, SArray* pDataBlock) {
|
||||
if (pDataBlock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SQuery* pQuery = pRuntimeEnv->pQuery;
|
||||
for (int32_t k = 0; k < pQuery->numOfCols; ++k) {
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, k);
|
||||
memcpy(pRuntimeEnv->prevRow[k], ((char*)pColInfo->pData) + (pColInfo->info.bytes * (pDataBlockInfo->rows - 1)),
|
||||
pColInfo->info.bytes);
|
||||
}
|
||||
}
|
||||
|
||||
static TSKEY getStartTsKey(SQuery* pQuery, SDataBlockInfo* pDataBlockInfo, TSKEY* tsCols, int32_t step) {
|
||||
TSKEY ts = TSKEY_INITIAL_VAL;
|
||||
|
||||
if (tsCols == NULL) {
|
||||
ts = QUERY_IS_ASC_QUERY(pQuery) ? pDataBlockInfo->window.skey : pDataBlockInfo->window.ekey;
|
||||
} else {
|
||||
int32_t offset = GET_COL_DATA_POS(pQuery, 0, step);
|
||||
ts = tsCols[offset];
|
||||
}
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
|
||||
* @param pRuntimeEnv
|
||||
|
@ -1000,16 +1149,15 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas
|
|||
* @return the incremental number of output value, so it maybe 0 for fixed number of query,
|
||||
* such as count/min/max etc.
|
||||
*/
|
||||
static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pStatis,
|
||||
SDataBlockInfo *pDataBlockInfo, SWindowResInfo *pWindowResInfo,
|
||||
__block_search_fn_t searchFn, SArray *pDataBlock) {
|
||||
static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pStatis, SDataBlockInfo *pDataBlockInfo,
|
||||
SWindowResInfo *pWindowResInfo, __block_search_fn_t searchFn, SArray *pDataBlock) {
|
||||
SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx;
|
||||
bool masterScan = IS_MASTER_SCAN(pRuntimeEnv);
|
||||
bool masterScan = IS_MASTER_SCAN(pRuntimeEnv);
|
||||
|
||||
SQuery *pQuery = pRuntimeEnv->pQuery;
|
||||
TSKEY *tsCols = NULL;
|
||||
if (pDataBlock != NULL) {
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, 0);
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pDataBlock, 0);
|
||||
tsCols = (TSKEY *)(pColInfo->pData);
|
||||
}
|
||||
|
||||
|
@ -1018,7 +1166,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
|
|||
longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SQInfo* pQInfo = GET_QINFO_ADDR(pRuntimeEnv);
|
||||
SQInfo *pQInfo = GET_QINFO_ADDR(pRuntimeEnv);
|
||||
for (int32_t k = 0; k < pQuery->numOfOutput; ++k) {
|
||||
char *dataBlock = getDataBlock(pRuntimeEnv, &sasArray[k], k, pDataBlockInfo->rows, pDataBlock);
|
||||
setExecParams(pQuery, &pCtx[k], dataBlock, tsCols, pDataBlockInfo, pStatis, &sasArray[k], k, pQInfo->vgId);
|
||||
|
@ -1026,18 +1174,13 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
|
|||
|
||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
|
||||
if (QUERY_IS_INTERVAL_QUERY(pQuery)) {
|
||||
TSKEY ts = TSKEY_INITIAL_VAL;
|
||||
TSKEY ts = getStartTsKey(pQuery, pDataBlockInfo, tsCols, step);
|
||||
|
||||
if (tsCols == NULL) {
|
||||
ts = QUERY_IS_ASC_QUERY(pQuery)? pDataBlockInfo->window.skey:pDataBlockInfo->window.ekey;
|
||||
} else {
|
||||
int32_t offset = GET_COL_DATA_POS(pQuery, 0, step);
|
||||
ts = tsCols[offset];
|
||||
}
|
||||
|
||||
bool hasTimeWindow = false;
|
||||
bool hasTimeWindow = false;
|
||||
SResultRow* pResult = NULL;
|
||||
STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery);
|
||||
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo, &win, masterScan, &hasTimeWindow) != TSDB_CODE_SUCCESS) {
|
||||
int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo, &win, masterScan, &hasTimeWindow, &pResult);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
tfree(sasArray);
|
||||
return;
|
||||
}
|
||||
|
@ -1045,11 +1188,32 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
|
|||
int32_t forwardStep = 0;
|
||||
int32_t startPos = pQuery->pos;
|
||||
|
||||
// in case of repeat scan/reverse scan, no new time window added.
|
||||
if (hasTimeWindow) {
|
||||
TSKEY ekey = reviseWindowEkey(pQuery, &win);
|
||||
forwardStep = getNumOfRowsInTimeWindow(pQuery, pDataBlockInfo, tsCols, pQuery->pos, ekey, searchFn, true);
|
||||
|
||||
bool pStatus = getTimeWindowResStatus(pWindowResInfo, curTimeWindowIndex(pWindowResInfo));
|
||||
// window start key interpolation
|
||||
if (pRuntimeEnv->timeWindowInterpo) {
|
||||
bool alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
|
||||
if (!alreadyInterp) {
|
||||
bool interp = setTimeWindowInterpolationStartTs(pRuntimeEnv, pQuery->pos, pDataBlock, tsCols, &win);
|
||||
if (interp) {
|
||||
setResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
|
||||
}
|
||||
}
|
||||
|
||||
alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
if (!alreadyInterp) {
|
||||
bool interp = setTimeWindowInterpolationEndTs(pRuntimeEnv, pQuery->pos + forwardStep - 1, pDataBlock, tsCols,
|
||||
pDataBlockInfo->window.ekey, &win);
|
||||
if (interp) {
|
||||
setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool pStatus = getResultRowStatus(pWindowResInfo, curTimeWindowIndex(pWindowResInfo));
|
||||
doBlockwiseApplyFunctions(pRuntimeEnv, pStatus, &win, startPos, forwardStep, tsCols, pDataBlockInfo->rows);
|
||||
}
|
||||
|
||||
|
@ -1065,7 +1229,8 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
|
|||
|
||||
// null data, failed to allocate more memory buffer
|
||||
hasTimeWindow = false;
|
||||
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo, &nextWin, masterScan, &hasTimeWindow) != TSDB_CODE_SUCCESS) {
|
||||
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo, &nextWin, masterScan, &hasTimeWindow, &pResult) !=
|
||||
TSDB_CODE_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1076,7 +1241,26 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
|
|||
TSKEY ekey = reviseWindowEkey(pQuery, &nextWin);
|
||||
forwardStep = getNumOfRowsInTimeWindow(pQuery, pDataBlockInfo, tsCols, startPos, ekey, searchFn, true);
|
||||
|
||||
bool closed = getTimeWindowResStatus(pWindowResInfo, curTimeWindowIndex(pWindowResInfo));
|
||||
// window start(end) key interpolation
|
||||
if (pRuntimeEnv->timeWindowInterpo) {
|
||||
bool alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
|
||||
if (!alreadyInterp) {
|
||||
bool interp = setTimeWindowInterpolationStartTs(pRuntimeEnv, startPos, pDataBlock, tsCols, &nextWin);
|
||||
if (interp) {
|
||||
setResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
|
||||
}
|
||||
}
|
||||
|
||||
alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
if (!alreadyInterp) {
|
||||
bool interp = setTimeWindowInterpolationEndTs(pRuntimeEnv, startPos + forwardStep - 1, pDataBlock, tsCols, pDataBlockInfo->window.ekey, &nextWin);
|
||||
if (interp) {
|
||||
setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool closed = getResultRowStatus(pWindowResInfo, curTimeWindowIndex(pWindowResInfo));
|
||||
doBlockwiseApplyFunctions(pRuntimeEnv, closed, &nextWin, startPos, forwardStep, tsCols, pDataBlockInfo->rows);
|
||||
}
|
||||
|
||||
|
@ -1090,12 +1274,17 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
|
|||
for (int32_t k = 0; k < pQuery->numOfOutput; ++k) {
|
||||
int32_t functionId = pQuery->pExpr1[k].base.functionId;
|
||||
if (functionNeedToExecute(pRuntimeEnv, &pCtx[k], functionId)) {
|
||||
pCtx[k].nStartQueryTimestamp = pDataBlockInfo->window.skey;
|
||||
aAggs[functionId].xFunction(&pCtx[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < pQuery->numOfOutput; ++i) {
|
||||
if (pRuntimeEnv->timeWindowInterpo) {
|
||||
saveDataBlockLastRow(pRuntimeEnv, pDataBlockInfo, pDataBlock);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pQuery->numOfOutput; ++i) {
|
||||
if (pQuery->pExpr1[i].base.functionId != TSDB_FUNC_ARITHM) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1318,20 +1507,20 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
|
|||
pQuery->order.order, pRuntimeEnv->pTSBuf->cur.order);
|
||||
}
|
||||
|
||||
int32_t j = 0;
|
||||
int32_t offset = -1;
|
||||
// TSKEY prev = -1;
|
||||
|
||||
for (j = 0; j < pDataBlockInfo->rows; ++j) {
|
||||
for (int32_t j = 0; j < pDataBlockInfo->rows; ++j) {
|
||||
offset = GET_COL_DATA_POS(pQuery, j, step);
|
||||
|
||||
if (pRuntimeEnv->pTSBuf != NULL) {
|
||||
int32_t r = doTSJoinFilter(pRuntimeEnv, offset);
|
||||
if (r == TS_JOIN_TAG_NOT_EQUALS) {
|
||||
int32_t ret = doTSJoinFilter(pRuntimeEnv, offset);
|
||||
if (ret == TS_JOIN_TAG_NOT_EQUALS) {
|
||||
break;
|
||||
} else if (r == TS_JOIN_TS_NOT_EQUALS) {
|
||||
} else if (ret == TS_JOIN_TS_NOT_EQUALS) {
|
||||
continue;
|
||||
} else {
|
||||
assert(r == TS_JOIN_TS_EQUAL);
|
||||
assert(ret == TS_JOIN_TS_EQUAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1344,8 +1533,9 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
|
|||
int64_t ts = tsCols[offset];
|
||||
STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery);
|
||||
|
||||
bool hasTimeWindow = false;
|
||||
int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo, &win, masterScan, &hasTimeWindow);
|
||||
bool hasTimeWindow = false;
|
||||
SResultRow* pResult = NULL;
|
||||
int32_t ret = setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo, &win, masterScan, &hasTimeWindow, &pResult);
|
||||
if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code
|
||||
continue;
|
||||
}
|
||||
|
@ -1353,8 +1543,28 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
|
|||
if (!hasTimeWindow) {
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
// window start key interpolation
|
||||
if (pRuntimeEnv->timeWindowInterpo) {
|
||||
bool alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
|
||||
if (!alreadyInterp) {
|
||||
bool interp = setTimeWindowInterpolationStartTs(pRuntimeEnv, pos, pDataBlock, tsCols, &win);
|
||||
if (interp) {
|
||||
setResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
|
||||
}
|
||||
}
|
||||
|
||||
bool closed = getTimeWindowResStatus(pWindowResInfo, curTimeWindowIndex(pWindowResInfo));
|
||||
alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
if (!alreadyInterp) {
|
||||
bool interp = setTimeWindowInterpolationEndTs(pRuntimeEnv, pQuery->pos + forwardStep - 1, pDataBlock, tsCols,
|
||||
pDataBlockInfo->window.ekey, &win);
|
||||
if (interp) {
|
||||
setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
bool closed = getResultRowStatus(pWindowResInfo, curTimeWindowIndex(pWindowResInfo));
|
||||
doRowwiseApplyFunctions(pRuntimeEnv, closed, &win, offset);
|
||||
|
||||
STimeWindow nextWin = win;
|
||||
|
@ -1373,12 +1583,32 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
|
|||
|
||||
// null data, failed to allocate more memory buffer
|
||||
hasTimeWindow = false;
|
||||
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo, &nextWin, masterScan, &hasTimeWindow) != TSDB_CODE_SUCCESS) {
|
||||
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo, &nextWin, masterScan, &hasTimeWindow, &pResult) != TSDB_CODE_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (hasTimeWindow) {
|
||||
closed = getTimeWindowResStatus(pWindowResInfo, curTimeWindowIndex(pWindowResInfo));
|
||||
/*
|
||||
// window start(end) key interpolation
|
||||
if (pRuntimeEnv->timeWindowInterpo) {
|
||||
bool alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
|
||||
if (!alreadyInterp) {
|
||||
bool interp = setTimeWindowInterpolationStartTs(pRuntimeEnv, startPos, pDataBlock, tsCols, &nextWin);
|
||||
if (interp) {
|
||||
setResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
|
||||
}
|
||||
}
|
||||
|
||||
alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
if (!alreadyInterp) {
|
||||
bool interp = setTimeWindowInterpolationEndTs(pRuntimeEnv, startPos + forwardStep - 1, pDataBlock, tsCols, pDataBlockInfo->window.ekey, &nextWin);
|
||||
if (interp) {
|
||||
setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
closed = getResultRowStatus(pWindowResInfo, curTimeWindowIndex(pWindowResInfo));
|
||||
doRowwiseApplyFunctions(pRuntimeEnv, closed, &nextWin, offset);
|
||||
}
|
||||
}
|
||||
|
@ -1403,6 +1633,8 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
|
|||
}
|
||||
}
|
||||
|
||||
// prev = tsCols[offset];
|
||||
|
||||
if (pRuntimeEnv->pTSBuf != NULL) {
|
||||
// if timestamp filter list is empty, quit current query
|
||||
if (!tsBufNextPos(pRuntimeEnv->pTSBuf)) {
|
||||
|
@ -1528,10 +1760,10 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, void* inputData, TSKEY
|
|||
* top/bottom values emerge, so does diff function
|
||||
*/
|
||||
if (functionId == TSDB_FUNC_TWA) {
|
||||
SResultRowCellInfo* pInfo = GET_RES_INFO(pCtx);
|
||||
STwaInfo *pTWAInfo = (STwaInfo*) GET_ROWCELL_INTERBUF(pInfo);
|
||||
pTWAInfo->SKey = pQuery->window.skey;
|
||||
pTWAInfo->EKey = pQuery->window.ekey;
|
||||
pCtx->param[1].i64Key = pQuery->window.skey;
|
||||
pCtx->param[1].nType = TSDB_DATA_TYPE_BIGINT;
|
||||
pCtx->param[2].i64Key = pQuery->window.ekey;
|
||||
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
|
||||
}
|
||||
|
||||
} else if (functionId == TSDB_FUNC_ARITHM) {
|
||||
|
@ -1677,6 +1909,8 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
|
|||
pCtx->functionId = pSqlFuncMsg->functionId;
|
||||
pCtx->stableQuery = pRuntimeEnv->stableQuery;
|
||||
pCtx->interBufBytes = pQuery->pExpr1[i].interBytes;
|
||||
pCtx->start.key = INT64_MIN;
|
||||
pCtx->end.key = INT64_MIN;
|
||||
|
||||
pCtx->numOfParams = pSqlFuncMsg->numOfParams;
|
||||
for (int32_t j = 0; j < pCtx->numOfParams; ++j) {
|
||||
|
@ -1711,6 +1945,8 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
|
|||
|
||||
}
|
||||
|
||||
*(int64_t*) pRuntimeEnv->prevRow[0] = INT64_MIN;
|
||||
|
||||
// if it is group by normal column, do not set output buffer, the output buffer is pResult
|
||||
// fixed output query/multi-output query for normal table
|
||||
if (!pRuntimeEnv->groupbyNormalCol && !pRuntimeEnv->stableQuery && !QUERY_IS_INTERVAL_QUERY(pRuntimeEnv->pQuery)) {
|
||||
|
@ -1781,6 +2017,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
|
|||
tfree(pRuntimeEnv->offset);
|
||||
tfree(pRuntimeEnv->keyBuf);
|
||||
tfree(pRuntimeEnv->rowCellInfoOffset);
|
||||
tfree(pRuntimeEnv->prevRow);
|
||||
|
||||
taosHashCleanup(pRuntimeEnv->pResultRowHashTable);
|
||||
pRuntimeEnv->pResultRowHashTable = NULL;
|
||||
|
@ -2279,12 +2516,14 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo * pW
|
|||
// the filter result may be incorrect. So in case of interval query, we need to set the correct time output buffer
|
||||
if (QUERY_IS_INTERVAL_QUERY(pQuery)) {
|
||||
bool hasTimeWindow = false;
|
||||
SResultRow* pResult = NULL;
|
||||
|
||||
bool masterScan = IS_MASTER_SCAN(pRuntimeEnv);
|
||||
|
||||
TSKEY k = QUERY_IS_ASC_QUERY(pQuery)? pBlockInfo->window.skey:pBlockInfo->window.ekey;
|
||||
|
||||
STimeWindow win = getActiveTimeWindow(pWindowResInfo, k, pQuery);
|
||||
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pBlockInfo, &win, masterScan, &hasTimeWindow) !=
|
||||
if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pBlockInfo, &win, masterScan, &hasTimeWindow, &pResult) !=
|
||||
TSDB_CODE_SUCCESS) {
|
||||
// todo handle error in set result for timewindow
|
||||
}
|
||||
|
@ -3266,7 +3505,7 @@ static void disableFuncInReverseScanImpl(SQueryRuntimeEnv* pRuntimeEnv, SWindowR
|
|||
SQuery* pQuery = pRuntimeEnv->pQuery;
|
||||
|
||||
for (int32_t i = 0; i < pWindowResInfo->size; ++i) {
|
||||
bool closed = getTimeWindowResStatus(pWindowResInfo, i);
|
||||
bool closed = getResultRowStatus(pWindowResInfo, i);
|
||||
if (!closed) {
|
||||
continue;
|
||||
}
|
||||
|
@ -4617,6 +4856,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo
|
|||
|
||||
pRuntimeEnv->topBotQuery = isTopBottomQuery(pQuery);
|
||||
pRuntimeEnv->hasTagResults = hasTagValOutput(pQuery);
|
||||
pRuntimeEnv->timeWindowInterpo = timeWindowInterpoRequired(pQuery);
|
||||
|
||||
setScanLimitationByResultBuffer(pQuery);
|
||||
|
||||
|
@ -6447,9 +6687,11 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
|
|||
goto _cleanup;
|
||||
}
|
||||
|
||||
int32_t srcSize = 0;
|
||||
for (int16_t i = 0; i < numOfCols; ++i) {
|
||||
pQuery->colList[i] = pQueryMsg->colList[i];
|
||||
pQuery->colList[i].filters = tscFilterInfoClone(pQueryMsg->colList[i].filters, pQuery->colList[i].numOfFilters);
|
||||
srcSize += pQuery->colList[i].bytes;
|
||||
}
|
||||
|
||||
// calculate the result row size
|
||||
|
@ -6518,6 +6760,14 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
|
|||
pQInfo->runtimeEnv.pResultRowHashTable = taosHashInit(pTableGroupInfo->numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
pQInfo->runtimeEnv.keyBuf = malloc(TSDB_MAX_BYTES_PER_ROW);
|
||||
pQInfo->runtimeEnv.pool = initResultRowPool(getWindowResultSize(&pQInfo->runtimeEnv));
|
||||
pQInfo->runtimeEnv.prevRow = malloc(POINTER_BYTES * pQuery->numOfCols + srcSize);
|
||||
|
||||
char* start = POINTER_BYTES * pQuery->numOfCols + (char*) pQInfo->runtimeEnv.prevRow;
|
||||
pQInfo->runtimeEnv.prevRow[0] = start;
|
||||
|
||||
for(int32_t i = 1; i < pQuery->numOfCols; ++i) {
|
||||
pQInfo->runtimeEnv.prevRow[i] = pQInfo->runtimeEnv.prevRow[i - 1] + pQuery->colList[i-1].bytes;
|
||||
}
|
||||
|
||||
pQInfo->pBuf = calloc(pTableGroupInfo->numOfTables, sizeof(STableQueryInfo));
|
||||
if (pQInfo->pBuf == NULL) {
|
||||
|
|
|
@ -423,9 +423,8 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) {
|
|||
unlink(pResultBuf->path);
|
||||
tfree(pResultBuf->path);
|
||||
|
||||
SHashMutableIterator* iter = taosHashCreateIter(pResultBuf->groupSet);
|
||||
while(taosHashIterNext(iter)) {
|
||||
SArray** p = (SArray**) taosHashIterGet(iter);
|
||||
SArray** p = taosHashIterate(pResultBuf->groupSet, NULL);
|
||||
while(p) {
|
||||
size_t n = taosArrayGetSize(*p);
|
||||
for(int32_t i = 0; i < n; ++i) {
|
||||
SPageInfo* pi = taosArrayGetP(*p, i);
|
||||
|
@ -434,10 +433,9 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) {
|
|||
}
|
||||
|
||||
taosArrayDestroy(*p);
|
||||
p = taosHashIterate(pResultBuf->groupSet, p);
|
||||
}
|
||||
|
||||
taosHashDestroyIter(iter);
|
||||
|
||||
tdListFree(pResultBuf->lruList);
|
||||
taosArrayDestroy(pResultBuf->emptyDummyIdList);
|
||||
taosHashCleanup(pResultBuf->groupSet);
|
||||
|
|
|
@ -395,11 +395,10 @@ uint64_t getResultInfoUId(SQueryRuntimeEnv* pRuntimeEnv) {
|
|||
}
|
||||
|
||||
SQuery* pQuery = pRuntimeEnv->pQuery;
|
||||
if ((pQuery->checkBuffer == 1 && pQuery->interval.interval == 0) || isPointInterpoQuery(pQuery) ||
|
||||
pRuntimeEnv->groupbyNormalCol) {
|
||||
if (pQuery->interval.interval == 0 || isPointInterpoQuery(pQuery) || pRuntimeEnv->groupbyNormalCol) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
STableId* id = TSDB_TABLEID(pRuntimeEnv->pQuery->current);
|
||||
STableId* id = TSDB_TABLEID(pRuntimeEnv->pQuery->current->pTable);
|
||||
return id->uid;
|
||||
}
|
|
@ -371,10 +371,13 @@ void taosCloseTcpConnection(void *chandle) {
|
|||
|
||||
int taosSendTcpData(uint32_t ip, uint16_t port, void *data, int len, void *chandle) {
|
||||
SFdObj *pFdObj = chandle;
|
||||
|
||||
if (pFdObj == NULL || pFdObj->signature != pFdObj) return -1;
|
||||
SThreadObj *pThreadObj = pFdObj->pThreadObj;
|
||||
|
||||
return taosWriteMsg(pFdObj->fd, data, len);
|
||||
int ret = taosWriteMsg(pFdObj->fd, data, len);
|
||||
tTrace("%s %p TCP data is sent, FD:%p fd:%d bytes:%d", pThreadObj->label, pFdObj->thandle, pFdObj, pFdObj->fd, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void taosReportBrokenLink(SFdObj *pFdObj) {
|
||||
|
@ -409,7 +412,7 @@ static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) {
|
|||
|
||||
headLen = taosReadMsg(pFdObj->fd, &rpcHead, sizeof(SRpcHead));
|
||||
if (headLen != sizeof(SRpcHead)) {
|
||||
tDebug("%s %p read error, headLen:%d", pThreadObj->label, pFdObj->thandle, headLen);
|
||||
tDebug("%s %p read error, FD:%p headLen:%d", pThreadObj->label, pFdObj->thandle, pFdObj, headLen);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -420,7 +423,7 @@ static int taosReadTcpData(SFdObj *pFdObj, SRecvInfo *pInfo) {
|
|||
tError("%s %p TCP malloc(size:%d) fail", pThreadObj->label, pFdObj->thandle, msgLen);
|
||||
return -1;
|
||||
} else {
|
||||
tTrace("TCP malloc mem:%p size:%d", buffer, size);
|
||||
tTrace("%s %p read data, FD:%p fd:%d TCP malloc mem:%p", pThreadObj->label, pFdObj->thandle, pFdObj, pFdObj->fd, buffer);
|
||||
}
|
||||
|
||||
msg = buffer + tsRpcOverhead;
|
||||
|
@ -583,8 +586,8 @@ static void taosFreeFdObj(SFdObj *pFdObj) {
|
|||
|
||||
pthread_mutex_unlock(&pThreadObj->mutex);
|
||||
|
||||
tDebug("%s %p TCP connection is closed, FD:%p numOfFds:%d",
|
||||
pThreadObj->label, pFdObj->thandle, pFdObj, pThreadObj->numOfFds);
|
||||
tDebug("%s %p TCP connection is closed, FD:%p fd:%d numOfFds:%d",
|
||||
pThreadObj->label, pFdObj->thandle, pFdObj, pFdObj->fd, pThreadObj->numOfFds);
|
||||
|
||||
tfree(pFdObj);
|
||||
}
|
||||
|
|
|
@ -139,6 +139,7 @@ typedef struct SsyncPeer {
|
|||
char id[TSDB_EP_LEN + 32]; // peer vgId + end point
|
||||
uint64_t version;
|
||||
uint64_t sversion; // track the peer version in retrieve process
|
||||
uint64_t lastVer; // track the file version while retrieve
|
||||
int32_t syncFd;
|
||||
int32_t peerFd; // forward FD
|
||||
int32_t numOfRetrieves; // number of retrieves tried
|
||||
|
@ -172,6 +173,7 @@ typedef struct SSyncNode {
|
|||
FNotifyRole notifyRole;
|
||||
FNotifyFlowCtrl notifyFlowCtrl;
|
||||
FNotifyFileSynced notifyFileSynced;
|
||||
FGetFileVersion getFileVersion;
|
||||
pthread_mutex_t mutex;
|
||||
} SSyncNode;
|
||||
|
||||
|
|
|
@ -196,6 +196,7 @@ int64_t syncStart(const SSyncInfo *pInfo) {
|
|||
pNode->confirmForward = pInfo->confirmForward;
|
||||
pNode->notifyFlowCtrl = pInfo->notifyFlowCtrl;
|
||||
pNode->notifyFileSynced = pInfo->notifyFileSynced;
|
||||
pNode->getFileVersion = pInfo->getFileVersion;
|
||||
|
||||
pNode->selfIndex = -1;
|
||||
pNode->vgId = pInfo->vgId;
|
||||
|
@ -540,7 +541,7 @@ static SSyncPeer *syncAddPeer(SSyncNode *pNode, const SNodeInfo *pInfo) {
|
|||
pPeer->ip = ip;
|
||||
pPeer->port = pInfo->nodePort;
|
||||
pPeer->fqdn[sizeof(pPeer->fqdn) - 1] = 0;
|
||||
snprintf(pPeer->id, sizeof(pPeer->id), "vgId:%d, peer:%s:%u", pNode->vgId, pPeer->fqdn, pPeer->port);
|
||||
snprintf(pPeer->id, sizeof(pPeer->id), "vgId:%d, nodeId:%d", pNode->vgId, pPeer->nodeId);
|
||||
|
||||
pPeer->peerFd = -1;
|
||||
pPeer->syncFd = -1;
|
||||
|
@ -1143,8 +1144,7 @@ static void syncProcessIncommingConnection(int32_t connFd, uint32_t sourceIp) {
|
|||
pPeer->syncFd = connFd;
|
||||
syncCreateRestoreDataThread(pPeer);
|
||||
} else {
|
||||
sDebug("%s, TCP connection is already up(pfd:%d), close one, new pfd:%d sfd:%d", pPeer->id, pPeer->peerFd, connFd,
|
||||
pPeer->syncFd);
|
||||
sDebug("%s, TCP connection is up, pfd:%d sfd:%d, old pfd:%d", pPeer->id, connFd, pPeer->syncFd, pPeer->peerFd);
|
||||
syncClosePeerConn(pPeer);
|
||||
pPeer->peerFd = connFd;
|
||||
pPeer->pConn = taosAllocateTcpConn(tsTcpPool, pPeer, connFd);
|
||||
|
|
|
@ -52,12 +52,12 @@ static void syncRemoveExtraFile(SSyncPeer *pPeer, int32_t sindex, int32_t eindex
|
|||
|
||||
static int32_t syncRestoreFile(SSyncPeer *pPeer, uint64_t *fversion) {
|
||||
SSyncNode *pNode = pPeer->pSyncNode;
|
||||
SFileInfo minfo; memset(&minfo, 0, sizeof(minfo)); /* = {0}; */ // master file info
|
||||
SFileInfo sinfo; memset(&sinfo, 0, sizeof(sinfo)); /* = {0}; */ // slave file info
|
||||
SFileAck fileAck;
|
||||
SFileInfo minfo; memset(&minfo, 0, sizeof(SFileInfo)); /* = {0}; */
|
||||
SFileInfo sinfo; memset(&sinfo, 0, sizeof(SFileInfo)); /* = {0}; */
|
||||
SFileAck fileAck = {0};
|
||||
int32_t code = -1;
|
||||
char name[TSDB_FILENAME_LEN * 2] = {0};
|
||||
uint32_t pindex = 0; // index in last restore
|
||||
uint32_t pindex = 0; // index in last restore
|
||||
bool fileChanged = false;
|
||||
|
||||
*fversion = 0;
|
||||
|
@ -134,7 +134,7 @@ static int32_t syncRestoreFile(SSyncPeer *pPeer, uint64_t *fversion) {
|
|||
// data file is changed, code shall be set to 1
|
||||
*fversion = minfo.fversion;
|
||||
code = 1;
|
||||
sDebug("%s, file changed while restore file", pPeer->id);
|
||||
sDebug("%s, file changed after restore file, fver:%" PRIu64, pPeer->id, *fversion);
|
||||
}
|
||||
|
||||
if (code < 0) {
|
||||
|
@ -160,7 +160,7 @@ static int32_t syncRestoreWal(SSyncPeer *pPeer) {
|
|||
}
|
||||
|
||||
if (pHead->len == 0) {
|
||||
sDebug("%s, wal is synced over", pPeer->id);
|
||||
sDebug("%s, wal is synced over, last wver:%" PRIu64, pPeer->id, lastVer);
|
||||
code = 0;
|
||||
break;
|
||||
} // wal sync over
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include <sys/inotify.h>
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
#include "tutil.h"
|
||||
#include "tglobal.h"
|
||||
|
@ -25,85 +26,35 @@
|
|||
#include "tsync.h"
|
||||
#include "syncInt.h"
|
||||
|
||||
static int32_t syncAddIntoWatchList(SSyncPeer *pPeer, char *name) {
|
||||
sDebug("%s, start to monitor:%s", pPeer->id, name);
|
||||
static int32_t syncAreFilesModified(SSyncNode *pNode, SSyncPeer *pPeer) {
|
||||
if (pNode->getFileVersion == NULL) return TSDB_CODE_SUCCESS;
|
||||
|
||||
if (pPeer->notifyFd <= 0) {
|
||||
pPeer->watchNum = 0;
|
||||
pPeer->notifyFd = inotify_init1(IN_NONBLOCK);
|
||||
if (pPeer->notifyFd < 0) {
|
||||
sError("%s, failed to init inotify since %s", pPeer->id, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pPeer->watchFd == NULL) pPeer->watchFd = malloc(sizeof(int32_t) * tsMaxWatchFiles);
|
||||
if (pPeer->watchFd == NULL) {
|
||||
sError("%s, failed to allocate watchFd", pPeer->id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(pPeer->watchFd, -1, sizeof(int32_t) * tsMaxWatchFiles);
|
||||
uint64_t fver = 0;
|
||||
int32_t code = (*pNode->getFileVersion)(pNode->vgId, &fver);
|
||||
if (code != 0) {
|
||||
sInfo("%s, vnode is commiting while retrieve, last fver:%" PRIu64, pPeer->id, pPeer->lastVer);
|
||||
pPeer->fileChanged = 1;
|
||||
return TSDB_CODE_SYN_VND_COMMITING;
|
||||
}
|
||||
|
||||
int32_t *wd = pPeer->watchFd + pPeer->watchNum;
|
||||
|
||||
if (*wd >= 0) {
|
||||
if (inotify_rm_watch(pPeer->notifyFd, *wd) < 0) {
|
||||
sError("%s, failed to remove wd:%d since %s", pPeer->id, *wd, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (fver != pPeer->lastVer) {
|
||||
sInfo("%s, files are modified while retrieve, fver:%" PRIu64 ", last fver:%" PRIu64, pPeer->id, fver, pPeer->lastVer);
|
||||
pPeer->fileChanged = 1;
|
||||
return TSDB_CODE_SYN_FILE_CHNAGED;
|
||||
}
|
||||
|
||||
*wd = inotify_add_watch(pPeer->notifyFd, name, IN_MODIFY | IN_DELETE);
|
||||
if (*wd == -1) {
|
||||
sError("%s, failed to add %s since %s", pPeer->id, name, strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
sDebug("%s, monitor %s, wd:%d watchNum:%d", pPeer->id, name, *wd, pPeer->watchNum);
|
||||
}
|
||||
|
||||
pPeer->watchNum = (pPeer->watchNum + 1) % tsMaxWatchFiles;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t syncAreFilesModified(SSyncPeer *pPeer) {
|
||||
if (pPeer->notifyFd <= 0) return 0;
|
||||
|
||||
char buf[2048];
|
||||
int32_t len = read(pPeer->notifyFd, buf, sizeof(buf));
|
||||
if (len < 0 && errno != EAGAIN) {
|
||||
sError("%s, failed to read notify FD since %s", pPeer->id, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
if (len > 0) {
|
||||
const struct inotify_event *event;
|
||||
char *ptr;
|
||||
for (ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + event->len) {
|
||||
event = (const struct inotify_event *)ptr;
|
||||
if ((event->mask & IN_MODIFY) || (event->mask & IN_DELETE)) {
|
||||
sDebug("%s, processed file is changed", pPeer->id);
|
||||
pPeer->fileChanged = 1;
|
||||
code = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
pPeer->fileChanged = 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t syncRetrieveFile(SSyncPeer *pPeer) {
|
||||
SSyncNode *pNode = pPeer->pSyncNode;
|
||||
SFileInfo fileInfo;
|
||||
SFileAck fileAck;
|
||||
int32_t code = -1;
|
||||
SFileInfo fileInfo; memset(&fileInfo, 0, sizeof(SFileInfo));
|
||||
SFileAck fileAck = {0};
|
||||
int32_t code = TSDB_CODE_SYN_APP_ERROR;
|
||||
char name[TSDB_FILENAME_LEN * 2] = {0};
|
||||
|
||||
memset(&fileInfo, 0, sizeof(fileInfo));
|
||||
memset(&fileAck, 0, sizeof(fileAck));
|
||||
if (pNode->getFileVersion) (*pNode->getFileVersion)(pNode->vgId, &pPeer->lastVer);
|
||||
|
||||
while (1) {
|
||||
// retrieve file info
|
||||
|
@ -111,24 +62,27 @@ static int32_t syncRetrieveFile(SSyncPeer *pPeer) {
|
|||
fileInfo.magic = (*pNode->getFileInfo)(pNode->vgId, fileInfo.name, &fileInfo.index, TAOS_SYNC_MAX_INDEX,
|
||||
&fileInfo.size, &fileInfo.fversion);
|
||||
// fileInfo.size = htonl(size);
|
||||
sDebug("%s, file:%s info is sent, size:%" PRId64, pPeer->id, fileInfo.name, fileInfo.size);
|
||||
|
||||
// send the file info
|
||||
int32_t ret = taosWriteMsg(pPeer->syncFd, &(fileInfo), sizeof(fileInfo));
|
||||
if (ret < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
sError("%s, failed to write file:%s info while retrieve file since %s", pPeer->id, fileInfo.name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
// if no file anymore, break
|
||||
if (fileInfo.magic == 0 || fileInfo.name[0] == 0) {
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
sDebug("%s, no more files to sync", pPeer->id);
|
||||
code = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// wait for the ack from peer
|
||||
ret = taosReadMsg(pPeer->syncFd, &fileAck, sizeof(fileAck));
|
||||
if (ret < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
sError("%s, failed to read file:%s ack while retrieve file since %s", pPeer->id, fileInfo.name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
@ -136,15 +90,6 @@ static int32_t syncRetrieveFile(SSyncPeer *pPeer) {
|
|||
// set the peer sync version
|
||||
pPeer->sversion = fileInfo.fversion;
|
||||
|
||||
// get the full path to file
|
||||
snprintf(name, sizeof(name), "%s/%s", pNode->path, fileInfo.name);
|
||||
|
||||
// add the file into watch list
|
||||
if (syncAddIntoWatchList(pPeer, name) < 0) {
|
||||
sError("%s, failed to watch file:%s while retrieve file since %s", pPeer->id, fileInfo.name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
// if sync is not required, continue
|
||||
if (fileAck.sync == 0) {
|
||||
fileInfo.index++;
|
||||
|
@ -152,9 +97,13 @@ static int32_t syncRetrieveFile(SSyncPeer *pPeer) {
|
|||
continue;
|
||||
}
|
||||
|
||||
// get the full path to file
|
||||
snprintf(name, sizeof(name), "%s/%s", pNode->path, fileInfo.name);
|
||||
|
||||
// send the file to peer
|
||||
int32_t sfd = open(name, O_RDONLY);
|
||||
if (sfd < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
sError("%s, failed to open file:%s while retrieve file since %s", pPeer->id, fileInfo.name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
@ -162,22 +111,21 @@ static int32_t syncRetrieveFile(SSyncPeer *pPeer) {
|
|||
ret = taosSendFile(pPeer->syncFd, sfd, NULL, fileInfo.size);
|
||||
close(sfd);
|
||||
if (ret < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
sError("%s, failed to send file:%s while retrieve file since %s", pPeer->id, fileInfo.name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
sDebug("%s, %s is sent, size:%" PRId64, pPeer->id, name, fileInfo.size);
|
||||
sDebug("%s, file:%s is sent, size:%" PRId64, pPeer->id, fileInfo.name, fileInfo.size);
|
||||
fileInfo.index++;
|
||||
|
||||
// check if processed files are modified
|
||||
if (syncAreFilesModified(pPeer) != 0) {
|
||||
sInfo("%s, file:%s are modified while retrieve file since %s", pPeer->id, fileInfo.name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
code = syncAreFilesModified(pNode, pPeer);
|
||||
if (code != TSDB_CODE_SUCCESS) break;
|
||||
}
|
||||
|
||||
if (code < 0) {
|
||||
sError("%s, failed to retrieve file", pPeer->id);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
sError("%s, failed to retrieve file since %s", pPeer->id, tstrerror(code));
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -308,9 +256,9 @@ static int32_t syncRetrieveLastWal(SSyncPeer *pPeer, char *name, uint64_t fversi
|
|||
static int32_t syncProcessLastWal(SSyncPeer *pPeer, char *wname, int64_t index) {
|
||||
SSyncNode *pNode = pPeer->pSyncNode;
|
||||
int32_t code = -1;
|
||||
char fname[TSDB_FILENAME_LEN * 2]; // full path to wal file
|
||||
char fname[TSDB_FILENAME_LEN * 2] = {0}; // full path to wal file
|
||||
|
||||
if (syncAreFilesModified(pPeer) != 0) return -1;
|
||||
if (syncAreFilesModified(pNode, pPeer) != 0) return -1;
|
||||
|
||||
while (1) {
|
||||
int32_t once = 0; // last WAL has once ever been processed
|
||||
|
@ -429,9 +377,7 @@ static int32_t syncRetrieveWal(SSyncPeer *pPeer) {
|
|||
close(sfd);
|
||||
if (code < 0) break;
|
||||
|
||||
index++;
|
||||
|
||||
if (syncAreFilesModified(pPeer) != 0) break;
|
||||
if (syncAreFilesModified(pNode, pPeer) != 0) break;
|
||||
}
|
||||
|
||||
if (code == 0) {
|
||||
|
@ -481,18 +427,18 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) {
|
|||
|
||||
pPeer->sversion = 0;
|
||||
pPeer->sstatus = TAOS_SYNC_STATUS_FILE;
|
||||
sInfo("%s, start to retrieve file, set sstatus:%s", pPeer->id, syncStatus[pPeer->sstatus]);
|
||||
sInfo("%s, start to retrieve files, set sstatus:%s", pPeer->id, syncStatus[pPeer->sstatus]);
|
||||
if (syncRetrieveFile(pPeer) < 0) {
|
||||
sError("%s, failed to retrieve file", pPeer->id);
|
||||
sError("%s, failed to retrieve files", pPeer->id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// if no files are synced, there must be wal to sync, sversion must be larger than one
|
||||
if (pPeer->sversion == 0) pPeer->sversion = 1;
|
||||
|
||||
sInfo("%s, start to retrieve wal", pPeer->id);
|
||||
sInfo("%s, start to retrieve wals", pPeer->id);
|
||||
if (syncRetrieveWal(pPeer) < 0) {
|
||||
sError("%s, failed to retrieve wal", pPeer->id);
|
||||
sError("%s, failed to retrieve wals", pPeer->id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -506,7 +452,6 @@ void *syncRetrieveData(void *param) {
|
|||
|
||||
if (pNode->notifyFlowCtrl) (*pNode->notifyFlowCtrl)(pNode->vgId, pPeer->numOfRetrieves);
|
||||
|
||||
pPeer->fileChanged = 0;
|
||||
pPeer->syncFd = taosOpenTcpClientSocket(pPeer->ip, pPeer->port, 0);
|
||||
if (pPeer->syncFd < 0) {
|
||||
sError("%s, failed to open socket to sync", pPeer->id);
|
||||
|
|
|
@ -31,16 +31,18 @@ extern "C" {
|
|||
typedef void (*_hash_free_fn_t)(void *param);
|
||||
|
||||
typedef struct SHashNode {
|
||||
// char *key;
|
||||
struct SHashNode *next;
|
||||
uint32_t hashVal; // the hash value of key
|
||||
uint32_t keyLen; // length of the key
|
||||
// char *data;
|
||||
size_t dataLen; // length of data
|
||||
int8_t count; // reference count
|
||||
int8_t removed; // flag to indicate removed
|
||||
char data[];
|
||||
} SHashNode;
|
||||
|
||||
#define GET_HASH_NODE_KEY(_n) ((char*)(_n) + sizeof(SHashNode))
|
||||
#define GET_HASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SHashNode) + (_n)->keyLen)
|
||||
|
||||
#define GET_HASH_NODE_KEY(_n) ((char*)(_n) + sizeof(SHashNode) + (_n)->dataLen)
|
||||
#define GET_HASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SHashNode))
|
||||
#define GET_HASH_PNODE(_n) ((char*)(_n) - sizeof(SHashNode));
|
||||
typedef enum SHashLockTypeE {
|
||||
HASH_NO_LOCK = 0,
|
||||
HASH_ENTRY_LOCK = 1,
|
||||
|
@ -65,15 +67,6 @@ typedef struct SHashObj {
|
|||
SArray *pMemBlock; // memory block allocated for SHashEntry
|
||||
} SHashObj;
|
||||
|
||||
typedef struct SHashMutableIterator {
|
||||
SHashObj *pHashObj;
|
||||
int32_t entryIndex;
|
||||
SHashNode *pCur;
|
||||
SHashNode *pNext; // current node can be deleted for mutable iterator, so keep the next one before return current
|
||||
size_t numOfChecked; // already check number of elements in hash table
|
||||
size_t numOfEntries; // number of entries while the iterator is created
|
||||
} SHashMutableIterator;
|
||||
|
||||
/**
|
||||
* init the hash table
|
||||
*
|
||||
|
@ -142,33 +135,9 @@ int32_t taosHashCondTraverse(SHashObj *pHashObj, bool (*fp)(void *, void *), voi
|
|||
*/
|
||||
void taosHashCleanup(SHashObj *pHashObj);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pHashObj
|
||||
* @return
|
||||
*/
|
||||
SHashMutableIterator* taosHashCreateIter(SHashObj *pHashObj);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param iter
|
||||
* @return
|
||||
*/
|
||||
bool taosHashIterNext(SHashMutableIterator *iter);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param iter
|
||||
* @return
|
||||
*/
|
||||
void *taosHashIterGet(SHashMutableIterator *iter);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param iter
|
||||
* @return
|
||||
*/
|
||||
void* taosHashDestroyIter(SHashMutableIterator* iter);
|
||||
/*
|
||||
void *SHashMutableIterator* taosHashCreateIter(SHashObj *pHashObj, void *);
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -179,6 +148,9 @@ int32_t taosHashGetMaxOverflowLinkLength(const SHashObj *pHashObj);
|
|||
|
||||
size_t taosHashGetMemSize(const SHashObj *pHashObj);
|
||||
|
||||
void *taosHashIterate(SHashObj *pHashObj, void *p);
|
||||
void taosHashCancelIterate(SHashObj *pHashObj, void *p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,23 +20,26 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
// init taos file module
|
||||
int32_t tfinit();
|
||||
int32_t tfInit();
|
||||
|
||||
// clean up taos file module
|
||||
void tfcleanup();
|
||||
void tfCleanup();
|
||||
|
||||
// the same syntax as UNIX standard open/close/read/write
|
||||
// but FD is int64_t and will never be reused
|
||||
int64_t tfopen(const char *pathname, int32_t flags);
|
||||
int64_t tfclose(int64_t tfd);
|
||||
int64_t tfwrite(int64_t tfd, void *buf, int64_t count);
|
||||
int64_t tfread(int64_t tfd, void *buf, int64_t count);
|
||||
int64_t tfOpen(const char *pathname, int32_t flags);
|
||||
int64_t tfOpenM(const char *pathname, int32_t flags, mode_t mode);
|
||||
int64_t tfClose(int64_t tfd);
|
||||
int64_t tfWrite(int64_t tfd, void *buf, int64_t count);
|
||||
int64_t tfRead(int64_t tfd, void *buf, int64_t count);
|
||||
int32_t tfFsync(int64_t tfd);
|
||||
bool tfValid(int64_t tfd);
|
||||
int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence);
|
||||
int32_t tfFtruncate(int64_t tfd, int64_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_TREF_H
|
||||
#endif // TDENGINE_TFILE_H
|
||||
|
|
|
@ -76,7 +76,7 @@ static FORCE_INLINE int32_t taosHashCapacity(int32_t length) {
|
|||
static FORCE_INLINE SHashNode *doSearchInEntryList(SHashEntry *pe, const void *key, size_t keyLen, uint32_t hashVal) {
|
||||
SHashNode *pNode = pe->next;
|
||||
while (pNode) {
|
||||
if ((pNode->keyLen == keyLen) && (memcmp(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0)) {
|
||||
if ((pNode->keyLen == keyLen) && (memcmp(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) && pNode->removed == 0) {
|
||||
assert(pNode->hashVal == hashVal);
|
||||
break;
|
||||
}
|
||||
|
@ -114,15 +114,25 @@ static SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *p
|
|||
* @param dsize size of actual data
|
||||
* @return hash node
|
||||
*/
|
||||
static FORCE_INLINE SHashNode *doUpdateHashNode(SHashEntry* pe, SHashNode* prev, SHashNode *pNode, SHashNode *pNewNode) {
|
||||
static FORCE_INLINE SHashNode *doUpdateHashNode(SHashObj *pHashObj, SHashEntry* pe, SHashNode* prev, SHashNode *pNode, SHashNode *pNewNode) {
|
||||
assert(pNode->keyLen == pNewNode->keyLen);
|
||||
|
||||
pNode->count--;
|
||||
if (prev != NULL) {
|
||||
prev->next = pNewNode;
|
||||
} else {
|
||||
pe->next = pNewNode;
|
||||
}
|
||||
|
||||
pNewNode->next = pNode->next;
|
||||
if (pNode->count <= 0) {
|
||||
pNewNode->next = pNode->next;
|
||||
DO_FREE_HASH_NODE(pNode);
|
||||
} else {
|
||||
pNewNode->next = pNode;
|
||||
pe->num++;
|
||||
atomic_add_fetch_64(&pHashObj->size, 1);
|
||||
}
|
||||
|
||||
return pNewNode;
|
||||
}
|
||||
|
||||
|
@ -139,7 +149,6 @@ static void pushfrontNodeInEntryList(SHashEntry *pEntry, SHashNode *pNode);
|
|||
* @param pIter
|
||||
* @return
|
||||
*/
|
||||
static SHashNode *getNextHashNode(SHashMutableIterator *pIter);
|
||||
|
||||
SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTypeE type) {
|
||||
if (capacity == 0 || fn == NULL) {
|
||||
|
@ -213,7 +222,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
|
|||
|
||||
SHashNode* prev = NULL;
|
||||
while (pNode) {
|
||||
if ((pNode->keyLen == keyLen) && (memcmp(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0)) {
|
||||
if ((pNode->keyLen == keyLen) && (memcmp(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) && pNode->removed == 0) {
|
||||
assert(pNode->hashVal == hashVal);
|
||||
break;
|
||||
}
|
||||
|
@ -244,8 +253,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
|
|||
} else {
|
||||
// not support the update operation, return error
|
||||
if (pHashObj->enableUpdate) {
|
||||
doUpdateHashNode(pe, prev, pNode, pNewNode);
|
||||
DO_FREE_HASH_NODE(pNode);
|
||||
doUpdateHashNode(pHashObj, pe, prev, pNode, pNewNode);
|
||||
} else {
|
||||
DO_FREE_HASH_NODE(pNewNode);
|
||||
}
|
||||
|
@ -335,22 +343,10 @@ int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLe
|
|||
int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity);
|
||||
SHashEntry *pe = pHashObj->hashList[slot];
|
||||
|
||||
// no data, return directly
|
||||
if (pe->num == 0) {
|
||||
__rd_unlock(&pHashObj->lock, pHashObj->type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosWLockLatch(&pe->latch);
|
||||
}
|
||||
|
||||
if (pe->num == 0) {
|
||||
assert(pe->next == NULL);
|
||||
} else {
|
||||
assert(pe->next != NULL);
|
||||
}
|
||||
|
||||
// double check after locked
|
||||
if (pe->num == 0) {
|
||||
assert(pe->next == NULL);
|
||||
|
@ -360,37 +356,37 @@ int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLe
|
|||
return -1;
|
||||
}
|
||||
|
||||
int code = -1;
|
||||
SHashNode *pNode = pe->next;
|
||||
SHashNode *pRes = NULL;
|
||||
SHashNode *prevNode = NULL;
|
||||
|
||||
// remove it
|
||||
if ((pNode->keyLen == keyLen) && (memcmp(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0)) {
|
||||
pe->num -= 1;
|
||||
pRes = pNode;
|
||||
pe->next = pNode->next;
|
||||
} else {
|
||||
while (pNode->next != NULL) {
|
||||
if (((pNode->next)->keyLen == keyLen) && (memcmp(GET_HASH_NODE_KEY((pNode->next)), key, keyLen) == 0)) {
|
||||
assert((pNode->next)->hashVal == hashVal);
|
||||
break;
|
||||
while (pNode) {
|
||||
if ((pNode->keyLen == keyLen) && (memcmp(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) && pNode->removed == 0)
|
||||
break;
|
||||
|
||||
prevNode = pNode;
|
||||
pNode = pNode->next;
|
||||
}
|
||||
|
||||
if (pNode) {
|
||||
code = 0; // it is found
|
||||
|
||||
pNode->count--;
|
||||
pNode->removed = 1;
|
||||
if (pNode->count <= 0) {
|
||||
if (prevNode) {
|
||||
prevNode->next = pNode->next;
|
||||
} else {
|
||||
pe->next = pNode->next;
|
||||
}
|
||||
|
||||
if (data) memcpy(data, GET_HASH_NODE_DATA(pNode), dsize);
|
||||
|
||||
pNode = pNode->next;
|
||||
pe->num--;
|
||||
atomic_sub_fetch_64(&pHashObj->size, 1);
|
||||
FREE_HASH_NODE(pHashObj, pNode);
|
||||
}
|
||||
|
||||
|
||||
if (pNode->next != NULL) {
|
||||
pe->num -= 1;
|
||||
pRes = pNode->next;
|
||||
pNode->next = pNode->next->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (pe->num == 0) {
|
||||
assert(pe->next == NULL);
|
||||
} else {
|
||||
assert(pe->next != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosWUnLockLatch(&pe->latch);
|
||||
|
@ -398,17 +394,7 @@ int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLe
|
|||
|
||||
__rd_unlock(&pHashObj->lock, pHashObj->type);
|
||||
|
||||
if (data != NULL && pRes != NULL) {
|
||||
memcpy(data, GET_HASH_NODE_DATA(pRes), dsize);
|
||||
}
|
||||
|
||||
if (pRes != NULL) {
|
||||
atomic_sub_fetch_64(&pHashObj->size, 1);
|
||||
FREE_HASH_NODE(pHashObj, pRes);
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t taosHashCondTraverse(SHashObj *pHashObj, bool (*fp)(void *, void *), void *param) {
|
||||
|
@ -531,98 +517,6 @@ void taosHashCleanup(SHashObj *pHashObj) {
|
|||
free(pHashObj);
|
||||
}
|
||||
|
||||
SHashMutableIterator *taosHashCreateIter(SHashObj *pHashObj) {
|
||||
SHashMutableIterator *pIter = calloc(1, sizeof(SHashMutableIterator));
|
||||
if (pIter == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pIter->pHashObj = pHashObj;
|
||||
|
||||
// keep it in local variable, in case the resize operation expand the size
|
||||
pIter->numOfEntries = pHashObj->capacity;
|
||||
return pIter;
|
||||
}
|
||||
|
||||
bool taosHashIterNext(SHashMutableIterator *pIter) {
|
||||
if (pIter == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t size = taosHashGetSize(pIter->pHashObj);
|
||||
if (size == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check the first one
|
||||
if (pIter->numOfChecked == 0) {
|
||||
assert(pIter->pCur == NULL && pIter->pNext == NULL);
|
||||
|
||||
while (1) {
|
||||
SHashEntry *pEntry = pIter->pHashObj->hashList[pIter->entryIndex];
|
||||
if (pEntry->num == 0) {
|
||||
assert(pEntry->next == NULL);
|
||||
|
||||
pIter->entryIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pIter->pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosRLockLatch(&pEntry->latch);
|
||||
}
|
||||
|
||||
pIter->pCur = pEntry->next;
|
||||
|
||||
if (pIter->pCur->next) {
|
||||
pIter->pNext = pIter->pCur->next;
|
||||
|
||||
if (pIter->pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosRUnLockLatch(&pEntry->latch);
|
||||
}
|
||||
} else {
|
||||
if (pIter->pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosRUnLockLatch(&pEntry->latch);
|
||||
}
|
||||
|
||||
pIter->pNext = getNextHashNode(pIter);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
pIter->numOfChecked++;
|
||||
return true;
|
||||
} else {
|
||||
assert(pIter->pCur != NULL);
|
||||
if (pIter->pNext) {
|
||||
pIter->pCur = pIter->pNext;
|
||||
} else { // no more data in the hash list
|
||||
return false;
|
||||
}
|
||||
|
||||
pIter->numOfChecked++;
|
||||
|
||||
if (pIter->pCur->next) {
|
||||
pIter->pNext = pIter->pCur->next;
|
||||
} else {
|
||||
pIter->pNext = getNextHashNode(pIter);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void *taosHashIterGet(SHashMutableIterator *iter) { return (iter == NULL) ? NULL : GET_HASH_NODE_DATA(iter->pCur); }
|
||||
|
||||
void *taosHashDestroyIter(SHashMutableIterator *iter) {
|
||||
if (iter == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free(iter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// for profile only
|
||||
int32_t taosHashGetMaxOverflowLinkLength(const SHashObj *pHashObj) {
|
||||
if (pHashObj == NULL || pHashObj->size == 0) {
|
||||
|
@ -759,6 +653,8 @@ SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, s
|
|||
|
||||
pNewNode->keyLen = (uint32_t)keyLen;
|
||||
pNewNode->hashVal = hashVal;
|
||||
pNewNode->dataLen = dsize;
|
||||
pNewNode->count = 1;
|
||||
|
||||
memcpy(GET_HASH_NODE_DATA(pNewNode), pData, dsize);
|
||||
memcpy(GET_HASH_NODE_KEY(pNewNode), key, keyLen);
|
||||
|
@ -775,35 +671,6 @@ void pushfrontNodeInEntryList(SHashEntry *pEntry, SHashNode *pNode) {
|
|||
pEntry->num += 1;
|
||||
}
|
||||
|
||||
SHashNode *getNextHashNode(SHashMutableIterator *pIter) {
|
||||
assert(pIter != NULL);
|
||||
|
||||
pIter->entryIndex++;
|
||||
SHashNode *p = NULL;
|
||||
|
||||
while (pIter->entryIndex < pIter->numOfEntries) {
|
||||
SHashEntry *pEntry = pIter->pHashObj->hashList[pIter->entryIndex];
|
||||
if (pEntry->num == 0) {
|
||||
pIter->entryIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pIter->pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosRLockLatch(&pEntry->latch);
|
||||
}
|
||||
|
||||
p = pEntry->next;
|
||||
|
||||
if (pIter->pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosRUnLockLatch(&pEntry->latch);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t taosHashGetMemSize(const SHashObj *pHashObj) {
|
||||
if (pHashObj == NULL) {
|
||||
return 0;
|
||||
|
@ -811,3 +678,129 @@ size_t taosHashGetMemSize(const SHashObj *pHashObj) {
|
|||
|
||||
return (pHashObj->capacity * (sizeof(SHashEntry) + POINTER_BYTES)) + sizeof(SHashNode) * taosHashGetSize(pHashObj) + sizeof(SHashObj);
|
||||
}
|
||||
|
||||
// release the pNode, return next pNode, and lock the current entry
|
||||
static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) {
|
||||
|
||||
SHashNode *pOld = (SHashNode *)GET_HASH_PNODE(p);
|
||||
SHashNode *prevNode = NULL;
|
||||
|
||||
*slot = HASH_INDEX(pOld->hashVal, pHashObj->capacity);
|
||||
SHashEntry *pe = pHashObj->hashList[*slot];
|
||||
|
||||
// lock entry
|
||||
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosWLockLatch(&pe->latch);
|
||||
}
|
||||
|
||||
SHashNode *pNode = pe->next;
|
||||
|
||||
while (pNode) {
|
||||
if (pNode == pOld)
|
||||
break;
|
||||
|
||||
prevNode = pNode;
|
||||
pNode = pNode->next;
|
||||
}
|
||||
|
||||
if (pNode) {
|
||||
pNode = pNode->next;
|
||||
while (pNode) {
|
||||
if (pNode->removed == 0) break;
|
||||
pNode = pNode->next;
|
||||
}
|
||||
|
||||
pOld->count--;
|
||||
if (pOld->count <=0) {
|
||||
if (prevNode) {
|
||||
prevNode->next = pOld->next;
|
||||
} else {
|
||||
pe->next = pOld->next;
|
||||
}
|
||||
|
||||
pe->num--;
|
||||
atomic_sub_fetch_64(&pHashObj->size, 1);
|
||||
FREE_HASH_NODE(pHashObj, pOld);
|
||||
}
|
||||
} else {
|
||||
uError("pNode:%p data:%p is not there!!!", pNode, p);
|
||||
}
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
void *taosHashIterate(SHashObj *pHashObj, void *p) {
|
||||
if (pHashObj == NULL) return NULL;
|
||||
|
||||
int slot = 0;
|
||||
char *data = NULL;
|
||||
|
||||
// only add the read lock to disable the resize process
|
||||
__rd_lock(&pHashObj->lock, pHashObj->type);
|
||||
|
||||
SHashNode *pNode = NULL;
|
||||
if (p) {
|
||||
pNode = taosHashReleaseNode(pHashObj, p, &slot);
|
||||
if (pNode == NULL) {
|
||||
SHashEntry *pe = pHashObj->hashList[slot];
|
||||
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosWUnLockLatch(&pe->latch);
|
||||
}
|
||||
|
||||
slot = slot + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pNode == NULL) {
|
||||
for (; slot < pHashObj->capacity; ++slot) {
|
||||
SHashEntry *pe = pHashObj->hashList[slot];
|
||||
|
||||
// lock entry
|
||||
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosWLockLatch(&pe->latch);
|
||||
}
|
||||
|
||||
pNode = pe->next;
|
||||
while (pNode) {
|
||||
if (pNode->removed == 0) break;
|
||||
pNode = pNode->next;
|
||||
}
|
||||
|
||||
if (pNode) break;
|
||||
|
||||
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosWUnLockLatch(&pe->latch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pNode) {
|
||||
SHashEntry *pe = pHashObj->hashList[slot];
|
||||
pNode->count++;
|
||||
data = GET_HASH_NODE_DATA(pNode);
|
||||
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosWUnLockLatch(&pe->latch);
|
||||
}
|
||||
}
|
||||
|
||||
__rd_unlock(&pHashObj->lock, pHashObj->type);
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
void taosHashCancelIterate(SHashObj *pHashObj, void *p) {
|
||||
if (pHashObj == NULL || p == NULL) return;
|
||||
|
||||
// only add the read lock to disable the resize process
|
||||
__rd_lock(&pHashObj->lock, pHashObj->type);
|
||||
|
||||
int slot;
|
||||
taosHashReleaseNode(pHashObj, p, &slot);
|
||||
|
||||
SHashEntry *pe = pHashObj->hashList[slot];
|
||||
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
||||
taosWUnLockLatch(&pe->latch);
|
||||
}
|
||||
|
||||
__rd_unlock(&pHashObj->lock, pHashObj->type);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "tulog.h"
|
||||
|
@ -21,40 +22,52 @@
|
|||
|
||||
static int32_t tsFileRsetId = -1;
|
||||
|
||||
static void taosCloseFile(void *p) {
|
||||
static void tfCloseFile(void *p) {
|
||||
close((int32_t)(uintptr_t)p);
|
||||
}
|
||||
|
||||
int32_t tfinit() {
|
||||
tsFileRsetId = taosOpenRef(2000, taosCloseFile);
|
||||
return tsFileRsetId;
|
||||
int32_t tfInit() {
|
||||
tsFileRsetId = taosOpenRef(2000, tfCloseFile);
|
||||
if (tsFileRsetId > 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void tfcleanup() {
|
||||
void tfCleanup() {
|
||||
if (tsFileRsetId >= 0) taosCloseRef(tsFileRsetId);
|
||||
tsFileRsetId = -1;
|
||||
}
|
||||
|
||||
int64_t tfopen(const char *pathname, int32_t flags) {
|
||||
int32_t fd = open(pathname, flags);
|
||||
|
||||
static int64_t tfOpenImp(int32_t fd) {
|
||||
if (fd < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void *p = (void *)(int64_t)fd;
|
||||
void * p = (void *)(int64_t)fd;
|
||||
int64_t rid = taosAddRef(tsFileRsetId, p);
|
||||
if (rid < 0) close(fd);
|
||||
|
||||
return rid;
|
||||
}
|
||||
|
||||
int64_t tfclose(int64_t tfd) {
|
||||
int64_t tfOpen(const char *pathname, int32_t flags) {
|
||||
int32_t fd = open(pathname, flags);
|
||||
return tfOpenImp(fd);
|
||||
}
|
||||
|
||||
int64_t tfOpenM(const char *pathname, int32_t flags, mode_t mode) {
|
||||
int32_t fd = open(pathname, flags, mode);
|
||||
return tfOpenImp(fd);
|
||||
}
|
||||
|
||||
int64_t tfClose(int64_t tfd) {
|
||||
return taosRemoveRef(tsFileRsetId, tfd);
|
||||
}
|
||||
|
||||
int64_t tfwrite(int64_t tfd, void *buf, int64_t count) {
|
||||
int64_t tfWrite(int64_t tfd, void *buf, int64_t count) {
|
||||
void *p = taosAcquireRef(tsFileRsetId, tfd);
|
||||
if (p == NULL) return -1;
|
||||
|
||||
|
@ -67,7 +80,7 @@ int64_t tfwrite(int64_t tfd, void *buf, int64_t count) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
int64_t tfread(int64_t tfd, void *buf, int64_t count) {
|
||||
int64_t tfRead(int64_t tfd, void *buf, int64_t count) {
|
||||
void *p = taosAcquireRef(tsFileRsetId, tfd);
|
||||
if (p == NULL) return -1;
|
||||
|
||||
|
@ -79,3 +92,32 @@ int64_t tfread(int64_t tfd, void *buf, int64_t count) {
|
|||
taosReleaseRef(tsFileRsetId, tfd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int64_t tfFsync(int64_t tfd) {
|
||||
void *p = taosAcquireRef(tsFileRsetId, tfd);
|
||||
if (p == NULL) return -1;
|
||||
|
||||
int32_t fd = (int32_t)(uintptr_t)p;
|
||||
return fsync(fd);
|
||||
}
|
||||
|
||||
bool tfValid(int64_t tfd) {
|
||||
void *p = taosAcquireRef(tsFileRsetId, tfd);
|
||||
return p != NULL;
|
||||
}
|
||||
|
||||
int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence) {
|
||||
void *p = taosAcquireRef(tsFileRsetId, tfd);
|
||||
if (p == NULL) return -1;
|
||||
|
||||
int32_t fd = (int32_t)(uintptr_t)p;
|
||||
return taosLSeek(fd, offset, whence);
|
||||
}
|
||||
|
||||
int32_t tfFtruncate(int64_t tfd, int64_t length) {
|
||||
void *p = taosAcquireRef(tsFileRsetId, tfd);
|
||||
if (p == NULL) return -1;
|
||||
|
||||
int32_t fd = (int32_t)(uintptr_t)p;
|
||||
return taosFtruncate(fd, length);
|
||||
}
|
||||
|
|
|
@ -529,7 +529,7 @@ static int tdRestoreKVStore(SKVStore *pStore) {
|
|||
void * buf = NULL;
|
||||
int64_t maxBufSize = 0;
|
||||
SKVRecord rInfo = {0};
|
||||
SHashMutableIterator *pIter = NULL;
|
||||
SKVRecord *pRecord = NULL;
|
||||
|
||||
ASSERT(TD_KVSTORE_HEADER_SIZE == lseek(pStore->fd, 0, SEEK_CUR));
|
||||
ASSERT(pStore->info.size == TD_KVSTORE_HEADER_SIZE);
|
||||
|
@ -582,16 +582,8 @@ static int tdRestoreKVStore(SKVStore *pStore) {
|
|||
goto _err;
|
||||
}
|
||||
|
||||
pIter = taosHashCreateIter(pStore->map);
|
||||
if (pIter == NULL) {
|
||||
uError("failed to create hash iter while opening KV store %s", pStore->fname);
|
||||
terrno = TSDB_CODE_COM_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
while (taosHashIterNext(pIter)) {
|
||||
SKVRecord *pRecord = taosHashIterGet(pIter);
|
||||
|
||||
pRecord = taosHashIterate(pStore->map, NULL);
|
||||
while (pRecord) {
|
||||
if (lseek(pStore->fd, (off_t)(pRecord->offset + sizeof(SKVRecord)), SEEK_SET) < 0) {
|
||||
uError("failed to lseek file %s since %s, offset %" PRId64, pStore->fname, strerror(errno), pRecord->offset);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
@ -613,16 +605,17 @@ static int tdRestoreKVStore(SKVStore *pStore) {
|
|||
goto _err;
|
||||
}
|
||||
}
|
||||
|
||||
pRecord = taosHashIterate(pStore->map, pRecord);
|
||||
}
|
||||
|
||||
if (pStore->aFunc) (*pStore->aFunc)(pStore->appH);
|
||||
|
||||
taosHashDestroyIter(pIter);
|
||||
tfree(buf);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
taosHashDestroyIter(pIter);
|
||||
taosHashCancelIterate(pStore->map, pRecord);
|
||||
tfree(buf);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ typedef struct {
|
|||
int8_t role;
|
||||
int8_t accessState;
|
||||
int8_t isFull;
|
||||
int8_t isCommiting;
|
||||
uint64_t version; // current version
|
||||
uint64_t fversion; // version on saved data file
|
||||
void *wqueue;
|
||||
|
|
|
@ -38,6 +38,7 @@ static void vnodeCtrlFlow(int32_t vgId, int32_t level);
|
|||
static int32_t vnodeNotifyFileSynced(int32_t vgId, uint64_t fversion);
|
||||
static void vnodeConfirmForard(int32_t vgId, void *wparam, int32_t code);
|
||||
static int32_t vnodeWriteToCache(int32_t vgId, void *wparam, int32_t qtype, void *rparam);
|
||||
static int32_t vnodeGetFileVersion(int32_t vgId, uint64_t *fver);
|
||||
|
||||
#ifndef _SYNC
|
||||
int64_t syncStart(const SSyncInfo *info) { return NULL; }
|
||||
|
@ -352,6 +353,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
|||
syncInfo.notifyRole = vnodeNotifyRole;
|
||||
syncInfo.notifyFlowCtrl = vnodeCtrlFlow;
|
||||
syncInfo.notifyFileSynced = vnodeNotifyFileSynced;
|
||||
syncInfo.getFileVersion = vnodeGetFileVersion;
|
||||
pVnode->sync = syncStart(&syncInfo);
|
||||
|
||||
#ifndef _SYNC
|
||||
|
@ -520,11 +522,10 @@ static void vnodeBuildVloadMsg(SVnodeObj *pVnode, SStatusMsg *pStatus) {
|
|||
}
|
||||
|
||||
int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
|
||||
SHashMutableIterator *pIter = taosHashCreateIter(tsVnodesHash);
|
||||
while (taosHashIterNext(pIter)) {
|
||||
SVnodeObj **pVnode = taosHashIterGet(pIter);
|
||||
if (pVnode == NULL) continue;
|
||||
if (*pVnode == NULL) continue;
|
||||
void *pIter = taosHashIterate(tsVnodesHash, NULL);
|
||||
while (pIter) {
|
||||
SVnodeObj **pVnode = pIter;
|
||||
if (*pVnode) {
|
||||
|
||||
(*numOfVnodes)++;
|
||||
if (*numOfVnodes >= TSDB_MAX_VNODES) {
|
||||
|
@ -533,25 +534,25 @@ int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
|
|||
} else {
|
||||
vnodeList[*numOfVnodes - 1] = (*pVnode)->vgId;
|
||||
}
|
||||
}
|
||||
|
||||
taosHashDestroyIter(pIter);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(tsVnodesHash, pIter);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void vnodeBuildStatusMsg(void *param) {
|
||||
SStatusMsg *pStatus = param;
|
||||
SHashMutableIterator *pIter = taosHashCreateIter(tsVnodesHash);
|
||||
|
||||
while (taosHashIterNext(pIter)) {
|
||||
SVnodeObj **pVnode = taosHashIterGet(pIter);
|
||||
if (pVnode == NULL) continue;
|
||||
if (*pVnode == NULL) continue;
|
||||
|
||||
vnodeBuildVloadMsg(*pVnode, pStatus);
|
||||
void *pIter = taosHashIterate(tsVnodesHash, NULL);
|
||||
while (pIter) {
|
||||
SVnodeObj **pVnode = pIter;
|
||||
if (*pVnode) {
|
||||
vnodeBuildVloadMsg(*pVnode, pStatus);
|
||||
}
|
||||
pIter = taosHashIterate(tsVnodesHash, pIter);
|
||||
}
|
||||
|
||||
taosHashDestroyIter(pIter);
|
||||
}
|
||||
|
||||
void vnodeSetAccess(SVgroupAccess *pAccess, int32_t numOfVnodes) {
|
||||
|
@ -597,18 +598,19 @@ static void vnodeCleanUp(SVnodeObj *pVnode) {
|
|||
vnodeRelease(pVnode);
|
||||
}
|
||||
|
||||
// TODO: this is a simple implement
|
||||
static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno) {
|
||||
SVnodeObj *pVnode = arg;
|
||||
|
||||
if (eno != TSDB_CODE_SUCCESS) {
|
||||
vError("vgId:%d, failed to commit since %s, fver:%" PRIu64 " vver:%" PRIu64, pVnode->vgId, tstrerror(eno),
|
||||
pVnode->fversion, pVnode->version);
|
||||
pVnode->isCommiting = 0;
|
||||
pVnode->isFull = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (status == TSDB_STATUS_COMMIT_START) {
|
||||
pVnode->isCommiting = 1;
|
||||
pVnode->fversion = pVnode->version;
|
||||
vDebug("vgId:%d, start commit, fver:%" PRIu64 " vver:%" PRIu64, pVnode->vgId, pVnode->fversion, pVnode->version);
|
||||
if (pVnode->status != TAOS_VN_STATUS_INIT) {
|
||||
|
@ -619,6 +621,7 @@ static int32_t vnodeProcessTsdbStatus(void *arg, int32_t status, int32_t eno) {
|
|||
|
||||
if (status == TSDB_STATUS_COMMIT_OVER) {
|
||||
vDebug("vgId:%d, commit over, fver:%" PRIu64 " vver:%" PRIu64, pVnode->vgId, pVnode->fversion, pVnode->version);
|
||||
pVnode->isCommiting = 0;
|
||||
pVnode->isFull = 0;
|
||||
if (pVnode->status != TAOS_VN_STATUS_INIT) {
|
||||
walRemoveOneOldFile(pVnode->wal);
|
||||
|
@ -684,8 +687,10 @@ static void vnodeCtrlFlow(int32_t vgId, int32_t level) {
|
|||
return;
|
||||
}
|
||||
|
||||
pVnode->flowctrlLevel = level;
|
||||
vDebug("vgId:%d, set flowctrl level:%d", pVnode->vgId, level);
|
||||
if (pVnode->flowctrlLevel != level) {
|
||||
vDebug("vgId:%d, set flowctrl level from %d to %d", pVnode->vgId, pVnode->flowctrlLevel, level);
|
||||
pVnode->flowctrlLevel = level;
|
||||
}
|
||||
|
||||
vnodeRelease(pVnode);
|
||||
}
|
||||
|
@ -765,3 +770,22 @@ static int32_t vnodeWriteToCache(int32_t vgId, void *wparam, int32_t qtype, void
|
|||
vnodeRelease(pVnode);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t vnodeGetFileVersion(int32_t vgId, uint64_t *fver) {
|
||||
SVnodeObj *pVnode = vnodeAcquire(vgId);
|
||||
if (pVnode == NULL) {
|
||||
vError("vgId:%d, vnode not found while write to cache", vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
if (pVnode->isCommiting) {
|
||||
vDebug("vgId:%d, vnode is commiting while get file version", vgId);
|
||||
code = -1;
|
||||
} else {
|
||||
*fver = pVnode->fversion;
|
||||
}
|
||||
|
||||
vnodeRelease(pVnode);
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -282,13 +282,15 @@ static void vnodeFlowCtrlMsgToWQueue(void *param, void *tmrId) {
|
|||
|
||||
pWrite->processedCount++;
|
||||
if (pWrite->processedCount > 100) {
|
||||
vError("vgId:%d, msg:%p, failed to process since %s", pVnode->vgId, pWrite, tstrerror(code));
|
||||
vError("vgId:%d, msg:%p, failed to process since %s, retry:%d", pVnode->vgId, pWrite, tstrerror(code),
|
||||
pWrite->processedCount);
|
||||
pWrite->processedCount = 1;
|
||||
dnodeSendRpcVWriteRsp(pWrite->pVnode, pWrite, code);
|
||||
} else {
|
||||
code = vnodePerformFlowCtrl(pWrite);
|
||||
if (code == 0) {
|
||||
vTrace("vgId:%d, write into vwqueue after flowctrl", pVnode->vgId);
|
||||
vDebug("vgId:%d, msg:%p, write into vwqueue after flowctrl, retry:%d", pVnode->vgId, pWrite,
|
||||
pWrite->processedCount);
|
||||
pWrite->processedCount = 0;
|
||||
taosWriteQitem(pVnode->wqueue, pWrite->qtype, pWrite);
|
||||
}
|
||||
|
@ -310,7 +312,7 @@ static int32_t vnodePerformFlowCtrl(SVWriteMsg *pWrite) {
|
|||
void *unUsed = NULL;
|
||||
taosTmrReset(vnodeFlowCtrlMsgToWQueue, 100, pWrite, tsDnodeTmr, &unUsed);
|
||||
|
||||
vTrace("vgId:%d, msg:%p, app:%p, perform flowctrl, count:%d", pVnode->vgId, pWrite, pWrite->rpcMsg.ahandle,
|
||||
vTrace("vgId:%d, msg:%p, app:%p, perform flowctrl, retry:%d", pVnode->vgId, pWrite, pWrite->rpcMsg.ahandle,
|
||||
pWrite->processedCount);
|
||||
return TSDB_CODE_VND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ typedef struct {
|
|||
uint64_t version;
|
||||
int64_t fileId;
|
||||
int64_t rid;
|
||||
int64_t tfd;
|
||||
int32_t vgId;
|
||||
int32_t fd;
|
||||
int32_t keep;
|
||||
int32_t level;
|
||||
int32_t fsyncPeriod;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "tref.h"
|
||||
#include "tfile.h"
|
||||
#include "twal.h"
|
||||
#include "walInt.h"
|
||||
|
||||
|
@ -61,7 +62,7 @@ void *walOpen(char *path, SWalCfg *pCfg) {
|
|||
}
|
||||
|
||||
pWal->vgId = pCfg->vgId;
|
||||
pWal->fd = -1;
|
||||
pWal->tfd = -1;
|
||||
pWal->fileId = -1;
|
||||
pWal->level = pCfg->walLevel;
|
||||
pWal->keep = pCfg->keep;
|
||||
|
@ -124,7 +125,7 @@ void walClose(void *handle) {
|
|||
|
||||
SWal *pWal = handle;
|
||||
pthread_mutex_lock(&pWal->mutex);
|
||||
taosClose(pWal->fd);
|
||||
tfClose(pWal->tfd);
|
||||
pthread_mutex_unlock(&pWal->mutex);
|
||||
taosRemoveRef(tsWal.refId, pWal->rid);
|
||||
}
|
||||
|
@ -143,7 +144,7 @@ static void walFreeObj(void *wal) {
|
|||
SWal *pWal = wal;
|
||||
wDebug("vgId:%d, wal:%p is freed", pWal->vgId, pWal);
|
||||
|
||||
taosClose(pWal->fd);
|
||||
tfClose(pWal->tfd);
|
||||
pthread_mutex_destroy(&pWal->mutex);
|
||||
tfree(pWal);
|
||||
}
|
||||
|
@ -172,7 +173,7 @@ static void walFsyncAll() {
|
|||
while (pWal) {
|
||||
if (walNeedFsync(pWal)) {
|
||||
wTrace("vgId:%d, do fsync, level:%d seq:%d rseq:%d", pWal->vgId, pWal->level, pWal->fsyncSeq, tsWal.seq);
|
||||
int32_t code = fsync(pWal->fd);
|
||||
int32_t code = tfFsync(pWal->tfd);
|
||||
if (code != 0) {
|
||||
wError("vgId:%d, file:%s, failed to fsync since %s", pWal->vgId, pWal->name, strerror(code));
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "tchecksum.h"
|
||||
#include "tfile.h"
|
||||
#include "twal.h"
|
||||
#include "walInt.h"
|
||||
|
||||
|
@ -36,8 +37,8 @@ int32_t walRenew(void *handle) {
|
|||
|
||||
pthread_mutex_lock(&pWal->mutex);
|
||||
|
||||
if (pWal->fd >= 0) {
|
||||
tclose(pWal->fd);
|
||||
if (tfValid(pWal->tfd)) {
|
||||
tfClose(pWal->tfd);
|
||||
wDebug("vgId:%d, file:%s, it is closed", pWal->vgId, pWal->name);
|
||||
}
|
||||
|
||||
|
@ -49,9 +50,9 @@ int32_t walRenew(void *handle) {
|
|||
}
|
||||
|
||||
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->fileId);
|
||||
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
pWal->tfd = tfOpenM(pWal->name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
|
||||
if (pWal->fd < 0) {
|
||||
if (!tfValid(pWal->tfd)) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->name, strerror(errno));
|
||||
} else {
|
||||
|
@ -67,7 +68,7 @@ void walRemoveOneOldFile(void *handle) {
|
|||
SWal *pWal = handle;
|
||||
if (pWal == NULL) return;
|
||||
if (pWal->keep == TAOS_WAL_KEEP) return;
|
||||
if (pWal->fd <= 0) return;
|
||||
if (!tfValid(pWal->tfd)) return;
|
||||
|
||||
pthread_mutex_lock(&pWal->mutex);
|
||||
|
||||
|
@ -113,7 +114,7 @@ int32_t walWrite(void *handle, SWalHead *pHead) {
|
|||
int32_t code = 0;
|
||||
|
||||
// no wal
|
||||
if (pWal->fd <= 0) return 0;
|
||||
if (!tfValid(pWal->tfd)) return 0;
|
||||
if (pWal->level == TAOS_WAL_NOLOG) return 0;
|
||||
if (pHead->version <= pWal->version) return 0;
|
||||
|
||||
|
@ -123,12 +124,12 @@ int32_t walWrite(void *handle, SWalHead *pHead) {
|
|||
|
||||
pthread_mutex_lock(&pWal->mutex);
|
||||
|
||||
if (taosWrite(pWal->fd, pHead, contLen) != contLen) {
|
||||
if (tfWrite(pWal->tfd, pHead, contLen) != contLen) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
wError("vgId:%d, file:%s, failed to write since %s", pWal->vgId, pWal->name, strerror(errno));
|
||||
} else {
|
||||
wTrace("vgId:%d, write wal, fileId:%" PRId64 " fd:%d hver:%" PRId64 " wver:%" PRIu64 " len:%d", pWal->vgId,
|
||||
pWal->fileId, pWal->fd, pHead->version, pWal->version, pHead->len);
|
||||
wTrace("vgId:%d, write wal, fileId:%" PRId64 " tfd:%" PRId64 " hver:%" PRId64 " wver:%" PRIu64 " len:%d", pWal->vgId,
|
||||
pWal->fileId, pWal->tfd, pHead->version, pWal->version, pHead->len);
|
||||
pWal->version = pHead->version;
|
||||
}
|
||||
|
||||
|
@ -141,11 +142,11 @@ int32_t walWrite(void *handle, SWalHead *pHead) {
|
|||
|
||||
void walFsync(void *handle, bool forceFsync) {
|
||||
SWal *pWal = handle;
|
||||
if (pWal == NULL || pWal->fd < 0) return;
|
||||
if (pWal == NULL || !tfValid(pWal->tfd)) return;
|
||||
|
||||
if (forceFsync || (pWal->level == TAOS_WAL_FSYNC && pWal->fsyncPeriod == 0)) {
|
||||
wTrace("vgId:%d, fileId:%" PRId64 ", do fsync", pWal->vgId, pWal->fileId);
|
||||
if (fsync(pWal->fd) < 0) {
|
||||
if (tfFsync(pWal->tfd) < 0) {
|
||||
wError("vgId:%d, fileId:%" PRId64 ", fsync failed since %s", pWal->vgId, pWal->fileId, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
@ -186,8 +187,8 @@ int32_t walRestore(void *handle, void *pVnode, FWalWrite writeFp) {
|
|||
// open the existing WAL file in append mode
|
||||
pWal->fileId = 0;
|
||||
snprintf(pWal->name, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->fileId);
|
||||
pWal->fd = open(pWal->name, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if (pWal->fd < 0) {
|
||||
pWal->tfd = tfOpenM(pWal->name, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if (!tfValid(pWal->tfd)) {
|
||||
wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->name, strerror(errno));
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
@ -211,28 +212,28 @@ int32_t walGetWalFile(void *handle, char *fileName, int64_t *fileId) {
|
|||
code = (*fileId == pWal->fileId) ? 0 : 1;
|
||||
}
|
||||
|
||||
wTrace("vgId:%d, get wal file, code:%d curId:%" PRId64 " outId:%" PRId64, pWal->vgId, code, pWal->fileId, *fileId);
|
||||
wDebug("vgId:%d, get wal file, code:%d curId:%" PRId64 " outId:%" PRId64, pWal->vgId, code, pWal->fileId, *fileId);
|
||||
pthread_mutex_unlock(&(pWal->mutex));
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static void walFtruncate(SWal *pWal, int32_t fd, int64_t offset) {
|
||||
taosFtruncate(fd, offset);
|
||||
fsync(fd);
|
||||
static void walFtruncate(SWal *pWal, int64_t tfd, int64_t offset) {
|
||||
tfFtruncate(tfd, offset);
|
||||
tfFsync(tfd);
|
||||
}
|
||||
|
||||
static int32_t walSkipCorruptedRecord(SWal *pWal, SWalHead *pHead, int32_t fd, int64_t *offset) {
|
||||
static int32_t walSkipCorruptedRecord(SWal *pWal, SWalHead *pHead, int64_t tfd, int64_t *offset) {
|
||||
int64_t pos = *offset;
|
||||
while (1) {
|
||||
pos++;
|
||||
|
||||
if (lseek(fd, pos, SEEK_SET) < 0) {
|
||||
if (tfLseek(tfd, pos, SEEK_SET) < 0) {
|
||||
wError("vgId:%d, failed to seek from corrupted wal file since %s", pWal->vgId, strerror(errno));
|
||||
return TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||
}
|
||||
|
||||
if (taosRead(fd, pHead, sizeof(SWalHead)) <= 0) {
|
||||
if (tfRead(tfd, pHead, sizeof(SWalHead)) <= 0) {
|
||||
wError("vgId:%d, read to end of corrupted wal file, offset:%" PRId64, pWal->vgId, pos);
|
||||
return TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||
}
|
||||
|
@ -259,8 +260,8 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
|
|||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
int32_t fd = open(name, O_RDWR);
|
||||
if (fd < 0) {
|
||||
int64_t tfd = tfOpen(name, O_RDWR);
|
||||
if (!tfValid(tfd)) {
|
||||
wError("vgId:%d, file:%s, failed to open for restore since %s", pWal->vgId, name, strerror(errno));
|
||||
tfree(buffer);
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
|
@ -273,7 +274,7 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
|
|||
SWalHead *pHead = buffer;
|
||||
|
||||
while (1) {
|
||||
int32_t ret = taosRead(fd, pHead, sizeof(SWalHead));
|
||||
int32_t ret = tfRead(tfd, pHead, sizeof(SWalHead));
|
||||
if (ret == 0) break;
|
||||
|
||||
if (ret < 0) {
|
||||
|
@ -284,16 +285,16 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
|
|||
|
||||
if (ret < sizeof(SWalHead)) {
|
||||
wError("vgId:%d, file:%s, failed to read wal head, ret is %d", pWal->vgId, name, ret);
|
||||
walFtruncate(pWal, fd, offset);
|
||||
walFtruncate(pWal, tfd, offset);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!taosCheckChecksumWhole((uint8_t *)pHead, sizeof(SWalHead))) {
|
||||
wError("vgId:%d, file:%s, wal head cksum is messed up, hver:%" PRIu64 " len:%d offset:%" PRId64, pWal->vgId, name,
|
||||
pHead->version, pHead->len, offset);
|
||||
code = walSkipCorruptedRecord(pWal, pHead, fd, &offset);
|
||||
code = walSkipCorruptedRecord(pWal, pHead, tfd, &offset);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
walFtruncate(pWal, fd, offset);
|
||||
walFtruncate(pWal, tfd, offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -310,7 +311,7 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
|
|||
pHead = buffer;
|
||||
}
|
||||
|
||||
ret = taosRead(fd, pHead->cont, pHead->len);
|
||||
ret = tfRead(tfd, pHead->cont, pHead->len);
|
||||
if (ret < 0) {
|
||||
wError("vgId:%d, file:%s, failed to read wal body since %s", pWal->vgId, name, strerror(errno));
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
|
@ -325,14 +326,14 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
|
|||
|
||||
offset = offset + sizeof(SWalHead) + pHead->len;
|
||||
|
||||
wTrace("vgId:%d, restore wal, fileId:%" PRId64 " hver:%" PRIu64 " wver:%" PRIu64 " len:%d", pWal->vgId,
|
||||
wDebug("vgId:%d, restore wal, fileId:%" PRId64 " hver:%" PRIu64 " wver:%" PRIu64 " len:%d", pWal->vgId,
|
||||
fileId, pHead->version, pWal->version, pHead->len);
|
||||
|
||||
pWal->version = pHead->version;
|
||||
(*writeFp)(pVnode, pHead, TAOS_QTYPE_WAL, NULL);
|
||||
}
|
||||
|
||||
tclose(fd);
|
||||
tfClose(tfd);
|
||||
tfree(buffer);
|
||||
|
||||
return code;
|
||||
|
|
|
@ -14,7 +14,6 @@ run general/table/vgroup.sim
|
|||
run general/user/authority.sim
|
||||
run general/vector/metrics_mix.sim
|
||||
run general/vector/table_field.sim
|
||||
run general/user/authority.sim
|
||||
run general/tag/set.sim
|
||||
run general/table/delete_writing.sim
|
||||
run general/stable/disk.sim
|
||||
|
|
|
@ -117,16 +117,17 @@ run general/parser/col_arithmetic_query.sim
|
|||
# ================================================================================================
|
||||
|
||||
print ====================> crash
|
||||
# sql select spread(ts )/(1000*3600*24) from ca_stb0 interval(1y)
|
||||
sql use $db
|
||||
sql select spread(ts )/(1000*3600*24) from $stb interval(1y)
|
||||
|
||||
sql_error select first(c1, c2) - last(c1, c2) from stb interval(1y)
|
||||
sql_error select first(ts) - last(ts) from stb interval(1y)
|
||||
sql_error select top(c1, 2) - last(c1) from stb;
|
||||
sql_error select stddev(c1) - last(c1) from stb;
|
||||
sql_error select diff(c1) - last(c1) from stb;
|
||||
sql_error select first(c7) - last(c7) from stb;
|
||||
sql_error select first(c8) - last(c8) from stb;
|
||||
sql_error select first(c9) - last(c9) from stb;
|
||||
sql_error select first(c1, c2) - last(c1, c2) from $stb interval(1y)
|
||||
sql_error select first(ts) - last(ts) from $stb interval(1y)
|
||||
sql_error select top(c1, 2) - last(c1) from $stb;
|
||||
sql_error select stddev(c1) - last(c1) from $stb;
|
||||
sql_error select diff(c1) - last(c1) from $stb;
|
||||
sql_error select first(c7) - last(c7) from $stb;
|
||||
sql_error select first(c8) - last(c8) from $stb;
|
||||
sql_error select first(c9) - last(c9) from $stb;
|
||||
sql_error select max(c2*2) from $tb
|
||||
sql_error select max(c1-c2) from $tb
|
||||
|
||||
|
|
|
@ -62,24 +62,73 @@ if $data91 != 1.000000000 then
|
|||
return -1
|
||||
endi
|
||||
|
||||
sql select (c1 * 2) % 7.9 from $tb order by ts desc;
|
||||
sql select (c1 * 2) % 7.9, c1*1, c1*1*1, c1*c1, c1*c1*c1 from $tb order by ts desc;
|
||||
if $rows != 10000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data00 != 0.100000000 then
|
||||
print expect 0.100000000, acutal:$data00
|
||||
if $data00 != 2.200000000 then
|
||||
print expect 2.200000000, actual:$data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data10 != 2.100000000 then
|
||||
if $data01 != 9.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data90 != 6.000000000 then
|
||||
if $data02 != 9.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data03 != 81.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data04 != 729.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
||||
if $data10 != 0.200000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data11 != 8.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data12 != 8.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data13 != 64.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data14 != 512.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data90 != 0.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data91 != 0.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data92 != 0.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data93 != 0.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data94 != 0.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# [d.3]
|
||||
sql select c1 * c2 /4 from $tb where ts < 1537166000000 and ts > 1537156000000
|
||||
if $rows != 17 then
|
||||
|
@ -95,7 +144,7 @@ if $data10 != 16.000000000 then
|
|||
endi
|
||||
|
||||
if $data20 != 20.250000000 then
|
||||
print expect 20.250000000, acutal:$data21
|
||||
print expect 20.250000000, actual:$data21
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
@ -320,7 +369,9 @@ sql_error select c7-c9 from $tb interval(2y)
|
|||
# multiple retrieve [d.20]===============================================================
|
||||
sql select c2-c2, 911 from $tb
|
||||
|
||||
#======================================= aggregation function arithmetic query cases ================
|
||||
#======================================= aggregation function arithmetic query cases ===================================
|
||||
# on $tb percentile() spread(ts) bug
|
||||
|
||||
# asc/desc order [d.2]
|
||||
sql select first(c1) * ( 2 / 3 ) from $stb order by ts asc;
|
||||
if $rows != 1 then
|
||||
|
@ -349,11 +400,11 @@ if $data00 != 1.800000000 then
|
|||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != 100000 then
|
||||
if $data01 != 100000.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data02 != 200000 then
|
||||
if $data02 != 200000.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
@ -374,77 +425,192 @@ if $data02 != 9.000000020 then
|
|||
return -1
|
||||
endi
|
||||
|
||||
# all possible function in the arithmetic expressioin
|
||||
sql select min(c1) * max(c2) /4, sum(c1) * percentile(c2, 20), apercentile(c4, 33) + 52/9, spread(c5)/min(c2) from $stb where ts < and ts >
|
||||
# all possible function in the arithmetic expression, add more
|
||||
sql select min(c1) * max(c2) /4, sum(c1) * apercentile(c2, 20), apercentile(c4, 33) + 52/9, spread(c5)/min(c2), count(1)/sum(c1), avg(c2)*count(c2) from $stb where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-11-25 19:30:00.000';
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# no result return [d.3]
|
||||
if $data00 != 0.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != 225000.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data02 != 8.077777778 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data03 != inf then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data04 != 0.444444444 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data05 != 450000.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# no result return [d.3]===============================================================
|
||||
sql select first(c1) * 91 - 7, last(c3) from $stb where ts < 1537146000000
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# no result return [d.3]
|
||||
sql select sum(c2) - avg(c2) from $tb where ts>xxx
|
||||
sql select sum(c2) - avg(c2) from $stb where ts > '2018-11-25 19:30:00.000'
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# single row result aggregation [d.4]
|
||||
sql select
|
||||
# single row result aggregation [d.4]===================================================
|
||||
# all those cases are aggregation test cases.
|
||||
|
||||
# error cases
|
||||
sql_error select first(c1, c2) - last(c1, c2) from $tb
|
||||
sql_error select first(c1, c2) - last(c1, c2) from $stb
|
||||
sql_error select top(c1, 5) - bottom(c1, 5) from $stb
|
||||
sql_error select first(*) - 99 from $stb
|
||||
|
||||
# multi row result aggregation [d.4]
|
||||
sql select top(c1, 1) - bottom(c1, 1) from $tb
|
||||
sql select top(c1, 99) - bottom(c1, 99) from $tb
|
||||
sql_error select top(c1, 1) - bottom(c1, 1) from $stb
|
||||
sql_error select top(c1, 99) - bottom(c1, 99) from $stb
|
||||
|
||||
# all data types [d.6]
|
||||
sql select c2-c1, c3/c2, c4*c3, c5%c4, c6+99%22 from $tb
|
||||
# query on super table [d.5]=============================================================
|
||||
# all cases in this part are query on super table
|
||||
|
||||
# all data types [d.6]===================================================================
|
||||
sql select c2-c1, c3/c2, c4*c3, c5%c4, c6+99%22 from $stb
|
||||
|
||||
# error case, ts/bool/binary/nchar not support arithmetic expression
|
||||
sql_error select ts+ts from $tb
|
||||
sql_error select ts+22 from $tb
|
||||
sql_error select c7*12 from $tb
|
||||
sql_error select c8/55 from $tb
|
||||
sql_error select c9+c8 from $tb
|
||||
sql_error select first(c7)*12 from $stb
|
||||
sql_error select last(c8)/55 from $stb
|
||||
sql_error select last_row(c9) + last_row(c8) from $stb
|
||||
|
||||
# arithmetic expression in join [d.7]
|
||||
# arithmetic expression in join [d.7]===============================================================
|
||||
|
||||
|
||||
# arithmetic expression in union [d.8]
|
||||
# arithmetic expression in union [d.8]===============================================================
|
||||
|
||||
|
||||
# arithmetic expression in group by [d.9]
|
||||
# arithmetic expression in group by [d.9]===============================================================
|
||||
# in group by tag
|
||||
# not support for normal table
|
||||
sql_error select c5*99 from $tb group by t1
|
||||
sql select avg(c4)*99 from $stb group by t1
|
||||
if $rows != 10 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data00 != 445.500000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data90 != 445.500000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data91 != 9 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# in group by column
|
||||
sql_error select c6-c6+c3*12 from $tb group by c3;
|
||||
sql select apercentile(c6, 50)-first(c6)+last(c5)*12, last(c5)*12 from ca_stb0 group by c2;
|
||||
if $rows != 10 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select first(c6) - last(c6) *12 / count(*) from $tb group by c3;
|
||||
if $data00 != 0.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# limit offset [d.10]
|
||||
sql select c6-c6+12 from $tb limit 12 offset 99;
|
||||
sql select c4/99.123 from $tb limit 1 offset 9999;
|
||||
if $data01 != 0.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# slimit/soffset not suport for normal table query. [d.11]
|
||||
sql_error select sum(c1) from $tb slimit 1 soffset 19;
|
||||
if $data10 != 12.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# fill [d.12]
|
||||
sql_error select c2-c2, c3-c4, c5%c6 from $tb fill(value, 12);
|
||||
if $data11 != 12.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# constant column. [d.13]
|
||||
if $data20 != 24.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data21 != 24.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql_error select first(c6) - last(c6) *12 / count(*) from $stb group by c3;
|
||||
|
||||
sql select first(c6) - last(c6) *12 / count(*) from $stb group by c5;
|
||||
if $rows != 10 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data00 != 0.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data10 != 0.997600000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data90 != 8.978400000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# limit offset [d.10]===============================================================
|
||||
sql select first(c6) - sum(c6) + 12 from $stb limit 12 offset 0;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data00 != -449988.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select apercentile(c4, 21) / 99.123 from $stb limit 1 offset 1;
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select apercentile(c4, 21) / sum(c4) from $stb interval(1s) limit 1 offset 1;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# slimit/soffset not support for normal table query. [d.11]===============================================================
|
||||
sql select sum(c1) from $stb slimit 1 soffset 19;
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select sum(c1) from $stb interval(1s) group by tbname slimit 1 soffset 1
|
||||
sql select sum(c1) from ca_stb0 interval(1s) group by tbname slimit 2 soffset 4 limit 10 offset 1
|
||||
|
||||
# fill [d.12]===============================================================
|
||||
sql_error select first(c1)-last(c1), sum(c3)*count(c3), spread(c5 ) % count(*) from $stb interval(1s) fill(prev);
|
||||
sql_error select first(c1) from $stb fill(value, 20);
|
||||
|
||||
# constant column. [d.13]===============================================================
|
||||
|
||||
|
||||
# column value filter [d.14]
|
||||
# column value filter [d.14]===============================================================
|
||||
|
||||
|
||||
# tag filter(not support for normal table). [d.15]
|
||||
sql_error select sum(c2)+99 from $tb where t1=12;
|
||||
# tag filter. [d.15]===============================================================
|
||||
sql select sum(c2)+99 from $stb where t1=12;
|
||||
|
||||
# multi-field output [d.16]
|
||||
# multi-field output [d.16]===============================================================
|
||||
sql select count(*), sum(c1)*avg(c2), avg(c3)*count(c3), sum(c3), sum(c4), first(c7), last(c8), first(c9), first(c7), last(c8) from $tb
|
||||
|
||||
sql select c4*1+1/2 from $tb
|
||||
|
@ -461,18 +627,30 @@ if $data90 != 9.500000000 then
|
|||
return -1
|
||||
endi
|
||||
|
||||
# interval query [d.17]
|
||||
sql_error select c2*c2, c3-c3, c4+9 from $tb interval(1s)
|
||||
sql_error select c7-c9 from $tb interval(2y)
|
||||
# interval query [d.17]===============================================================
|
||||
sql select avg(c2)*count(c2), sum(c3)-first(c3), last(c4)+9 from $stb interval(1s)
|
||||
if $rows != 10000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# aggregation query [d.18]
|
||||
# see test cases below
|
||||
if $data00 != @18-09-17 09:00:00.000@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
# first/last query [d.19]
|
||||
# see test cases below
|
||||
sql_error select first(c7)- last(c1) from $tb interval(2y)
|
||||
|
||||
# multiple retrieve [d.20]
|
||||
sql select c2-c2 from $tb;
|
||||
# aggregation query [d.18]===============================================================
|
||||
# all cases in this part are aggregation query test.
|
||||
|
||||
# first/last query [d.19]===============================================================
|
||||
|
||||
|
||||
# multiple retrieve [d.20]===============================================================
|
||||
sql select c2-c2 from $tb
|
||||
|
||||
|
||||
sql select first(c1)-last(c1), spread(c2), max(c3) - min(c3), avg(c4)*count(c4) from $tb
|
||||
|
||||
|
||||
#====================================================super table query==================================================
|
||||
|
||||
|
|
|
@ -703,13 +703,13 @@ sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where t
|
|||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 4.499549955 then
|
||||
if $data00 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != 4.499549955 then
|
||||
if $data02 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
if $data05 != 4.499549955 then
|
||||
if $data05 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
@ -717,10 +717,12 @@ sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from
|
|||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1
|
||||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != 3 then
|
||||
return -1
|
||||
endi
|
||||
|
@ -731,7 +733,6 @@ if $data23 != 9.00000 then
|
|||
return -1
|
||||
endi
|
||||
|
||||
|
||||
sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
|
|
|
@ -327,22 +327,22 @@ sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where t
|
|||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 4.000000000 then
|
||||
if $data00 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 4.000000000 then
|
||||
if $data01 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != 4.000000000 then
|
||||
if $data02 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
if $data03 != 4.000000000 then
|
||||
if $data03 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
if $data04 != 4.000000000 then
|
||||
if $data04 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
if $data05 != 4.000000000 then
|
||||
if $data05 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
@ -690,13 +690,13 @@ sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where t
|
|||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 4.000000000 then
|
||||
if $data00 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != 4.000000000 then
|
||||
if $data02 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
if $data05 != 4.000000000 then
|
||||
if $data05 != 4.500000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
|
|
@ -131,7 +131,6 @@ if $data00 != $rowNum then
|
|||
return -1
|
||||
endi
|
||||
|
||||
|
||||
## like
|
||||
sql_error select * from $mt where c1 like 1
|
||||
#sql_error select * from $mt where t1 like 1
|
||||
|
@ -178,7 +177,8 @@ sql create table wh_mt2_tb1 using wh_mt2 tags ('wh_mt2_tb1')
|
|||
# 2019-01-01 09:00:00.000 1546304400000
|
||||
# 2019-01-01 09:10:00.000 1546305000000
|
||||
sql insert into wh_mt2_tb1 values ('2019-01-01 00:00:00.000', '2019-01-01 09:00:00.000', 'binary10', 'nchar10')
|
||||
sql insert into wh_mt2_tb1 values ('2019-01-01 00:10:00.000', '2019-01-01 09:10:00.000', 'binary10', 'nchar10')
|
||||
sql insert into wh_mt2_tb1 values ('2019-01-01 00:10:00.000', '2019-01-01 09:10:00.000', 'binary10', 'nchar10')
|
||||
|
||||
sql select * from wh_mt2_tb1 where c1 > 1546304400000
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
|
|
|
@ -82,6 +82,7 @@ restful d1 table_rest 1591772800 30000
|
|||
restful d1 table_rest 1591872800 30000
|
||||
restful d1 table_rest 1591972800 30000
|
||||
|
||||
sleep 1000
|
||||
sql select * from table_rest;
|
||||
print rows: $rows
|
||||
if $rows != 300000 then
|
||||
|
|
|
@ -20,6 +20,10 @@ system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 20000
|
|||
system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 20000
|
||||
system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 20000
|
||||
|
||||
system sh/cfg.sh -n dnode1 -c minTablesPerVnode -v 1000
|
||||
system sh/cfg.sh -n dnode2 -c minTablesPerVnode -v 1000
|
||||
system sh/cfg.sh -n dnode3 -c minTablesPerVnode -v 1000
|
||||
|
||||
system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 20
|
||||
system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 20
|
||||
system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 20
|
||||
|
|
|
@ -31,8 +31,8 @@ IF (TD_LINUX)
|
|||
#add_executable(createTablePerformance createTablePerformance.c)
|
||||
#target_link_libraries(createTablePerformance taos_static tutil common pthread)
|
||||
|
||||
#add_executable(createNormalTable createNormalTable.c)
|
||||
#target_link_libraries(createNormalTable taos_static tutil common pthread)
|
||||
add_executable(createNormalTable createNormalTable.c)
|
||||
target_link_libraries(createNormalTable taos_static tutil common pthread)
|
||||
|
||||
#add_executable(queryPerformance queryPerformance.c)
|
||||
#target_link_libraries(queryPerformance taos_static tutil common pthread)
|
||||
|
@ -45,5 +45,8 @@ IF (TD_LINUX)
|
|||
|
||||
#add_executable(invalidTableId invalidTableId.c)
|
||||
#target_link_libraries(invalidTableId taos_static tutil common pthread)
|
||||
|
||||
add_executable(hashIterator hashIterator.c)
|
||||
target_link_libraries(hashIterator taos_static tutil common pthread)
|
||||
ENDIF()
|
||||
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taos.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#include "hash.h"
|
||||
|
||||
typedef struct HashTestRow {
|
||||
int32_t keySize;
|
||||
char key[100];
|
||||
} HashTestRow;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
_hash_fn_t hashFp = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
||||
void * hashHandle = taosHashInit(100, hashFp, true, HASH_ENTRY_LOCK);
|
||||
|
||||
pPrint("insert 3 rows to hash");
|
||||
for (int32_t t = 0; t < 3; ++t) {
|
||||
HashTestRow row = {0};
|
||||
row.keySize = sprintf(row.key, "0.db.st%d", t);
|
||||
|
||||
taosHashPut(hashHandle, row.key, row.keySize, &row, sizeof(HashTestRow));
|
||||
}
|
||||
|
||||
pPrint("start iterator");
|
||||
HashTestRow *row = taosHashIterate(hashHandle, NULL);
|
||||
while (row) {
|
||||
pPrint("drop key:%s", row->key);
|
||||
taosHashRemove(hashHandle, row->key, row->keySize);
|
||||
|
||||
pPrint("get rows from hash");
|
||||
for (int32_t t = 0; t < 3; ++t) {
|
||||
HashTestRow r = {0};
|
||||
r.keySize = sprintf(r.key, "0.db.st%d", t);
|
||||
|
||||
void *result = taosHashGet(hashHandle, r.key, r.keySize);
|
||||
pPrint("get key:%s result:%p", r.key, result);
|
||||
}
|
||||
|
||||
//Before getting the next iterator, the object just deleted can be obtained
|
||||
row = taosHashIterate(hashHandle, row);
|
||||
}
|
||||
|
||||
pPrint("stop iterator");
|
||||
taosHashCancelIterate(hashHandle, row);
|
||||
|
||||
pPrint("get rows from hash");
|
||||
for (int32_t t = 0; t < 3; ++t) {
|
||||
HashTestRow r = {0};
|
||||
r.keySize = sprintf(r.key, "0.db.st%d", t);
|
||||
|
||||
void *result = taosHashGet(hashHandle, r.key, r.keySize);
|
||||
pPrint("get key:%s result:%p", r.key, result);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue