提交 f4959b03 编写于 作者: H hzcheng

more

上级 f3f657a6
......@@ -6,10 +6,7 @@
TEST(TsdbTest, createTsdbRepo) {
STSDBCfg *pCfg = (STSDBCfg *)malloc(sizeof(STSDBCfg));
pCfg->rootDir = "/var/lib/taos/";
free(pCfg);
int32_t err_num = 0;
tsdb_repo_t *pRepo = tsdbCreateRepo(pCfg, &err_num);
ASSERT_EQ(pRepo, NULL);
ASSERT_EQ(1, 2/2);
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ typedef int16_t tsdb_id_t; // TSDB repository ID
// Submit message
typedef struct {
int32_t numOfTables;
int32_t compressed;
char data[];
} SSubmitMsg;
......@@ -111,49 +112,44 @@ typedef struct {
/**
* Create a new TSDB repository
* @param pCfg the TSDB repository configuration, upper layer to free the pointer
* @param error the error number to set when failure occurs
*
* @return a TSDB repository handle on success, NULL for failure and the error number is set
*/
tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error);
tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg);
/**
* Close and free all resources taken by the repository
* @param pRepo the TSDB repository handle. The interface will free the handle too, so upper
* @param repo the TSDB repository handle. The interface will free the handle too, so upper
* layer do NOT need to free the repo handle again.
* @param error the error number to set when failure occurs
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t tsdbDropRepo(tsdb_repo_t *pRepo, int32_t *error);
int32_t tsdbDropRepo(tsdb_repo_t *repo);
/**
* Open an existing TSDB storage repository
* @param tsdbDir the existing TSDB root directory
* @param error the error number to set when failure occurs
*
* @return a TSDB repository handle on success, NULL for failure and the error number is set
*/
tsdb_repo_t *tsdbOpenRepo(char *tsdbDir, int32_t *error);
tsdb_repo_t *tsdbOpenRepo(char *tsdbDir);
/**
* Close a TSDB repository. Only free memory resources, and keep the files.
* @param pRepo the opened TSDB repository handle. The interface will free the handle too, so upper
* @param repo the opened TSDB repository handle. The interface will free the handle too, so upper
* layer do NOT need to free the repo handle again.
* @param error the error number to set when failure occurs
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t tsdbCloseRepo(tsdb_repo_t *pRepo, int32_t *error);
int32_t tsdbCloseRepo(tsdb_repo_t *repo);
/**
* Change the configuration of a repository
* @param pCfg the repository configuration, the upper layer should free the pointer
* @param error the error number to set when failure occurs
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t tsdbConfigRepo(STSDBCfg *pCfg, int32_t *error);
int32_t tsdbConfigRepo(tsdb_repo_t repo, STSDBCfg *pCfg);
/**
* Get the TSDB repository information, including some statistics
......@@ -163,20 +159,19 @@ int32_t tsdbConfigRepo(STSDBCfg *pCfg, int32_t *error);
* @return a info struct handle on success, NULL for failure and the error number is set. The upper
* layers should free the info handle themselves or memory leak will occur
*/
STSDBRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo, int32_t *error);
STSDBRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo);
// -- For table manipulation
/**
* Create/Alter a table in a TSDB repository handle
* @param pRepo the TSDB repository handle
* @param repo the TSDB repository handle
* @param pCfg the table configurations, the upper layer should free the pointer
* @param error the error number to set when failure occurs
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t tsdbCreateTable(tsdb_repo_t *pRepo, STableCfg *pCfg, int32_t *error);
int32_t tsdbAlterTable(tsdb_repo_t *pRepo, STableCfg *pCfg, int32_t *error);
int32_t tsdbCreateTable(tsdb_repo_t *repo, STableCfg *pCfg);
int32_t tsdbAlterTable(tsdb_repo_t *repo, STableCfg *pCfg);
/**
* Drop a table in a repository and free all the resources it takes
......
......@@ -36,5 +36,6 @@ typedef struct STSDBCache {
#define TSDB_PREV_CACHE_BLOCK(pBlock) ((pBlock)->prev)
SCacheHandle *tsdbCreateCache(int32_t numOfBlocks);
int32_t tsdbFreeCache(SCacheHandle *pHandle);
#endif // _TD_TSDBCACHE_H_
......@@ -29,12 +29,12 @@ typedef struct {
SFileInfo fInfo;
} SFILE;
typedef struct {
int64_t offset;
int64_t skey;
int64_t ekey;
int16_t numOfBlocks;
} SDataBlock;
// typedef struct {
// int64_t offset;
// int64_t skey;
// int64_t ekey;
// int16_t numOfBlocks;
// } SDataBlock;
char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type);
......
......@@ -84,9 +84,10 @@ SSchema *tsdbGetTableSchema(STable *pTable);
#define TSDB_GET_TABLE_OF_NAME(pHandle, name) /* TODO */
// Create a new meta handle with configuration
SMetaHandle * tsdbCreateMetaHandle (int32_t numOfTables);
SMetaHandle * tsdbCreateMetaHandle (int32_t numOfTables);
int32_t tsdbFreeMetaHandle(SMetaHandle *pMetaHandle);
// Recover the meta handle from the file
SMetaHandle * tsdbOpenMetaHandle(int fd);
SMetaHandle * tsdbOpenMetaHandle(char *tsdbDir);
int32_t tsdbCreateMeterImpl(SMetaHandle *pHandle, STableCfg *pCfg);
int32_t tsdbCreateTableImpl(SMetaHandle *pHandle, STableCfg *pCfg);
......@@ -13,7 +13,13 @@
#include "tsdbCache.h"
#include "tsdbMeta.h"
typedef struct STSDBRepo {
enum {
TSDB_REPO_STATE_ACTIVE,
TSDB_REPO_STATE_CLOSED,
TSDB_REPO_STATE_CONFIGURING
};
typedef struct _tsdb_repo {
// TSDB configuration
STSDBCfg *pCfg;
......@@ -31,10 +37,14 @@ typedef struct STSDBRepo {
pthread_mutex_t tsdbMutex;
int8_t state;
} STSDBRepo;
#define TSDB_GET_TABLE_BY_ID(pRepo, sid) (((STSDBRepo *)pRepo)->pTableList)[sid]
#define TSDB_GET_TABLE_BY_NAME(pRepo, name)
#define TSDB_IS_REPO_ACTIVE(pRepo) ((pRepo)->state == TSDB_REPO_STATE_ACTIVE)
#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) {
......@@ -47,11 +57,18 @@ static int32_t tsdbCheckCfg(STSDBCfg *pCfg) {
return 0;
}
tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) {
int32_t err = 0;
err = tsdbCheckCfg(pCfg);
if (err != 0) {
// TODO: deal with the error here
static int32_t tsdbCreateFiles(STSDBRepo *pRepo) {
// TODO
}
static int32_t tsdbClearFiles(STSDBRepo *pRepo) {
// TODO
}
tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg) {
// Check the configuration
if (tsdbCheckCfg(pCfg) < 0) {
return NULL;
}
......@@ -73,74 +90,108 @@ tsdb_repo_t *tsdbCreateRepo(STSDBCfg *pCfg, int32_t *error) {
pRepo->pCacheHandle = tsdbCreateCache(5);
if (pRepo->pCacheHandle == NULL) {
// TODO: free the object and return error
tsdbFreeMetaHandle(pRepo->pCacheHandle);
free(pRepo);
return NULL;
}
// Create the Meta data file and data directory
// Set configuration
pRepo->pCfg = pCfg;
char *pTsdbMetaFName = tsdbGetFileName(pCfg->rootDir, "tsdb", TSDB_FILE_TYPE_META);
// int fd = open(pTsdbMetaFName, )
// if (open)
// Create the Meta data file and data directory
if (tsdbCreateFiles(pRepo) < 0) {
// Failed to create and save files
tsdbFreeMetaHandle(pRepo->pCacheHandle);
free(pRepo);
return NULL;
}
pRepo->state = TSDB_REPO_STATE_ACTIVE;
return (tsdb_repo_t *)pRepo;
}
int32_t tsdbDropRepo(tsdb_repo_t *pRepo, int32_t *error) {
STSDBRepo *pTRepo = (STSDBRepo *)pRepo;
int32_t tsdbDropRepo(tsdb_repo_t *repo) {
STSDBRepo *pRepo = (STSDBRepo *)repo;
pRepo->state = TSDB_REPO_STATE_CLOSED;
// TODO: Close the metaHandle
// Free the metaHandle
tsdbFreeMetaHandle(pRepo->pMetaHandle);
// TODO: Close the cache
// Free the cache
tsdbFreeCache(pRepo->pCacheHandle);
tsdbClearFiles(pRepo);
return 0;
}
tsdb_repo_t *tsdbOpenRepo(char *tsdbDir, int32_t *error) {
tsdb_repo_t *tsdbOpenRepo(char *tsdbDir) {
if (access(tsdbDir, F_OK|W_OK|R_OK) < 0) {
return NULL;
}
STSDBRepo *pRepo = (STSDBRepo *)malloc(sizeof(STSDBRepo));
if (pRepo == NULL) {
return NULL;
}
// TODO: Initialize configuration from the file
{
// TODO: Initialize the pMetaHandle
}
pRepo->pMetaHandle = tsdbOpenMetaHandle();
if (pRepo->pMetaHandle == NULL) {
free(pRepo);
return NULL;
}
{
// TODO: initialize the pCacheHandle
}
pRepo->pCacheHandle = tsdbCreateCache(5);
if (pRepo->pCacheHandle == NULL) {
// TODO: deal with error
return NULL;
}
pRepo->state = TSDB_REPO_STATE_ACTIVE;
return (tsdb_repo_t *)pRepo;
}
int32_t tsdbCloseRepo(tsdb_repo_t *pRepo, int32_t *error) {
STSDBRepo *pTRepo = (STSDBRepo *)pRepo;
static int32_t tsdbFlushCache(STSDBRepo *pRepo) {
// TODO
}
int32_t tsdbCloseRepo(tsdb_repo_t *repo) {
STSDBRepo *pRepo = (STSDBRepo *)repo;
tsdbFlushCache(pRepo);
pRepo->state = TSDB_REPO_STATE_CLOSED;
tsdbFreeMetaHandle(pRepo->pMetaHandle);
tsdbFreeCache(pRepo->pMetaHandle);
return 0;
}
int32_t tsdbConfigRepo(STSDBCfg *pCfg, int32_t *error) {
int32_t tsdbConfigRepo(tsdb_repo_t *repo, STSDBCfg *pCfg) {
STSDBRepo *pRepo = (STSDBRepo *)repo;
pRepo->pCfg = pCfg;
// TODO
return 0;
}
STSDBRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo, int32_t *error) {
STSDBRepoInfo *tsdbGetStatus(tsdb_repo_t *pRepo) {
// TODO
}
int32_t tsdbCreateTable(tsdb_repo_t *pRepo, STableCfg *pCfg, int32_t *error) {
// TODO
int32_t tsdbCreateTable(tsdb_repo_t *repo, STableCfg *pCfg) {
STSDBRepo *pRepo = (STSDBRepo *)repo;
return tsdbCreateTableImpl(pRepo->pMetaHandle, pCfg);
}
int32_t tsdbAlterTable(tsdb_repo_t *pRepo, STableCfg *pCfg, int32_t *error) {
int32_t tsdbAlterTable(tsdb_repo_t *pRepo, STableCfg *pCfg) {
// TODO
}
......
......@@ -12,4 +12,7 @@ SCacheHandle *tsdbCreateCache(int32_t numOfBlocks) {
return pCacheHandle;
}
int32_t tsdbFreeCache(SCacheHandle *pHandle) {
}
\ No newline at end of file
......@@ -29,9 +29,14 @@ SMetaHandle *tsdbCreateMetaHandle(int32_t numOfTables) {
return pMetahandle;
}
int32_t tsdbFreeMetaHandle(SMetaHandle *pMetaHandle) {
// TODO
}
static int32_t tsdbCheckTableCfg(STableCfg *pCfg) { return 0; }
int32_t tsdbCreateMeterImpl(SMetaHandle *pHandle, STableCfg *pCfg) {
int32_t tsdbCreateTableImpl(SMetaHandle *pHandle, STableCfg *pCfg) {
if (tsdbCheckTableCfg(pCfg) < 0) {
return -1;
}
......@@ -46,4 +51,15 @@ int32_t tsdbCreateMeterImpl(SMetaHandle *pHandle, STableCfg *pCfg) {
// TODO: add name to it
return 0;
}
SMetaHandle * tsdbOpenMetaHandle(char *tsdbDir) {
// Open meta file for reading
SMetaHandle *pHandle = (SMetaHandle *)malloc(sizeof(SMetaHandle));
if (pHandle == NULL) {
return NULL;
}
return pHandle;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册