Merge remote-tracking branch 'origin/3.0' into feature/dnode3

This commit is contained in:
Shengliang Guan 2021-12-02 14:41:23 +08:00
commit 7d39592d85
76 changed files with 1661 additions and 451 deletions

View File

@ -45,6 +45,16 @@ if(${BUILD_WITH_ROCKSDB})
add_definitions(-DUSE_ROCKSDB) add_definitions(-DUSE_ROCKSDB)
endif(${BUILD_WITH_ROCKSDB}) endif(${BUILD_WITH_ROCKSDB})
## bdb
if(${BUILD_WITH_BDB})
cat("${CMAKE_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${DEPS_TMP_FILE})
endif(${BUILD_WITH_DBD})
## sqlite
if(${BUILD_WITH_SQLITE})
cat("${CMAKE_SUPPORT_DIR}/sqlite_CMakeLists.txt.in" ${DEPS_TMP_FILE})
endif(${BUILD_WITH_SQLITE})
## lucene ## lucene
if(${BUILD_WITH_LUCENE}) if(${BUILD_WITH_LUCENE})
cat("${CMAKE_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${DEPS_TMP_FILE}) cat("${CMAKE_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${DEPS_TMP_FILE})

View File

@ -0,0 +1,13 @@
# bdb
ExternalProject_Add(bdb
GIT_REPOSITORY https://github.com/berkeleydb/libdb.git
GIT_TAG v5.3.28
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/bdb"
BINARY_DIR "${CMAKE_SOURCE_DIR}/deps/bdb"
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND "./dist/configure"
BUILD_COMMAND "$(MAKE)"
INSTALL_COMMAND ""
TEST_COMMAND ""
)

View File

@ -19,6 +19,18 @@ option(
ON ON
) )
option(
BUILD_WITH_SQLITE
"If build with sqlite"
ON
)
option(
BUILD_WITH_BDB
"If build with BerkleyDB"
ON
)
option( option(
BUILD_WITH_LUCENE BUILD_WITH_LUCENE
"If build with lucene" "If build with lucene"
@ -34,7 +46,7 @@ option(
option( option(
BUILD_DEPENDENCY_TESTS BUILD_DEPENDENCY_TESTS
"If build dependency tests" "If build dependency tests"
OFF ON
) )
option( option(

View File

@ -0,0 +1,13 @@
# sqlite
ExternalProject_Add(sqlite
GIT_REPOSITORY https://github.com/sqlite/sqlite.git
GIT_TAG version-3.36.0
SOURCE_DIR "${CMAKE_SOURCE_DIR}/deps/sqlite"
BINARY_DIR "${CMAKE_SOURCE_DIR}/deps/sqlite"
#BUILD_IN_SOURCE TRUE
CONFIGURE_COMMAND "./configure"
BUILD_COMMAND "$(MAKE)"
INSTALL_COMMAND ""
TEST_COMMAND ""
)

27
deps/CMakeLists.txt vendored
View File

@ -80,6 +80,33 @@ if(${BUILD_WITH_NURAFT})
add_subdirectory(nuraft) add_subdirectory(nuraft)
endif(${BUILD_WITH_NURAFT}) endif(${BUILD_WITH_NURAFT})
# BDB
if(${BUILD_WITH_BDB})
add_library(bdb STATIC IMPORTED)
set_target_properties(bdb PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/bdb/libdb.a"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/bdb"
)
target_link_libraries(bdb
INTERFACE pthread
)
endif(${BUILD_WITH_BDB})
# SQLite
if(${BUILD_WITH_SQLITE})
add_library(sqlite STATIC IMPORTED)
set_target_properties(sqlite PROPERTIES
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.libs/libsqlite3.a"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sqlite"
)
target_link_libraries(sqlite
INTERFACE m
INTERFACE pthread
INTERFACE dl
)
endif(${BUILD_WITH_SQLITE})
# ================================================================================================ # ================================================================================================
# DEPENDENCY TEST # DEPENDENCY TEST

View File

@ -6,3 +6,13 @@ endif(${BUILD_WITH_ROCKSDB})
if(${BUILD_WITH_LUCENE}) if(${BUILD_WITH_LUCENE})
add_subdirectory(lucene) add_subdirectory(lucene)
endif(${BUILD_WITH_LUCENE}) endif(${BUILD_WITH_LUCENE})
if(${BUILD_WITH_BDB})
add_subdirectory(bdb)
endif(${BUILD_WITH_BDB})
if(${BUILD_WITH_SQLITE})
add_subdirectory(sqlite)
endif(${BUILD_WITH_SQLITE})
add_subdirectory(tdev)

7
deps/test/bdb/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,7 @@
add_executable(bdbTest "")
target_sources(
bdbTest PRIVATE
"bdbTest.c"
)
target_link_libraries(bdbTest bdb)

28
deps/test/bdb/bdbTest.c vendored Normal file
View File

@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include "db.h"
// refer: https://docs.oracle.com/cd/E17076_05/html/gsg/C/BerkeleyDB-Core-C-GSG.pdf
int main(int argc, char const *argv[]) {
DB * db;
int ret;
uint32_t flags;
ret = db_create(&db, NULL, 0);
if (ret != 0) {
exit(1);
}
flags = DB_CREATE;
ret = db->open(db, NULL, "test.db", NULL, DB_BTREE, flags, 0);
if (ret != 0) {
exit(1);
}
db->close(db, 0);
return 0;
}

6
deps/test/sqlite/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,6 @@
add_executable(sqliteTest "")
target_sources(
sqliteTest PRIVATE
"sqliteTest.c"
)
target_link_libraries(sqliteTest sqlite)

84
deps/test/sqlite/sqliteTest.c vendored Normal file
View File

@ -0,0 +1,84 @@
#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"
static void count_table(sqlite3 *db) {
int rc;
char * sql = "select * from t;";
sqlite3_stmt *stmt = NULL;
int nrows = 0;
rc = sqlite3_prepare_v2(db, sql, -1, &stmt, NULL);
while (SQLITE_ROW == sqlite3_step(stmt)) {
nrows++;
}
printf("Number of rows: %d\n", nrows);
}
int main(int argc, char const *argv[]) {
sqlite3 *db;
char * err_msg = 0;
int rc = sqlite3_open("test.db", &db);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
char *sql =
"DROP TABLE IF EXISTS t;"
"CREATE TABLE t(id BIGINT);";
rc = sqlite3_exec(db, sql, 0, 0, &err_msg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error: %s\n", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
return 1;
}
{
// Write a lot of data
int nrows = 1000;
int batch = 100;
char tsql[1024];
int v = 0;
// sqlite3_exec(db, "PRAGMA journal_mode=WAL;", 0, 0, &err_msg);
sqlite3_exec(db, "PRAGMA read_uncommitted=true;", 0, 0, &err_msg);
for (int k = 0; k < nrows / batch; k++) {
sqlite3_exec(db, "begin;", 0, 0, &err_msg);
for (int i = 0; i < batch; i++) {
v++;
sprintf(tsql, "insert into t values (%d)", v);
rc = sqlite3_exec(db, tsql, 0, 0, &err_msg);
if (rc != SQLITE_OK) {
fprintf(stderr, "SQL error: %s\n", err_msg);
sqlite3_free(err_msg);
sqlite3_close(db);
return 1;
}
}
count_table(db);
sqlite3_exec(db, "commit;", 0, 0, &err_msg);
}
}
sqlite3_close(db);
return 0;
}

4
deps/test/tdev/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,4 @@
aux_source_directory(src TDEV_SRC)
add_executable(tdev ${TDEV_SRC})
target_include_directories(tdev PUBLIC inc)

87
deps/test/tdev/src/main.c vendored Normal file
View File

@ -0,0 +1,87 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#define POINTER_SHIFT(ptr, s) ((void *)(((char *)ptr) + (s)))
#define POINTER_DISTANCE(pa, pb) ((char *)(pb) - (char *)(pa))
#define tPutA(buf, val) \
({ \
memcpy(buf, &val, sizeof(val)); \
POINTER_SHIFT(buf, sizeof(val)); \
})
#define tPutB(buf, val) \
({ \
((uint8_t *)buf)[3] = ((val) >> 24) & 0xff; \
((uint8_t *)buf)[2] = ((val) >> 16) & 0xff; \
((uint8_t *)buf)[1] = ((val) >> 8) & 0xff; \
((uint8_t *)buf)[0] = (val)&0xff; \
POINTER_SHIFT(buf, sizeof(val)); \
})
#define tPutC(buf, val) \
({ \
((uint64_t *)buf)[0] = (val); \
POINTER_SHIFT(buf, sizeof(val)); \
})
typedef enum { A, B, C } T;
static void func(T t) {
uint64_t val = 198;
char buf[1024];
void * pBuf = buf;
switch (t) {
case A:
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
pBuf = tPutA(pBuf, val);
if (POINTER_DISTANCE(buf, pBuf) == 1024) {
pBuf = buf;
}
}
break;
case B:
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
pBuf = tPutB(pBuf, val);
if (POINTER_DISTANCE(buf, pBuf) == 1024) {
pBuf = buf;
}
}
break;
case C:
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
pBuf = tPutC(pBuf, val);
if (POINTER_DISTANCE(buf, pBuf) == 1024) {
pBuf = buf;
}
}
break;
default:
break;
}
}
static uint64_t now() {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
}
int main(int argc, char const *argv[]) {
uint64_t t1 = now();
func(A);
uint64_t t2 = now();
printf("A: %ld\n", t2 - t1);
func(B);
uint64_t t3 = now();
printf("B: %ld\n", t3 - t2);
func(C);
uint64_t t4 = now();
printf("C: %ld\n", t4 - t3);
return 0;
}

View File

@ -17,53 +17,108 @@
#define _TD_COMMON_ROW_H_ #define _TD_COMMON_ROW_H_
#include "os.h" #include "os.h"
#include "tbuffer.h"
#include "tdataformat.h"
#include "tdef.h"
#include "tschema.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// types #define TD_UNDECIDED_ROW 0
typedef void * SRow; #define TD_OR_ROW 1
typedef struct SRowBatch SRowBatch; #define TD_KV_ROW 2
typedef struct SRowBuilder SRowBuilder;
typedef struct SRowBatchIter SRowBatchIter;
typedef struct SRowBatchBuilder SRowBatchBuilder;
// SRow typedef struct {
#define ROW_HEADER_SIZE (sizeof(uint8_t) + 2 * sizeof(uint16_t) + sizeof(uint64_t)) // TODO
#define rowType(r) (*(uint8_t *)(r)) // row type } SOrRow;
#define rowLen(r) (*(uint16_t *)POINTER_SHIFT(r, sizeof(uint8_t))) // row length
#define rowSVer(r) \
(*(uint16_t *)POINTER_SHIFT(r, sizeof(uint8_t) + sizeof(uint16_t))) // row schema version, only for SDataRow
#define rowNCols(r) rowSVer(r) // only for SKVRow
#define rowVer(r) (*(uint64_t)POINTER_SHIFT(r, sizeof(uint8_t) + 2 * sizeof(uint16_t))) // row version
#define rowCopy(dest, r) memcpy((dest), r, rowLen(r))
static FORCE_INLINE SRow rowDup(SRow row) { typedef struct {
SRow r = malloc(rowLen(row)); col_id_t cid;
if (r == NULL) { uint32_t offset;
return NULL; } SKvRowIdx;
}
rowCopy(r, row); typedef struct {
uint16_t ncols;
SKvRowIdx cidx[];
} SKvRow;
return r; typedef struct {
} union {
/// union field for encode and decode
uint32_t info;
struct {
/// row type
uint32_t type : 2;
/// row schema version
uint32_t sver : 16;
/// is delete row
uint32_t del : 1;
/// reserved for back compatibility
uint32_t reserve : 13;
};
};
/// row total length
uint32_t len;
/// row version
uint64_t ver;
/// timestamp
TSKEY ts;
/// the inline data, maybe a tuple or a k-v tuple
char data[];
} STSRow;
// SRowBatch typedef struct {
uint32_t nRows;
char rows[];
} STSRowBatch;
// SRowBuilder typedef enum {
SRowBuilder *rowBuilderCreate(); /// ordinary row builder
void rowBuilderDestroy(SRowBuilder *); TD_OR_ROW_BUILDER = 0,
/// kv row builder
TD_KV_ROW_BUILDER,
/// self-determined row builder
TD_SD_ROW_BUILDER
} ERowBbuilderT;
// SRowBatchIter typedef struct {
SRowBatchIter *rowBatchIterCreate(SRowBatch *); /// row builder type
void rowBatchIterDestroy(SRowBatchIter *); ERowBbuilderT type;
const SRow rowBatchIterNext(SRowBatchIter *); /// buffer writer
SBufferWriter bw;
/// target row
STSRow *pRow;
} STSRowBuilder;
// SRowBatchBuilder typedef struct {
SRowBatchBuilder *rowBatchBuilderCreate(); STSchema *pSchema;
void rowBatchBuilderDestroy(SRowBatchBuilder *); STSRow * pRow;
} STSRowReader;
typedef struct {
uint32_t it;
STSRowBatch *pRowBatch;
} STSRowBatchIter;
// STSRowBuilder
#define trbInit(rt, allocator, endian, target, size) \
{ .type = (rt), .bw = tbufInitWriter(allocator, endian), .pRow = (target) }
void trbSetRowInfo(STSRowBuilder *pRB, bool del, uint16_t sver);
void trbSetRowVersion(STSRowBuilder *pRB, uint64_t ver);
void trbSetRowTS(STSRowBuilder *pRB, TSKEY ts);
int trbWriteCol(STSRowBuilder *pRB, void *pData, col_id_t cid);
// STSRowReader
#define tRowReaderInit(schema, row) \
{ .schema = (schema), .row = (row) }
int tRowReaderRead(STSRowReader *pRowReader, col_id_t cid, void *target, uint64_t size);
// STSRowBatchIter
#define tRowBatchIterInit(pRB) \
{ .it = 0, .pRowBatch = (pRB) }
const STSRow *tRowBatchIterNext(STSRowBatchIter *pRowBatchIter);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -16,10 +16,65 @@
#ifndef _TD_COMMON_SCHEMA_H_ #ifndef _TD_COMMON_SCHEMA_H_
#define _TD_COMMON_SCHEMA_H_ #define _TD_COMMON_SCHEMA_H_
#include "os.h"
#include "tarray.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef uint16_t col_id_t;
#if 0
typedef struct STColumn {
/// column name
char *cname;
union {
/// for encode purpose
uint64_t info;
struct {
uint64_t sma : 1;
/// column data type
uint64_t type : 7;
/// column id
uint64_t cid : 16;
/// max bytes of the column
uint64_t bytes : 32;
/// reserved
uint64_t reserve : 8;
};
};
/// comment about the column
char *comment;
} STColumn;
typedef struct STSchema {
/// schema version
uint16_t sver;
/// number of columns
uint16_t ncols;
/// sma attributes
struct {
bool sma;
SArray *smaArray;
};
/// column info
STColumn cols[];
} STSchema;
typedef struct {
uint64_t size;
STSchema *pSchema;
} STShemaBuilder;
#define tSchemaBuilderInit(target, capacity) \
{ .size = (capacity), .pSchema = (target) }
void tSchemaBuilderSetSver(STShemaBuilder *pSchemaBuilder, uint16_t sver);
void tSchemaBuilderSetSMA(bool sma, SArray *smaArray);
int tSchemaBuilderPutColumn(char *cname, bool sma, uint8_t type, col_id_t cid, uint32_t bytes, char *comment);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -13,18 +13,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_VNODE_FILE_SYSTEM_H_ #ifndef _TD_TYPE_H_
#define _TD_VNODE_FILE_SYSTEM_H_ #define _TD_TYPE_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef struct {
} SVnodeFS;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_VNODE_FILE_SYSTEM_H_*/ #endif /*_TD_TYPE_H_*/

