tsdb/readerwriter: use tsdb's s3 block cache to read file page

This commit is contained in:
Minglei Jin 2023-09-20 15:24:54 +08:00
parent 0181bb24d3
commit d155cfcf0f
2 changed files with 36 additions and 26 deletions

View File

@ -869,6 +869,9 @@ int32_t tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h);
int32_t tsdbCacheGetBlockIdx(SLRUCache *pCache, SDataFReader *pFileReader, LRUHandle **handle);
int32_t tsdbBICacheRelease(SLRUCache *pCache, LRUHandle *h);
int32_t tsdbCacheGetBlockS3(SLRUCache *pCache, STsdbFD *pFD, LRUHandle **handle);
int32_t tsdbBCacheRelease(SLRUCache *pCache, LRUHandle *h);
int32_t tsdbCacheDeleteLastrow(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);
int32_t tsdbCacheDeleteLast(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);
int32_t tsdbCacheDelete(SLRUCache *pCache, tb_uid_t uid, TSKEY eKey);

View File

@ -163,20 +163,26 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno) {
}
}
int64_t offset = PAGE_OFFSET(pgno, pFD->szPage);
if (pFD->s3File) {
// 1. convert pgno to block no,
// block_size(# of pages) & block_cache_size (# of blocks)
// block_no = pgno / block_size + 1;
// block_offset = (block_no - 1) * block_size * pFD->szPage
// 2, lookup block cache to fetch block
// 3, if found, memcpy page from block
// 4, if not found, download block from s3
// check pg checksum in the block
// insert into block cache and goto step 3.
LRUHandle *handle = NULL;
pFD->blkno = (pgno + tsS3BlockSize - 1) / tsS3BlockSize;
int32_t code = tsdbCacheGetBlockS3(pFD->pTsdb->bCache, pFD, &handle);
if (code != TSDB_CODE_SUCCESS || handle == NULL) {
tsdbBCacheRelease(pFD->pTsdb->bCache, handle);
goto _exit;
}
uint8_t *pBlock = (uint8_t *)taosLRUCacheValue(pFD->pTsdb->bCache, handle);
int64_t blk_offset = (pFD->blkno - 1) * tsS3BlockSize * pFD->szPage;
memcpy(pFD->pBuf, pBlock + (offset - blk_offset), pFD->szPage);
tsdbBCacheRelease(pFD->pTsdb->bCache, handle);
} else {
// seek
int64_t offset = PAGE_OFFSET(pgno, pFD->szPage);
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
if (n < 0) {
code = TAOS_SYSTEM_ERROR(errno);
@ -192,6 +198,7 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno) {
code = TSDB_CODE_FILE_CORRUPTED;
goto _exit;
}
}
// check
if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) {