From 5a4b51a9685043cd70235da2dd3d72cf7e2f3450 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 25 Jun 2022 20:36:38 +0800 Subject: [PATCH] fix index bug --- include/libs/index/index.h | 23 +- source/dnode/vnode/src/meta/metaTable.c | 45 ++-- source/libs/executor/src/executil.c | 135 ++++++------ source/libs/index/inc/indexInt.h | 2 + source/libs/index/src/index.c | 53 ++++- source/libs/index/src/indexFilter.c | 16 +- source/os/src/osAtomic.c | 276 +++++++++++------------- 7 files changed, 290 insertions(+), 260 deletions(-) diff --git a/include/libs/index/index.h b/include/libs/index/index.h index 9e71c941d3..dd991b3d4f 100644 --- a/include/libs/index/index.h +++ b/include/libs/index/index.h @@ -127,7 +127,7 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* query, SArray* result); * @parma opt (input, rebuild index opts) * @return error code */ -int indexRebuild(SIndex* index, SIndexOpts* opt); +// int indexRebuild(SIndex* index, SIndexOpts* opt); /* * open index @@ -185,6 +185,25 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn operType, uint8_t c int32_t nColName, const char* colVal, int32_t nColVal); void indexTermDestroy(SIndexTerm* p); +/* + * rebuild index + */ +void indexRebuild(SIndexJson* idx, void* iter); + +/* + * check index json status + **/ +bool indexIsRebuild(SIndex* idx); +/* + * rebuild index json + */ +void indexJsonRebuild(SIndexJson* idx, void* iter); + +/* + * check index json status + **/ +bool indexJsonIsRebuild(SIndexJson* idx); + /* * init index env * @@ -203,7 +222,7 @@ typedef enum { SFLT_NOT_INDEX, SFLT_COARSE_INDEX, SFLT_ACCURATE_INDEX } SIdxFltS SIdxFltStatus idxGetFltStatus(SNode* pFilterNode); -int32_t doFilterTag(const SNode* pFilterNode, SIndexMetaArg* metaArg, SArray* result); +int32_t doFilterTag(SNode* pFilterNode, SIndexMetaArg* metaArg, SArray* result, SIdxFltStatus* status); /* * destory index env * diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 7109bf1dfc..7272475af8 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -374,22 +374,22 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi int metaTtlDropTable(SMeta *pMeta, int64_t ttl, SArray *tbUids) { metaWLock(pMeta); int ret = metaTtlSmaller(pMeta, ttl, tbUids); - if(ret != 0){ + if (ret != 0) { metaULock(pMeta); return ret; } for (int i = 0; i < taosArrayGetSize(tbUids); ++i) { tb_uid_t *uid = (tb_uid_t *)taosArrayGet(tbUids, i); metaDropTableByUid(pMeta, *uid, NULL); - metaDebug("ttl drop table:%"PRId64, *uid); + metaDebug("ttl drop table:%" PRId64, *uid); } metaULock(pMeta); return 0; } -static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){ - int64_t ttlDays; - int64_t ctime; +static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME) { + int64_t ttlDays; + int64_t ctime; if (pME->type == TSDB_CHILD_TABLE) { ctime = pME->ctbEntry.ctime; ttlDays = pME->ctbEntry.ttlDays; @@ -409,11 +409,10 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){ static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { STtlIdxKey ttlKey = {0}; metaBuildTtlIdxKey(&ttlKey, pME); - if(ttlKey.dtime == 0) return 0; + if (ttlKey.dtime == 0) return 0; return tdbTbDelete(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), &pMeta->txn); } - static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { void * pData = NULL; int nData = 0; @@ -434,7 +433,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pMeta->txn); tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn); tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn); - if(e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e); + if (e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e); if (e.type == TSDB_CHILD_TABLE) { tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn); @@ -757,15 +756,15 @@ _err: } static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { - void * pVal = NULL; - int nVal = 0; - const void * pData = NULL; - int nData = 0; - int ret = 0; - tb_uid_t uid; - int64_t oversion; - SMetaEntry entry = {0}; - int c = 0; + void * pVal = NULL; + int nVal = 0; + const void *pData = NULL; + int nData = 0; + int ret = 0; + tb_uid_t uid; + int64_t oversion; + SMetaEntry entry = {0}; + int c = 0; // search name index ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); @@ -808,22 +807,22 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p metaWLock(pMeta); // build SMetaEntry if (entry.type == TSDB_CHILD_TABLE) { - if(pAlterTbReq->updateTTL) { + if (pAlterTbReq->updateTTL) { metaDeleteTtlIdx(pMeta, &entry); entry.ctbEntry.ttlDays = pAlterTbReq->newTTL; metaUpdateTtlIdx(pMeta, &entry); } - if(pAlterTbReq->newCommentLen >= 0) { + if (pAlterTbReq->newCommentLen >= 0) { entry.ctbEntry.commentLen = pAlterTbReq->newCommentLen; entry.ctbEntry.comment = pAlterTbReq->newComment; } } else { - if(pAlterTbReq->updateTTL) { + if (pAlterTbReq->updateTTL) { metaDeleteTtlIdx(pMeta, &entry); entry.ntbEntry.ttlDays = pAlterTbReq->newTTL; metaUpdateTtlIdx(pMeta, &entry); } - if(pAlterTbReq->newCommentLen >= 0) { + if (pAlterTbReq->newCommentLen >= 0) { entry.ntbEntry.commentLen = pAlterTbReq->newCommentLen; entry.ntbEntry.comment = pAlterTbReq->newComment; } @@ -918,7 +917,7 @@ static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) { static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { STtlIdxKey ttlKey = {0}; metaBuildTtlIdxKey(&ttlKey, pME); - if(ttlKey.dtime == 0) return 0; + if (ttlKey.dtime == 0) return 0; return tdbTbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn); } @@ -976,7 +975,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { SDecoder dc = {0}; // get super table - if(tdbTbGet(pMeta->pUidIdx, &pCtbEntry->ctbEntry.suid, sizeof(tb_uid_t), &pData, &nData) != 0){ + if (tdbTbGet(pMeta->pUidIdx, &pCtbEntry->ctbEntry.suid, sizeof(tb_uid_t), &pData, &nData) != 0) { return -1; } tbDbKey.uid = pCtbEntry->ctbEntry.suid; diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 5ac5957f2b..7dc345a0d6 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -13,10 +13,10 @@ * along with this program. If not, see . */ -#include "os.h" -#include "index.h" #include "function.h" #include "functionMgt.h" +#include "index.h" +#include "os.h" #include "tdatablock.h" #include "thash.h" #include "tmsg.h" @@ -25,45 +25,41 @@ #include "executorimpl.h" #include "tcompression.h" -void initResultRowInfo(SResultRowInfo *pResultRowInfo) { - pResultRowInfo->size = 0; +void initResultRowInfo(SResultRowInfo* pResultRowInfo) { + pResultRowInfo->size = 0; pResultRowInfo->cur.pageId = -1; } -void cleanupResultRowInfo(SResultRowInfo *pResultRowInfo) { +void cleanupResultRowInfo(SResultRowInfo* pResultRowInfo) { if (pResultRowInfo == NULL) { return; } - for(int32_t i = 0; i < pResultRowInfo->size; ++i) { -// if (pResultRowInfo->pResult[i]) { -// taosMemoryFreeClear(pResultRowInfo->pResult[i]->key); -// } + for (int32_t i = 0; i < pResultRowInfo->size; ++i) { + // if (pResultRowInfo->pResult[i]) { + // taosMemoryFreeClear(pResultRowInfo->pResult[i]->key); + // } } } -void closeAllResultRows(SResultRowInfo *pResultRowInfo) { -// do nothing +void closeAllResultRows(SResultRowInfo* pResultRowInfo) { + // do nothing } -bool isResultRowClosed(SResultRow* pRow) { - return (pRow->closed == true); -} +bool isResultRowClosed(SResultRow* pRow) { return (pRow->closed == true); } -void closeResultRow(SResultRow* pResultRow) { - pResultRow->closed = true; -} +void closeResultRow(SResultRow* pResultRow) { pResultRow->closed = true; } // TODO refactor: use macro SResultRowEntryInfo* getResultEntryInfo(const SResultRow* pRow, int32_t index, const int32_t* offset) { assert(index >= 0 && offset != NULL); - return (SResultRowEntryInfo*)((char*) pRow->pEntryInfo + offset[index]); + return (SResultRowEntryInfo*)((char*)pRow->pEntryInfo + offset[index]); } size_t getResultRowSize(SqlFunctionCtx* pCtx, int32_t numOfOutput) { int32_t rowSize = (numOfOutput * sizeof(SResultRowEntryInfo)) + sizeof(SResultRow); - for(int32_t i = 0; i < numOfOutput; ++i) { + for (int32_t i = 0; i < numOfOutput; ++i) { rowSize += pCtx[i].resDataInfo.interBufSize; } @@ -74,31 +70,29 @@ void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo) { assert(pGroupResInfo != NULL); taosArrayDestroy(pGroupResInfo->pRows); - pGroupResInfo->pRows = NULL; - pGroupResInfo->index = 0; + pGroupResInfo->pRows = NULL; + pGroupResInfo->index = 0; } static int32_t resultrowComparAsc(const void* p1, const void* p2) { - SResKeyPos* pp1 = *(SResKeyPos**) p1; - SResKeyPos* pp2 = *(SResKeyPos**) p2; + SResKeyPos* pp1 = *(SResKeyPos**)p1; + SResKeyPos* pp2 = *(SResKeyPos**)p2; if (pp1->groupId == pp2->groupId) { - int64_t pts1 = *(int64_t*) pp1->key; - int64_t pts2 = *(int64_t*) pp2->key; + int64_t pts1 = *(int64_t*)pp1->key; + int64_t pts2 = *(int64_t*)pp2->key; if (pts1 == pts2) { return 0; } else { - return pts1 < pts2? -1:1; + return pts1 < pts2 ? -1 : 1; } } else { - return pp1->groupId < pp2->groupId? -1:1; + return pp1->groupId < pp2->groupId ? -1 : 1; } } -static int32_t resultrowComparDesc(const void* p1, const void* p2) { - return resultrowComparAsc(p2, p1); -} +static int32_t resultrowComparDesc(const void* p1, const void* p2) { return resultrowComparAsc(p2, p1); } void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SHashObj* pHashmap, int32_t order) { if (pGroupResInfo->pRows != NULL) { @@ -110,20 +104,20 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SHashObj* pHashmap, int pGroupResInfo->pRows = taosArrayInit(10, POINTER_BYTES); size_t keyLen = 0; - while((pData = taosHashIterate(pHashmap, pData)) != NULL) { + while ((pData = taosHashIterate(pHashmap, pData)) != NULL) { void* key = taosHashGetKey(pData, &keyLen); SResKeyPos* p = taosMemoryMalloc(keyLen + sizeof(SResultRowPosition)); - p->groupId = *(uint64_t*) key; - p->pos = *(SResultRowPosition*) pData; + p->groupId = *(uint64_t*)key; + p->pos = *(SResultRowPosition*)pData; memcpy(p->key, (char*)key + sizeof(uint64_t), keyLen - sizeof(uint64_t)); taosArrayPush(pGroupResInfo->pRows, &p); } if (order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC) { - __compar_fn_t fn = (order == TSDB_ORDER_ASC)? resultrowComparAsc:resultrowComparDesc; + __compar_fn_t fn = (order == TSDB_ORDER_ASC) ? resultrowComparAsc : resultrowComparDesc; qsort(pGroupResInfo->pRows->pData, taosArrayGetSize(pGroupResInfo->pRows), POINTER_BYTES, fn); } @@ -155,7 +149,7 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) { return 0; } - return (int32_t) taosArrayGetSize(pGroupResInfo->pRows); + return (int32_t)taosArrayGetSize(pGroupResInfo->pRows); } SArray* createSortInfo(SNodeList* pNodeList) { @@ -189,12 +183,13 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) { pBlock->info.type = STREAM_INVALID; for (int32_t i = 0; i < numOfCols; ++i) { - SSlotDescNode* pDescNode = (SSlotDescNode*)nodesListGetNode(pNode->pSlots, i); -// if (!pDescNode->output) { // todo disable it temporarily -// continue; -// } + SSlotDescNode* pDescNode = (SSlotDescNode*)nodesListGetNode(pNode->pSlots, i); + // if (!pDescNode->output) { // todo disable it temporarily + // continue; + // } - SColumnInfoData idata = createColumnInfoData(pDescNode->dataType.type, pDescNode->dataType.bytes, pDescNode->slotId); + SColumnInfoData idata = + createColumnInfoData(pDescNode->dataType.type, pDescNode->dataType.bytes, pDescNode->slotId); idata.info.scale = pDescNode->dataType.scale; idata.info.precision = pDescNode->dataType.precision; @@ -206,10 +201,10 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) { EDealRes doTranslateTagExpr(SNode** pNode, void* pContext) { SMetaReader* mr = (SMetaReader*)pContext; - if(nodeType(*pNode) == QUERY_NODE_COLUMN){ + if (nodeType(*pNode) == QUERY_NODE_COLUMN) { SColumnNode* pSColumnNode = *(SColumnNode**)pNode; - SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); + SValueNode* res = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); if (NULL == res) { return DEAL_RES_ERROR; } @@ -222,8 +217,8 @@ EDealRes doTranslateTagExpr(SNode** pNode, void* pContext) { const char* p = metaGetTableTagVal(&mr->me, pSColumnNode->node.resType.type, &tagVal); if (p == NULL) { res->node.resType.type = TSDB_DATA_TYPE_NULL; - }else if (pSColumnNode->node.resType.type == TSDB_DATA_TYPE_JSON) { - int32_t len = ((const STag*)p) -> len; + } else if (pSColumnNode->node.resType.type == TSDB_DATA_TYPE_JSON) { + int32_t len = ((const STag*)p)->len; res->datum.p = taosMemoryCalloc(len + 1, 1); memcpy(res->datum.p, p, len); } else if (IS_VAR_DATA_TYPE(pSColumnNode->node.resType.type)) { @@ -235,10 +230,10 @@ EDealRes doTranslateTagExpr(SNode** pNode, void* pContext) { } nodesDestroyNode(*pNode); *pNode = (SNode*)res; - }else if (nodeType(*pNode) == QUERY_NODE_FUNCTION){ - SFunctionNode * pFuncNode = *(SFunctionNode**)pNode; - if(pFuncNode->funcType == FUNCTION_TYPE_TBNAME){ - SValueNode *res = (SValueNode *)nodesMakeNode(QUERY_NODE_VALUE); + } else if (nodeType(*pNode) == QUERY_NODE_FUNCTION) { + SFunctionNode* pFuncNode = *(SFunctionNode**)pNode; + if (pFuncNode->funcType == FUNCTION_TYPE_TBNAME) { + SValueNode* res = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); if (NULL == res) { return DEAL_RES_ERROR; } @@ -258,12 +253,12 @@ EDealRes doTranslateTagExpr(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } -static bool isTableOk(STableKeyInfo* info, SNode *pTagCond, SMeta *metaHandle){ - SMetaReader mr = {0}; +static bool isTableOk(STableKeyInfo* info, SNode* pTagCond, SMeta* metaHandle) { + SMetaReader mr = {0}; metaReaderInit(&mr, metaHandle, 0); metaGetTableEntryByUid(&mr, info->uid); - SNode *pTagCondTmp = nodesCloneNode(pTagCond); + SNode* pTagCondTmp = nodesCloneNode(pTagCond); nodesRewriteExprPostOrder(&pTagCondTmp, doTranslateTagExpr, &mr); metaReaderClear(&mr); @@ -276,7 +271,7 @@ static bool isTableOk(STableKeyInfo* info, SNode *pTagCond, SMeta *metaHandle){ } ASSERT(nodeType(pNew) == QUERY_NODE_VALUE); - SValueNode *pValue = (SValueNode *)pNew; + SValueNode* pValue = (SValueNode*)pNew; ASSERT(pValue->node.resType.type == TSDB_DATA_TYPE_BOOL); bool result = pValue->datum.b; @@ -287,12 +282,12 @@ static bool isTableOk(STableKeyInfo* info, SNode *pTagCond, SMeta *metaHandle){ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo* pListInfo) { int32_t code = TSDB_CODE_SUCCESS; pListInfo->pTableList = taosArrayInit(8, sizeof(STableKeyInfo)); - if(pListInfo->pTableList == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (pListInfo->pTableList == NULL) return TSDB_CODE_OUT_OF_MEMORY; uint64_t tableUid = pScanNode->uid; pListInfo->suid = pScanNode->suid; - + SNode* pTagCond = (SNode*)pListInfo->pTagCond; SNode* pTagIndexCond = (SNode*)pListInfo->pTagIndexCond; if (pScanNode->tableType == TSDB_SUPER_TABLE) { @@ -300,9 +295,12 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo SIndexMetaArg metaArg = { .metaEx = metaHandle, .idx = tsdbGetIdx(metaHandle), .ivtIdx = tsdbGetIvtIdx(metaHandle), .suid = tableUid}; - SArray* res = taosArrayInit(8, sizeof(uint64_t)); - //code = doFilterTag(pTagIndexCond, &metaArg, res); - code = TSDB_CODE_INDEX_REBUILDING; + SArray* res = taosArrayInit(8, sizeof(uint64_t)); + SIdxFltStatus status = SFLT_NOT_INDEX; + code = doFilterTag(pTagIndexCond, &metaArg, res, &status); + if (code != 0 || status == SFLT_NOT_INDEX) { + code = TSDB_CODE_INDEX_REBUILDING; + } if (code == TSDB_CODE_INDEX_REBUILDING) { code = tsdbGetAllTableList(metaHandle, tableUid, pListInfo->pTableList); } else if (code != TSDB_CODE_SUCCESS) { @@ -323,33 +321,33 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo code = tsdbGetAllTableList(metaHandle, tableUid, pListInfo->pTableList); } - if(pTagCond){ + if (pTagCond) { int32_t i = 0; - while(i < taosArrayGetSize(pListInfo->pTableList)) { + while (i < taosArrayGetSize(pListInfo->pTableList)) { STableKeyInfo* info = taosArrayGet(pListInfo->pTableList, i); - bool isOk = isTableOk(info, pTagCond, metaHandle); - if(!isOk){ + bool isOk = isTableOk(info, pTagCond, metaHandle); + if (!isOk) { taosArrayRemove(pListInfo->pTableList, i); continue; } i++; } } - }else { // Create one table group. + } else { // Create one table group. STableKeyInfo info = {.lastKey = 0, .uid = tableUid}; taosArrayPush(pListInfo->pTableList, &info); } pListInfo->pGroupList = taosArrayInit(4, POINTER_BYTES); - if(pListInfo->pGroupList == NULL) return TSDB_CODE_OUT_OF_MEMORY; + if (pListInfo->pGroupList == NULL) return TSDB_CODE_OUT_OF_MEMORY; - //put into list as default group, remove it if grouping sorting is required later + // put into list as default group, remove it if grouping sorting is required later taosArrayPush(pListInfo->pGroupList, &pListInfo->pTableList); return code; } SArray* extractPartitionColInfo(SNodeList* pNodeList) { - if(!pNodeList) { + if (!pNodeList) { return NULL; } @@ -378,7 +376,6 @@ SArray* extractPartitionColInfo(SNodeList* pNodeList) { return pList; } - SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols, int32_t type) { size_t numOfCols = LIST_LENGTH(pNodeList); @@ -394,7 +391,7 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod SColMatchInfo c = {0}; c.output = true; - c.colId = pColNode->colId; + c.colId = pColNode->colId; c.srcSlotId = pColNode->slotId; c.matchType = type; c.targetSlotId = pNode->slotId; @@ -670,8 +667,8 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, } for (int32_t i = 1; i < numOfOutput; ++i) { - (*rowEntryInfoOffset)[i] = - (int32_t)((*rowEntryInfoOffset)[i - 1] + sizeof(SResultRowEntryInfo) + pFuncCtx[i - 1].resDataInfo.interBufSize); + (*rowEntryInfoOffset)[i] = (int32_t)((*rowEntryInfoOffset)[i - 1] + sizeof(SResultRowEntryInfo) + + pFuncCtx[i - 1].resDataInfo.interBufSize); } setSelectValueColumnInfo(pFuncCtx, numOfOutput); diff --git a/source/libs/index/inc/indexInt.h b/source/libs/index/inc/indexInt.h index 906cbb6a20..d50fa0e917 100644 --- a/source/libs/index/inc/indexInt.h +++ b/source/libs/index/inc/indexInt.h @@ -45,6 +45,7 @@ extern "C" { typedef enum { LT, LE, GT, GE, CONTAINS, EQ } RangeType; typedef enum { kTypeValue, kTypeDeletion } STermValueType; +typedef enum { kRebuild, kFinished } SIdxStatus; typedef struct SIndexStat { int32_t totalAdded; // @@ -65,6 +66,7 @@ struct SIndex { char* path; + int8_t status; SIndexStat stat; TdThreadMutex mtx; tsem_t sem; diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index d6d55c6be0..1f23d66490 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -39,7 +39,7 @@ #define INDEX_DATA_BIGINT_NULL 0x8000000000000000LL #define INDEX_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL -#define INDEX_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN +#define INDEX_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN #define INDEX_DATA_DOUBLE_NULL 0x7FFFFF0000000000LL // an NAN #define INDEX_DATA_NCHAR_NULL 0xFFFFFFFF #define INDEX_DATA_BINARY_NULL 0xFF @@ -230,7 +230,7 @@ int indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* result } int indexDelete(SIndex* index, SIndexMultiTermQuery* query) { return 1; } -int indexRebuild(SIndex* index, SIndexOpts* opts) { return 0; } +// int indexRebuild(SIndex* index, SIndexOpts* opts) { return 0; } SIndexOpts* indexOptsCreate() { return NULL; } void indexOptsDestroy(SIndexOpts* opts) { return; } @@ -299,6 +299,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy return tm; } + void indexTermDestroy(SIndexTerm* p) { taosMemoryFree(p->colName); taosMemoryFree(p->colVal); @@ -319,6 +320,54 @@ void indexMultiTermDestroy(SIndexMultiTerm* terms) { taosArrayDestroy(terms); } +/* + * rebuild index + */ + +static void idxSchedRebuildIdx(SSchedMsg* msg) { + // TODO + SIndex* idx = msg->ahandle; + + int8_t st = kFinished; + atomic_store_8(&idx->status, st); + idxReleaseRef(idx->refId); +} +void indexRebuild(SIndexJson* idx, void* iter) { + // set up rebuild status + int8_t st = kRebuild; + atomic_store_8(&idx->status, st); + + // task put into BG thread + SSchedMsg schedMsg = {0}; + schedMsg.fp = idxSchedRebuildIdx; + schedMsg.ahandle = idx; + idxAcquireRef(idx->refId); + taosScheduleTask(indexQhandle, &schedMsg); +} + +/* + * check index json status + **/ +bool indexIsRebuild(SIndex* idx) { + // idx rebuild or not + return ((SIdxStatus)atomic_load_8(&idx->status)) == kRebuild ? true : false; +} +/* + * rebuild index + */ +void indexJsonRebuild(SIndexJson* idx, void* iter) { + // idx rebuild or not + indexRebuild(idx, iter); +} + +/* + * check index json status + **/ +bool indexJsonIsRebuild(SIndexJson* idx) { + // load idx rebuild or not + return ((SIdxStatus)atomic_load_8(&idx->status)) == kRebuild ? true : false; +} + static int idxTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result) { SIndexTerm* term = query->term; const char* colName = term->colName; diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index 90aafb1097..74beef4f82 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -192,7 +192,7 @@ static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) { switch (nodeType(node)) { case QUERY_NODE_VALUE: { SValueNode *vn = (SValueNode *)node; - if (vn->typeData == TSDB_DATA_TYPE_NULL && (vn->literal == NULL || strlen(vn->literal) == 0)) { + if (vn->typeData == TSDB_DATA_TYPE_NULL || (vn->literal == NULL || strlen(vn->literal) == 0)) { param->status = SFLT_NOT_INDEX; return 0; } @@ -737,21 +737,20 @@ static int32_t sifGetFltHint(SNode *pNode, SIdxFltStatus *status) { SIF_RET(code); } -int32_t doFilterTag(const SNode *pFilterNode, SIndexMetaArg *metaArg, SArray *result) { - if (pFilterNode == NULL) { - return TSDB_CODE_SUCCESS; +int32_t doFilterTag(SNode *pFilterNode, SIndexMetaArg *metaArg, SArray *result, SIdxFltStatus *status) { + SIdxFltStatus st = idxGetFltStatus(pFilterNode); + if (st == SFLT_NOT_INDEX) { + *status = st; + return 0; } SFilterInfo *filter = NULL; - // todo move to the initialization function - // SIF_ERR_RET(filterInitFromNode((SNode *)pFilterNode, &filter, 0)); SArray * output = taosArrayInit(8, sizeof(uint64_t)); SIFParam param = {.arg = *metaArg, .result = output}; SIF_ERR_RET(sifCalculate((SNode *)pFilterNode, ¶m)); taosArrayAddAll(result, param.result); - // taosArrayAddAll(result, param.result); sifFreeParam(¶m); SIF_RET(TSDB_CODE_SUCCESS); } @@ -761,9 +760,6 @@ SIdxFltStatus idxGetFltStatus(SNode *pFilterNode) { if (pFilterNode == NULL) { return SFLT_NOT_INDEX; } - // SFilterInfo *filter = NULL; - // todo move to the initialization function - // SIF_ERR_RET(filterInitFromNode((SNode *)pFilterNode, &filter, 0)); SIF_ERR_RET(sifGetFltHint((SNode *)pFilterNode, &st)); return st; diff --git a/source/os/src/osAtomic.c b/source/os/src/osAtomic.c index e4d880f40a..33290d301a 100644 --- a/source/os/src/osAtomic.c +++ b/source/os/src/osAtomic.c @@ -19,23 +19,19 @@ #ifdef WINDOWS // add -int8_t interlocked_add_fetch_8(int8_t volatile* ptr, int8_t val) { - return _InterlockedExchangeAdd8(ptr, val) + val; -} +int8_t interlocked_add_fetch_8(int8_t volatile* ptr, int8_t val) { return _InterlockedExchangeAdd8(ptr, val) + val; } int16_t interlocked_add_fetch_16(int16_t volatile* ptr, int16_t val) { return _InterlockedExchangeAdd16(ptr, val) + val; } -int32_t interlocked_add_fetch_32(int32_t volatile* ptr, int32_t val) { - return _InterlockedExchangeAdd(ptr, val) + val; -} +int32_t interlocked_add_fetch_32(int32_t volatile* ptr, int32_t val) { return _InterlockedExchangeAdd(ptr, val) + val; } int64_t interlocked_add_fetch_64(int64_t volatile* ptr, int64_t val) { return InterlockedExchangeAdd64(ptr, val) + val; } -void* interlocked_add_fetch_ptr(void* volatile* ptr, void* val) { +void* interlocked_add_fetch_ptr(void* volatile* ptr, void* val) { #ifdef WINDOWS return (void*)(_InterlockedExchangeAdd((int32_t volatile*)(ptr), (int32_t)val) + (int32_t)val); #else @@ -43,17 +39,11 @@ void* interlocked_add_fetch_ptr(void* volatile* ptr, void* val) { #endif } -int8_t interlocked_and_fetch_8(int8_t volatile* ptr, int8_t val) { - return _InterlockedAnd8(ptr, val) & val; -} +int8_t interlocked_and_fetch_8(int8_t volatile* ptr, int8_t val) { return _InterlockedAnd8(ptr, val) & val; } -int16_t interlocked_and_fetch_16(int16_t volatile* ptr, int16_t val) { - return _InterlockedAnd16(ptr, val) & val; -} +int16_t interlocked_and_fetch_16(int16_t volatile* ptr, int16_t val) { return _InterlockedAnd16(ptr, val) & val; } -int32_t interlocked_and_fetch_32(int32_t volatile* ptr, int32_t val) { - return _InterlockedAnd(ptr, val) & val; -} +int32_t interlocked_and_fetch_32(int32_t volatile* ptr, int32_t val) { return _InterlockedAnd(ptr, val) & val; } int64_t interlocked_and_fetch_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS @@ -96,17 +86,11 @@ void* interlocked_fetch_and_ptr(void* volatile* ptr, void* val) { #endif } -int8_t interlocked_or_fetch_8(int8_t volatile* ptr, int8_t val) { - return _InterlockedOr8(ptr, val) | val; -} +int8_t interlocked_or_fetch_8(int8_t volatile* ptr, int8_t val) { return _InterlockedOr8(ptr, val) | val; } -int16_t interlocked_or_fetch_16(int16_t volatile* ptr, int16_t val) { - return _InterlockedOr16(ptr, val) | val; -} +int16_t interlocked_or_fetch_16(int16_t volatile* ptr, int16_t val) { return _InterlockedOr16(ptr, val) | val; } -int32_t interlocked_or_fetch_32(int32_t volatile* ptr, int32_t val) { - return _InterlockedOr(ptr, val) | val; -} +int32_t interlocked_or_fetch_32(int32_t volatile* ptr, int32_t val) { return _InterlockedOr(ptr, val) | val; } int64_t interlocked_or_fetch_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS @@ -114,7 +98,7 @@ int64_t interlocked_or_fetch_64(int64_t volatile* ptr, int64_t val) { do { old = *ptr; res = old | val; - } while(_InterlockedCompareExchange64(ptr, res, old) != old); + } while (_InterlockedCompareExchange64(ptr, res, old) != old); return res; #else return _InterlockedOr64(ptr, val) & val; @@ -134,7 +118,7 @@ int64_t interlocked_fetch_or_64(int64_t volatile* ptr, int64_t val) { int64_t old; do { old = *ptr; - } while(_InterlockedCompareExchange64(ptr, old | val, old) != old); + } while (_InterlockedCompareExchange64(ptr, old | val, old) != old); return old; #else return _InterlockedOr64((int64_t volatile*)(ptr), (int64_t)(val)); @@ -149,17 +133,11 @@ void* interlocked_fetch_or_ptr(void* volatile* ptr, void* val) { #endif } -int8_t interlocked_xor_fetch_8(int8_t volatile* ptr, int8_t val) { - return _InterlockedXor8(ptr, val) ^ val; -} +int8_t interlocked_xor_fetch_8(int8_t volatile* ptr, int8_t val) { return _InterlockedXor8(ptr, val) ^ val; } -int16_t interlocked_xor_fetch_16(int16_t volatile* ptr, int16_t val) { - return _InterlockedXor16(ptr, val) ^ val; -} +int16_t interlocked_xor_fetch_16(int16_t volatile* ptr, int16_t val) { return _InterlockedXor16(ptr, val) ^ val; } -int32_t interlocked_xor_fetch_32(int32_t volatile* ptr, int32_t val) { - return _InterlockedXor(ptr, val) ^ val; -} +int32_t interlocked_xor_fetch_32(int32_t volatile* ptr, int32_t val) { return _InterlockedXor(ptr, val) ^ val; } int64_t interlocked_xor_fetch_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS @@ -167,7 +145,7 @@ int64_t interlocked_xor_fetch_64(int64_t volatile* ptr, int64_t val) { do { old = *ptr; res = old ^ val; - } while(_InterlockedCompareExchange64(ptr, res, old) != old); + } while (_InterlockedCompareExchange64(ptr, res, old) != old); return res; #else return _InterlockedXor64(ptr, val) ^ val; @@ -202,13 +180,9 @@ void* interlocked_fetch_xor_ptr(void* volatile* ptr, void* val) { #endif } -int32_t interlocked_sub_fetch_32(int32_t volatile* ptr, int32_t val) { - return interlocked_add_fetch_32(ptr, -val); -} +int32_t interlocked_sub_fetch_32(int32_t volatile* ptr, int32_t val) { return interlocked_add_fetch_32(ptr, -val); } -int64_t interlocked_sub_fetch_64(int64_t volatile* ptr, int64_t val) { - return interlocked_add_fetch_64(ptr, -val); -} +int64_t interlocked_sub_fetch_64(int64_t volatile* ptr, int64_t val) { return interlocked_add_fetch_64(ptr, -val); } void* interlocked_sub_fetch_ptr(void* volatile* ptr, void* val) { #ifdef WINDOWS @@ -217,13 +191,9 @@ void* interlocked_sub_fetch_ptr(void* volatile* ptr, void* val) { return (void*)interlocked_add_fetch_64((int64_t volatile*)ptr, (int64_t)val); #endif } -int32_t interlocked_fetch_sub_32(int32_t volatile* ptr, int32_t val) { - return _InterlockedExchangeAdd(ptr, -val); -} +int32_t interlocked_fetch_sub_32(int32_t volatile* ptr, int32_t val) { return _InterlockedExchangeAdd(ptr, -val); } -int64_t interlocked_fetch_sub_64(int64_t volatile* ptr, int64_t val) { - return _InterlockedExchangeAdd64(ptr, -val); -} +int64_t interlocked_fetch_sub_64(int64_t volatile* ptr, int64_t val) { return _InterlockedExchangeAdd64(ptr, -val); } void* interlocked_fetch_sub_ptr(void* volatile* ptr, void* val) { #ifdef WINDOWS @@ -236,45 +206,44 @@ void* interlocked_fetch_sub_ptr(void* volatile* ptr, void* val) { #endif #ifdef _TD_NINGSI_60 -void* atomic_exchange_ptr_impl(void** ptr, void* val ) { - void *old; +void* atomic_exchange_ptr_impl(void** ptr, void* val) { + void* old; do { old = *ptr; - } while( !__sync_bool_compare_and_swap(ptr, old, val) ); + } while (!__sync_bool_compare_and_swap(ptr, old, val)); return old; } -int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val ) { +int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val) { int8_t old; do { old = *ptr; - } while( !__sync_bool_compare_and_swap(ptr, old, val) ); + } while (!__sync_bool_compare_and_swap(ptr, old, val)); return old; } -int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val ) { +int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val) { int16_t old; do { old = *ptr; - } while( !__sync_bool_compare_and_swap(ptr, old, val) ); + } while (!__sync_bool_compare_and_swap(ptr, old, val)); return old; } -int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val ) { +int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val) { int32_t old; do { old = *ptr; - } while( !__sync_bool_compare_and_swap(ptr, old, val) ); + } while (!__sync_bool_compare_and_swap(ptr, old, val)); return old; } -int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val ) { +int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val) { int64_t old; do { old = *ptr; - } while( !__sync_bool_compare_and_swap(ptr, old, val) ); + } while (!__sync_bool_compare_and_swap(ptr, old, val)); return old; } #endif - -int8_t atomic_load_8(int8_t volatile *ptr) { +int8_t atomic_load_8(int8_t volatile* ptr) { #ifdef WINDOWS return (*(int8_t volatile*)(ptr)); #elif defined(_TD_NINGSI_60) @@ -284,7 +253,7 @@ int8_t atomic_load_8(int8_t volatile *ptr) { #endif } -int16_t atomic_load_16(int16_t volatile *ptr) { +int16_t atomic_load_16(int16_t volatile* ptr) { #ifdef WINDOWS return (*(int16_t volatile*)(ptr)); #elif defined(_TD_NINGSI_60) @@ -294,7 +263,7 @@ int16_t atomic_load_16(int16_t volatile *ptr) { #endif } -int32_t atomic_load_32(int32_t volatile *ptr) { +int32_t atomic_load_32(int32_t volatile* ptr) { #ifdef WINDOWS return (*(int32_t volatile*)(ptr)); #elif defined(_TD_NINGSI_60) @@ -304,7 +273,7 @@ int32_t atomic_load_32(int32_t volatile *ptr) { #endif } -int64_t atomic_load_64(int64_t volatile *ptr) { +int64_t atomic_load_64(int64_t volatile* ptr) { #ifdef WINDOWS return (*(int64_t volatile*)(ptr)); #elif defined(_TD_NINGSI_60) @@ -314,7 +283,7 @@ int64_t atomic_load_64(int64_t volatile *ptr) { #endif } -void* atomic_load_ptr(void *ptr) { +void* atomic_load_ptr(void* ptr) { #ifdef WINDOWS return (*(void* volatile*)(ptr)); #elif defined(_TD_NINGSI_60) @@ -324,57 +293,57 @@ void* atomic_load_ptr(void *ptr) { #endif } -void atomic_store_8(int8_t volatile *ptr, int8_t val) { +void atomic_store_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS ((*(int8_t volatile*)(ptr)) = (int8_t)(val)); #elif defined(_TD_NINGSI_60) - (*(ptr)=(val)); + (*(ptr) = (val)); #else __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST); #endif } -void atomic_store_16(int16_t volatile *ptr, int16_t val) { +void atomic_store_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS ((*(int16_t volatile*)(ptr)) = (int16_t)(val)); #elif defined(_TD_NINGSI_60) - (*(ptr)=(val)); + (*(ptr) = (val)); #else __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST); #endif } -void atomic_store_32(int32_t volatile *ptr, int32_t val) { +void atomic_store_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS ((*(int32_t volatile*)(ptr)) = (int32_t)(val)); #elif defined(_TD_NINGSI_60) - (*(ptr)=(val)); + (*(ptr) = (val)); #else __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST); #endif } -void atomic_store_64(int64_t volatile *ptr, int64_t val) { +void atomic_store_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS ((*(int64_t volatile*)(ptr)) = (int64_t)(val)); #elif defined(_TD_NINGSI_60) - (*(ptr)=(val)); + (*(ptr) = (val)); #else __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST); #endif } -void atomic_store_ptr(void *ptr, void *val) { +void atomic_store_ptr(void* ptr, void* val) { #ifdef WINDOWS ((*(void* volatile*)(ptr)) = (void*)(val)); #elif defined(_TD_NINGSI_60) - (*(ptr)=(val)); + (*(ptr) = (val)); #else - __atomic_store_n((void **)(ptr), (val), __ATOMIC_SEQ_CST); + __atomic_store_n((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_exchange_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_exchange_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return _InterlockedExchange8((int8_t volatile*)(ptr), (int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -384,7 +353,7 @@ int8_t atomic_exchange_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_exchange_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_exchange_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return _InterlockedExchange16((int16_t volatile*)(ptr), (int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -394,7 +363,7 @@ int16_t atomic_exchange_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_exchange_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_exchange_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return _InterlockedExchange((int32_t volatile*)(ptr), (int32_t)(val)); #elif defined(_TD_NINGSI_60) @@ -404,7 +373,7 @@ int32_t atomic_exchange_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_exchange_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_exchange_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return _InterlockedExchange64((int64_t volatile*)(ptr), (int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -414,21 +383,21 @@ int64_t atomic_exchange_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_exchange_ptr(void *ptr, void *val) { +void* atomic_exchange_ptr(void* ptr, void* val) { #ifdef WINDOWS - #ifdef _WIN64 +#ifdef _WIN64 return _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)); - #else +#else return _InlineInterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)); - #endif +#endif #elif defined(_TD_NINGSI_60) - return atomic_exchange_ptr_impl((void *)ptr, (void*)val); + return atomic_exchange_ptr_impl((void*)ptr, (void*)val); #else - return __atomic_exchange_n((void **)(ptr), (val), __ATOMIC_SEQ_CST); + return __atomic_exchange_n((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_val_compare_exchange_8(int8_t volatile *ptr, int8_t oldval, int8_t newval) { +int8_t atomic_val_compare_exchange_8(int8_t volatile* ptr, int8_t oldval, int8_t newval) { #ifdef WINDOWS return _InterlockedCompareExchange8((int8_t volatile*)(ptr), (int8_t)(newval), (int8_t)(oldval)); #elif defined(_TD_NINGSI_60) @@ -438,7 +407,7 @@ int8_t atomic_val_compare_exchange_8(int8_t volatile *ptr, int8_t oldval, int8_t #endif } -int16_t atomic_val_compare_exchange_16(int16_t volatile *ptr, int16_t oldval, int16_t newval) { +int16_t atomic_val_compare_exchange_16(int16_t volatile* ptr, int16_t oldval, int16_t newval) { #ifdef WINDOWS return _InterlockedCompareExchange16((int16_t volatile*)(ptr), (int16_t)(newval), (int16_t)(oldval)); #elif defined(_TD_NINGSI_60) @@ -448,7 +417,7 @@ int16_t atomic_val_compare_exchange_16(int16_t volatile *ptr, int16_t oldval, in #endif } -int32_t atomic_val_compare_exchange_32(int32_t volatile *ptr, int32_t oldval, int32_t newval) { +int32_t atomic_val_compare_exchange_32(int32_t volatile* ptr, int32_t oldval, int32_t newval) { #ifdef WINDOWS return _InterlockedCompareExchange((int32_t volatile*)(ptr), (int32_t)(newval), (int32_t)(oldval)); #elif defined(_TD_NINGSI_60) @@ -458,7 +427,7 @@ int32_t atomic_val_compare_exchange_32(int32_t volatile *ptr, int32_t oldval, in #endif } -int64_t atomic_val_compare_exchange_64(int64_t volatile *ptr, int64_t oldval, int64_t newval) { +int64_t atomic_val_compare_exchange_64(int64_t volatile* ptr, int64_t oldval, int64_t newval) { #ifdef WINDOWS return _InterlockedCompareExchange64((int64_t volatile*)(ptr), (int64_t)(newval), (int64_t)(oldval)); #elif defined(_TD_NINGSI_60) @@ -468,17 +437,17 @@ int64_t atomic_val_compare_exchange_64(int64_t volatile *ptr, int64_t oldval, in #endif } -void* atomic_val_compare_exchange_ptr(void *ptr, void *oldval, void *newval) { +void* atomic_val_compare_exchange_ptr(void* ptr, void* oldval, void* newval) { #ifdef WINDOWS return _InterlockedCompareExchangePointer((void* volatile*)(ptr), (void*)(newval), (void*)(oldval)); #elif defined(_TD_NINGSI_60) return __sync_val_compare_and_swap(ptr, oldval, newval); #else - return __sync_val_compare_and_swap((void **)ptr, oldval, newval); + return __sync_val_compare_and_swap((void**)ptr, oldval, newval); #endif } -int8_t atomic_add_fetch_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_add_fetch_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return interlocked_add_fetch_8((int8_t volatile*)(ptr), (int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -488,7 +457,7 @@ int8_t atomic_add_fetch_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_add_fetch_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_add_fetch_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return interlocked_add_fetch_16((int16_t volatile*)(ptr), (int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -498,7 +467,7 @@ int16_t atomic_add_fetch_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_add_fetch_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_add_fetch_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return interlocked_add_fetch_32((int32_t volatile*)(ptr), (int32_t)(val)); #elif defined(_TD_NINGSI_60) @@ -508,7 +477,7 @@ int32_t atomic_add_fetch_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_add_fetch_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_add_fetch_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return interlocked_add_fetch_64((int64_t volatile*)(ptr), (int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -518,17 +487,17 @@ int64_t atomic_add_fetch_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_add_fetch_ptr(void *ptr, void *val) { +void* atomic_add_fetch_ptr(void* ptr, void* val) { #ifdef WINDOWS return interlocked_add_fetch_ptr((void* volatile*)(ptr), (void*)(val)); #elif defined(_TD_NINGSI_60) return __sync_add_and_fetch((ptr), (val)); #else - return __atomic_add_fetch((void **)(ptr), (size_t)(val), __ATOMIC_SEQ_CST); + return __atomic_add_fetch((void**)(ptr), (size_t)(val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_fetch_add_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_fetch_add_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return _InterlockedExchangeAdd8((int8_t volatile*)(ptr), (int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -538,7 +507,7 @@ int8_t atomic_fetch_add_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_fetch_add_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_fetch_add_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return _InterlockedExchangeAdd16((int16_t volatile*)(ptr), (int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -548,7 +517,7 @@ int16_t atomic_fetch_add_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_fetch_add_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return _InterlockedExchangeAdd((int32_t volatile*)(ptr), (int32_t)(val)); #elif defined(_TD_NINGSI_60) @@ -558,7 +527,7 @@ int32_t atomic_fetch_add_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_fetch_add_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return _InterlockedExchangeAdd64((int64_t volatile*)(ptr), (int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -568,17 +537,17 @@ int64_t atomic_fetch_add_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_fetch_add_ptr(void *ptr, void *val) { +void* atomic_fetch_add_ptr(void* ptr, void* val) { #ifdef WINDOWS return _InterlockedExchangePointer((void* volatile*)(ptr), (void*)(val)); #elif defined(_TD_NINGSI_60) return __sync_fetch_and_add((ptr), (val)); #else - return __atomic_fetch_add((void **)(ptr), (size_t)(val), __ATOMIC_SEQ_CST); + return __atomic_fetch_add((void**)(ptr), (size_t)(val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_sub_fetch_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return interlocked_add_fetch_8((int8_t volatile*)(ptr), -(int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -588,7 +557,7 @@ int8_t atomic_sub_fetch_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_sub_fetch_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return interlocked_add_fetch_16((int16_t volatile*)(ptr), -(int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -598,7 +567,7 @@ int16_t atomic_sub_fetch_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_sub_fetch_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return interlocked_sub_fetch_32(ptr, val); #elif defined(_TD_NINGSI_60) @@ -608,7 +577,7 @@ int32_t atomic_sub_fetch_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_sub_fetch_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_sub_fetch_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return interlocked_sub_fetch_64(ptr, val); #elif defined(_TD_NINGSI_60) @@ -618,17 +587,17 @@ int64_t atomic_sub_fetch_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_sub_fetch_ptr(void *ptr, void* val) { +void* atomic_sub_fetch_ptr(void* ptr, void* val) { #ifdef WINDOWS return interlocked_sub_fetch_ptr(ptr, val); #elif defined(_TD_NINGSI_60) return __sync_sub_and_fetch((ptr), (val)); #else - return __atomic_sub_fetch((void **)(ptr), (val), __ATOMIC_SEQ_CST); + return __atomic_sub_fetch((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_fetch_sub_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_fetch_sub_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return _InterlockedExchangeAdd8((int8_t volatile*)(ptr), -(int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -638,7 +607,7 @@ int8_t atomic_fetch_sub_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_fetch_sub_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_fetch_sub_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return _InterlockedExchangeAdd16((int16_t volatile*)(ptr), -(int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -648,7 +617,7 @@ int16_t atomic_fetch_sub_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_fetch_sub_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_fetch_sub_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return interlocked_fetch_sub_32(ptr, val); #elif defined(_TD_NINGSI_60) @@ -658,7 +627,7 @@ int32_t atomic_fetch_sub_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_fetch_sub_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return _InterlockedExchangeAdd64((int64_t volatile*)(ptr), -(int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -668,17 +637,17 @@ int64_t atomic_fetch_sub_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_fetch_sub_ptr(void *ptr, void* val) { +void* atomic_fetch_sub_ptr(void* ptr, void* val) { #ifdef WINDOWS return interlocked_fetch_sub_ptr(ptr, val); #elif defined(_TD_NINGSI_60) return __sync_fetch_and_sub((ptr), (val)); #else - return __atomic_fetch_sub((void **)(ptr), (val), __ATOMIC_SEQ_CST); + return __atomic_fetch_sub((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_and_fetch_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_and_fetch_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return interlocked_and_fetch_8((int8_t volatile*)(ptr), (int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -688,7 +657,7 @@ int8_t atomic_and_fetch_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_and_fetch_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return interlocked_and_fetch_16((int16_t volatile*)(ptr), (int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -698,7 +667,7 @@ int16_t atomic_and_fetch_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_and_fetch_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return interlocked_and_fetch_32((int32_t volatile*)(ptr), (int32_t)(val)); #elif defined(_TD_NINGSI_60) @@ -708,7 +677,7 @@ int32_t atomic_and_fetch_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_and_fetch_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_and_fetch_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return interlocked_and_fetch_64((int64_t volatile*)(ptr), (int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -718,17 +687,17 @@ int64_t atomic_and_fetch_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_and_fetch_ptr(void *ptr, void *val) { +void* atomic_and_fetch_ptr(void* ptr, void* val) { #ifdef WINDOWS return interlocked_and_fetch_ptr((void* volatile*)(ptr), (void*)(val)); #elif defined(_TD_NINGSI_60) return __sync_and_and_fetch((ptr), (val)); #else - return __atomic_and_fetch((void **)(ptr), (val), __ATOMIC_SEQ_CST); + return __atomic_and_fetch((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_fetch_and_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_fetch_and_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return _InterlockedAnd8((int8_t volatile*)(ptr), (int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -738,7 +707,7 @@ int8_t atomic_fetch_and_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_fetch_and_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_fetch_and_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return _InterlockedAnd16((int16_t volatile*)(ptr), (int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -748,7 +717,7 @@ int16_t atomic_fetch_and_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_fetch_and_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_fetch_and_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return _InterlockedAnd((int32_t volatile*)(ptr), (int32_t)(val)); #elif defined(_TD_NINGSI_60) @@ -758,7 +727,7 @@ int32_t atomic_fetch_and_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_fetch_and_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_fetch_and_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return interlocked_fetch_and_64((int64_t volatile*)(ptr), (int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -768,17 +737,17 @@ int64_t atomic_fetch_and_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_fetch_and_ptr(void *ptr, void *val) { +void* atomic_fetch_and_ptr(void* ptr, void* val) { #ifdef WINDOWS return interlocked_fetch_and_ptr((void* volatile*)(ptr), (void*)(val)); #elif defined(_TD_NINGSI_60) return __sync_fetch_and_and((ptr), (val)); #else - return __atomic_fetch_and((void **)(ptr), (val), __ATOMIC_SEQ_CST); + return __atomic_fetch_and((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_or_fetch_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_or_fetch_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return interlocked_or_fetch_8((int8_t volatile*)(ptr), (int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -788,7 +757,7 @@ int8_t atomic_or_fetch_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_or_fetch_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_or_fetch_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return interlocked_or_fetch_16((int16_t volatile*)(ptr), (int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -798,7 +767,7 @@ int16_t atomic_or_fetch_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_or_fetch_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_or_fetch_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return interlocked_or_fetch_32((int32_t volatile*)(ptr), (int32_t)(val)); #elif defined(_TD_NINGSI_60) @@ -808,7 +777,7 @@ int32_t atomic_or_fetch_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_or_fetch_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_or_fetch_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return interlocked_or_fetch_64((int64_t volatile*)(ptr), (int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -818,17 +787,17 @@ int64_t atomic_or_fetch_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_or_fetch_ptr(void *ptr, void *val) { +void* atomic_or_fetch_ptr(void* ptr, void* val) { #ifdef WINDOWS return interlocked_or_fetch_ptr((void* volatile*)(ptr), (void*)(val)); #elif defined(_TD_NINGSI_60) return __sync_or_and_fetch((ptr), (val)); #else - return __atomic_or_fetch((void **)(ptr), (val), __ATOMIC_SEQ_CST); + return __atomic_or_fetch((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_fetch_or_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_fetch_or_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return _InterlockedOr8((int8_t volatile*)(ptr), (int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -838,7 +807,7 @@ int8_t atomic_fetch_or_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_fetch_or_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_fetch_or_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return _InterlockedOr16((int16_t volatile*)(ptr), (int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -848,7 +817,7 @@ int16_t atomic_fetch_or_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_fetch_or_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_fetch_or_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return _InterlockedOr((int32_t volatile*)(ptr), (int32_t)(val)); #elif defined(_TD_NINGSI_60) @@ -858,7 +827,7 @@ int32_t atomic_fetch_or_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_fetch_or_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_fetch_or_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return interlocked_fetch_or_64((int64_t volatile*)(ptr), (int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -868,17 +837,17 @@ int64_t atomic_fetch_or_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_fetch_or_ptr(void *ptr, void *val) { +void* atomic_fetch_or_ptr(void* ptr, void* val) { #ifdef WINDOWS return interlocked_fetch_or_ptr((void* volatile*)(ptr), (void*)(val)); #elif defined(_TD_NINGSI_60) return __sync_fetch_and_or((ptr), (val)); #else - return __atomic_fetch_or((void **)(ptr), (val), __ATOMIC_SEQ_CST); + return __atomic_fetch_or((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_xor_fetch_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_xor_fetch_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return interlocked_xor_fetch_8((int8_t volatile*)(ptr), (int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -888,7 +857,7 @@ int8_t atomic_xor_fetch_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_xor_fetch_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_xor_fetch_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return interlocked_xor_fetch_16((int16_t volatile*)(ptr), (int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -898,7 +867,7 @@ int16_t atomic_xor_fetch_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_xor_fetch_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_xor_fetch_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return interlocked_xor_fetch_32((int32_t volatile*)(ptr), (int32_t)(val)); #elif defined(_TD_NINGSI_60) @@ -908,7 +877,7 @@ int32_t atomic_xor_fetch_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_xor_fetch_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_xor_fetch_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return interlocked_xor_fetch_64((int64_t volatile*)(ptr), (int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -918,17 +887,17 @@ int64_t atomic_xor_fetch_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_xor_fetch_ptr(void *ptr, void *val) { +void* atomic_xor_fetch_ptr(void* ptr, void* val) { #ifdef WINDOWS return interlocked_xor_fetch_ptr((void* volatile*)(ptr), (void*)(val)); #elif defined(_TD_NINGSI_60) return __sync_xor_and_fetch((ptr), (val)); #else - return __atomic_xor_fetch((void **)(ptr), (val), __ATOMIC_SEQ_CST); + return __atomic_xor_fetch((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } -int8_t atomic_fetch_xor_8(int8_t volatile *ptr, int8_t val) { +int8_t atomic_fetch_xor_8(int8_t volatile* ptr, int8_t val) { #ifdef WINDOWS return _InterlockedXor8((int8_t volatile*)(ptr), (int8_t)(val)); #elif defined(_TD_NINGSI_60) @@ -938,7 +907,7 @@ int8_t atomic_fetch_xor_8(int8_t volatile *ptr, int8_t val) { #endif } -int16_t atomic_fetch_xor_16(int16_t volatile *ptr, int16_t val) { +int16_t atomic_fetch_xor_16(int16_t volatile* ptr, int16_t val) { #ifdef WINDOWS return _InterlockedXor16((int16_t volatile*)(ptr), (int16_t)(val)); #elif defined(_TD_NINGSI_60) @@ -948,7 +917,7 @@ int16_t atomic_fetch_xor_16(int16_t volatile *ptr, int16_t val) { #endif } -int32_t atomic_fetch_xor_32(int32_t volatile *ptr, int32_t val) { +int32_t atomic_fetch_xor_32(int32_t volatile* ptr, int32_t val) { #ifdef WINDOWS return _InterlockedXor((int32_t volatile*)(ptr), (int32_t)(val)); #elif defined(_TD_NINGSI_60) @@ -958,7 +927,7 @@ int32_t atomic_fetch_xor_32(int32_t volatile *ptr, int32_t val) { #endif } -int64_t atomic_fetch_xor_64(int64_t volatile *ptr, int64_t val) { +int64_t atomic_fetch_xor_64(int64_t volatile* ptr, int64_t val) { #ifdef WINDOWS return interlocked_fetch_xor_64((int64_t volatile*)(ptr), (int64_t)(val)); #elif defined(_TD_NINGSI_60) @@ -968,13 +937,12 @@ int64_t atomic_fetch_xor_64(int64_t volatile *ptr, int64_t val) { #endif } -void* atomic_fetch_xor_ptr(void *ptr, void *val) { +void* atomic_fetch_xor_ptr(void* ptr, void* val) { #ifdef WINDOWS return interlocked_fetch_xor_ptr((void* volatile*)(ptr), (void*)(val)); #elif defined(_TD_NINGSI_60) return __sync_fetch_and_xor((ptr), (val)); #else - return __atomic_fetch_xor((void **)(ptr), (val), __ATOMIC_SEQ_CST); + return __atomic_fetch_xor((void**)(ptr), (val), __ATOMIC_SEQ_CST); #endif } - -- GitLab