View File

@ -1,75 +0,0 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_META_IMPL_H_
#define _TD_META_IMPL_H_
#include "os.h"
#include "taosmsg.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef uint64_t tb_uid_t;
/* ------------------------ SMetaOptions ------------------------ */
struct SMetaOptions {
size_t lruCacheSize; // LRU cache size
};
/* ------------------------ STbOptions ------------------------ */
#define META_NORMAL_TABLE ((uint8_t)1)
#define META_SUPER_TABLE ((uint8_t)2)
#define META_CHILD_TABLE ((uint8_t)3)
typedef struct {
} SSMAOptions;
// super table options
typedef struct {
tb_uid_t uid;
STSchema* pSchema;
STSchema* pTagSchema;
} SSTbOptions;
// child table options
typedef struct {
tb_uid_t suid;
SKVRow tags;
} SCTbOptions;
// normal table options
typedef struct {
STSchema* pSchame;
} SNTbOptions;
struct STbOptions {
uint8_t type;
char* name;
uint32_t ttl; // time to live in (SECONDS)
SSMAOptions bsma; // Block-wise sma
union {
SSTbOptions stbOptions;
SNTbOptions ntbOptions;
SCTbOptions ctbOptions;
};
};
#ifdef __cplusplus
}
#endif
#endif /*_TD_META_IMPL_H_*/

View File

