diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index eac4f06132658f6d3c75314e9b970fc86d3ed383..76bfc217b3f070660cefd3451f8c5e9ae35aeb5d 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -250,10 +250,16 @@ int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx, uint8_t **ppBuf); int32_t tsdbOpenCache(STsdb *pTsdb); void tsdbCloseCache(SLRUCache *pCache); int32_t tsdbCacheInsertLastrow(SLRUCache *pCache, tb_uid_t uid, STSRow *row); + +// bug api, deprecated, USE H version int32_t tsdbCacheGetLastrow(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, STSRow **ppRow); -int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey); + +int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **h); +int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **h); int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h); +int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey); + // structs ======================= typedef struct { int minFid; diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 12f323e92ed137212f4f2c07fb21c68a8a6aefe4..3cd8ac922a20fdc29f72aa22c9fbc878e5953a39 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -1007,7 +1007,7 @@ int32_t tsdbCacheGetLastrow(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, STSRo return code; } - +#if 0 int32_t tsdbCacheGetLast(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, STSRow **ppRow) { int32_t code = 0; char key[32] = {0}; @@ -1034,6 +1034,63 @@ int32_t tsdbCacheGetLast(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, STSRow * return code; } +#endif +int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **handle) { + int32_t code = 0; + char key[32] = {0}; + int keyLen = 0; + + getTableCacheKey(uid, "lr", key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + //*ppRow = (STSRow *)taosLRUCacheValue(pCache, h); + } else { + STSRow *pRow = NULL; + code = mergeLastRow(uid, pTsdb, &pRow); + // if table's empty or error, return code of -1 + if (code < 0 || pRow == NULL) { + return -1; + } + + tsdbCacheInsertLastrow(pCache, uid, pRow); + h = taosLRUCacheLookup(pCache, key, keyLen); + //*ppRow = (STSRow *)taosLRUCacheValue(pCache, h); + } + + *handle = h; + // taosLRUCacheRelease(pCache, h, true); + + return code; +} + +int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHandle **handle) { + int32_t code = 0; + char key[32] = {0}; + int keyLen = 0; + + getTableCacheKey(uid, "l", key, &keyLen); + LRUHandle *h = taosLRUCacheLookup(pCache, key, keyLen); + if (h) { + //*ppRow = (STSRow *)taosLRUCacheValue(pCache, h); + + } else { + STSRow *pRow = NULL; + code = mergeLast(uid, pTsdb, &pRow); + // if table's empty or error, return code of -1 + if (code < 0 || pRow == NULL) { + return -1; + } + + tsdbCacheInsertLast(pCache, uid, pRow); + h = taosLRUCacheLookup(pCache, key, keyLen); + //*ppRow = (STSRow *)taosLRUCacheValue(pCache, h); + } + + *handle = h; + // taosLRUCacheRelease(pCache, h, true); + + return code; +} int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey) { int32_t code = 0;