diff --git a/src/vnode/tests/tsdb/tsdbTests.cpp b/src/vnode/tests/tsdb/tsdbTests.cpp index 580279e566a6fd0af9d5133f4b6390a719eac22d..3d7f41df24177793e0df01f4e59e53954edf4194 100644 --- a/src/vnode/tests/tsdb/tsdbTests.cpp +++ b/src/vnode/tests/tsdb/tsdbTests.cpp @@ -4,7 +4,7 @@ #include "tsdb.h" TEST(TsdbTest, createTsdbRepo) { - STSDBCfg *pCfg = (STSDBCfg *)malloc(sizeof(STSDBCfg)); + STsdbCfg *pCfg = (STsdbCfg *)malloc(sizeof(STsdbCfg)); free(pCfg); diff --git a/src/vnode/tsdb/inc/tsdb.h b/src/vnode/tsdb/inc/tsdb.h index b46f886b5dd817c8d7b12b1ab0b26c0abcf249dc..57dbf6d180d4a778c59eaac2c87217ccd8814eb8 100644 --- a/src/vnode/tsdb/inc/tsdb.h +++ b/src/vnode/tsdb/inc/tsdb.h @@ -8,17 +8,19 @@ #include #include -// #include "cache.h" #include "schema.h" #define TSDB_VERSION_MAJOR 1 #define TSDB_VERSION_MINOR 0 -typedef void tsdb_repo_t; // use void to hide implementation details from outside -typedef int32_t table_id_t; // table ID type in this repository -typedef int16_t tsdb_id_t; // TSDB repository ID +typedef void tsdb_repo_t; // use void to hide implementation details from outside -// Submit message +typedef struct { + int64_t uid; // the unique table ID + int32_t tableId; // the table ID in the repository. +} STableId; + +// Submit message for this TSDB typedef struct { int32_t numOfTables; int32_t compressed; @@ -27,10 +29,9 @@ typedef struct { // Submit message for one table typedef struct { - table_id_t tableId; // table ID to insert + STableId tid; int32_t sversion; // data schema version int32_t numOfRows; // number of rows data - int64_t uid; // table UID to insert char data[]; } SSubmitBlock; @@ -55,27 +56,20 @@ typedef struct { int32_t maxRowsPerFileBlock; } SBlockRowsPolicy; -// Applications trying to manipulate a table should provide both uid and tableId. -// tableId is used for table quick access and uid for verification. -typedef struct { - int64_t uid; // the unique table ID - table_id_t tableId; // the table ID in the repository. -} STableId; - // the TSDB repository configuration typedef struct { char * rootDir; // TSDB repository root directory, TODO: need to adjust here - tsdb_id_t tsdbId; + int32_t tsdbId; int32_t maxTables; // maximum number of tables this repository can have SDataShardPolicy dataShardPolicy; SBlockRowsPolicy blockRowsPolicy; SRetentionPolicy retentionPlicy; // retention configuration void * cachePool; // the cache pool the repository to use -} STSDBCfg; +} STsdbCfg; // the TSDB repository info typedef struct STSDBRepoInfo { - STSDBCfg tsdbCfg; + STsdbCfg tsdbCfg; int64_t version; // version of the repository int64_t tsdbTotalDataSize; // the original inserted data size int64_t tsdbTotalDiskSize; // the total disk size taken by this TSDB repository @@ -86,7 +80,7 @@ typedef struct STSDBRepoInfo { typedef struct { char * tableName; int64_t uid; // uid given by upper layer - table_id_t tableId; // table ID allocated from upper layer + int32_t tableId; // table ID allocated from upper layer char *stableName; // if not NULL, the table is created from a super table, need to make sure the super // table exists in this TSDB. @@ -115,7 +109,7 @@ typedef struct { * * @return a TSDB repository handle on success, NULL for failure and the error number is set */ -tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg); +tsdb_repo_t *tsdbCreateRepo(STsdbCfg *pCfg); /** * Close and free all resources taken by the repository @@ -149,7 +143,7 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo); * * @return 0 for success, -1 for failure and the error number is set */ -int32_t tsdbConfigRepo(tsdb_repo_t repo, STSDBCfg *pCfg); +int32_t tsdbConfigRepo(tsdb_repo_t repo, STsdbCfg *pCfg); /** * Get the TSDB repository information, including some statistics diff --git a/src/vnode/tsdb/inc/tsdbMeta.h b/src/vnode/tsdb/inc/tsdbMeta.h index 17d49ba38ade2cd01ddac49b592c61ddf7a14e2a..78d55e68ad54d8f36ed6bf8ac79ef19d39ee9cc5 100644 --- a/src/vnode/tsdb/inc/tsdbMeta.h +++ b/src/vnode/tsdb/inc/tsdbMeta.h @@ -16,7 +16,7 @@ typedef enum { } TSDB_TABLE_TYPE; typedef struct STable { - tsdb_id_t tableId; + int32_t tableId; int64_t uid; char * tableName; TSDB_TABLE_TYPE type; @@ -24,7 +24,7 @@ typedef struct STable { int64_t createdTime; // super table UID - tsdb_id_t superTableId; + int32_t superTableId; // Schema for this table // For TSDB_SUPER_TABLE, it is the schema including tags diff --git a/src/vnode/tsdb/src/tsdb.c b/src/vnode/tsdb/src/tsdbMain.c similarity index 78% rename from src/vnode/tsdb/src/tsdb.c rename to src/vnode/tsdb/src/tsdbMain.c index dec46bea97458208ffe7594d04ee51cdd2fc62ff..3ebef5498cd860d8a3b2e1ef72e768437bb50baf 100644 --- a/src/vnode/tsdb/src/tsdb.c +++ b/src/vnode/tsdb/src/tsdbMain.c @@ -21,19 +21,19 @@ enum { typedef struct _tsdb_repo { // TSDB configuration - STSDBCfg *pCfg; + STsdbCfg *pCfg; // The meter meta handle of this TSDB repository - SMetaHandle *pMetaHandle; + SMetaHandle *tsdbMeta; // The cache Handle - SCacheHandle *pCacheHandle; + SCacheHandle *tsdbCache; // Disk tier handle for multi-tier storage - void *pDiskTier; + void *diskTier; // File Store - void *pFileStore; + void *tsdbFiles; pthread_mutex_t tsdbMutex; @@ -47,7 +47,7 @@ typedef struct _tsdb_repo { #define TSDB_IS_REPO_CLOSED(pRepo) ((pRepo)->state == TSDB_REPO_STATE_CLOSED) // Check the correctness of the TSDB configuration -static int32_t tsdbCheckCfg(STSDBCfg *pCfg) { +static int32_t tsdbCheckCfg(STsdbCfg *pCfg) { if (pCfg->rootDir == NULL) return -1; if (access(pCfg->rootDir, F_OK|R_OK|W_OK) == -1) { @@ -65,7 +65,7 @@ static int32_t tsdbClearFiles(STSDBRepo *pRepo) { // TODO } -tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg) { +tsdb_repo_t *tsdbCreateRepo(STsdbCfg *pCfg) { // Check the configuration if (tsdbCheckCfg(pCfg) < 0) { @@ -79,18 +79,18 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg) { } // TODO: Initailize pMetahandle - pRepo->pMetaHandle = tsdbCreateMetaHandle(pCfg->maxTables); - if (pRepo->pMetaHandle == NULL) { + pRepo->tsdbMeta = tsdbCreateMetaHandle(pCfg->maxTables); + if (pRepo->tsdbMeta == NULL) { // TODO: deal with error free(pRepo); return NULL; } // TODO: Initialize cache handle - pRepo->pCacheHandle = tsdbCreateCache(5); - if (pRepo->pCacheHandle == NULL) { + pRepo->tsdbCache = tsdbCreateCache(5); + if (pRepo->tsdbCache == NULL) { // TODO: free the object and return error - tsdbFreeMetaHandle(pRepo->pCacheHandle); + tsdbFreeMetaHandle(pRepo->tsdbCache); free(pRepo); return NULL; } @@ -101,7 +101,7 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg) { // Create the Meta data file and data directory if (tsdbCreateFiles(pRepo) < 0) { // Failed to create and save files - tsdbFreeMetaHandle(pRepo->pCacheHandle); + tsdbFreeMetaHandle(pRepo->tsdbCache); free(pRepo); return NULL; } @@ -117,10 +117,10 @@ int32_t tsdbDropRepo(tsdb_repo_t *repo) { pRepo->state = TSDB_REPO_STATE_CLOSED; // Free the metaHandle - tsdbFreeMetaHandle(pRepo->pMetaHandle); + tsdbFreeMetaHandle(pRepo->tsdbMeta); // Free the cache - tsdbFreeCache(pRepo->pCacheHandle); + tsdbFreeCache(pRepo->tsdbCache); tsdbClearFiles(pRepo); @@ -139,14 +139,14 @@ tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) { } // TODO: Initialize configuration from the file - pRepo->pMetaHandle = tsdbOpenMetaHandle(); - if (pRepo->pMetaHandle == NULL) { + pRepo->tsdbMeta = tsdbOpenMetaHandle(); + if (pRepo->tsdbMeta == NULL) { free(pRepo); return NULL; } - pRepo->pCacheHandle = tsdbCreateCache(5); - if (pRepo->pCacheHandle == NULL) { + pRepo->tsdbCache = tsdbCreateCache(5); + if (pRepo->tsdbCache == NULL) { // TODO: deal with error return NULL; } @@ -167,14 +167,14 @@ int32_t tsdbCloseRepo(tsdb_repo_t *repo) { pRepo->state = TSDB_REPO_STATE_CLOSED; - tsdbFreeMetaHandle(pRepo->pMetaHandle); + tsdbFreeMetaHandle(pRepo->tsdbMeta); - tsdbFreeCache(pRepo->pMetaHandle); + tsdbFreeCache(pRepo->tsdbMeta); return 0; } -int32_t tsdbConfigRepo(tsdb_repo_t *repo, STSDBCfg *pCfg) { +int32_t tsdbConfigRepo(tsdb_repo_t *repo, STsdbCfg *pCfg) { STSDBRepo *pRepo = (STSDBRepo *)repo; pRepo->pCfg = pCfg; @@ -188,7 +188,7 @@ STSDBRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo) { int32_t tsdbCreateTable(tsdb_repo_t *repo, STableCfg *pCfg) { STSDBRepo *pRepo = (STSDBRepo *)repo; - return tsdbCreateTableImpl(pRepo->pMetaHandle, pCfg); + return tsdbCreateTableImpl(pRepo->tsdbMeta, pCfg); } int32_t tsdbAlterTable(tsdb_repo_t *pRepo, STableCfg *pCfg) {