@ -16,36 +16,96 @@
#ifndef _TD_META_H_ #ifndef _TD_META_H_
#define _TD_META_H_ #define _TD_META_H_
#include "impl/metaImpl.h" #include "os.h"
#include "trow.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// Types exported // Types exported
typedef uint64_t tb_uid_t;
typedef struct SMeta SMeta; typedef struct SMeta SMeta;
typedef struct SMetaOptions SMetaOptions;
typedef struct STbOptions STbOptions; #define META_SUPER_TABLE 0
#define META_CHILD_TABLE 1
#define META_NORMAL_TABLE 2
typedef struct SMetaCfg {
/// LRU cache size
uint64_t lruSize;
} SMetaCfg;
typedef struct STbCfg {
/// name of the table
char *name;
/// time to live of the table
uint32_t ttl;
/// keep time of this table
uint32_t keep;
/// type of table
uint8_t type;
union {
/// super table configurations
struct {
/// super table UID
tb_uid_t suid;
/// row schema
STSchema *pSchema;
/// tag schema
STSchema *pTagSchema;
} stbCfg;
/// normal table configuration
struct {
/// row schema
STSchema *pSchema;
} ntbCfg;
/// child table configuration
struct {
/// super table UID
tb_uid_t suid;
SKVRow pTag;
} ctbCfg;
};
} STbCfg;
// SMeta operations // SMeta operations
SMeta *metaOpen(const char *path, const SMetaOptions *pOptions); SMeta *metaOpen(const char *path, const SMetaCfg *pOptions);
void metaClose(SMeta *pMeta); void metaClose(SMeta *pMeta);
void metaRemove(const char *path); void metaRemove(const char *path);
int metaCreateTable(SMeta *pMeta, const STbOptions *pTbOptions); int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg);
int metaDropTable(SMeta *pMeta, tb_uid_t uid); int metaDropTable(SMeta *pMeta, tb_uid_t uid);
int metaCommit(SMeta *pMeta); int metaCommit(SMeta *pMeta);
// Options // Options
void metaOptionsInit(SMetaOptions *pOptions); void metaOptionsInit(SMetaCfg *pOptions);
void metaOptionsClear(SMetaOptions *pOptions); void metaOptionsClear(SMetaCfg *pOptions);
// STableOpts // STbCfg
#define META_TABLE_OPTS_DECLARE(name) STableOpts name = {0} #define META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \
void metaNormalTableOptsInit(STbOptions *pTbOptions, const char *name, const STSchema *pSchema); { \
void metaSuperTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t uid, const STSchema *pSchema, .name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_SUPER_TABLE, .stbCfg = { \
const STSchema *pTagSchema); .suid = (SUID), \
void metaChildTableOptsInit(STbOptions *pTbOptions, const char *name, tb_uid_t suid, const SKVRow tags); .pSchema = (PSCHEMA), \
void metaTableOptsClear(STbOptions *pTbOptions); .pTagSchema = (PTAGSCHEMA) \
} \
}
#define META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) \
{ \
.name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_CHILD_TABLE, .ctbCfg = {.suid = (SUID), .pTag = PTAG } \
}
#define META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) \
{ \
.name = (NAME), .ttl = (TTL), .keep = (KEEP), .type = META_NORMAL_TABLE, .ntbCfg = {.pSchema = (PSCHEMA) } \
}
#define META_CLEAR_TB_CFG(pTbCfg)
int metaEncodeTbCfg(void **pBuf, STbCfg *pTbCfg);
void *metaDecodeTbCfg(void *pBuf, STbCfg **pTbCfg);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -161,9 +161,9 @@ typedef struct TqLogReader {
int64_t (*logGetLastVer)(void* logHandle); int64_t (*logGetLastVer)(void* logHandle);
} TqLogReader; } TqLogReader;
typedef struct TqConfig { typedef struct STqCfg {
// TODO // TODO
} TqConfig; } STqCfg;
typedef struct TqMemRef { typedef struct TqMemRef {
SMemAllocatorFactory *pAlloctorFactory; SMemAllocatorFactory *pAlloctorFactory;
@ -256,14 +256,14 @@ typedef struct STQ {
// the collection of group handle // the collection of group handle
// the handle of kvstore // the handle of kvstore
char* path; char* path;
TqConfig* tqConfig; STqCfg* tqConfig;
TqLogReader* tqLogReader; TqLogReader* tqLogReader;
TqMemRef tqMemRef; TqMemRef tqMemRef;
TqMetaStore* tqMeta; TqMetaStore* tqMeta;
} STQ; } STQ;
// open in each vnode // open in each vnode
STQ* tqOpen(const char* path, TqConfig* tqConfig, TqLogReader* tqLogReader, SMemAllocatorFactory *allocFac); STQ* tqOpen(const char* path, STqCfg* tqConfig, TqLogReader* tqLogReader, SMemAllocatorFactory *allocFac);
void tqDestroy(STQ*); void tqDestroy(STQ*);
// void* will be replace by a msg type // void* will be replace by a msg type

View File

@ -22,21 +22,25 @@ extern "C" {
// TYPES EXPOSED // TYPES EXPOSED
typedef struct STsdb STsdb; typedef struct STsdb STsdb;
typedef struct STsdbOptions STsdbOptions; typedef struct STsdbCfg STsdbCfg;
typedef struct STsdbMemAllocator STsdbMemAllocator; typedef struct STsdbMemAllocator STsdbMemAllocator;
// STsdb // STsdb
STsdb *tsdbOpen(const char *path, const STsdbOptions *); STsdb *tsdbOpen(const char *path, const STsdbCfg *);
void tsdbClose(STsdb *); void tsdbClose(STsdb *);
void tsdbRemove(const char *path); void tsdbRemove(const char *path);
int tsdbInsertData(STsdb *pTsdb, void *pData, int len);
// STsdbOptions // STsdbCfg
int tsdbOptionsInit(STsdbOptions *); int tsdbOptionsInit(STsdbCfg *);
void tsdbOptionsClear(STsdbOptions *); void tsdbOptionsClear(STsdbCfg *);
/* ------------------------ STRUCT DEFINITIONS ------------------------ */ /* ------------------------ STRUCT DEFINITIONS ------------------------ */
struct STsdbOptions { struct STsdbCfg {
uint64_t lruCacheSize; uint64_t lruCacheSize;
uint32_t keep0;
uint32_t keep1;
uint32_t keep2;
/* TODO */ /* TODO */
}; };

View File

@ -23,6 +23,7 @@
#include "tarray.h" #include "tarray.h"
#include "tq.h" #include "tq.h"
#include "tsdb.h" #include "tsdb.h"
#include "wal.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -30,17 +31,59 @@ extern "C" {
/* ------------------------ TYPES EXPOSED ------------------------ */ /* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SVnode SVnode; typedef struct SVnode SVnode;
typedef struct SVnodeOptions SVnodeOptions; typedef struct SVnodeCfg {
/** vnode buffer pool options */
struct {
/** write buffer size */
uint64_t wsize;
/** use heap allocator or arena allocator */
bool isHeapAllocator;
};
/** time to live of tables in this vnode */
uint32_t ttl;
/** data to keep in this vnode */
uint32_t keep;
/** if TS data is eventually consistency */
bool isWeak;
/** TSDB config */
STsdbCfg tsdbCfg;
/** META config */
SMetaCfg metaCfg;
/** TQ config */
STqCfg tqCfg;
/** WAL config */
SWalCfg walCfg;
} SVnodeCfg;
/* ------------------------ SVnode ------------------------ */ /* ------------------------ SVnode ------------------------ */
/**
* @brief Initialize the vnode module
*
* @return int 0 for success and -1 for failure
*/
int vnodeInit();
/**
* @brief clear a vnode
*
*/
void vnodeClear();
/** /**
* @brief Open a VNODE. * @brief Open a VNODE.
* *
* @param path path of the vnode * @param path path of the vnode
* @param pVnodeOptions options of the vnode * @param pVnodeCfg options of the vnode
* @return SVnode* The vnode object * @return SVnode* The vnode object
*/ */
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions); SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg);
/** /**
* @brief Close a VNODE * @brief Close a VNODE
@ -85,61 +128,55 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
*/ */
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
/* ------------------------ SVnodeOptions ------------------------ */ /* ------------------------ SVnodeCfg ------------------------ */
/** /**
* @brief Initialize VNODE options. * @brief Initialize VNODE options.
* *
* @param pOptions The options object to be initialized. It should not be NULL. * @param pOptions The options object to be initialized. It should not be NULL.
*/ */
void vnodeOptionsInit(SVnodeOptions *pOptions); void vnodeOptionsInit(SVnodeCfg *pOptions);
/** /**
* @brief Clear VNODE options. * @brief Clear VNODE options.
* *
* @param pOptions Options to clear. * @param pOptions Options to clear.
*/ */
void vnodeOptionsClear(SVnodeOptions *pOptions); void vnodeOptionsClear(SVnodeCfg *pOptions);
/* ------------------------ STRUCT DEFINITIONS ------------------------ */ /* ------------------------ REQUESTS ------------------------ */
struct SVnodeOptions { typedef STbCfg SVCreateTableReq;
/** typedef struct {
* @brief write buffer size in BYTES tb_uid_t uid;
* } SVDropTableReq;
*/
uint64_t wsize;
/** typedef struct {
* @brief time to live of tables in this vnode // TODO
* in SECONDS } SVSubmitReq;
*
*/
uint32_t ttl;
/** typedef struct {
* @brief if time-series requests eventual consistency uint64_t ver;
* union {
*/ SVCreateTableReq ctReq;
bool isWeak; SVDropTableReq dtReq;
/**
* @brief if the allocator is heap allcator or arena allocator
*
*/
bool isHeapAllocator;
/**
* @brief TSDB options
*
*/
STsdbOptions tsdbOptions;
/**
* @brief META options
*
*/
SMetaOptions metaOptions;
// STqOptions tqOptions; // TODO
}; };
} SVnodeReq;
typedef struct {
int err;
char info[];
} SVnodeRsp;
#define VNODE_INIT_CREATE_STB_REQ(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \
{ .ver = 0, .ctReq = META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) }
#define VNODE_INIT_CREATE_CTB_REQ(NAME, TTL, KEEP, SUID, PTAG) \
{ .ver = 0, .ctReq = META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) }
#define VNODE_INIT_CREATE_NTB_REQ(NAME, TTL, KEEP, SUID, PSCHEMA) \
{ .ver = 0, .ctReq = META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) }
int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type);
void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type);
/* ------------------------ FOR COMPILE ------------------------ */ /* ------------------------ FOR COMPILE ------------------------ */
@ -148,27 +185,27 @@ struct SVnodeOptions {
#include "taosmsg.h" #include "taosmsg.h"
#include "trpc.h" #include "trpc.h"
typedef struct { // typedef struct {
char db[TSDB_FULL_DB_NAME_LEN]; // char db[TSDB_FULL_DB_NAME_LEN];
int32_t cacheBlockSize; // MB // int32_t cacheBlockSize; // MB
int32_t totalBlocks; // int32_t totalBlocks;
int32_t daysPerFile; // int32_t daysPerFile;
int32_t daysToKeep0; // int32_t daysToKeep0;
int32_t daysToKeep1; // int32_t daysToKeep1;
int32_t daysToKeep2; // int32_t daysToKeep2;
int32_t minRowsPerFileBlock; // int32_t minRowsPerFileBlock;
int32_t maxRowsPerFileBlock; // int32_t maxRowsPerFileBlock;
int8_t precision; // time resolution // int8_t precision; // time resolution
int8_t compression; // int8_t compression;
int8_t cacheLastRow; // int8_t cacheLastRow;
int8_t update; // int8_t update;
int8_t quorum; // int8_t quorum;
int8_t replica; // int8_t replica;
int8_t selfIndex; // int8_t selfIndex;
int8_t walLevel; // int8_t walLevel;
int32_t fsyncPeriod; // millisecond // int32_t fsyncPeriod; // millisecond
SReplica replicas[TSDB_MAX_REPLICA]; // SReplica replicas[TSDB_MAX_REPLICA];
} SVnodeCfg; // } SVnodeCfg;
typedef enum { typedef enum {
VN_MSG_TYPE_WRITE = 1, VN_MSG_TYPE_WRITE = 1,

View File

@ -23,9 +23,9 @@ extern "C" {
#endif #endif
typedef struct SMemAllocator SMemAllocator; typedef struct SMemAllocator SMemAllocator;
typedef struct SMemAllocatorFactory SMemAllocatorFactory;
struct SMemAllocator { struct SMemAllocator {
char name[16];
void *impl; void *impl;
void *(*malloc)(SMemAllocator *, uint64_t size); void *(*malloc)(SMemAllocator *, uint64_t size);
void *(*calloc)(SMemAllocator *, uint64_t nmemb, uint64_t size); void *(*calloc)(SMemAllocator *, uint64_t nmemb, uint64_t size);
@ -34,11 +34,11 @@ struct SMemAllocator {
uint64_t (*usage)(SMemAllocator *); uint64_t (*usage)(SMemAllocator *);
}; };
typedef struct { struct SMemAllocatorFactory {
void *impl; void *impl;
SMemAllocator *(*create)(); SMemAllocator *(*create)(SMemAllocatorFactory *);
void (*destroy)(SMemAllocator *); void (*destroy)(SMemAllocatorFactory *, SMemAllocator *);
} SMemAllocatorFactory; };
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -15,75 +15,21 @@
#include "trow.h" #include "trow.h"
/* ------------ Structures ---------- */ #if 0
struct SRowBatch { void trbSetRowInfo(SRowBuilder *pRB, bool del, uint16_t sver) {
int32_t compress : 1; // if batch row is compressed
int32_t nrows : 31; // number of rows
int32_t tlen; // total length (including `nrows` and `tlen`)
char rows[];
};
struct SRowBuilder {
// TODO // TODO
}; }
struct SRowBatchIter { void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver) {
int32_t counter; // row counter
SRowBatch *rb; // row batch to iter
SRow nrow; // next row
};
struct SRowBatchBuilder {
// TODO // TODO
}; }
/* ------------ Methods ---------- */ void trbSetRowTS(SRowBuilder *pRB, TSKEY ts) {
// SRowBuilder
SRowBuilder *rowBuilderCreate() {
SRowBuilder *pRowBuilder = NULL;
// TODO // TODO
return pRowBuilder;
} }
void rowBuilderDestroy(SRowBuilder *pRowBuilder) { int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) {
if (pRowBuilder) { // TODO
free(pRowBuilder); return 0;
} }
} #endif
// SRowBatchIter
SRowBatchIter *rowBatchIterCreate(SRowBatch *pRowBatch) {
SRowBatchIter *pRowBatchIter = (SRowBatchIter *)malloc(sizeof(*pRowBatchIter));
if (pRowBatchIter == NULL) {
return NULL;
}
pRowBatchIter->counter = 0;
pRowBatchIter->rb = pRowBatch;
pRowBatchIter->nrow = pRowBatch->rows;
return pRowBatchIter;
};
void rowBatchIterDestroy(SRowBatchIter *pRowBatchIter) {
if (pRowBatchIter) {
free(pRowBatchIter);
}
}
const SRow rowBatchIterNext(SRowBatchIter *pRowBatchIter) {
SRow r = NULL;
if (pRowBatchIter->counter < pRowBatchIter->rb->nrows) {
r = pRowBatchIter->nrow;
pRowBatchIter->counter += 1;
pRowBatchIter->nrow = (SRow)POINTER_SHIFT(r, rowLen(r));
}
return r;
}
// SRowBatchBuilder
SRowBatchBuilder *rowBatchBuilderCreate();
void rowBatchBuilderDestroy(SRowBatchBuilder *);

View File

@ -0,0 +1,23 @@
#include <gtest/gtest.h>
#include "trow.h"
TEST(td_row_test, build_row_to_target) {
#if 0
char dst[1024];
SRow* pRow = (SRow*)dst;
int ncols = 10;
col_id_t cid;
void* pData;
SRowBuilder rb = trbInit(TD_OR_ROW_BUILDER, NULL, 0, pRow, 1024);
trbSetRowInfo(&rb, false, 0);
trbSetRowTS(&rb, 1637550210000);
for (int c = 0; c < ncols; c++) {
cid = c;
if (trbWriteCol(&rb, pData, cid) < 0) {
// TODO
}
}
#endif
}

View File

@ -0,0 +1,6 @@
#include <gtest/gtest.h>
#include "tschema.h"
TEST(td_schema_test, build_schema_test) {
}

14
source/common/type/type.c Normal file
View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -527,6 +527,7 @@ static int32_t dndParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg
SCreateVnodeMsg *pCreate = rpcMsg->pCont; SCreateVnodeMsg *pCreate = rpcMsg->pCont;
*vgId = htonl(pCreate->vgId); *vgId = htonl(pCreate->vgId);
#if 0
tstrncpy(pCfg->db, pCreate->db, TSDB_FULL_DB_NAME_LEN); tstrncpy(pCfg->db, pCreate->db, TSDB_FULL_DB_NAME_LEN);
pCfg->cacheBlockSize = htonl(pCreate->cacheBlockSize); pCfg->cacheBlockSize = htonl(pCreate->cacheBlockSize);
pCfg->totalBlocks = htonl(pCreate->totalBlocks); pCfg->totalBlocks = htonl(pCreate->totalBlocks);
@ -549,6 +550,7 @@ static int32_t dndParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg
pCfg->replicas[i].port = htons(pCreate->replicas[i].port); pCfg->replicas[i].port = htons(pCreate->replicas[i].port);
tstrncpy(pCfg->replicas[i].fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN); tstrncpy(pCfg->replicas[i].fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN);
} }
#endif
return 0; return 0;
} }

