diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index ab15e851e76e1c7ad29a81a7cd1874a9e89d82ed..431c9116ccec57d90a1dbe2405845f6c26a5fef6 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -244,6 +244,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TDB_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0613) //"No available disk") #define TSDB_CODE_TDB_MESSED_MSG TAOS_DEF_ERROR_CODE(0, 0x0614) //"TSDB messed message") #define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0615) //"TSDB invalid tag value") +#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0616) //"TSDB no cache last row data") // query #define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700) //"Invalid handle") diff --git a/src/tsdb/inc/tsdbint.h b/src/tsdb/inc/tsdbint.h index 049c1bdb6ea37121a202a931faa17a4ea36cf6dc..7cf88826319b0b4ad8a7d128b19264d2b67434d0 100644 --- a/src/tsdb/inc/tsdbint.h +++ b/src/tsdb/inc/tsdbint.h @@ -78,7 +78,6 @@ struct STsdbRepo { bool config_changed; // config changed flag pthread_mutex_t save_mutex; // protect save config - uint8_t hasCachedLastRow; uint8_t hasCachedLastColumn; STsdbAppH appH; diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index ce20bf1821b11880978eac3d46c7000229e1b9e7..bb02e0128337dbd0436e3c8b83894097b1c21c4c 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -553,7 +553,6 @@ static STsdbRepo *tsdbNewRepo(STsdbCfg *pCfg, STsdbAppH *pAppH) { return NULL; } pRepo->config_changed = false; - atomic_store_8(&pRepo->hasCachedLastRow, 0); atomic_store_8(&pRepo->hasCachedLastColumn, 0); code = tsem_init(&(pRepo->readyToCommit), 0, 1); @@ -857,9 +856,7 @@ int tsdbRestoreInfo(STsdbRepo *pRepo) { } tsdbDestroyReadH(&readh); - if (CACHE_LAST_ROW(pCfg)) { - atomic_store_8(&pRepo->hasCachedLastRow, 1); - } + if (CACHE_LAST_NULL_COLUMN(pCfg)) { atomic_store_8(&pRepo->hasCachedLastColumn, 1); } @@ -900,9 +897,6 @@ int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) { // if close last option,need to free data if (need_free_last_row || need_free_last_col) { - if (need_free_last_row) { - atomic_store_8(&pRepo->hasCachedLastRow, 0); - } if (need_free_last_col) { atomic_store_8(&pRepo->hasCachedLastColumn, 0); } @@ -982,9 +976,6 @@ int tsdbCacheLastData(STsdbRepo *pRepo, STsdbCfg* oldCfg) { tsdbDestroyReadH(&readh); - if (cacheLastRow) { - atomic_store_8(&pRepo->hasCachedLastRow, 1); - } if (cacheLastCol) { atomic_store_8(&pRepo->hasCachedLastColumn, 1); } diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 1545d44395d6baca6f33c850e35796c96af8d52f..bbfa723cb5a217a5682eaff8c2af8ad09df8e60a 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -2469,7 +2469,6 @@ static bool loadCachedLastRow(STsdbQueryHandle* pQueryHandle) { if (ret != TSDB_CODE_SUCCESS) { return false; } - copyOneRowFromMem(pQueryHandle, pQueryHandle->outputCapacity, 0, pRow, numOfCols, pCheckInfo->pTableObj, NULL); tfree(pRow); @@ -2860,24 +2859,27 @@ bool tsdbGetExternalRow(TsdbQueryHandleT pHandle) { } /* - * 1. no data at all (pTable->lastKey = TSKEY_INITIAL_VAL), just return TSKEY_INITIAL_VAL - * 2. has data but not loaded, just return lastKey but not set pRes - * 3. has data and loaded, return lastKey and set pRes + * if lastRow == NULL, return TSDB_CODE_TDB_NO_CACHE_LAST_ROW + * else set pRes and return TSDB_CODE_SUCCESS */ int32_t tsdbGetCachedLastRow(STable* pTable, SDataRow* pRes, TSKEY* lastKey) { + int32_t code = TSDB_CODE_SUCCESS; + TSDB_RLOCK_TABLE(pTable); - *lastKey = pTable->lastKey; - if ((*lastKey) != TSKEY_INITIAL_VAL && pTable->lastRow) { - *pRes = tdDataRowDup(pTable->lastRow); - if (*pRes == NULL) { - TSDB_RUNLOCK_TABLE(pTable); - return TSDB_CODE_TDB_OUT_OF_MEMORY; - } + if (!pTable->lastRow) { + code = TSDB_CODE_TDB_NO_CACHE_LAST_ROW; + goto out; } + *pRes = tdDataRowDup(pTable->lastRow); + if (*pRes == NULL) { + code = TSDB_CODE_TDB_OUT_OF_MEMORY; + } + +out: TSDB_RUNLOCK_TABLE(pTable); - return TSDB_CODE_SUCCESS; + return code; } bool isTsdbCacheLastRow(TsdbQueryHandleT* pQueryHandle) {