提交 3283fe93 编写于 作者: H Hongze Cheng

more progress

上级 5be50635
...@@ -58,7 +58,7 @@ void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, ST ...@@ -58,7 +58,7 @@ void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, ST
bool tsdbTbDataIterNext(STbDataIter *pIter); bool tsdbTbDataIterNext(STbDataIter *pIter);
bool tsdbTbDataIterGet(STbDataIter *pIter, TSDBROW *pRow); bool tsdbTbDataIterGet(STbDataIter *pIter, TSDBROW *pRow);
int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, STbDataIter *pIter, TSKEY maxKey, int maxRowsToRead,
SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo); SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo);
// tsdbMemTable2.c ============================================================================================== // tsdbMemTable2.c ==============================================================================================
...@@ -322,16 +322,24 @@ static void *taosTZfree(void *ptr); ...@@ -322,16 +322,24 @@ static void *taosTZfree(void *ptr);
static size_t taosTSizeof(void *ptr); static size_t taosTSizeof(void *ptr);
static void taosTMemset(void *ptr, int c); static void taosTMemset(void *ptr, int c);
static FORCE_INLINE STSRow *tsdbNextIterRow(SSkipListIterator *pIter) { struct TSDBROW {
int64_t version;
STSRow *pTSRow;
};
static FORCE_INLINE STSRow *tsdbNextIterRow(STbDataIter *pIter) {
TSDBROW row;
if (pIter == NULL) return NULL; if (pIter == NULL) return NULL;
SSkipListNode *node = tSkipListIterGet(pIter); if (tsdbTbDataIterGet(pIter, &row)) {
if (node == NULL) return NULL; return row.pTSRow;
}
return (STSRow *)SL_GET_NODE_DATA(node); return NULL;
} }
static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator *pIter) { static FORCE_INLINE TSKEY tsdbNextIterKey(STbDataIter *pIter) {
STSRow *row = tsdbNextIterRow(pIter); STSRow *row = tsdbNextIterRow(pIter);
if (row == NULL) return TSDB_DATA_TIMESTAMP_NULL; if (row == NULL) return TSDB_DATA_TIMESTAMP_NULL;
...@@ -675,11 +683,6 @@ struct SFSIter { ...@@ -675,11 +683,6 @@ struct SFSIter {
#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC #define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC
#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC #define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC
struct TSDBROW {
int64_t version;
STSRow *pTSRow;
};
struct TABLEID { struct TABLEID {
tb_uid_t suid; tb_uid_t suid;
tb_uid_t uid; tb_uid_t uid;
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#define TSDB_MAX_SUBBLOCKS 8 #define TSDB_MAX_SUBBLOCKS 8
typedef struct { typedef struct {
STable *pTable; STable *pTable;
SSkipListIterator *pIter; STbDataIter *pIter;
} SCommitIter; } SCommitIter;
typedef struct { typedef struct {
...@@ -457,7 +457,9 @@ static int32_t tsdbCreateCommitIters(SCommitH *pCommith) { ...@@ -457,7 +457,9 @@ static int32_t tsdbCreateCommitIters(SCommitH *pCommith) {
int32_t code = 0; int32_t code = 0;
STsdb *pRepo = TSDB_COMMIT_REPO(pCommith); STsdb *pRepo = TSDB_COMMIT_REPO(pCommith);
SMemTable *pMem = pRepo->imem; SMemTable *pMem = pRepo->imem;
STbData *pTbData;
SCommitIter *pCommitIter; SCommitIter *pCommitIter;
STSchema *pTSchema = NULL;
pCommith->niters = taosArrayGetSize(pMem->aTbData); pCommith->niters = taosArrayGetSize(pMem->aTbData);
pCommith->iters = (SCommitIter *)taosMemoryCalloc(pCommith->niters, sizeof(SCommitIter)); pCommith->iters = (SCommitIter *)taosMemoryCalloc(pCommith->niters, sizeof(SCommitIter));
...@@ -467,46 +469,12 @@ static int32_t tsdbCreateCommitIters(SCommitH *pCommith) { ...@@ -467,46 +469,12 @@ static int32_t tsdbCreateCommitIters(SCommitH *pCommith) {
} }
for (int32_t iIter = 0; iIter < pCommith->niters; iIter++) { for (int32_t iIter = 0; iIter < pCommith->niters; iIter++) {
pCommitIter = (SCommitIter *)taosArrayGetP(pMem->aTbData, iIter); pTbData = (STbData *)taosArrayGetP(pMem->aTbData, iIter);
// TODO pCommitIter = &pCommith->iters[iIter];
// pCommitIter->pIter =
}
return code;
_err:
return code;
#if 0
SSkipListIterator *pSlIter;
SSkipListNode *pNode;
STbData *pTbData;
STSchema *pTSchema = NULL;
pCommith->niters = SL_SIZE(pMem->pSlIdx);
pCommith->iters = (SCommitIter *)taosMemoryCalloc(pCommith->niters, sizeof(SCommitIter));
if (pCommith->iters == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return -1;
}
// Loop to create iters for each skiplist
pSlIter = tSkipListCreateIter(pMem->pSlIdx);
if (pSlIter == NULL) {
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
return -1;
}
for (int i = 0; i < pCommith->niters; i++) {
tSkipListIterNext(pSlIter);
pNode = tSkipListIterGet(pSlIter);
pTbData = (STbData *)pNode->pData;
pCommitIter = pCommith->iters + i;
pTSchema = metaGetTbTSchema(REPO_META(pRepo), pTbData->uid, -1); pTSchema = metaGetTbTSchema(REPO_META(pRepo), pTbData->uid, -1);
if (pTSchema) { if (pTSchema) {
pCommitIter->pIter = tSkipListCreateIter(pTbData->pData); tsdbTbDataIterCreate(pTbData, NULL, 0, &pCommitIter->pIter);
tSkipListIterNext(pCommitIter->pIter);
pCommitIter->pTable = (STable *)taosMemoryMalloc(sizeof(STable)); pCommitIter->pTable = (STable *)taosMemoryMalloc(sizeof(STable));
pCommitIter->pTable->uid = pTbData->uid; pCommitIter->pTable->uid = pTbData->uid;
...@@ -515,15 +483,18 @@ _err: ...@@ -515,15 +483,18 @@ _err:
pCommitIter->pTable->pCacheSchema = NULL; pCommitIter->pTable->pCacheSchema = NULL;
} }
} }
tSkipListDestroyIter(pSlIter);
#endif return code;
_err:
return code;
} }
static void tsdbDestroyCommitIters(SCommitH *pCommith) { static void tsdbDestroyCommitIters(SCommitH *pCommith) {
if (pCommith->iters == NULL) return; if (pCommith->iters == NULL) return;
for (int i = 1; i < pCommith->niters; i++) { for (int i = 1; i < pCommith->niters; i++) {
tSkipListDestroyIter(pCommith->iters[i].pIter); tsdbTbDataIterDestroy(pCommith->iters[i].pIter);
if (pCommith->iters[i].pTable) { if (pCommith->iters[i].pTable) {
tdFreeSchema(pCommith->iters[i].pTable->pSchema); tdFreeSchema(pCommith->iters[i].pTable->pSchema);
tdFreeSchema(pCommith->iters[i].pTable->pCacheSchema); tdFreeSchema(pCommith->iters[i].pTable->pCacheSchema);
...@@ -1333,7 +1304,7 @@ static int tsdbMergeMemData(SCommitH *pCommith, SCommitIter *pIter, int bidx) { ...@@ -1333,7 +1304,7 @@ static int tsdbMergeMemData(SCommitH *pCommith, SCommitIter *pIter, int bidx) {
keyLimit = pBlock[1].minKey.ts - 1; keyLimit = pBlock[1].minKey.ts - 1;
} }
SSkipListIterator titer = *(pIter->pIter); STbDataIter titer = *(pIter->pIter);
if (tsdbLoadBlockDataCols(&(pCommith->readh), pBlock, NULL, &colId, 1, false) < 0) return -1; if (tsdbLoadBlockDataCols(&(pCommith->readh), pBlock, NULL, &colId, 1, false) < 0) return -1;
tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, &titer, keyLimit, INT32_MAX, NULL, tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, &titer, keyLimit, INT32_MAX, NULL,
...@@ -1542,7 +1513,7 @@ static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *i ...@@ -1542,7 +1513,7 @@ static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *i
lastKey = key2; lastKey = key2;
} }
tSkipListIterNext(pCommitIter->pIter); tsdbTbDataIterNext(pCommitIter->pIter);
} else { } else {
if (lastKey != key1) { if (lastKey != key1) {
if (lastKey != TSKEY_INITIAL_VAL) { if (lastKey != TSKEY_INITIAL_VAL) {
...@@ -1574,7 +1545,7 @@ static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *i ...@@ -1574,7 +1545,7 @@ static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *i
tdAppendSTSRowToDataCol(row, pSchema, pTarget, true); tdAppendSTSRowToDataCol(row, pSchema, pTarget, true);
} }
++(*iter); ++(*iter);
tSkipListIterNext(pCommitIter->pIter); tsdbTbDataIterNext(pCommitIter->pIter);
} }
if (pTarget->numOfRows >= (maxRows - 1)) break; if (pTarget->numOfRows >= (maxRows - 1)) break;
......
...@@ -321,7 +321,7 @@ bool tsdbTbDataIterGet(STbDataIter *pIter, TSDBROW *pRow) { ...@@ -321,7 +321,7 @@ bool tsdbTbDataIterGet(STbDataIter *pIter, TSDBROW *pRow) {
* *
* The function tries to procceed AS MUCH AS POSSIBLE. * The function tries to procceed AS MUCH AS POSSIBLE.
*/ */
int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, STbDataIter *pIter, TSKEY maxKey, int maxRowsToRead,
SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo) { SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo) {
ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0); ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0);
if (pIter == NULL) return 0; if (pIter == NULL) return 0;
...@@ -404,7 +404,7 @@ int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter ...@@ -404,7 +404,7 @@ int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter
} }
} }
tSkipListIterNext(pIter); tsdbTbDataIterNext(pIter);
row = tsdbNextIterRow(pIter); row = tsdbNextIterRow(pIter);
if (row == NULL || TD_ROW_KEY(row) > maxKey) { if (row == NULL || TD_ROW_KEY(row) > maxKey) {
rowKey = INT64_MAX; rowKey = INT64_MAX;
...@@ -444,7 +444,7 @@ int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter ...@@ -444,7 +444,7 @@ int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter
} }
} }
tSkipListIterNext(pIter); tsdbTbDataIterNext(pIter);
row = tsdbNextIterRow(pIter); row = tsdbNextIterRow(pIter);
if (row == NULL || TD_ROW_KEY(row) > maxKey) { if (row == NULL || TD_ROW_KEY(row) > maxKey) {
rowKey = INT64_MAX; rowKey = INT64_MAX;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册