From 96bcd5c26f2d22eadbcfcd8b43cb15c7daea56a4 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 25 Dec 2020 02:29:43 +0000 Subject: [PATCH] implement get cached last row function --- src/tsdb/src/tsdbRead.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index a7af44b1ee..e79b033d32 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -2183,8 +2183,25 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { return ret; } -int32_t tsdbGetCachedLastRow(STable* pTable, void** pRes) { - return 0; +/* + * 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 + */ +TSKEY tsdbGetCachedLastRow(STable* pTable, void** pRes) { + TSKEY lastKey; + + TSDB_RLOCK_TABLE(pTable); + lastKey = pTable->lastKey; + + if (lastKey != TSKEY_INITIAL_VAL && pTable->lastRow) { + *pRes = tdDataRowDup(pTable->lastRow); + if (*pRes == NULL) { + // TODO: handle error + } + } + TSDB_RUNLOCK_TABLE(pTable); + return lastKey; } void checkCachedLastRow(STsdbQueryHandle* pQueryHandle, STableGroupInfo *groupList) { -- GitLab