Merge pull request #1629 from taosdata/hotfix/refactor_tsdb_h
refactor tsdb.h
This commit is contained in:
commit
b7147d95c8
|
@ -20,10 +20,10 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "dataformat.h"
|
#include "dataformat.h"
|
||||||
|
#include "name.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
#include "name.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -62,14 +62,11 @@ void tsdbFreeCfg(STsdbCfg *pCfg);
|
||||||
// --------- TSDB REPOSITORY DEFINITION
|
// --------- TSDB REPOSITORY DEFINITION
|
||||||
typedef void tsdb_repo_t; // use void to hide implementation details from outside
|
typedef void tsdb_repo_t; // use void to hide implementation details from outside
|
||||||
|
|
||||||
int tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter);
|
int tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter);
|
||||||
int32_t tsdbDropRepo(tsdb_repo_t *repo);
|
int32_t tsdbDropRepo(tsdb_repo_t *repo);
|
||||||
tsdb_repo_t * tsdbOpenRepo(char *tsdbDir, STsdbAppH *pAppH);
|
tsdb_repo_t *tsdbOpenRepo(char *tsdbDir, STsdbAppH *pAppH);
|
||||||
int32_t tsdbCloseRepo(tsdb_repo_t *repo);
|
int32_t tsdbCloseRepo(tsdb_repo_t *repo);
|
||||||
int32_t tsdbConfigRepo(tsdb_repo_t *repo, STsdbCfg *pCfg);
|
int32_t tsdbConfigRepo(tsdb_repo_t *repo, STsdbCfg *pCfg);
|
||||||
int32_t tsdbTriggerCommit(tsdb_repo_t *repo);
|
|
||||||
int32_t tsdbLockRepo(tsdb_repo_t *repo);
|
|
||||||
int32_t tsdbUnLockRepo(tsdb_repo_t *repo);
|
|
||||||
|
|
||||||
// --------- TSDB TABLE DEFINITION
|
// --------- TSDB TABLE DEFINITION
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -99,27 +96,6 @@ int tsdbCreateTable(tsdb_repo_t *repo, STableCfg *pCfg);
|
||||||
int tsdbDropTable(tsdb_repo_t *pRepo, STableId tableId);
|
int tsdbDropTable(tsdb_repo_t *pRepo, STableId tableId);
|
||||||
int tsdbAlterTable(tsdb_repo_t *repo, STableCfg *pCfg);
|
int tsdbAlterTable(tsdb_repo_t *repo, STableCfg *pCfg);
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int32_t totalLen;
|
|
||||||
int32_t len;
|
|
||||||
SDataRow row;
|
|
||||||
} SSubmitBlkIter;
|
|
||||||
|
|
||||||
int tsdbInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter);
|
|
||||||
SDataRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter);
|
|
||||||
|
|
||||||
#define TSDB_SUBMIT_MSG_HEAD_SIZE sizeof(SSubmitMsg)
|
|
||||||
|
|
||||||
// SSubmitMsg Iterator
|
|
||||||
typedef struct {
|
|
||||||
int32_t totalLen;
|
|
||||||
int32_t len;
|
|
||||||
SSubmitBlk *pBlock;
|
|
||||||
} SSubmitMsgIter;
|
|
||||||
|
|
||||||
int tsdbInitSubmitMsgIter(SSubmitMsg *pMsg, SSubmitMsgIter *pIter);
|
|
||||||
SSubmitBlk *tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter);
|
|
||||||
|
|
||||||
// the TSDB repository info
|
// the TSDB repository info
|
||||||
typedef struct STsdbRepoInfo {
|
typedef struct STsdbRepoInfo {
|
||||||
STsdbCfg tsdbCfg;
|
STsdbCfg tsdbCfg;
|
||||||
|
@ -137,35 +113,7 @@ typedef struct {
|
||||||
int64_t tableTotalDataSize; // In bytes
|
int64_t tableTotalDataSize; // In bytes
|
||||||
int64_t tableTotalDiskSize; // In bytes
|
int64_t tableTotalDiskSize; // In bytes
|
||||||
} STableInfo;
|
} STableInfo;
|
||||||
STableInfo * tsdbGetTableInfo(tsdb_repo_t *pRepo, STableId tid);
|
STableInfo *tsdbGetTableInfo(tsdb_repo_t *pRepo, STableId tid);
|
||||||
|
|
||||||
// -- For table manipulation
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create/Alter a table in a TSDB repository handle
|
|
||||||
* @param repo the TSDB repository handle
|
|
||||||
* @param pCfg the table configurations, the upper layer should free the pointer
|
|
||||||
*
|
|
||||||
* @return 0 for success, -1 for failure and the error number is set
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drop a table in a repository and free all the resources it takes
|
|
||||||
* @param pRepo the TSDB repository handle
|
|
||||||
* @param tid the ID of the table to drop
|
|
||||||
* @param error the error number to set when failure occurs
|
|
||||||
*
|
|
||||||
* @return 0 for success, -1 for failure and the error number is set
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the information of a table in the repository
|
|
||||||
* @param pRepo the TSDB repository handle
|
|
||||||
* @param tid the ID of the table to drop
|
|
||||||
* @param error the error number to set when failure occurs
|
|
||||||
*
|
|
||||||
* @return a table information handle for success, NULL for failure and the error number is set
|
|
||||||
*/
|
|
||||||
|
|
||||||
// -- FOR INSERT DATA
|
// -- FOR INSERT DATA
|
||||||
/**
|
/**
|
||||||
|
@ -179,18 +127,18 @@ int32_t tsdbInsertData(tsdb_repo_t *pRepo, SSubmitMsg *pMsg);
|
||||||
|
|
||||||
// -- FOR QUERY TIME SERIES DATA
|
// -- FOR QUERY TIME SERIES DATA
|
||||||
|
|
||||||
typedef void* tsdb_query_handle_t; // Use void to hide implementation details
|
typedef void *tsdb_query_handle_t; // Use void to hide implementation details
|
||||||
|
|
||||||
typedef struct STableGroupList { // qualified table object list in group
|
typedef struct STableGroupList { // qualified table object list in group
|
||||||
SArray* pGroupList;
|
SArray *pGroupList;
|
||||||
int32_t numOfTables;
|
int32_t numOfTables;
|
||||||
} STableGroupList;
|
} STableGroupList;
|
||||||
|
|
||||||
// query condition to build vnode iterator
|
// query condition to build vnode iterator
|
||||||
typedef struct STsdbQueryCond {
|
typedef struct STsdbQueryCond {
|
||||||
STimeWindow twindow;
|
STimeWindow twindow;
|
||||||
int32_t order; // desc/asc order to iterate the data block
|
int32_t order; // desc/asc order to iterate the data block
|
||||||
SColumnInfoData* colList;
|
SColumnInfoData *colList;
|
||||||
} STsdbQueryCond;
|
} STsdbQueryCond;
|
||||||
|
|
||||||
typedef struct SBlockInfo {
|
typedef struct SBlockInfo {
|
||||||
|
@ -202,12 +150,6 @@ typedef struct SBlockInfo {
|
||||||
STableId tableId;
|
STableId tableId;
|
||||||
} SBlockInfo;
|
} SBlockInfo;
|
||||||
|
|
||||||
// TODO: move this data struct out of the module
|
|
||||||
//typedef struct SData {
|
|
||||||
// int32_t num;
|
|
||||||
// char * data;
|
|
||||||
//} SData;
|
|
||||||
|
|
||||||
typedef struct SDataBlockInfo {
|
typedef struct SDataBlockInfo {
|
||||||
STimeWindow window;
|
STimeWindow window;
|
||||||
int32_t rows;
|
int32_t rows;
|
||||||
|
@ -235,7 +177,7 @@ typedef void *tsdbpos_t;
|
||||||
* @param pTableList table sid list
|
* @param pTableList table sid list
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
tsdb_query_handle_t *tsdbQueryTables(tsdb_repo_t* tsdb, STsdbQueryCond *pCond, SArray *idList, SArray *pColumnInfo);
|
tsdb_query_handle_t *tsdbQueryTables(tsdb_repo_t *tsdb, STsdbQueryCond *pCond, SArray *idList, SArray *pColumnInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move to next block
|
* move to next block
|
||||||
|
@ -284,7 +226,7 @@ SArray *tsdbRetrieveDataBlock(tsdb_query_handle_t *pQueryHandle, SArray *pIdList
|
||||||
* @param order ascending order or descending order
|
* @param order ascending order or descending order
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t tsdbResetQuery(tsdb_query_handle_t *pQueryHandle, STimeWindow* window, tsdbpos_t position, int16_t order);
|
int32_t tsdbResetQuery(tsdb_query_handle_t *pQueryHandle, STimeWindow *window, tsdbpos_t position, int16_t order);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the access position of current query handle
|
* return the access position of current query handle
|
||||||
|
@ -337,10 +279,10 @@ SArray *tsdbGetTableList(tsdb_query_handle_t *pQueryHandle);
|
||||||
* @param pTagCond. tag query condition
|
* @param pTagCond. tag query condition
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int32_t tsdbQueryTags(tsdb_repo_t* tsdb, int64_t uid, const char* pTagCond, size_t len, SArray** pGroupList,
|
int32_t tsdbQueryTags(tsdb_repo_t *tsdb, int64_t uid, const char *pTagCond, size_t len, SArray **pGroupList,
|
||||||
SColIndex* pColIndex, int32_t numOfCols);
|
SColIndex *pColIndex, int32_t numOfCols);
|
||||||
|
|
||||||
int32_t tsdbGetOneTableGroup(tsdb_repo_t* tsdb, int64_t uid, SArray** pGroupList);
|
int32_t tsdbGetOneTableGroup(tsdb_repo_t *tsdb, int64_t uid, SArray **pGroupList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clean up the query handle
|
* clean up the query handle
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
#ifndef _TD_TSDB_MAIN_H_
|
#ifndef _TD_TSDB_MAIN_H_
|
||||||
#define _TD_TSDB_MAIN_H_
|
#define _TD_TSDB_MAIN_H_
|
||||||
|
|
||||||
#include "tsdb.h"
|
|
||||||
#include "tlist.h"
|
|
||||||
#include "tglobalcfg.h"
|
#include "tglobalcfg.h"
|
||||||
|
#include "tlist.h"
|
||||||
|
#include "tsdb.h"
|
||||||
#include "tskiplist.h"
|
#include "tskiplist.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
|
@ -90,9 +90,9 @@ typedef struct {
|
||||||
|
|
||||||
STable *superList; // super table list TODO: change it to list container
|
STable *superList; // super table list TODO: change it to list container
|
||||||
|
|
||||||
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 maxRowBytes;
|
||||||
int maxCols;
|
int maxCols;
|
||||||
} STsdbMeta;
|
} STsdbMeta;
|
||||||
|
@ -119,14 +119,14 @@ STSchema * tsdbGetTableTagSchema(STsdbMeta *pMeta, STable *pTable);
|
||||||
#define TSDB_TABLE_OF_ID(pHandle, id) ((pHandle)->pTables)[id]
|
#define TSDB_TABLE_OF_ID(pHandle, id) ((pHandle)->pTables)[id]
|
||||||
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */
|
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */
|
||||||
|
|
||||||
STsdbMeta* tsdbGetMeta(tsdb_repo_t* pRepo);
|
STsdbMeta *tsdbGetMeta(tsdb_repo_t *pRepo);
|
||||||
|
|
||||||
int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg);
|
int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg);
|
||||||
int32_t tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId);
|
int32_t tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId);
|
||||||
STable *tsdbIsValidTableToInsert(STsdbMeta *pMeta, STableId tableId);
|
STable *tsdbIsValidTableToInsert(STsdbMeta *pMeta, STableId tableId);
|
||||||
// int32_t tsdbInsertRowToTableImpl(SSkipListNode *pNode, STable *pTable);
|
// int32_t tsdbInsertRowToTableImpl(SSkipListNode *pNode, STable *pTable);
|
||||||
STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid);
|
STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid);
|
||||||
char *getTupleKey(const void * data);
|
char * getTupleKey(const void *data);
|
||||||
|
|
||||||
// ------------------------------ TSDB CACHE INTERFACES ------------------------------
|
// ------------------------------ TSDB CACHE INTERFACES ------------------------------
|
||||||
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16 * 1024 * 1024 /* 16M */
|
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16 * 1024 * 1024 /* 16M */
|
||||||
|
@ -192,8 +192,8 @@ typedef struct {
|
||||||
} SFileInfo;
|
} SFileInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int fd;
|
int fd;
|
||||||
char fname[128];
|
char fname[128];
|
||||||
SFileInfo info;
|
SFileInfo info;
|
||||||
} SFile;
|
} SFile;
|
||||||
|
|
||||||
|
@ -217,13 +217,15 @@ typedef struct {
|
||||||
|
|
||||||
STsdbFileH *tsdbInitFileH(char *dataDir, int maxFiles);
|
STsdbFileH *tsdbInitFileH(char *dataDir, int maxFiles);
|
||||||
void tsdbCloseFileH(STsdbFileH *pFileH);
|
void tsdbCloseFileH(STsdbFileH *pFileH);
|
||||||
int tsdbCreateFile(char *dataDir, int fileId, const char *suffix, int maxTables, SFile *pFile, int writeHeader, int toClose);
|
int tsdbCreateFile(char *dataDir, int fileId, const char *suffix, int maxTables, SFile *pFile, int writeHeader,
|
||||||
|
int toClose);
|
||||||
int tsdbCreateFGroup(STsdbFileH *pFileH, char *dataDir, int fid, int maxTables);
|
int tsdbCreateFGroup(STsdbFileH *pFileH, char *dataDir, int fid, int maxTables);
|
||||||
int tsdbOpenFile(SFile *pFile, int oflag);
|
int tsdbOpenFile(SFile *pFile, int oflag);
|
||||||
int tsdbCloseFile(SFile *pFile); SFileGroup *tsdbOpenFilesForCommit(STsdbFileH *pFileH, int fid);
|
int tsdbCloseFile(SFile *pFile);
|
||||||
|
SFileGroup *tsdbOpenFilesForCommit(STsdbFileH *pFileH, int fid);
|
||||||
int tsdbRemoveFileGroup(STsdbFileH *pFile, int fid);
|
int tsdbRemoveFileGroup(STsdbFileH *pFile, int fid);
|
||||||
|
|
||||||
#define TSDB_FGROUP_ITER_FORWARD TSDB_ORDER_ASC
|
#define TSDB_FGROUP_ITER_FORWARD TSDB_ORDER_ASC
|
||||||
#define TSDB_FGROUP_ITER_BACKWARD TSDB_ORDER_DESC
|
#define TSDB_FGROUP_ITER_BACKWARD TSDB_ORDER_DESC
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -278,15 +280,15 @@ typedef struct {
|
||||||
} SCompInfo;
|
} SCompInfo;
|
||||||
|
|
||||||
#define TSDB_COMPBLOCK_AT(pCompInfo, idx) ((pCompInfo)->blocks + (idx))
|
#define TSDB_COMPBLOCK_AT(pCompInfo, idx) ((pCompInfo)->blocks + (idx))
|
||||||
#define TSDB_COMPBLOCK_GET_START_AND_SIZE(pCompInfo, pCompBlock, size)\
|
#define TSDB_COMPBLOCK_GET_START_AND_SIZE(pCompInfo, pCompBlock, size) \
|
||||||
do {\
|
do { \
|
||||||
if (pCompBlock->numOfSubBlocks > 1) {\
|
if (pCompBlock->numOfSubBlocks > 1) { \
|
||||||
pCompBlock = pCompInfo->blocks + pCompBlock->offset;\
|
pCompBlock = pCompInfo->blocks + pCompBlock->offset; \
|
||||||
size = pCompBlock->numOfSubBlocks;\
|
size = pCompBlock->numOfSubBlocks; \
|
||||||
} else {\
|
} else { \
|
||||||
size = 1;\
|
size = 1; \
|
||||||
}\
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// TODO: take pre-calculation into account
|
// TODO: take pre-calculation into account
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -304,9 +306,10 @@ typedef struct {
|
||||||
SCompCol cols[];
|
SCompCol cols[];
|
||||||
} SCompData;
|
} SCompData;
|
||||||
|
|
||||||
STsdbFileH* tsdbGetFile(tsdb_repo_t* pRepo);
|
STsdbFileH *tsdbGetFile(tsdb_repo_t *pRepo);
|
||||||
|
|
||||||
int tsdbCopyBlockDataInFile(SFile *pOutFile, SFile *pInFile, SCompInfo *pCompInfo, int idx, int isLast, SDataCols *pCols);
|
int tsdbCopyBlockDataInFile(SFile *pOutFile, SFile *pInFile, SCompInfo *pCompInfo, int idx, int isLast,
|
||||||
|
SDataCols *pCols);
|
||||||
|
|
||||||
int tsdbLoadCompIdx(SFileGroup *pGroup, void *buf, int maxTables);
|
int tsdbLoadCompIdx(SFileGroup *pGroup, void *buf, int maxTables);
|
||||||
int tsdbLoadCompBlocks(SFileGroup *pGroup, SCompIdx *pIdx, void *buf);
|
int tsdbLoadCompBlocks(SFileGroup *pGroup, SCompIdx *pIdx, void *buf);
|
||||||
|
@ -350,6 +353,30 @@ typedef struct _tsdb_repo {
|
||||||
|
|
||||||
} STsdbRepo;
|
} STsdbRepo;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t totalLen;
|
||||||
|
int32_t len;
|
||||||
|
SDataRow row;
|
||||||
|
} SSubmitBlkIter;
|
||||||
|
|
||||||
|
int tsdbInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter);
|
||||||
|
SDataRow tsdbGetSubmitBlkNext(SSubmitBlkIter *pIter);
|
||||||
|
|
||||||
|
#define TSDB_SUBMIT_MSG_HEAD_SIZE sizeof(SSubmitMsg)
|
||||||
|
|
||||||
|
// SSubmitMsg Iterator
|
||||||
|
typedef struct {
|
||||||
|
int32_t totalLen;
|
||||||
|
int32_t len;
|
||||||
|
SSubmitBlk *pBlock;
|
||||||
|
} SSubmitMsgIter;
|
||||||
|
|
||||||
|
int tsdbInitSubmitMsgIter(SSubmitMsg *pMsg, SSubmitMsgIter *pIter);
|
||||||
|
SSubmitBlk *tsdbGetSubmitMsgNext(SSubmitMsgIter *pIter);
|
||||||
|
|
||||||
|
int32_t tsdbTriggerCommit(tsdb_repo_t *repo);
|
||||||
|
int32_t tsdbLockRepo(tsdb_repo_t *repo);
|
||||||
|
int32_t tsdbUnLockRepo(tsdb_repo_t *repo);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue