提交 a92a1f12 编写于 作者: H hzcheng

more

上级 e534caef
......@@ -50,6 +50,8 @@ typedef char * SDataCols;
#define TD_DATAROW_LEN(pDataRow) (*(int32_t *)(pDataRow))
#define TD_DATAROW_DATA(pDataRow) ((pDataRow) + sizeof(int32_t))
SDataRow tdSDataRowDup(SDataRow rdata);
// ---- operation on SDataRows
#define TD_DATAROWS_LEN(pDataRows) (*(int32_t *)(pDataRows))
#define TD_DATAROWS_ROWS(pDataRows) (*(int32_t *)(pDataRows + sizeof(int32_t)))
......
......@@ -67,6 +67,7 @@ typedef char *SISchema;
SISchema tdConvertSchemaToInline(SSchema *pSchema);
int32_t tdGetColumnIdxByName(SSchema *pSchema, char *colName);
int32_t tdGetColumnIdxById(SSchema *pSchema, int32_t colId);
SSchema *tdDupSchema(SSchema *pSchema);
// ---- TODO: operations to modify schema
......
......@@ -8,6 +8,7 @@
#include <stdbool.h>
#include <stdint.h>
#include "dataformat.h"
#include "schema.h"
#define TSDB_VERSION_MAJOR 1
......@@ -35,8 +36,11 @@ typedef struct {
char data[];
} SSubmitBlock;
enum { TSDB_PRECISION_MILLI, TSDB_PRECISION_MICRO, TSDB_PRECISION_NANO };
// the TSDB repository configuration
typedef struct {
int8_t precision;
int32_t tsdbId;
int32_t maxTables; // maximum number of tables this repository can have
int32_t daysPerFile; // day per file sharding policy
......@@ -57,19 +61,17 @@ typedef struct STsdbRepoInfo {
// the meter configuration
typedef struct {
char * tableName;
STableId tableId;
char *superTable; // if not NULL, the table is created from a super table, need to make sure the super
// table exists in this TSDB.
int64_t stableUid;
int64_t createdTime;
int32_t numOfCols; // number of columns. For table form super table, not includes the tag schema
SSchema *schema; // If numOfCols == schema_->numOfCols, it is a normal table, stableName = NULL
// If numOfCols < schema->numOfCols, it is a table created from super table
// assert(numOfCols <= schema->numOfCols);
char *tagValues; // NULL if it is normal table
SDataRow tagValues; // NULL if it is normal table
// otherwise, it contains the tag values.
} STableCfg;
......@@ -154,7 +156,7 @@ int32_t tsdbAlterTable(tsdb_repo_t *repo, STableCfg *pCfg);
*
* @return 0 for success, -1 for failure and the error number is set
*/
int32_t tsdbDropTable(tsdb_repo_t *pRepo, STableId tid, int32_t *error);
int32_t tsdbDropTable(tsdb_repo_t *pRepo, STableId tid);
/**
* Get the information of a table in the repository
......@@ -164,7 +166,7 @@ int32_t tsdbDropTable(tsdb_repo_t *pRepo, STableId tid, int32_t *error);
*
* @return a table information handle for success, NULL for failure and the error number is set
*/
STableInfo *tsdbGetTableInfo(tsdb_repo_t *pRepo, STableId tid, int32_t *error);
STableInfo *tsdbGetTableInfo(tsdb_repo_t *pRepo, STableId tid);
// -- FOR INSERT DATA
/**
......@@ -176,7 +178,7 @@ STableInfo *tsdbGetTableInfo(tsdb_repo_t *pRepo, STableId tid, int32_t *error);
*
* @return the number of points inserted, -1 for failure and the error number is set
*/
int32_t tsdbInsertData(tsdb_repo_t *pRepo, STableId tid, char *pData, int32_t *error);
int32_t tsdbInsertData(tsdb_repo_t *pRepo, STableId tid, char *pData);
// -- FOR QUERY TIME SERIES DATA
......
......@@ -4,6 +4,8 @@
#include <pthread.h>
#include "dataformat.h"
// #include "taosdef.h"
// Initially, there are 4 tables
......@@ -16,14 +18,15 @@ typedef enum {
} TSDB_TABLE_TYPE;
typedef struct STable {
int32_t tableId;
int64_t uid;
STableId tableId;
TSDB_TABLE_TYPE type;
int64_t createdTime;
// super table UID
int32_t superTableId;
// super table UID -1 for normal table
int32_t stableUid;
int32_t numOfCols;
// Schema for this table
// For TSDB_SUPER_TABLE, it is the schema including tags
......@@ -34,7 +37,7 @@ typedef struct STable {
// Tag value for this table
// For TSDB_SUPER_TABLE and TSDB_NTABLE, it is NULL
// For TSDB_STABLE, it is the tag value string
char *pTagVal;
SDataRow pTagVal;
// Object content;
// For TSDB_SUPER_TABLE, it is the index of tables created from it
......@@ -45,10 +48,10 @@ typedef struct STable {
} content;
// A handle to deal with event
void *eventHandle;
void *eventHandler;
// A handle to deal with stream
void *streamHandle;
void *streamHandler;
struct STable *next;
......@@ -56,7 +59,6 @@ typedef struct STable {
typedef struct {
int32_t maxTables;
int32_t numOfSuperTables; // Number of super tables (#TSDB_SUPER_TABLE)
STable ** tables; // array of normal tables
STable * stables; // linked list of super tables
void * tableMap; // hash map of uid ==> STable *
......@@ -89,3 +91,5 @@ int32_t tsdbFreeMeta(STsdbMeta *pMeta);
STsdbMeta *tsdbOpenMetaHandle(char *tsdbDir);
int32_t tsdbCreateTableImpl(STsdbMeta *pHandle, STableCfg *pCfg);
int32_t tsdbInsertDataImpl(STsdbMeta *pMeta, STableId tableId, char *pData);
\ No newline at end of file
......@@ -200,13 +200,20 @@ int32_t tsdbAlterTable(tsdb_repo_t *pRepo, STableCfg *pCfg) {
return 0;
}
STableInfo *tsdbGetTableInfo(tsdb_repo_t *pRepo, STableId tid, int32_t *error) {
int32_t tsdbDropTable(tsdb_repo_t *pRepo, STableId tid) {
return 0;
}
STableInfo *tsdbGetTableInfo(tsdb_repo_t *pRepo, STableId tid) {
// TODO
return NULL;
}
int32_t tsdbInsertData(tsdb_repo_t *pRepo, STableId tid, char *pData, int32_t *error) {
// TODO
int32_t tsdbInsertData(tsdb_repo_t *repo, STableId tableId, char *pData) {
STsdbRepo *pRepo = (STsdbRepo *)repo;
tsdbInsertDataImpl(pRepo->tsdbMeta, tableId, pData);
return 0;
}
......
#include <stdlib.h>
// #include "taosdef.h"
#include "hash.h"
#include "tskiplist.h"
#include "tsdb.h"
#include "tsdbMeta.h"
#include "hash.h"
#define TSDB_MIN_TABLES 10
#define TSDB_MAX_TABLES 100000
......@@ -12,6 +13,11 @@
#define IS_VALID_MAX_TABLES(maxTables) (((maxTables) >= TSDB_MIN_TABLES) && ((maxTables) >= TSDB_MAX_TABLES))
static int tsdbFreeTable(STable *pTable);
static int32_t tsdbCheckTableCfg(STableCfg *pCfg);
static STable *tsdbGetTableByUid(int64_t uid);
static int tsdbAddTable(STsdbMeta *pMeta, STable *pTable);
static int tsdbAddTableIntoMap(STsdbMeta *pMeta, STable *pTable);
static int tsdbAddTableIntoIndex(pMeta, pTable);
STsdbMeta *tsdbCreateMeta(int32_t maxTables) {
if (!IS_VALID_MAX_TABLES(maxTables)) return NULL;
......@@ -22,7 +28,6 @@ STsdbMeta *tsdbCreateMeta(int32_t maxTables) {
}
pMeta->maxTables = maxTables;
pMeta->numOfSuperTables = 0;
pMeta->stables = NULL;
pMeta->tables = (STable **)calloc(maxTables, sizeof(STable *));
if (pMeta->tables == NULL) {
......@@ -65,19 +70,52 @@ int32_t tsdbFreeMeta(STsdbMeta *pMeta) {
return 0;
}
static int32_t tsdbCheckTableCfg(STableCfg *pCfg) { return 0; }
int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) {
if (tsdbCheckTableCfg(pCfg) < 0) {
return -1;
}
STable *pSTable = NULL;
if (pCfg->stableUid > 0) { // to create a TSDB_STABLE
pSTable = tsdbGetTableByUid(pCfg->stableUid);
if (pSTable == NULL) { // super table not exists, try to create it
pSTable = (STable *)calloc(1, sizeof(STable));
if (pSTable == NULL) return -1;
pSTable->tableId.uid = pCfg->stableUid;
pSTable->tableId.tid = -1;
pSTable->type = TSDB_SUPER_TABLE;
pSTable->createdTime = pCfg->createdTime; // The created time is not required
pSTable->stableUid = -1;
pSTable->numOfCols = pCfg->numOfCols;
pSTable->pSchema = tdDupSchema(pCfg->schema);
pSTable->content.pIndex = tSkipListCreate(5, 0, 10); // TODO: change here
tsdbAddTable(pMeta, pSTable);
} else {
if (pSTable->type != TSDB_SUPER_TABLE) return NULL;
}
}
STable *pTable = (STable *)malloc(sizeof(STable));
if (pTable == NULL) {
return -1;
}
pMeta->tables[pCfg->tableId.tid] = pTable;
pTable->tableId = pCfg->tableId;
pTable->createdTime = pCfg->createdTime;
if (1 /* */) { // TSDB_STABLE
pTable->type = TSDB_STABLE;
pTable->stableUid = pCfg->stableUid;
pTable->pTagVal = tdSDataRowDup(pCfg->tagValues);
} else { // TSDB_NTABLE
pTable->type = TSDB_NTABLE;
pTable->stableUid = -1;
pTable->pSchema = tdDupSchema(pCfg->schema);
}
pTable->content.pData = tSkipListCreate(5, 0, 10); // TODO: change here
tsdbAddTable(pMeta, pTable);
return 0;
}
......@@ -93,4 +131,52 @@ STsdbMeta *tsdbOpenMetaHandle(char *tsdbDir) {
return pMeta;
}
int32_t tsdbInsertDataImpl(STsdbMeta *pMeta, STableId tableId, char *pData) {
STable *pTable = pMeta->tables[tableId.tid];
if (pTable == NULL) {
// TODO: deal with the error here
return 0;
}
if (pTable->tableId.uid != tableId.uid) {
// TODO: deal with the error here
return 0;
}
return 0;
}
static int tsdbFreeTable(STable *pTable) { return 0; }
static int32_t tsdbCheckTableCfg(STableCfg *pCfg) { return 0; }
static STable *tsdbGetTableByUid(int64_t uid) { return NULL; }
static int tsdbAddTable(STsdbMeta *pMeta, STable *pTable) {
if (pTable->type == TSDB_SUPER_TABLE) {
if (pMeta->stables == NULL) {
pMeta->stables = pTable;
pTable->next = NULL;
} else {
STable *pTemp = pMeta->stables;
pMeta->stables = pTable;
pTable->next = pTemp;
}
} else {
pMeta->tables[pTable->tableId.tid] = pTable;
if (pTable->type == TSDB_STABLE) {
tsdbAddTableIntoIndex(pMeta, pTable);
}
}
return tsdbAddTableIntoMap(pMeta, pTable);
}
static int tsdbAddTableIntoMap(STsdbMeta *pMeta, STable *pTable) {
// TODO: add the table to the map
return 0;
}
static int tsdbAddTableIntoIndex(pMeta, pTable) {
// TODO
return 0;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册