View File

@ -27,6 +27,7 @@ typedef struct SVBufPool SVBufPool;
int vnodeOpenBufPool(SVnode *pVnode); int vnodeOpenBufPool(SVnode *pVnode);
void vnodeCloseBufPool(SVnode *pVnode); void vnodeCloseBufPool(SVnode *pVnode);
void *vnodeMalloc(SVnode *pVnode, uint64_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_VNODE_OPTIONS_H_ #ifndef _TD_VNODE_CFG_H_
#define _TD_VNODE_OPTIONS_H_ #define _TD_VNODE_CFG_H_
#include "vnode.h" #include "vnode.h"
@ -22,13 +22,13 @@
extern "C" { extern "C" {
#endif #endif
extern const SVnodeOptions defaultVnodeOptions; extern const SVnodeCfg defaultVnodeOptions;
int vnodeValidateOptions(const SVnodeOptions *); int vnodeValidateOptions(const SVnodeCfg *);
void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc); void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_VNODE_OPTIONS_H_*/ #endif /*_TD_VNODE_CFG_H_*/

View File

@ -20,12 +20,14 @@
#include "sync.h" #include "sync.h"
#include "tlockfree.h" #include "tlockfree.h"
#include "wal.h" #include "wal.h"
#include "tcoding.h"
#include "vnode.h" #include "vnode.h"
#include "vnodeBufferPool.h" #include "vnodeBufferPool.h"
#include "vnodeCfg.h"
#include "vnodeCommit.h" #include "vnodeCommit.h"
#include "vnodeFileSystem.h" #include "vnodeFS.h"
#include "vnodeOptions.h" #include "vnodeRequest.h"
#include "vnodeStateMgr.h" #include "vnodeStateMgr.h"
#include "vnodeSync.h" #include "vnodeSync.h"
@ -35,7 +37,7 @@ extern "C" {
struct SVnode { struct SVnode {
char* path; char* path;
SVnodeOptions options; SVnodeCfg config;
SVState state; SVState state;
SVBufPool* pBufPool; SVBufPool* pBufPool;
SMeta* pMeta; SMeta* pMeta;

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_VNODE_FS_H_
#define _TD_VNODE_FS_H_
#include "vnode.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
} SDir;
typedef struct {
} SFile;
typedef struct SFS {
void *pImpl;
int (*startEdit)(struct SFS *);
int (*endEdit)(struct SFS *);
} SFS;
typedef struct {
} SVnodeFS;
int vnodeOpenFS(SVnode *pVnode);
void vnodeCloseFS(SVnode *pVnode);
#ifdef __cplusplus
}
#endif
#endif /*_TD_VNODE_FS_H_*/

View File

@ -16,23 +16,15 @@
#ifndef _TD_VNODE_REQUEST_H_ #ifndef _TD_VNODE_REQUEST_H_
#define _TD_VNODE_REQUEST_H_ #define _TD_VNODE_REQUEST_H_
#include "vnode.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef struct SVnodeReq SVnodeReq; // SVDropTableReq
typedef struct SVnodeRsp SVnodeRsp; int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq);
void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq);
typedef enum {
} EVReqT;
struct SVnodeReq {
/* TODO */
};
struct SVnodeRsp {
/* TODO */
};
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -21,6 +21,9 @@ extern "C" {
#endif #endif
typedef struct { typedef struct {
uint64_t processed;
uint64_t committed;
uint64_t applied;
} SVState; } SVState;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -19,9 +19,12 @@
#define VNODE_BUF_POOL_SHARDS 3 #define VNODE_BUF_POOL_SHARDS 3
struct SVBufPool { struct SVBufPool {
// buffer pool impl
SList free; SList free;
SList incycle; SList incycle;
SListNode *inuse; SListNode *inuse;
// MAF for submodules
SMemAllocatorFactory maf;
}; };
typedef enum { typedef enum {
@ -49,6 +52,11 @@ typedef struct {
SVArenaNode node; SVArenaNode node;
} SVArenaAllocator; } SVArenaAllocator;
typedef struct {
SVnode * pVnode;
SListNode *pNode;
} SVMAWrapper;
typedef struct { typedef struct {
T_REF_DECLARE() T_REF_DECLARE()
uint64_t capacity; uint64_t capacity;
@ -61,6 +69,9 @@ typedef struct {
static SListNode * vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type); static SListNode * vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type);
static void vBufPoolFreeNode(SListNode *pNode); static void vBufPoolFreeNode(SListNode *pNode);
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf);
static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma);
static void * vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size);
int vnodeOpenBufPool(SVnode *pVnode) { int vnodeOpenBufPool(SVnode *pVnode) {
uint64_t capacity; uint64_t capacity;
@ -74,8 +85,8 @@ int vnodeOpenBufPool(SVnode *pVnode) {
tdListInit(&(pVnode->pBufPool->free), 0); tdListInit(&(pVnode->pBufPool->free), 0);
tdListInit(&(pVnode->pBufPool->incycle), 0); tdListInit(&(pVnode->pBufPool->incycle), 0);
capacity = pVnode->options.wsize / VNODE_BUF_POOL_SHARDS; capacity = pVnode->config.wsize / VNODE_BUF_POOL_SHARDS;
if (pVnode->options.isHeapAllocator) { if (pVnode->config.isHeapAllocator) {
type = E_V_HEAP_ALLOCATOR; type = E_V_HEAP_ALLOCATOR;
} }
@ -89,6 +100,10 @@ int vnodeOpenBufPool(SVnode *pVnode) {
tdListAppendNode(&(pVnode->pBufPool->free), pNode); tdListAppendNode(&(pVnode->pBufPool->free), pNode);
} }
pVnode->pBufPool->maf.impl = pVnode;
pVnode->pBufPool->maf.create = vBufPoolCreateMA;
pVnode->pBufPool->maf.destroy = vBufPoolDestroyMA;
return 0; return 0;
} }
@ -115,6 +130,24 @@ void vnodeCloseBufPool(SVnode *pVnode) {
} }
} }
void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
void *ptr;
if (pVnode->pBufPool->inuse == NULL) {
SListNode *pNode;
while ((pNode = tdListPopHead(&(pVnode->pBufPool->free))) == NULL) {
// todo
// tsem_wait();
ASSERT(0);
}
pVnode->pBufPool->inuse = pNode;
}
SVMemAllocator *pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data);
return vBufPoolMalloc(pvma, size);
}
/* ------------------------ STATIC METHODS ------------------------ */ /* ------------------------ STATIC METHODS ------------------------ */
static void vArenaAllocatorInit(SVArenaAllocator *pvaa, uint64_t capacity, uint64_t ssize, uint64_t lsize) { /* TODO */ static void vArenaAllocatorInit(SVArenaAllocator *pvaa, uint64_t capacity, uint64_t ssize, uint64_t lsize) { /* TODO */
pvaa->ssize = ssize; pvaa->ssize = ssize;
@ -186,3 +219,102 @@ static void vBufPoolFreeNode(SListNode *pNode) {
free(pNode); free(pNode);
} }
static void *vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size) {
void *ptr = NULL;
if (pvma->type == E_V_ARENA_ALLOCATOR) {
SVArenaAllocator *pvaa = &(pvma->vaa);
if (POINTER_DISTANCE(pvaa->inuse->ptr, pvaa->inuse->data) + size > pvaa->inuse->size) {
SVArenaNode *pNode = (SVArenaNode *)malloc(sizeof(*pNode) + MAX(size, pvaa->ssize));
if (pNode == NULL) {
// TODO: handle error
return NULL;
}
pNode->prev = pvaa->inuse;
pNode->size = MAX(size, pvaa->ssize);
pNode->ptr = pNode->data;
pvaa->inuse = pNode;
}
ptr = pvaa->inuse->ptr;
pvaa->inuse->ptr = POINTER_SHIFT(ptr, size);
} else if (pvma->type == E_V_HEAP_ALLOCATOR) {
/* TODO */
}
return ptr;
}
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf) {
SVnode * pVnode;
SMemAllocator * pma;
SVMemAllocator *pvma;
SVMAWrapper * pvmaw;
pVnode = (SVnode *)(pmaf->impl);
pma = (SMemAllocator *)calloc(1, sizeof(*pma) + sizeof(SVMAWrapper));
if (pma == NULL) {
// TODO: handle error
return NULL;
}
pvmaw = (SVMAWrapper *)POINTER_SHIFT(pma, sizeof(*pma));
// No allocator used currently
if (pVnode->pBufPool->inuse == NULL) {
while (listNEles(&(pVnode->pBufPool->free)) == 0) {
// TODO: wait until all released ro kill query
// tsem_wait();
ASSERT(0);
}
pVnode->pBufPool->inuse = tdListPopHead(&(pVnode->pBufPool->free));
pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data);
T_REF_INIT_VAL(pvma, 1);
} else {
pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data);
}
T_REF_INC(pvma);
pvmaw->pVnode = pVnode;
pvmaw->pNode = pVnode->pBufPool->inuse;
pma->impl = pvmaw;
pma->malloc = NULL;
pma->calloc = NULL; /* TODO */
pma->realloc = NULL; /* TODO */
pma->free = NULL; /* TODO */
pma->usage = NULL; /* TODO */
return pma;
}
static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma) { /* TODO */
SVnode * pVnode = (SVnode *)(pmaf->impl);
SListNode * pNode = ((SVMAWrapper *)(pma->impl))->pNode;
SVMemAllocator *pvma = (SVMemAllocator *)(pNode->data);
if (T_REF_DEC(pvma) == 0) {
if (pvma->type == E_V_ARENA_ALLOCATOR) {
SVArenaAllocator *pvaa = &(pvma->vaa);
while (pvaa->inuse != &(pvaa->node)) {
SVArenaNode *pNode = pvaa->inuse;
pvaa->inuse = pNode->prev;
/* code */
}
pvaa->inuse->ptr = pvaa->inuse->data;
} else if (pvma->type == E_V_HEAP_ALLOCATOR) {
} else {
ASSERT(0);
}
// Move node from incycle to free
tdListAppendNode(&(pVnode->pBufPool->free), tdListPopNode(&(pVnode->pBufPool->incycle), pNode));
// tsem_post(); todo: sem_post
}
}

View File

@ -15,20 +15,20 @@
#include "vnodeDef.h" #include "vnodeDef.h"
const SVnodeOptions defaultVnodeOptions = {0}; /* TODO */ const SVnodeCfg defaultVnodeOptions = {0}; /* TODO */
void vnodeOptionsInit(SVnodeOptions *pVnodeOptions) { /* TODO */ void vnodeOptionsInit(SVnodeCfg *pVnodeOptions) { /* TODO */
vnodeOptionsCopy(pVnodeOptions, &defaultVnodeOptions); vnodeOptionsCopy(pVnodeOptions, &defaultVnodeOptions);
} }
void vnodeOptionsClear(SVnodeOptions *pVnodeOptions) { /* TODO */ void vnodeOptionsClear(SVnodeCfg *pVnodeOptions) { /* TODO */
} }
int vnodeValidateOptions(const SVnodeOptions *pVnodeOptions) { int vnodeValidateOptions(const SVnodeCfg *pVnodeOptions) {
// TODO // TODO
return 0; return 0;
} }
void vnodeOptionsCopy(SVnodeOptions *pDest, const SVnodeOptions *pSrc) { void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) {
memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeOptions)); memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeCfg));
} }

View File

@ -15,27 +15,40 @@
#include "vnodeDef.h" #include "vnodeDef.h"
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions); static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg);
static void vnodeFree(SVnode *pVnode); static void vnodeFree(SVnode *pVnode);
static int vnodeOpenImpl(SVnode *pVnode); static int vnodeOpenImpl(SVnode *pVnode);
static void vnodeCloseImpl(SVnode *pVnode); static void vnodeCloseImpl(SVnode *pVnode);
SVnode *vnodeOpen(const char *path, const SVnodeOptions *pVnodeOptions) { int vnodeInit() {
// TODO
if (walInit() < 0) {
return -1;
}
return 0;
}
void vnodeClear() {
walCleanUp();
}
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
SVnode *pVnode = NULL; SVnode *pVnode = NULL;
// Set default options // Set default options
if (pVnodeOptions == NULL) { if (pVnodeCfg == NULL) {
pVnodeOptions = &defaultVnodeOptions; pVnodeCfg = &defaultVnodeOptions;
} }
// Validate options // Validate options
if (vnodeValidateOptions(pVnodeOptions) < 0) { if (vnodeValidateOptions(pVnodeCfg) < 0) {
// TODO // TODO
return NULL; return NULL;
} }
// Create the handle // Create the handle
pVnode = vnodeNew(path, pVnodeOptions); pVnode = vnodeNew(path, pVnodeCfg);
if (pVnode == NULL) { if (pVnode == NULL) {
// TODO: handle error // TODO: handle error
return NULL; return NULL;
@ -62,7 +75,7 @@ void vnodeClose(SVnode *pVnode) {
void vnodeDestroy(const char *path) { taosRemoveDir(path); } void vnodeDestroy(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */ /* ------------------------ STATIC METHODS ------------------------ */
static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) { static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg) {
SVnode *pVnode = NULL; SVnode *pVnode = NULL;
pVnode = (SVnode *)calloc(1, sizeof(*pVnode)); pVnode = (SVnode *)calloc(1, sizeof(*pVnode));
@ -72,7 +85,7 @@ static SVnode *vnodeNew(const char *path, const SVnodeOptions *pVnodeOptions) {
} }
pVnode->path = strdup(path); pVnode->path = strdup(path);
vnodeOptionsCopy(&(pVnode->options), pVnodeOptions); vnodeOptionsCopy(&(pVnode->config), pVnodeCfg);
return pVnode; return pVnode;
} }
@ -94,7 +107,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
// Open meta // Open meta
sprintf(dir, "%s/meta", pVnode->path); sprintf(dir, "%s/meta", pVnode->path);
pVnode->pMeta = metaOpen(dir, &(pVnode->options.metaOptions)); pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaCfg));
if (pVnode->pMeta == NULL) { if (pVnode->pMeta == NULL) {
// TODO: handle error // TODO: handle error
return -1; return -1;
@ -102,23 +115,23 @@ static int vnodeOpenImpl(SVnode *pVnode) {
// Open tsdb // Open tsdb
sprintf(dir, "%s/tsdb", pVnode->path); sprintf(dir, "%s/tsdb", pVnode->path);
pVnode->pTsdb = tsdbOpen(dir, &(pVnode->options.tsdbOptions)); pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbCfg));
if (pVnode->pTsdb == NULL) { if (pVnode->pTsdb == NULL) {
// TODO: handle error // TODO: handle error
return -1; return -1;
} }
// TODO: Open TQ // TODO: Open TQ
sprintf(dir, "%s/wal", pVnode->path); sprintf(dir, "%s/tq", pVnode->path);
// pVnode->pTq = tqOpen(dir, NULL /* TODO */); pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, NULL);
// if (pVnode->pTq == NULL) { if (pVnode->pTq == NULL) {
// // TODO: handle error // TODO: handle error
// return -1; return -1;
// } }
// Open WAL // Open WAL
sprintf(dir, "%s/wal", pVnode->path); sprintf(dir, "%s/wal", pVnode->path);
pVnode->pWal = walOpen(dir, NULL /* TODO */); pVnode->pWal = walOpen(dir, &(pVnode->config.walCfg));
if (pVnode->pWal == NULL) { if (pVnode->pWal == NULL) {
// TODO: handle error // TODO: handle error
return -1; return -1;

View File

@ -12,3 +12,104 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "vnodeDef.h"
static int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq);
static void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq);
int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) {
int tsize = 0;
tsize += taosEncodeFixedU64(buf, pReq->ver);
switch (type) {
case TSDB_MSG_TYPE_CREATE_TABLE:
tsize += vnodeBuildCreateTableReq(buf, &(pReq->ctReq));
/* code */
break;
default:
break;
}
/* TODO */
return tsize;
}
void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type) {
buf = taosDecodeFixedU64(buf, &(pReq->ver));
switch (type) {
case TSDB_MSG_TYPE_CREATE_TABLE:
buf = vnodeParseCreateTableReq(buf, &(pReq->ctReq));
break;
default:
break;
}
// TODO
return buf;
}
static int vnodeBuildCreateTableReq(void **buf, const SVCreateTableReq *pReq) {
int tsize = 0;
tsize += taosEncodeString(buf, pReq->name);
tsize += taosEncodeFixedU32(buf, pReq->ttl);
tsize += taosEncodeFixedU32(buf, pReq->keep);
tsize += taosEncodeFixedU8(buf, pReq->type);
switch (pReq->type) {
case META_SUPER_TABLE:
tsize += taosEncodeFixedU64(buf, pReq->stbCfg.suid);
tsize += tdEncodeSchema(buf, pReq->stbCfg.pSchema);
tsize += tdEncodeSchema(buf, pReq->stbCfg.pTagSchema);
break;
case META_CHILD_TABLE:
tsize += taosEncodeFixedU64(buf, pReq->ctbCfg.suid);
tsize += tdEncodeKVRow(buf, pReq->ctbCfg.pTag);
break;
case META_NORMAL_TABLE:
tsize += tdEncodeSchema(buf, pReq->ntbCfg.pSchema);
break;
default:
break;
}
return tsize;
}
static void *vnodeParseCreateTableReq(void *buf, SVCreateTableReq *pReq) {
buf = taosDecodeString(buf, &(pReq->name));
buf = taosDecodeFixedU32(buf, &(pReq->ttl));
buf = taosDecodeFixedU32(buf, &(pReq->keep));
buf = taosDecodeFixedU8(buf, &(pReq->type));
switch (pReq->type) {
case META_SUPER_TABLE:
buf = taosDecodeFixedU64(buf, &(pReq->stbCfg.suid));
buf = tdDecodeSchema(buf, &(pReq->stbCfg.pSchema));
buf = tdDecodeSchema(buf, &(pReq->stbCfg.pTagSchema));
break;
case META_CHILD_TABLE:
buf = taosDecodeFixedU64(buf, &(pReq->ctbCfg.suid));
buf = tdDecodeKVRow(buf, &(pReq->ctbCfg.pTag));
break;
case META_NORMAL_TABLE:
buf = tdDecodeSchema(buf, &(pReq->ntbCfg.pSchema));
break;
default:
break;
}
return buf;
}
int vnodeBuildDropTableReq(void **buf, const SVDropTableReq *pReq) {
// TODO
return 0;
}
void *vnodeParseDropTableReq(void *buf, SVDropTableReq *pReq) {
// TODO
}

View File

@ -16,51 +16,84 @@
#include "vnodeDef.h" #include "vnodeDef.h"
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
/* TODO */ SRpcMsg * pMsg;
return 0; SVnodeReq *pVnodeReq;
for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
// ser request version
void * pBuf = pMsg->pCont;
uint64_t ver = pVnode->state.processed++;
taosEncodeFixedU64(&pBuf, ver);
if (walWrite(pVnode->pWal, ver, pMsg->msgType, pMsg->pCont, pMsg->contLen) < 0) {
// TODO: handle error
}
} }
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { walFsync(pVnode->pWal, false);
#if 0
int reqType; /* TODO */
size_t reqSize; /* TODO */
uint64_t reqVersion = 0; /* TODO */
int code = 0;
// Copy the request to vnode buffer // Apply each request now
void *pReq = mMalloc(pVnode->inuse, reqSize); for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
if (pReq == NULL) { pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
SVnodeReq vReq;
// Apply the request
{
void *ptr = vnodeMalloc(pVnode, pMsg->contLen);
if (ptr == NULL) {
// TODO: handle error // TODO: handle error
} }
memcpy(pReq, pMsg, reqSize); // TODO: copy here need to be extended
memcpy(ptr, pMsg->pCont, pMsg->contLen);
// Push the request to TQ so consumers can consume // todo: change the interface here
tqPushMsg(pVnode->pTq, pReq, 0); uint64_t ver;
taosDecodeFixedU64(pMsg->pCont, &ver);
if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) {
// TODO: handle error
}
// Process the request vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType);
switch (reqType) {
switch (pMsg->msgType) {
case TSDB_MSG_TYPE_CREATE_TABLE: case TSDB_MSG_TYPE_CREATE_TABLE:
code = metaCreateTable(pVnode->pMeta, NULL /* TODO */); if (metaCreateTable(pVnode->pMeta, &(vReq.ctReq)) < 0) {
// TODO: handle error
}
// TODO: maybe need to clear the requst struct
break; break;
case TSDB_MSG_TYPE_DROP_TABLE: case TSDB_MSG_TYPE_DROP_TABLE:
code = metaDropTable(pVnode->pMeta, 0 /* TODO */); if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) {
// TODO: handle error
}
break; break;
case TSDB_MSG_TYPE_SUBMIT: case TSDB_MSG_TYPE_SUBMIT:
/* TODO */ /* code */
break; break;
default: default:
break; break;
} }
pVnode->state.applied = ver;
}
// Check if it needs to commit
if (vnodeShouldCommit(pVnode)) { if (vnodeShouldCommit(pVnode)) {
if (vnodeAsyncCommit(pVnode) < 0) { if (vnodeAsyncCommit(pVnode) < 0) {
// TODO: handle error // TODO: handle error
} }
} }
}
return code; return 0;
#endif }
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
// TODO
return 0; return 0;
} }

View File

@ -3,11 +3,173 @@
#include "vnode.h" #include "vnode.h"
static STSchema *createBasicSchema() {
STSchemaBuilder sb;
STSchema * pSchema = NULL;
tdInitTSchemaBuilder(&sb, 0);
tdAddColToSchema(&sb, TSDB_DATA_TYPE_TIMESTAMP, 0, 0);
for (int i = 1; i < 10; i++) {
tdAddColToSchema(&sb, TSDB_DATA_TYPE_INT, i, 0);
}
pSchema = tdGetSchemaFromBuilder(&sb);
tdDestroyTSchemaBuilder(&sb);
return pSchema;
}
static STSchema *createBasicTagSchema() {
STSchemaBuilder sb;
STSchema * pSchema = NULL;
tdInitTSchemaBuilder(&sb, 0);
tdAddColToSchema(&sb, TSDB_DATA_TYPE_TIMESTAMP, 0, 0);
for (int i = 10; i < 12; i++) {
tdAddColToSchema(&sb, TSDB_DATA_TYPE_BINARY, i, 20);
}
pSchema = tdGetSchemaFromBuilder(&sb);
tdDestroyTSchemaBuilder(&sb);
return pSchema;
}
static SKVRow createBasicTag() {
SKVRowBuilder rb;
SKVRow pTag;
tdInitKVRowBuilder(&rb);
for (int i = 10; i < 12; i++) {
void *pVal = malloc(sizeof(VarDataLenT) + strlen("foo"));
varDataLen(pVal) = strlen("foo");
memcpy(varDataVal(pVal), "foo", strlen("foo"));
tdAddColToKVRow(&rb, i, TSDB_DATA_TYPE_BINARY, pVal);
free(pVal);
}
pTag = tdGetKVRowFromBuilder(&rb);
tdDestroyKVRowBuilder(&rb);
return pTag;
}
#if 0
TEST(vnodeApiTest, test_create_table_encode_and_decode_function) {
tb_uid_t suid = 1638166374163;
STSchema *pSchema = createBasicSchema();
STSchema *pTagSchema = createBasicTagSchema();
char tbname[128] = "st";
char * buffer = new char[1024];
void * pBuf = (void *)buffer;
SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
SVnodeReq decoded_req;
vnodeParseReq(buffer, &decoded_req, TSDB_MSG_TYPE_CREATE_TABLE);
int k = 10;
}
#endif
TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
GTEST_ASSERT_GE(vnodeInit(), 0);
// Create and open a vnode // Create and open a vnode
SVnode *pVnode = vnodeOpen("vnode1", NULL); SVnode *pVnode = vnodeOpen("vnode1", NULL);
ASSERT_NE(pVnode, nullptr); ASSERT_NE(pVnode, nullptr);
tb_uid_t suid = 1638166374163;
{
// Create a super table
STSchema *pSchema = createBasicSchema();
STSchema *pTagSchema = createBasicTagSchema();
char tbname[128] = "st";
SArray * pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *));
SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
int zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs);
pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
pMsg->contLen = zs;
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg));
void *pBuf = pMsg->pCont;
vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
META_CLEAR_TB_CFG(&vCreateSTbReq);
taosArrayPush(pMsgs, &(pMsg));
vnodeProcessWMsgs(pVnode, pMsgs);
free(pMsg);
taosArrayDestroy(pMsgs);
tdFreeSchema(pSchema);
tdFreeSchema(pTagSchema);
}
{
// Create some child tables
int ntables = 100000;
int batch = 10;
for (int i = 0; i < ntables / batch; i++) {
SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *));
for (int j = 0; j < batch; j++) {
SKVRow pTag = createBasicTag();
char tbname[128];
sprintf(tbname, "tb%d", i * batch + j);
SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pTag);
int tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz);
pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
pMsg->contLen = tz;
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg));
void *pBuf = pMsg->pCont;
vnodeBuildReq(&pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
META_CLEAR_TB_CFG(&vCreateCTbReq);
free(pTag);
taosArrayPush(pMsgs, &(pMsg));
}
vnodeProcessWMsgs(pVnode, pMsgs);
for (int j = 0; j < batch; j++) {
SRpcMsg *pMsg = *(SRpcMsg **)taosArrayPop(pMsgs);
free(pMsg);
}
taosArrayDestroy(pMsgs);
// std::cout << "the " << i << "th batch is created" << std::endl;
}
}
// Close the vnode // Close the vnode
vnodeClose(pVnode); vnodeClose(pVnode);
vnodeClear();
}
TEST(vnodeApiTest, DISABLED_vnode_process_create_table) {
STSchema * pSchema = NULL;
STSchema * pTagSchema = NULL;
char stname[15];
SVCreateTableReq pReq = META_INIT_STB_CFG(stname, UINT32_MAX, UINT32_MAX, 0, pSchema, pTagSchema);
int k = 10;
META_CLEAR_TB_CFG(pReq);
} }

View File

@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_META_OPTIONS_H_ #ifndef _TD_META_CFG_H_
#define _TD_META_OPTIONS_H_ #define _TD_META_CFG_H_
#include "meta.h" #include "meta.h"
@ -22,13 +22,13 @@
extern "C" { extern "C" {
#endif #endif
extern const SMetaOptions defaultMetaOptions; extern const SMetaCfg defaultMetaOptions;
int metaValidateOptions(const SMetaOptions *); int metaValidateOptions(const SMetaCfg *);
void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc); void metaOptionsCopy(SMetaCfg *pDest, const SMetaCfg *pSrc);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_META_OPTIONS_H_*/ #endif /*_TD_META_CFG_H_*/

View File

@ -34,7 +34,7 @@ typedef struct {
int metaOpenDB(SMeta *pMeta); int metaOpenDB(SMeta *pMeta);
void metaCloseDB(SMeta *pMeta); void metaCloseDB(SMeta *pMeta);
int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions); int metaSaveTableToDB(SMeta *pMeta, const STbCfg *pTbOptions);
int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid); int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -20,10 +20,10 @@
#include "meta.h" #include "meta.h"
#include "metaCache.h" #include "metaCache.h"
#include "metaCfg.h"
#include "metaDB.h" #include "metaDB.h"
#include "metaIdx.h" #include "metaIdx.h"
#include "metaOptions.h" #include "metaTbCfg.h"
#include "metaTbOptions.h"
#include "metaTbTag.h" #include "metaTbTag.h"
#include "metaTbUid.h" #include "metaTbUid.h"
@ -33,7 +33,7 @@ extern "C" {
struct SMeta { struct SMeta {
char* path; char* path;
SMetaOptions options; SMetaCfg options;
meta_db_t* pDB; meta_db_t* pDB;
meta_index_t* pIdx; meta_index_t* pIdx;
meta_cache_t* pCache; meta_cache_t* pCache;

View File

@ -28,7 +28,7 @@ typedef rocksdb_t meta_index_t;
int metaOpenIdx(SMeta *pMeta); int metaOpenIdx(SMeta *pMeta);
void metaCloseIdx(SMeta *pMeta); void metaCloseIdx(SMeta *pMeta);
int metaSaveTableToIdx(SMeta *pMeta, const STbOptions *pTbOptions); int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions);
int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid); int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_META_TABLE_OPTIONS_H_ #ifndef _TD_META_TABLE_CFG_H_
#define _TD_META_TABLE_OPTIONS_H_ #define _TD_META_TABLE_CFG_H_
#include "meta.h" #include "meta.h"
@ -22,11 +22,15 @@
extern "C" { extern "C" {
#endif #endif
int metaValidateTbOptions(SMeta *pMeta, const STbOptions *); #define META_SUPER_TABLE 0
size_t metaEncodeTbObjFromTbOptions(const STbOptions *, void *pBuf, size_t bsize); #define META_CHILD_TABLE 1
#define META_NORMAL_TABLE 2
int metaValidateTbOptions(SMeta *pMeta, const STbCfg *);
size_t metaEncodeTbObjFromTbOptions(const STbCfg *, void *pBuf, size_t bsize);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_META_TABLE_OPTIONS_H_*/ #endif /*_TD_META_TABLE_CFG_H_*/

View File

@ -18,8 +18,8 @@
int metaOpenCache(SMeta *pMeta) { int metaOpenCache(SMeta *pMeta) {
// TODO // TODO
if (pMeta->options.lruCacheSize) { if (pMeta->options.lruSize) {
pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruCacheSize); pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruSize);
if (pMeta->pCache == NULL) { if (pMeta->pCache == NULL) {
// TODO: handle error // TODO: handle error
return -1; return -1;

View File

@ -15,20 +15,20 @@
#include "metaDef.h" #include "metaDef.h"
const SMetaOptions defaultMetaOptions = {.lruCacheSize = 0}; const SMetaCfg defaultMetaOptions = {.lruSize = 0};
/* ------------------------ EXPOSED METHODS ------------------------ */ /* ------------------------ EXPOSED METHODS ------------------------ */
void metaOptionsInit(SMetaOptions *pMetaOptions) { metaOptionsCopy(pMetaOptions, &defaultMetaOptions); } void metaOptionsInit(SMetaCfg *pMetaOptions) { metaOptionsCopy(pMetaOptions, &defaultMetaOptions); }
void metaOptionsClear(SMetaOptions *pMetaOptions) { void metaOptionsClear(SMetaCfg *pMetaOptions) {
// TODO // TODO
} }
int metaValidateOptions(const SMetaOptions *pMetaOptions) { int metaValidateOptions(const SMetaCfg *pMetaOptions) {
// TODO // TODO
return 0; return 0;
} }
void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); } void metaOptionsCopy(SMetaCfg *pDest, const SMetaCfg *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); }
/* ------------------------ STATIC METHODS ------------------------ */ /* ------------------------ STATIC METHODS ------------------------ */

View File

@ -92,7 +92,7 @@ void metaCloseDB(SMeta *pMeta) {
} }
} }
int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) { int metaSaveTableToDB(SMeta *pMeta, const STbCfg *pTbOptions) {
tb_uid_t uid; tb_uid_t uid;
char * err = NULL; char * err = NULL;
size_t size; size_t size;
@ -102,13 +102,14 @@ int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) {
// Generate a uid for child and normal table // Generate a uid for child and normal table
if (pTbOptions->type == META_SUPER_TABLE) { if (pTbOptions->type == META_SUPER_TABLE) {
uid = pTbOptions->stbOptions.uid; uid = pTbOptions->stbCfg.suid;
} else { } else {
uid = metaGenerateUid(pMeta); uid = metaGenerateUid(pMeta);
} }
// Save tbname -> uid to tbnameDB // Save tbname -> uid to tbnameDB
rocksdb_put(pMeta->pDB->nameDb, wopt, pTbOptions->name, strlen(pTbOptions->name), (char *)(&uid), sizeof(uid), &err); rocksdb_put(pMeta->pDB->nameDb, wopt, pTbOptions->name, strlen(pTbOptions->name), (char *)(&uid), sizeof(uid), &err);
rocksdb_writeoptions_disable_WAL(wopt, 1);
// Save uid -> tb_obj to tbDB // Save uid -> tb_obj to tbDB
size = metaEncodeTbObjFromTbOptions(pTbOptions, pBuf, 1024); size = metaEncodeTbObjFromTbOptions(pTbOptions, pBuf, 1024);
@ -117,22 +118,22 @@ int metaSaveTableToDB(SMeta *pMeta, const STbOptions *pTbOptions) {
switch (pTbOptions->type) { switch (pTbOptions->type) {
case META_NORMAL_TABLE: case META_NORMAL_TABLE:
// save schemaDB // save schemaDB
metaSaveSchemaDB(pMeta, uid, pTbOptions->ntbOptions.pSchame); metaSaveSchemaDB(pMeta, uid, pTbOptions->ntbCfg.pSchema);
break; break;
case META_SUPER_TABLE: case META_SUPER_TABLE:
// save schemaDB // save schemaDB
metaSaveSchemaDB(pMeta, uid, pTbOptions->stbOptions.pSchema); metaSaveSchemaDB(pMeta, uid, pTbOptions->stbCfg.pSchema);
// save mapDB (really need?) // save mapDB (really need?)
rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&uid), sizeof(uid), "", 0, &err); rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&uid), sizeof(uid), "", 0, &err);
break; break;
case META_CHILD_TABLE: case META_CHILD_TABLE:
// save tagDB // save tagDB
rocksdb_put(pMeta->pDB->tagDb, wopt, (char *)(&uid), sizeof(uid), pTbOptions->ctbOptions.tags, rocksdb_put(pMeta->pDB->tagDb, wopt, (char *)(&uid), sizeof(uid), pTbOptions->ctbCfg.pTag,
kvRowLen(pTbOptions->ctbOptions.tags), &err); kvRowLen(pTbOptions->ctbCfg.pTag), &err);
// save mapDB // save mapDB
metaSaveMapDB(pMeta, pTbOptions->ctbOptions.suid, uid); metaSaveMapDB(pMeta, pTbOptions->ctbCfg.suid, uid);
break; break;
default: default:
ASSERT(0); ASSERT(0);
@ -157,6 +158,7 @@ static void metaSaveSchemaDB(SMeta *pMeta, tb_uid_t uid, STSchema *pSchema) {
char * err = NULL; char * err = NULL;
rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create(); rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create();
rocksdb_writeoptions_disable_WAL(wopt, 1);
metaGetSchemaDBKey(key, uid, schemaVersion(pSchema)); metaGetSchemaDBKey(key, uid, schemaVersion(pSchema));
vsize = tdEncodeSchema((void **)(&ppBuf), pSchema); vsize = tdEncodeSchema((void **)(&ppBuf), pSchema);
@ -190,10 +192,12 @@ static int metaSaveMapDB(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid) {
memcpy(POINTER_SHIFT(nval, vlen), (void *)(&uid), sizeof(uid)); memcpy(POINTER_SHIFT(nval, vlen), (void *)(&uid), sizeof(uid));
rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create(); rocksdb_writeoptions_t *wopt = rocksdb_writeoptions_create();
rocksdb_writeoptions_disable_WAL(wopt, 1);
rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&suid), sizeof(suid), nval, vlen + sizeof(uid), &err); rocksdb_put(pMeta->pDB->mapDb, wopt, (char *)(&suid), sizeof(suid), nval, vlen + sizeof(uid), &err);
rocksdb_writeoptions_destroy(wopt); rocksdb_writeoptions_destroy(wopt);
free(nval);
return 0; return 0;
} }

View File

@ -47,7 +47,12 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */
} }
} }
int metaSaveTableToIdx(SMeta *pMeta, const STbOptions *pTbOptions) { int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions) {
// TODO
return 0;
}
int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid) {
// TODO // TODO
return 0; return 0;
} }

View File

@ -15,17 +15,14 @@
#include "tcoding.h" #include "tcoding.h"
#include "meta.h"
#include "metaDB.h"
#include "metaDef.h" #include "metaDef.h"
#include "metaOptions.h"
static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions); static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions);
static void metaFree(SMeta *pMeta); static void metaFree(SMeta *pMeta);
static int metaOpenImpl(SMeta *pMeta); static int metaOpenImpl(SMeta *pMeta);
static void metaCloseImpl(SMeta *pMeta); static void metaCloseImpl(SMeta *pMeta);
SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) { SMeta *metaOpen(const char *path, const SMetaCfg *pMetaOptions) {
SMeta *pMeta = NULL; SMeta *pMeta = NULL;
// Set default options // Set default options
@ -68,7 +65,7 @@ void metaClose(SMeta *pMeta) {
void metaRemove(const char *path) { taosRemoveDir(path); } void metaRemove(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */ /* ------------------------ STATIC METHODS ------------------------ */
static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions) { static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) {
SMeta *pMeta; SMeta *pMeta;
size_t psize = strlen(path); size_t psize = strlen(path);

View File

@ -15,21 +15,21 @@
#include "metaDef.h" #include "metaDef.h"
int metaCreateTable(SMeta *pMeta, const STbOptions *pTbOptions) { int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) {
// Validate the tbOptions // Validate the tbOptions
if (metaValidateTbOptions(pMeta, pTbOptions) < 0) { if (metaValidateTbOptions(pMeta, pTbCfg) < 0) {
// TODO: handle error // TODO: handle error
return -1; return -1;
} }
// TODO: add atomicity // TODO: add atomicity
if (metaSaveTableToDB(pMeta, pTbOptions) < 0) { if (metaSaveTableToDB(pMeta, pTbCfg) < 0) {
// TODO: handle error // TODO: handle error
return -1; return -1;
} }
if (metaSaveTableToIdx(pMeta, pTbOptions) < 0) { if (metaSaveTableToIdx(pMeta, pTbCfg) < 0) {
// TODO: handle error // TODO: handle error
return -1; return -1;
} }

View File

@ -16,12 +16,12 @@
#include "metaDef.h" #include "metaDef.h"
#include "tcoding.h" #include "tcoding.h"
int metaValidateTbOptions(SMeta *pMeta, const STbOptions *pTbOptions) { int metaValidateTbOptions(SMeta *pMeta, const STbCfg *pTbOptions) {
// TODO // TODO
return 0; return 0;
} }
size_t metaEncodeTbObjFromTbOptions(const STbOptions *pTbOptions, void *pBuf, size_t bsize) { size_t metaEncodeTbObjFromTbOptions(const STbCfg *pTbOptions, void *pBuf, size_t bsize) {
void **ppBuf = &pBuf; void **ppBuf = &pBuf;
int tlen = 0; int tlen = 0;
@ -31,12 +31,12 @@ size_t metaEncodeTbObjFromTbOptions(const STbOptions *pTbOptions, void *pBuf, si
switch (pTbOptions->type) { switch (pTbOptions->type) {
case META_SUPER_TABLE: case META_SUPER_TABLE:
tlen += taosEncodeFixedU64(ppBuf, pTbOptions->stbOptions.uid); tlen += taosEncodeFixedU64(ppBuf, pTbOptions->stbCfg.suid);
tlen += tdEncodeSchema(ppBuf, pTbOptions->stbOptions.pTagSchema); tlen += tdEncodeSchema(ppBuf, pTbOptions->stbCfg.pTagSchema);
// TODO: encode schema version array // TODO: encode schema version array
break; break;
case META_CHILD_TABLE: case META_CHILD_TABLE:
tlen += taosEncodeFixedU64(ppBuf, pTbOptions->ctbOptions.suid); tlen += taosEncodeFixedU64(ppBuf, pTbOptions->ctbCfg.suid);
break; break;
case META_NORMAL_TABLE: case META_NORMAL_TABLE:
// TODO: encode schema version array // TODO: encode schema version array
@ -47,3 +47,12 @@ size_t metaEncodeTbObjFromTbOptions(const STbOptions *pTbOptions, void *pBuf, si
return tlen; return tlen;
} }
int metaEncodeTbCfg(void **pBuf, STbCfg *pTbCfg) {
// TODO
return 0;
}
void *metaDecodeTbCfg(void *pBuf, STbCfg **pTbCfg) {
// TODO
}

View File

@ -40,17 +40,17 @@ void* tqSerializeBufItem(TqBufferItem* bufItem, void* ptr);
const void* tqDeserializeBufHandle(const void* pBytes, TqBufferHandle* bufHandle); const void* tqDeserializeBufHandle(const void* pBytes, TqBufferHandle* bufHandle);
const void* tqDeserializeBufItem(const void* pBytes, TqBufferItem* bufItem); const void* tqDeserializeBufItem(const void* pBytes, TqBufferItem* bufItem);
STQ* tqOpen(const char* path, TqConfig* tqConfig, TqLogReader* tqLogReader, SMemAllocatorFactory *allocFac) { STQ* tqOpen(const char* path, STqCfg* tqConfig, TqLogReader* tqLogReader, SMemAllocatorFactory *allocFac) {
STQ* pTq = malloc(sizeof(STQ)); STQ* pTq = malloc(sizeof(STQ));
if(pTq == NULL) { if(pTq == NULL) {
//TODO: memory error //TODO: memory error
return NULL; return NULL;
} }
strcpy(pTq->path, path); pTq->path = strdup(path);
pTq->tqConfig = tqConfig; pTq->tqConfig = tqConfig;
pTq->tqLogReader = tqLogReader; pTq->tqLogReader = tqLogReader;
pTq->tqMemRef.pAlloctorFactory = allocFac; // pTq->tqMemRef.pAlloctorFactory = allocFac;
pTq->tqMemRef.pAllocator = allocFac->create(); // pTq->tqMemRef.pAllocator = allocFac->create(allocFac);
if(pTq->tqMemRef.pAllocator == NULL) { if(pTq->tqMemRef.pAllocator == NULL) {
//TODO //TODO
} }

View File

@ -28,7 +28,7 @@ extern "C" {
struct STsdb { struct STsdb {
char * path; char * path;
STsdbOptions options; STsdbCfg options;
SMemAllocatorFactory *pmaf; SMemAllocatorFactory *pmaf;
}; };

View File

@ -20,10 +20,10 @@
extern "C" { extern "C" {
#endif #endif
extern const STsdbOptions defautlTsdbOptions; extern const STsdbCfg defautlTsdbOptions;
int tsdbValidateOptions(const STsdbOptions *); int tsdbValidateOptions(const STsdbCfg *);
void tsdbOptionsCopy(STsdbOptions *pDest, const STsdbOptions *pSrc); void tsdbOptionsCopy(STsdbCfg *pDest, const STsdbCfg *pSrc);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -15,12 +15,12 @@
#include "tsdbDef.h" #include "tsdbDef.h"
static STsdb *tsdbNew(const char *path, const STsdbOptions *pTsdbOptions); static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions);
static void tsdbFree(STsdb *pTsdb); static void tsdbFree(STsdb *pTsdb);
static int tsdbOpenImpl(STsdb *pTsdb); static int tsdbOpenImpl(STsdb *pTsdb);
static void tsdbCloseImpl(STsdb *pTsdb); static void tsdbCloseImpl(STsdb *pTsdb);
STsdb *tsdbOpen(const char *path, const STsdbOptions *pTsdbOptions) { STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbOptions) {
STsdb *pTsdb = NULL; STsdb *pTsdb = NULL;
// Set default TSDB Options // Set default TSDB Options
@ -62,7 +62,7 @@ void tsdbClose(STsdb *pTsdb) {
void tsdbRemove(const char *path) { taosRemoveDir(path); } void tsdbRemove(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */ /* ------------------------ STATIC METHODS ------------------------ */
static STsdb *tsdbNew(const char *path, const STsdbOptions *pTsdbOptions) { static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) {
STsdb *pTsdb = NULL; STsdb *pTsdb = NULL;
pTsdb = (STsdb *)calloc(1, sizeof(STsdb)); pTsdb = (STsdb *)calloc(1, sizeof(STsdb));

View File

@ -15,20 +15,20 @@
#include "tsdbDef.h" #include "tsdbDef.h"
const STsdbOptions defautlTsdbOptions = {.lruCacheSize = 0}; const STsdbCfg defautlTsdbOptions = {.lruCacheSize = 0};
int tsdbOptionsInit(STsdbOptions *pTsdbOptions) { int tsdbOptionsInit(STsdbCfg *pTsdbOptions) {
// TODO // TODO
return 0; return 0;
} }
void tsdbOptionsClear(STsdbOptions *pTsdbOptions) { void tsdbOptionsClear(STsdbCfg *pTsdbOptions) {
// TODO // TODO
} }
int tsdbValidateOptions(const STsdbOptions *pTsdbOptions) { int tsdbValidateOptions(const STsdbCfg *pTsdbOptions) {
// TODO // TODO
return 0; return 0;
} }
void tsdbOptionsCopy(STsdbOptions *pDest, const STsdbOptions *pSrc) { memcpy(pDest, pSrc, sizeof(STsdbOptions)); } void tsdbOptionsCopy(STsdbCfg *pDest, const STsdbCfg *pSrc) { memcpy(pDest, pSrc, sizeof(STsdbCfg)); }