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 "dataformat.h"
|
||||
#include "name.h"
|
||||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tarray.h"
|
||||
#include "name.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -62,14 +62,11 @@ void tsdbFreeCfg(STsdbCfg *pCfg);
|
|||
// --------- TSDB REPOSITORY DEFINITION
|
||||
typedef void tsdb_repo_t; // use void to hide implementation details from outside
|
||||
|
||||
int tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter);
|
||||
int32_t tsdbDropRepo(tsdb_repo_t *repo);
|
||||
tsdb_repo_t * tsdbOpenRepo(char *tsdbDir, STsdbAppH *pAppH);
|
||||
int32_t tsdbCloseRepo(tsdb_repo_t *repo);
|
||||
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);
|
||||
int tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter);
|
||||
int32_t tsdbDropRepo(tsdb_repo_t *repo);
|
||||
tsdb_repo_t *tsdbOpenRepo(char *tsdbDir, STsdbAppH *pAppH);
|
||||
int32_t tsdbCloseRepo(tsdb_repo_t *repo);
|
||||
int32_t tsdbConfigRepo(tsdb_repo_t *repo, STsdbCfg *pCfg);
|
||||
|
||||
// --------- TSDB TABLE DEFINITION
|
||||
typedef struct {
|
||||
|
@ -99,27 +96,6 @@ int tsdbCreateTable(tsdb_repo_t *repo, STableCfg *pCfg);
|
|||
int tsdbDropTable(tsdb_repo_t *pRepo, STableId tableId);
|
||||
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
|
||||
typedef struct STsdbRepoInfo {
|
||||
STsdbCfg tsdbCfg;
|
||||
|
@ -137,35 +113,7 @@ typedef struct {
|
|||
int64_t tableTotalDataSize; // In bytes
|
||||
int64_t tableTotalDiskSize; // In bytes
|
||||
} STableInfo;
|
||||
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
|
||||
*/
|
||||
STableInfo *tsdbGetTableInfo(tsdb_repo_t *pRepo, STableId tid);
|
||||
|
||||
// -- FOR INSERT DATA
|
||||
/**
|
||||
|
@ -179,18 +127,18 @@ int32_t tsdbInsertData(tsdb_repo_t *pRepo, SSubmitMsg *pMsg);
|
|||
|
||||
// -- 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
|
||||
SArray* pGroupList;
|
||||
int32_t numOfTables;
|
||||
typedef struct STableGroupList { // qualified table object list in group
|
||||
SArray *pGroupList;
|
||||
int32_t numOfTables;
|
||||
} STableGroupList;
|
||||
|
||||
// query condition to build vnode iterator
|
||||
typedef struct STsdbQueryCond {
|
||||
STimeWindow twindow;
|
||||
int32_t order; // desc/asc order to iterate the data block
|
||||
SColumnInfoData* colList;
|
||||
STimeWindow twindow;
|
||||
int32_t order; // desc/asc order to iterate the data block
|
||||
SColumnInfoData *colList;
|
||||
} STsdbQueryCond;
|
||||
|
||||
typedef struct SBlockInfo {
|
||||
|
@ -202,12 +150,6 @@ typedef struct SBlockInfo {
|
|||
STableId tableId;
|
||||
} SBlockInfo;
|
||||
|
||||
// TODO: move this data struct out of the module
|
||||
//typedef struct SData {
|
||||
// int32_t num;
|
||||
// char * data;
|
||||
//} SData;
|
||||
|
||||
typedef struct SDataBlockInfo {
|
||||
STimeWindow window;
|
||||
int32_t rows;
|
||||
|
@ -235,7 +177,7 @@ typedef void *tsdbpos_t;
|
|||
* @param pTableList table sid list
|
||||
* @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
|
||||
|
@ -284,7 +226,7 @@ SArray *tsdbRetrieveDataBlock(tsdb_query_handle_t *pQueryHandle, SArray *pIdList
|
|||
* @param order ascending order or descending order
|
||||
* @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
|
||||
|
@ -337,10 +279,10 @@ SArray *tsdbGetTableList(tsdb_query_handle_t *pQueryHandle);
|
|||
* @param pTagCond. tag query condition
|
||||
*
|
||||
*/
|
||||
int32_t tsdbQueryTags(tsdb_repo_t* tsdb, int64_t uid, const char* pTagCond, size_t len, SArray** pGroupList,
|
||||
SColIndex* pColIndex, int32_t numOfCols);
|
||||
int32_t tsdbQueryTags(tsdb_repo_t *tsdb, int64_t uid, const char *pTagCond, size_t len, SArray **pGroupList,
|
||||
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
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
#ifndef _TD_TSDB_MAIN_H_
|
||||
#define _TD_TSDB_MAIN_H_
|
||||
|
||||
#include "tsdb.h"
|
||||
#include "tlist.h"
|
||||
#include "tglobalcfg.h"
|
||||
#include "tlist.h"
|
||||
#include "tsdb.h"
|
||||
#include "tskiplist.h"
|
||||
#include "tutil.h"
|
||||
|
||||
|
@ -90,9 +90,9 @@ typedef struct {
|
|||
|
||||
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 maxCols;
|
||||
} STsdbMeta;
|
||||
|
@ -119,14 +119,14 @@ STSchema * tsdbGetTableTagSchema(STsdbMeta *pMeta, STable *pTable);
|
|||
#define TSDB_TABLE_OF_ID(pHandle, id) ((pHandle)->pTables)[id]
|
||||
#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 tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId);
|
||||
STable *tsdbIsValidTableToInsert(STsdbMeta *pMeta, STableId tableId);
|
||||
// int32_t tsdbInsertRowToTableImpl(SSkipListNode *pNode, STable *pTable);
|
||||
STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid);
|
||||
char *getTupleKey(const void * data);
|
||||
char * getTupleKey(const void *data);
|
||||
|
||||
// ------------------------------ TSDB CACHE INTERFACES ------------------------------
|
||||
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16 * 1024 * 1024 /* 16M */
|
||||
|
@ -192,8 +192,8 @@ typedef struct {
|
|||
} SFileInfo;
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
char fname[128];
|
||||
int fd;
|
||||
char fname[128];
|
||||
SFileInfo info;
|
||||
} SFile;
|
||||
|
||||
|
@ -217,13 +217,15 @@ typedef struct {
|
|||
|
||||
STsdbFileH *tsdbInitFileH(char *dataDir, int maxFiles);
|
||||
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 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);
|
||||
|
||||
#define TSDB_FGROUP_ITER_FORWARD TSDB_ORDER_ASC
|
||||
#define TSDB_FGROUP_ITER_FORWARD TSDB_ORDER_ASC
|
||||
#define TSDB_FGROUP_ITER_BACKWARD TSDB_ORDER_DESC
|
||||
|
||||
typedef struct {
|
||||
|
@ -278,15 +280,15 @@ typedef struct {
|
|||
} SCompInfo;
|
||||
|
||||
#define TSDB_COMPBLOCK_AT(pCompInfo, idx) ((pCompInfo)->blocks + (idx))
|
||||
#define TSDB_COMPBLOCK_GET_START_AND_SIZE(pCompInfo, pCompBlock, size)\
|
||||
do {\
|
||||
if (pCompBlock->numOfSubBlocks > 1) {\
|
||||
pCompBlock = pCompInfo->blocks + pCompBlock->offset;\
|
||||
size = pCompBlock->numOfSubBlocks;\
|
||||
} else {\
|
||||
size = 1;\
|
||||
}\
|
||||
} while (0)
|
||||
#define TSDB_COMPBLOCK_GET_START_AND_SIZE(pCompInfo, pCompBlock, size) \
|
||||
do { \
|
||||
if (pCompBlock->numOfSubBlocks > 1) { \
|
||||
pCompBlock = pCompInfo->blocks + pCompBlock->offset; \
|
||||
size = pCompBlock->numOfSubBlocks; \
|
||||
} else { \
|
||||
size = 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// TODO: take pre-calculation into account
|
||||
typedef struct {
|
||||
|
@ -304,9 +306,10 @@ typedef struct {
|
|||
SCompCol cols[];
|
||||
} 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 tsdbLoadCompBlocks(SFileGroup *pGroup, SCompIdx *pIdx, void *buf);
|
||||
|
@ -350,6 +353,30 @@ typedef struct _tsdb_repo {
|
|||
|
||||
} 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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue