diff --git a/src/vnode/tsdb/inc/tsdbMeta.h b/src/vnode/tsdb/inc/tsdbMeta.h index 03031f16cd38b169664438c4cf1ba3b9eb2f52d6..aba506f30d85816f06192b48a5158f0cbb604a21 100644 --- a/src/vnode/tsdb/inc/tsdbMeta.h +++ b/src/vnode/tsdb/inc/tsdbMeta.h @@ -74,6 +74,8 @@ typedef struct { void *map; // table map of (uid ===> table) SMetaFile *mfh; // meta file handle + int maxRowBytes; + int maxCols; } STsdbMeta; STsdbMeta *tsdbInitMeta(const char *rootDir, int32_t maxTables); diff --git a/src/vnode/tsdb/src/tsdbMain.c b/src/vnode/tsdb/src/tsdbMain.c index 7c1f7efb8d1c0f873326b707d4a214cb3389b402..3a4e427798e5953bb5f0d51808a8a4e63215d076 100644 --- a/src/vnode/tsdb/src/tsdbMain.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -44,6 +44,7 @@ #define TSDB_CFG_FILE_NAME "CONFIG" #define TSDB_DATA_DIR_NAME "data" +#define TSDB_DEFAULT_FILE_BLOCK_ROW_OPTION 0.7 enum { TSDB_REPO_STATE_ACTIVE, TSDB_REPO_STATE_CLOSED, TSDB_REPO_STATE_CONFIGURING }; @@ -717,25 +718,60 @@ static int32_t tsdbInsertDataToTable(tsdb_repo_t *repo, SSubmitBlk *pBlock) { return 0; } +static int tsdbReadRowsFromCache(SSkipListIterator *pIter, TSKEY minKey, TSKEY maxKey, int maxRowsToRead, void *dst) { + int numOfRows = 0; + do { + SSkipListNode *node = tSkiplistIterGet(pIter); + SDataRow row = SL_GET_NODE_DATA(node); + if (dataRowKey(row) > maxKey) break; + } while (tSkipListIterNext(pIter)); + return numOfRows; +} + // Commit to file static void *tsdbCommitToFile(void *arg) { // TODO - STsdbRepo *pRepo = (STsdbRepo *)arg; - STsdbMeta *pMeta = pRepo->tsdbMeta; - for (int i = 0; i < pRepo->config.maxTables; i++) { // Loop over table - STable *pTable = pMeta->tables[i]; - if (pTable == NULL || pTable->imem == NULL) continue; - - SMemTable *pMem = pTable->imem; - SSkipListIterator *pIter = tSkipListCreateIter(pMem->pData); - // Loop to commit to file - while (tSkipListIterNext(pIter)) { - SSkipListNode *node = tSkipListIterGet(pIter); - SDataRow row = SL_GET_NODE_DATA(node); - int k = 0; + STsdbRepo * pRepo = (STsdbRepo *)arg; + STsdbMeta * pMeta = pRepo->tsdbMeta; + STsdbCache *pCache = pRepo->tsdbCache; + STsdbRepo * pCfg = &(pRepo->config); + if (pCache->imem == NULL) return; + + int sfid = tsdbGetKeyFileId(pCache->imem->keyFirst); + int efid = tsdbGetKeyFileId(pCache->imem->keyLast); + SSkipListIterator **iters = (SSkipListIterator **)calloc(pCfg->maxTables, sizeof(SSkipListIterator *)); + if (iters == NULL) { + // TODO: deal with the error + return NULL; + } + + for (int fid = sfid; fid <= efid; fid++) { + TSKEY minKey = 0, maxKey = 0; + tsdbGetKeyRangeOfFileId(pCfg->daysPerFile, pCfg->precision, fid, &minKey, &maxKey); + + for (int tid = 0; tid < pCfg->maxTables; tid++) { + STable *pTable = pMeta->tables[tid]; + if (pTable == NULL || pTable->imem == NULL) continue; + if (iters[tid] == NULL) { // create table iterator + iters[tid] = tSkipListCreateIter(pTable->imem); + // TODO: deal with the error + if (iters[tid] == NULL) break; + if (!tSkipListIterNext(iters[tid])) { + // assert(0); + } + } + + // Loop the iterator + // tsdbReadRowsFromCache(); } - tSkipListDestroyIter(pIter); } + // Free the iterator + for (int tid = 0; tid < pCfg->maxTables; tid++) { + if (iters[tid] != NULL) tSkipListDestroyIter(iters[tid]); + } + + free(iters); + return NULL; } \ No newline at end of file diff --git a/src/vnode/tsdb/src/tsdbMeta.c b/src/vnode/tsdb/src/tsdbMeta.c index c7874fa5a2dee896b5a77faed8ca4de80cb6c404..b8b5450d232eb5453ed7890a3a101bb4be19492d 100644 --- a/src/vnode/tsdb/src/tsdbMeta.c +++ b/src/vnode/tsdb/src/tsdbMeta.c @@ -133,6 +133,8 @@ STsdbMeta *tsdbInitMeta(const char *rootDir, int32_t maxTables) { pMeta->nTables = 0; pMeta->superList = NULL; pMeta->tables = (STable **)calloc(maxTables, sizeof(STable *)); + pMeta->maxRowBytes = 0; + pMeta->maxCols = 0; if (pMeta->tables == NULL) { free(pMeta); return NULL;