TD-34
This commit is contained in:
parent
ca7340121d
commit
41f8bf1635
|
@ -74,6 +74,8 @@ typedef struct {
|
||||||
void *map; // table map of (uid ===> table)
|
void *map; // table map of (uid ===> table)
|
||||||
|
|
||||||
SMetaFile *mfh; // meta file handle
|
SMetaFile *mfh; // meta file handle
|
||||||
|
int maxRowBytes;
|
||||||
|
int maxCols;
|
||||||
} STsdbMeta;
|
} STsdbMeta;
|
||||||
|
|
||||||
STsdbMeta *tsdbInitMeta(const char *rootDir, int32_t maxTables);
|
STsdbMeta *tsdbInitMeta(const char *rootDir, int32_t maxTables);
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
|
|
||||||
#define TSDB_CFG_FILE_NAME "CONFIG"
|
#define TSDB_CFG_FILE_NAME "CONFIG"
|
||||||
#define TSDB_DATA_DIR_NAME "data"
|
#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 };
|
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;
|
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
|
// Commit to file
|
||||||
static void *tsdbCommitToFile(void *arg) {
|
static void *tsdbCommitToFile(void *arg) {
|
||||||
// TODO
|
// TODO
|
||||||
STsdbRepo *pRepo = (STsdbRepo *)arg;
|
STsdbRepo * pRepo = (STsdbRepo *)arg;
|
||||||
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
STsdbMeta * pMeta = pRepo->tsdbMeta;
|
||||||
for (int i = 0; i < pRepo->config.maxTables; i++) { // Loop over table
|
STsdbCache *pCache = pRepo->tsdbCache;
|
||||||
STable *pTable = pMeta->tables[i];
|
STsdbRepo * pCfg = &(pRepo->config);
|
||||||
if (pTable == NULL || pTable->imem == NULL) continue;
|
if (pCache->imem == NULL) return;
|
||||||
|
|
||||||
SMemTable *pMem = pTable->imem;
|
int sfid = tsdbGetKeyFileId(pCache->imem->keyFirst);
|
||||||
SSkipListIterator *pIter = tSkipListCreateIter(pMem->pData);
|
int efid = tsdbGetKeyFileId(pCache->imem->keyLast);
|
||||||
// Loop to commit to file
|
SSkipListIterator **iters = (SSkipListIterator **)calloc(pCfg->maxTables, sizeof(SSkipListIterator *));
|
||||||
while (tSkipListIterNext(pIter)) {
|
if (iters == NULL) {
|
||||||
SSkipListNode *node = tSkipListIterGet(pIter);
|
// TODO: deal with the error
|
||||||
SDataRow row = SL_GET_NODE_DATA(node);
|
return NULL;
|
||||||
int k = 0;
|
|
||||||
}
|
|
||||||
tSkipListDestroyIter(pIter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free the iterator
|
||||||
|
for (int tid = 0; tid < pCfg->maxTables; tid++) {
|
||||||
|
if (iters[tid] != NULL) tSkipListDestroyIter(iters[tid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(iters);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
|
@ -133,6 +133,8 @@ STsdbMeta *tsdbInitMeta(const char *rootDir, int32_t maxTables) {
|
||||||
pMeta->nTables = 0;
|
pMeta->nTables = 0;
|
||||||
pMeta->superList = NULL;
|
pMeta->superList = NULL;
|
||||||
pMeta->tables = (STable **)calloc(maxTables, sizeof(STable *));
|
pMeta->tables = (STable **)calloc(maxTables, sizeof(STable *));
|
||||||
|
pMeta->maxRowBytes = 0;
|
||||||
|
pMeta->maxCols = 0;
|
||||||
if (pMeta->tables == NULL) {
|
if (pMeta->tables == NULL) {
|
||||||
free(pMeta);
|
free(pMeta);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue