tsdbCacheRead: use new H version api of last_row
This commit is contained in:
parent
ac7f5190aa
commit
5e793c2f3f
|
@ -1087,7 +1087,8 @@ int32_t tsdbCacheGetLastrowH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUH
|
|||
code = mergeLastRow(uid, pTsdb, &pRow);
|
||||
// if table's empty or error, return code of -1
|
||||
if (code < 0 || pRow == NULL) {
|
||||
return -1;
|
||||
*handle = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
tsdbCacheInsertLastrow(pCache, uid, pRow);
|
||||
|
@ -1116,7 +1117,8 @@ int32_t tsdbCacheGetLastH(SLRUCache *pCache, tb_uid_t uid, STsdb *pTsdb, LRUHand
|
|||
code = mergeLast(uid, pTsdb, &pRow);
|
||||
// if table's empty or error, return code of -1
|
||||
if (code < 0 || pRow == NULL) {
|
||||
return -1;
|
||||
*handle = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
tsdbCacheInsertLast(pCache, uid, pRow);
|
||||
|
|
|
@ -22,15 +22,15 @@ typedef struct SLastrowReader {
|
|||
SVnode* pVnode;
|
||||
STSchema* pSchema;
|
||||
uint64_t uid;
|
||||
// int32_t* pSlotIds;
|
||||
char** transferBuf; // todo remove it soon
|
||||
int32_t numOfCols;
|
||||
int32_t type;
|
||||
int32_t tableIndex; // currently returned result tables
|
||||
SArray* pTableList; // table id list
|
||||
// int32_t* pSlotIds;
|
||||
char** transferBuf; // todo remove it soon
|
||||
int32_t numOfCols;
|
||||
int32_t type;
|
||||
int32_t tableIndex; // currently returned result tables
|
||||
SArray* pTableList; // table id list
|
||||
} SLastrowReader;
|
||||
|
||||
static void saveOneRow(STSRow* pRow, SSDataBlock* pBlock, SLastrowReader* pReader, const int32_t *slotIds) {
|
||||
static void saveOneRow(STSRow* pRow, SSDataBlock* pBlock, SLastrowReader* pReader, const int32_t* slotIds) {
|
||||
int32_t numOfRows = pBlock->info.rows;
|
||||
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||
|
||||
|
@ -60,21 +60,21 @@ static void saveOneRow(STSRow* pRow, SSDataBlock* pBlock, SLastrowReader* pReade
|
|||
pBlock->info.rows += 1;
|
||||
}
|
||||
|
||||
|
||||
int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t* colId, int32_t numOfCols, void** pReader) {
|
||||
int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t* colId, int32_t numOfCols,
|
||||
void** pReader) {
|
||||
SLastrowReader* p = taosMemoryCalloc(1, sizeof(SLastrowReader));
|
||||
if (p == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
p->type = type;
|
||||
p->pVnode = pVnode;
|
||||
p->numOfCols = numOfCols;
|
||||
p->type = type;
|
||||
p->pVnode = pVnode;
|
||||
p->numOfCols = numOfCols;
|
||||
p->transferBuf = taosMemoryCalloc(p->numOfCols, POINTER_BYTES);
|
||||
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pTableIdList, 0);
|
||||
p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, pKeyInfo->uid, -1);
|
||||
p->pTableList = pTableIdList;
|
||||
p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, pKeyInfo->uid, -1);
|
||||
p->pTableList = pTableIdList;
|
||||
#if 0
|
||||
for(int32_t i = 0; i < p->numOfCols; ++i) {
|
||||
for(int32_t j = 0; j < p->pSchema->numOfCols; ++j) {
|
||||
|
@ -101,7 +101,7 @@ int32_t tsdbLastRowReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList,
|
|||
int32_t tsdbLastrowReaderClose(void* pReader) {
|
||||
SLastrowReader* p = pReader;
|
||||
|
||||
for(int32_t i = 0; i < p->numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < p->numOfCols; ++i) {
|
||||
taosMemoryFreeClear(p->transferBuf[i]);
|
||||
}
|
||||
|
||||
|
@ -117,8 +117,9 @@ int32_t tsdbRetrieveLastRow(void* pReader, SSDataBlock* pResBlock, const int32_t
|
|||
|
||||
SLastrowReader* pr = pReader;
|
||||
|
||||
STSRow* pRow = NULL;
|
||||
size_t numOfTables = taosArrayGetSize(pr->pTableList);
|
||||
LRUHandle* h = NULL;
|
||||
STSRow* pRow = NULL;
|
||||
size_t numOfTables = taosArrayGetSize(pr->pTableList);
|
||||
|
||||
// retrieve the only one last row of all tables in the uid list.
|
||||
if (pr->type == LASTROW_RETRIEVE_TYPE_SINGLE) {
|
||||
|
@ -126,16 +127,18 @@ int32_t tsdbRetrieveLastRow(void* pReader, SSDataBlock* pResBlock, const int32_t
|
|||
bool internalResult = false;
|
||||
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pr->pTableList, i);
|
||||
|
||||
int32_t code = tsdbCacheGetLastrow(pr->pVnode->pTsdb->lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &pRow);
|
||||
|
||||
/* int32_t code = tsdbCacheGetLastrow(pr->pVnode->pTsdb->lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &pRow); */
|
||||
int32_t code = tsdbCacheGetLastrowH(pr->pVnode->pTsdb->lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &h);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pRow == NULL) {
|
||||
if (h == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pRow = (STSRow*)taosLRUCacheValue(pr->pVnode->pTsdb->lruCache, h);
|
||||
if (pRow->ts > lastKey) {
|
||||
// Set result row into the same rowIndex repeatly, so we need to check if the internal result row has already
|
||||
// appended or not.
|
||||
|
@ -147,23 +150,29 @@ int32_t tsdbRetrieveLastRow(void* pReader, SSDataBlock* pResBlock, const int32_t
|
|||
internalResult = true;
|
||||
lastKey = pRow->ts;
|
||||
}
|
||||
|
||||
tsdbCacheRelease(pr->pVnode->pTsdb->lruCache, h);
|
||||
}
|
||||
} else if (pr->type == LASTROW_RETRIEVE_TYPE_ALL) {
|
||||
for (int32_t i = pr->tableIndex; i < numOfTables; ++i) {
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pr->pTableList, i);
|
||||
|
||||
int32_t code = tsdbCacheGetLastrow(pr->pVnode->pTsdb->lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &pRow);
|
||||
/* int32_t code = tsdbCacheGetLastrow(pr->pVnode->pTsdb->lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &pRow); */
|
||||
int32_t code = tsdbCacheGetLastrowH(pr->pVnode->pTsdb->lruCache, pKeyInfo->uid, pr->pVnode->pTsdb, &h);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// no data in the table of Uid
|
||||
if (pRow == NULL) {
|
||||
if (h == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pRow = (STSRow*)taosLRUCacheValue(pr->pVnode->pTsdb->lruCache, h);
|
||||
saveOneRow(pRow, pResBlock, pr, slotIds);
|
||||
|
||||
tsdbCacheRelease(pr->pVnode->pTsdb->lruCache, h);
|
||||
|
||||
pr->tableIndex += 1;
|
||||
if (pResBlock->info.rows >= pResBlock->info.capacity) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue