提交 0237a2ba 编写于 作者: L Liu Jicong

Merge branch '3.0' into feature/tq

...@@ -45,6 +45,16 @@ if(${BUILD_WITH_ROCKSDB}) ...@@ -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})
......
# 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 ""
)
\ No newline at end of file
...@@ -19,6 +19,18 @@ option( ...@@ -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( ...@@ -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(
......
# 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 ""
)
\ No newline at end of file
...@@ -80,6 +80,33 @@ if(${BUILD_WITH_NURAFT}) ...@@ -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
......
...@@ -6,3 +6,13 @@ endif(${BUILD_WITH_ROCKSDB}) ...@@ -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)
add_executable(bdbTest "")
target_sources(
bdbTest PRIVATE
"bdbTest.c"
)
target_link_libraries(bdbTest bdb)
\ No newline at end of file
#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;
}
add_executable(sqliteTest "")
target_sources(
sqliteTest PRIVATE
"sqliteTest.c"
)
target_link_libraries(sqliteTest sqlite)
\ No newline at end of file
#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;
}
aux_source_directory(src TDEV_SRC)
add_executable(tdev ${TDEV_SRC})
target_include_directories(tdev PUBLIC inc)
\ No newline at end of file
#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;
}
...@@ -63,6 +63,8 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_USER, "drop-user" ) ...@@ -63,6 +63,8 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_USER, "drop-user" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DNODE, "create-dnode" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DNODE, "create-dnode" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE, "config-dnode" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE, "config-dnode" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DNODE, "drop-dnode" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DNODE, "drop-dnode" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_MNODE, "create-mnode" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_MNODE, "drop-mnode" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DB, "create-db" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DB, "create-db" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DB, "drop-db" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DB, "drop-db" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_USE_DB, "use-db" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_USE_DB, "use-db" )
...@@ -631,7 +633,7 @@ typedef struct { ...@@ -631,7 +633,7 @@ typedef struct {
typedef struct { typedef struct {
int32_t statusInterval; int32_t statusInterval;
int8_t reserved[4]; int32_t mnodeEqualVnodeNum;
int64_t checkTime; // 1970-01-01 00:00:00.000 int64_t checkTime; // 1970-01-01 00:00:00.000
char timezone[TSDB_TIMEZONE_LEN]; // tsTimezone char timezone[TSDB_TIMEZONE_LEN]; // tsTimezone
char locale[TSDB_LOCALE_LEN]; // tsLocale char locale[TSDB_LOCALE_LEN]; // tsLocale
...@@ -654,11 +656,14 @@ typedef struct { ...@@ -654,11 +656,14 @@ typedef struct {
} SVnodeLoads; } SVnodeLoads;
typedef struct SStatusMsg { typedef struct SStatusMsg {
uint32_t sversion; int32_t sver;
int32_t dnodeId; int32_t dnodeId;
int64_t clusterId; int32_t clusterId;
uint32_t rebootTime; // time stamp for last reboot uint32_t rebootTime; // time stamp for last reboot
int32_t numOfCores; int16_t numOfCores;
int16_t numOfSupportMnodes;
int16_t numOfSupportVnodes;
int16_t numOfSupportQnodes;
char dnodeEp[TSDB_EP_LEN]; char dnodeEp[TSDB_EP_LEN];
SClusterCfg clusterCfg; SClusterCfg clusterCfg;
SVnodeLoads vnodeLoads; SVnodeLoads vnodeLoads;
...@@ -666,9 +671,9 @@ typedef struct SStatusMsg { ...@@ -666,9 +671,9 @@ typedef struct SStatusMsg {
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
int32_t clusterId;
int8_t dropped; int8_t dropped;
char reserved[3]; char reserved[7];
int64_t clusterId;
} SDnodeCfg; } SDnodeCfg;
typedef struct { typedef struct {
......
...@@ -17,53 +17,108 @@ ...@@ -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 {
typedef struct SRowBatchBuilder SRowBatchBuilder; // TODO
} SOrRow;
// SRow
#define ROW_HEADER_SIZE (sizeof(uint8_t) + 2 * sizeof(uint16_t) + sizeof(uint64_t)) typedef struct {
#define rowType(r) (*(uint8_t *)(r)) // row type col_id_t cid;
#define rowLen(r) (*(uint16_t *)POINTER_SHIFT(r, sizeof(uint8_t))) // row length uint32_t offset;
#define rowSVer(r) \ } SKvRowIdx;
(*(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 typedef struct {
#define rowVer(r) (*(uint64_t)POINTER_SHIFT(r, sizeof(uint8_t) + 2 * sizeof(uint16_t))) // row version uint16_t ncols;
#define rowCopy(dest, r) memcpy((dest), r, rowLen(r)) SKvRowIdx cidx[];
} SKvRow;
static FORCE_INLINE SRow rowDup(SRow row) {
SRow r = malloc(rowLen(row)); typedef struct {
if (r == NULL) { union {
return NULL; /// union field for encode and decode
} uint32_t info;
struct {
rowCopy(r, row); /// row type
uint32_t type : 2;
return r; /// 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;
typedef struct {
uint32_t nRows;
char rows[];
} STSRowBatch;
typedef enum {
/// ordinary row builder
TD_OR_ROW_BUILDER = 0,
/// kv row builder
TD_KV_ROW_BUILDER,
/// self-determined row builder
TD_SD_ROW_BUILDER
} ERowBbuilderT;
typedef struct {
/// row builder type
ERowBbuilderT type;
/// buffer writer
SBufferWriter bw;
/// target row
STSRow *pRow;
} STSRowBuilder;
typedef struct {
STSchema *pSchema;
STSRow * pRow;
} STSRowReader;
// SRowBatch typedef struct {
uint32_t it;
STSRowBatch *pRowBatch;
} STSRowBatchIter;
// SRowBuilder // STSRowBuilder
SRowBuilder *rowBuilderCreate(); #define trbInit(rt, allocator, endian, target, size) \
void rowBuilderDestroy(SRowBuilder *); { .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);
// SRowBatchIter // STSRowReader
SRowBatchIter *rowBatchIterCreate(SRowBatch *); #define tRowReaderInit(schema, row) \
void rowBatchIterDestroy(SRowBatchIter *); { .schema = (schema), .row = (row) }
const SRow rowBatchIterNext(SRowBatchIter *); int tRowReaderRead(STSRowReader *pRowReader, col_id_t cid, void *target, uint64_t size);
// SRowBatchBuilder // STSRowBatchIter
SRowBatchBuilder *rowBatchBuilderCreate(); #define tRowBatchIterInit(pRB) \
void rowBatchBuilderDestroy(SRowBatchBuilder *); { .it = 0, .pRowBatch = (pRB) }
const STSRow *tRowBatchIterNext(STSRowBatchIter *pRowBatchIter);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -16,10 +16,65 @@ ...@@ -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
......
...@@ -13,18 +13,15 @@ ...@@ -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_*/
\ No newline at end of file \ No newline at end of file
...@@ -26,94 +26,24 @@ extern "C" { ...@@ -26,94 +26,24 @@ extern "C" {
typedef struct SDnode SDnode; typedef struct SDnode SDnode;
typedef struct { typedef struct {
/**
* @brief software version of the program.
*
*/
int32_t sver; int32_t sver;
int16_t numOfCores;
/** int16_t numOfSupportMnodes;
* @brief num of CPU cores. int16_t numOfSupportVnodes;
* int16_t numOfSupportQnodes;
*/ int32_t statusInterval;
int32_t numOfCores; int32_t mnodeEqualVnodeNum;
/**
* @brief number of threads per CPU core.
*
*/
float numOfThreadsPerCore; float numOfThreadsPerCore;
/**
* @brief the proportion of total CPU cores available for query processing.
*
*/
float ratioOfQueryCores; float ratioOfQueryCores;
/**
* @brief max number of connections allowed in dnode.
*
*/
int32_t maxShellConns; int32_t maxShellConns;
/**
* @brief time interval of heart beat from shell to dnode, seconds.
*
*/
int32_t shellActivityTimer; int32_t shellActivityTimer;
/**
* @brief time interval of dnode status reporting to mnode, seconds, for cluster only.
*
*/
int32_t statusInterval;
/**
* @brief first port number for the connection (12 continuous UDP/TCP port number are used).
*
*/
uint16_t serverPort; uint16_t serverPort;
/**
* @brief data file's directory.
*
*/
char dataDir[TSDB_FILENAME_LEN]; char dataDir[TSDB_FILENAME_LEN];
/**
* @brief local endpoint.
*
*/
char localEp[TSDB_EP_LEN]; char localEp[TSDB_EP_LEN];
/**
* @brieflocal fully qualified domain name (FQDN).
*
*/
char localFqdn[TSDB_FQDN_LEN]; char localFqdn[TSDB_FQDN_LEN];
/**
* @brief first fully qualified domain name (FQDN) for TDengine system.
*
*/
char firstEp[TSDB_EP_LEN]; char firstEp[TSDB_EP_LEN];
/**
* @brief system time zone.
*
*/
char timezone[TSDB_TIMEZONE_LEN]; char timezone[TSDB_TIMEZONE_LEN];
/**
* @brief system locale.
*
*/
char locale[TSDB_LOCALE_LEN]; char locale[TSDB_LOCALE_LEN];
/**
* @briefdefault system charset.
*
*/
char charset[TSDB_LOCALE_LEN]; char charset[TSDB_LOCALE_LEN];
} SDnodeOpt; } SDnodeOpt;
......
...@@ -30,133 +30,36 @@ typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); ...@@ -30,133 +30,36 @@ typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg); typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg);
typedef struct SMnodeLoad { typedef struct SMnodeLoad {
/**
* @brief the number of dnodes in cluster.
*
*/
int64_t numOfDnode; int64_t numOfDnode;
/**
* @brief the number of mnodes in cluster.
*
*/
int64_t numOfMnode; int64_t numOfMnode;
/**
* @brief the number of vgroups in cluster.
*
*/
int64_t numOfVgroup; int64_t numOfVgroup;
/**
* @brief the number of databases in cluster.
*
*/
int64_t numOfDatabase; int64_t numOfDatabase;
/**
* @brief the number of super tables in cluster.
*
*/
int64_t numOfSuperTable; int64_t numOfSuperTable;
/**
* @brief the number of child tables in cluster.
*
*/
int64_t numOfChildTable; int64_t numOfChildTable;
/**
* @brief the number of normal tables in cluster.
*
*/
int64_t numOfNormalTable; int64_t numOfNormalTable;
/**
* @brief the number of numOfTimeseries in cluster.
*
*/
int64_t numOfColumn; int64_t numOfColumn;
/**
* @brief total points written in cluster.
*
*/
int64_t totalPoints; int64_t totalPoints;
/**
* @brief total storage in cluster.
*
*/
int64_t totalStorage; int64_t totalStorage;
/**
* @brief total compressed storage in cluster.
*
*/
int64_t compStorage; int64_t compStorage;
} SMnodeLoad; } SMnodeLoad;
typedef struct { typedef struct {
/**
* @brief dnodeId of this mnode.
*
*/
int32_t dnodeId; int32_t dnodeId;
int32_t clusterId;
/**
* @brief clusterId of this mnode.
*
*/
int64_t clusterId;
/**
* @brief replica num of this mnode.
*
*/
int8_t replica; int8_t replica;
/**
* @brief self index in the array of replicas.
*
*/
int8_t selfIndex; int8_t selfIndex;
/**
* @brief detail replica information of this mnode.
*
*/
SReplica replicas[TSDB_MAX_REPLICA]; SReplica replicas[TSDB_MAX_REPLICA];
/**
* @brief the parent dnode of this mnode.
*
*/
SDnode *pDnode; SDnode *pDnode;
/**
* @brief put apply msg to the write queue in dnode.
*
*/
PutMsgToMnodeQFp putMsgToApplyMsgFp; PutMsgToMnodeQFp putMsgToApplyMsgFp;
/**
* @brief the callback function while send msg to dnode.
*
*/
SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToDnodeFp sendMsgToDnodeFp;
/**
* @brief the callback function while send msg to mnode.
*
*/
SendMsgToMnodeFp sendMsgToMnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp;
/**
* @brief the callback function while send redirect msg to clients or peers.
*
*/
SendRedirectMsgFp sendRedirectMsgFp; SendRedirectMsgFp sendRedirectMsgFp;
int32_t sver;
int32_t statusInterval;
int32_t mnodeEqualVnodeNum;
char *timezone;
char *locale;
char *charset;
} SMnodeOpt; } SMnodeOpt;
/* ------------------------ SMnode ------------------------ */ /* ------------------------ SMnode ------------------------ */
......
...@@ -38,6 +38,15 @@ extern "C" { ...@@ -38,6 +38,15 @@ extern "C" {
dataPos += sizeof(int32_t); \ dataPos += sizeof(int32_t); \
} }
#define SDB_GET_INT16(pData, pRow, dataPos, val) \
{ \
if (sdbGetRawInt16(pRaw, dataPos, val) != 0) { \
sdbFreeRow(pRow); \
return NULL; \
} \
dataPos += sizeof(int16_t); \
}
#define SDB_GET_INT8(pData, pRow, dataPos, val) \ #define SDB_GET_INT8(pData, pRow, dataPos, val) \
{ \ { \
if (sdbGetRawInt8(pRaw, dataPos, val) != 0) { \ if (sdbGetRawInt8(pRaw, dataPos, val) != 0) { \
...@@ -74,6 +83,15 @@ extern "C" { ...@@ -74,6 +83,15 @@ extern "C" {
dataPos += sizeof(int32_t); \ dataPos += sizeof(int32_t); \
} }
#define SDB_SET_INT16(pRaw, dataPos, val) \
{ \
if (sdbSetRawInt16(pRaw, dataPos, val) != 0) { \
sdbFreeRaw(pRaw); \
return NULL; \
} \
dataPos += sizeof(int16_t); \
}
#define SDB_SET_INT8(pRaw, dataPos, val) \ #define SDB_SET_INT8(pRaw, dataPos, val) \
{ \ { \
if (sdbSetRawInt8(pRaw, dataPos, val) != 0) { \ if (sdbSetRawInt8(pRaw, dataPos, val) != 0) { \
...@@ -100,6 +118,7 @@ extern "C" { ...@@ -100,6 +118,7 @@ extern "C" {
} \ } \
} }
typedef struct SMnode SMnode;
typedef struct SSdbRaw SSdbRaw; typedef struct SSdbRaw SSdbRaw;
typedef struct SSdbRow SSdbRow; typedef struct SSdbRow SSdbRow;
typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType; typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType;
...@@ -130,7 +149,7 @@ typedef struct SSdb SSdb; ...@@ -130,7 +149,7 @@ typedef struct SSdb SSdb;
typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj); typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj);
typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj); typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj);
typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj); typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj);
typedef int32_t (*SdbDeployFp)(SSdb *pSdb); typedef int32_t (*SdbDeployFp)(SMnode *pMnode);
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw); typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj); typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
...@@ -190,6 +209,12 @@ typedef struct SSdbOpt { ...@@ -190,6 +209,12 @@ typedef struct SSdbOpt {
* *
*/ */
const char *path; const char *path;
/**
* @brief The mnode object.
*
*/
SMnode *pMnode;
} SSdbOpt; } SSdbOpt;
/** /**
...@@ -291,12 +316,14 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type); ...@@ -291,12 +316,14 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen); SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen);
void sdbFreeRaw(SSdbRaw *pRaw); void sdbFreeRaw(SSdbRaw *pRaw);
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val); int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val);
int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val);
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val); int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val);
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val); int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val);
int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen); int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen);
int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen); int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen);
int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status); int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status);
int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val); int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val);
int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val);
int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val); int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val);
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val); int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val);
int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen); int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen);
......
/*
* 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_*/
\ No newline at end of file
...@@ -16,36 +16,96 @@ ...@@ -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
} }
......
...@@ -161,9 +161,9 @@ typedef struct TqLogReader { ...@@ -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 { ...@@ -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
......
...@@ -22,21 +22,25 @@ extern "C" { ...@@ -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 */
}; };
......
...@@ -23,6 +23,7 @@ ...@@ -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" { ...@@ -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); ...@@ -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;
};
} SVnodeReq;
/** typedef struct {
* @brief if the allocator is heap allcator or arena allocator int err;
* char info[];
*/ } SVnodeRsp;
bool isHeapAllocator;
/** #define VNODE_INIT_CREATE_STB_REQ(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \
* @brief TSDB options { .ver = 0, .ctReq = META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) }
*
*/
STsdbOptions tsdbOptions;
/** #define VNODE_INIT_CREATE_CTB_REQ(NAME, TTL, KEEP, SUID, PTAG) \
* @brief META options { .ver = 0, .ctReq = META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) }
*
*/ #define VNODE_INIT_CREATE_NTB_REQ(NAME, TTL, KEEP, SUID, PSCHEMA) \
SMetaOptions metaOptions; { .ver = 0, .ctReq = META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) }
// STqOptions tqOptions; // TODO
}; 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 { ...@@ -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,
......
...@@ -52,7 +52,7 @@ bool taosGetSysMemory(float *memoryUsedMB); ...@@ -52,7 +52,7 @@ bool taosGetSysMemory(float *memoryUsedMB);
void taosPrintOsInfo(); void taosPrintOsInfo();
int taosSystem(const char *cmd); int taosSystem(const char *cmd);
void taosKillSystem(); void taosKillSystem();
bool taosGetSystemUid(char *uid, int32_t uidlen); int32_t taosGetSystemUid(char *uid, int32_t uidlen);
char * taosGetCmdlineByPID(int pid); char * taosGetCmdlineByPID(int pid);
void taosSetCoreDump(bool enable); void taosSetCoreDump(bool enable);
......
...@@ -23,9 +23,9 @@ extern "C" { ...@@ -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 { ...@@ -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
} }
......
...@@ -115,25 +115,25 @@ int32_t* taosGetErrno(); ...@@ -115,25 +115,25 @@ int32_t* taosGetErrno();
#define TSDB_CODE_TSC_VALUE_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x0223) //"Value out of range") #define TSDB_CODE_TSC_VALUE_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x0223) //"Value out of range")
// mnode // mnode
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed") #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300)
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0301) //"Message is progressing") #define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0301)
#define TSDB_CODE_MND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0302) //"Messag need to be reprocessed") #define TSDB_CODE_MND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0302)
#define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0303) //"Insufficient privilege for operation") #define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0303)
#define TSDB_CODE_MND_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0304) //"Unexpected generic error in mnode") #define TSDB_CODE_MND_INVALID_OPTIONS TAOS_DEF_ERROR_CODE(0, 0x0304)
#define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0305) //"Invalid message connection") #define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0305)
#define TSDB_CODE_MND_INVALID_MSG_VERSION TAOS_DEF_ERROR_CODE(0, 0x0306) //"Incompatible protocol version") #define TSDB_CODE_MND_INVALID_MSG_VERSION TAOS_DEF_ERROR_CODE(0, 0x0306)
#define TSDB_CODE_MND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0307) //"Invalid message length") #define TSDB_CODE_MND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0307)
#define TSDB_CODE_MND_INVALID_MSG_TYPE TAOS_DEF_ERROR_CODE(0, 0x0308) //"Invalid message type") #define TSDB_CODE_MND_INVALID_MSG_TYPE TAOS_DEF_ERROR_CODE(0, 0x0308)
#define TSDB_CODE_MND_TOO_MANY_SHELL_CONNS TAOS_DEF_ERROR_CODE(0, 0x0309) //"Too many connections") #define TSDB_CODE_MND_TOO_MANY_SHELL_CONNS TAOS_DEF_ERROR_CODE(0, 0x0309)
#define TSDB_CODE_MND_INVALID_SHOWOBJ TAOS_DEF_ERROR_CODE(0, 0x030B) //"Data expired") #define TSDB_CODE_MND_INVALID_SHOWOBJ TAOS_DEF_ERROR_CODE(0, 0x030B)
#define TSDB_CODE_MND_INVALID_QUERY_ID TAOS_DEF_ERROR_CODE(0, 0x030C) //"Invalid query id") #define TSDB_CODE_MND_INVALID_QUERY_ID TAOS_DEF_ERROR_CODE(0, 0x030C)
#define TSDB_CODE_MND_INVALID_STREAM_ID TAOS_DEF_ERROR_CODE(0, 0x030D) //"Invalid stream id") #define TSDB_CODE_MND_INVALID_STREAM_ID TAOS_DEF_ERROR_CODE(0, 0x030D)
#define TSDB_CODE_MND_INVALID_CONN_ID TAOS_DEF_ERROR_CODE(0, 0x030E) //"Invalid connection id") #define TSDB_CODE_MND_INVALID_CONN_ID TAOS_DEF_ERROR_CODE(0, 0x030E)
#define TSDB_CODE_MND_MNODE_IS_RUNNING TAOS_DEF_ERROR_CODE(0, 0x0310) //"mnode is alreay running") #define TSDB_CODE_MND_MNODE_IS_RUNNING TAOS_DEF_ERROR_CODE(0, 0x0310)
#define TSDB_CODE_MND_FAILED_TO_CONFIG_SYNC TAOS_DEF_ERROR_CODE(0, 0x0311) //"failed to config sync") #define TSDB_CODE_MND_FAILED_TO_CONFIG_SYNC TAOS_DEF_ERROR_CODE(0, 0x0311)
#define TSDB_CODE_MND_FAILED_TO_START_SYNC TAOS_DEF_ERROR_CODE(0, 0x0312) //"failed to start sync") #define TSDB_CODE_MND_FAILED_TO_START_SYNC TAOS_DEF_ERROR_CODE(0, 0x0312)
#define TSDB_CODE_MND_FAILED_TO_CREATE_DIR TAOS_DEF_ERROR_CODE(0, 0x0313) //"failed to create mnode dir") #define TSDB_CODE_MND_FAILED_TO_CREATE_DIR TAOS_DEF_ERROR_CODE(0, 0x0313)
#define TSDB_CODE_MND_FAILED_TO_INIT_STEP TAOS_DEF_ERROR_CODE(0, 0x0314) //"failed to init components") #define TSDB_CODE_MND_FAILED_TO_INIT_STEP TAOS_DEF_ERROR_CODE(0, 0x0314)
#define TSDB_CODE_SDB_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0320) #define TSDB_CODE_SDB_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0320)
#define TSDB_CODE_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0321) #define TSDB_CODE_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0321)
......
...@@ -15,75 +15,21 @@ ...@@ -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
};
struct SRowBatchIter {
int32_t counter; // row counter
SRowBatch *rb; // row batch to iter
SRow nrow; // next row
};
struct SRowBatchBuilder {
// TODO // TODO
};
/* ------------ Methods ---------- */
// SRowBuilder
SRowBuilder *rowBuilderCreate() {
SRowBuilder *pRowBuilder = NULL;
// TODO
return pRowBuilder;
} }
void rowBuilderDestroy(SRowBuilder *pRowBuilder) { void trbSetRowVersion(SRowBuilder *pRB, uint64_t ver) {
if (pRowBuilder) { // TODO
free(pRowBuilder);
}
} }
// SRowBatchIter void trbSetRowTS(SRowBuilder *pRB, TSKEY ts) {
SRowBatchIter *rowBatchIterCreate(SRowBatch *pRowBatch) { // TODO
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) { int trbWriteCol(SRowBuilder *pRB, void *pData, col_id_t cid) {
SRow r = NULL; // TODO
if (pRowBatchIter->counter < pRowBatchIter->rb->nrows) { return 0;
r = pRowBatchIter->nrow;
pRowBatchIter->counter += 1;
pRowBatchIter->nrow = (SRow)POINTER_SHIFT(r, rowLen(r));
}
return r;
} }
#endif
// SRowBatchBuilder \ No newline at end of file
SRowBatchBuilder *rowBatchBuilderCreate();
void rowBatchBuilderDestroy(SRowBatchBuilder *);
\ No newline at end of file
#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
}
\ No newline at end of file
#include <gtest/gtest.h>
#include "tschema.h"
TEST(td_schema_test, build_schema_test) {
}
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
/*
* 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/>.
*/
\ No newline at end of file
...@@ -138,11 +138,15 @@ void dmnWaitSignal() { ...@@ -138,11 +138,15 @@ void dmnWaitSignal() {
void dmnInitOption(SDnodeOpt *pOption) { void dmnInitOption(SDnodeOpt *pOption) {
pOption->sver = tsVersion; pOption->sver = tsVersion;
pOption->numOfCores = tsNumOfCores; pOption->numOfCores = tsNumOfCores;
pOption->numOfSupportMnodes = 1;
pOption->numOfSupportVnodes = 1;
pOption->numOfSupportQnodes = 1;
pOption->statusInterval = tsStatusInterval;
pOption->mnodeEqualVnodeNum = tsMnodeEqualVnodeNum;
pOption->numOfThreadsPerCore = tsNumOfThreadsPerCore; pOption->numOfThreadsPerCore = tsNumOfThreadsPerCore;
pOption->ratioOfQueryCores = tsRatioOfQueryCores; pOption->ratioOfQueryCores = tsRatioOfQueryCores;
pOption->maxShellConns = tsMaxShellConns; pOption->maxShellConns = tsMaxShellConns;
pOption->shellActivityTimer = tsShellActivityTimer; pOption->shellActivityTimer = tsShellActivityTimer;
pOption->statusInterval = tsStatusInterval;
pOption->serverPort = tsServerPort; pOption->serverPort = tsServerPort;
tstrncpy(pOption->dataDir, tsDataDir, TSDB_FILENAME_LEN); tstrncpy(pOption->dataDir, tsDataDir, TSDB_FILENAME_LEN);
tstrncpy(pOption->localEp, tsLocalEp, TSDB_EP_LEN); tstrncpy(pOption->localEp, tsLocalEp, TSDB_EP_LEN);
......
...@@ -27,7 +27,7 @@ void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); ...@@ -27,7 +27,7 @@ void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
int32_t dndGetDnodeId(SDnode *pDnode); int32_t dndGetDnodeId(SDnode *pDnode);
int64_t dndGetClusterId(SDnode *pDnode); int32_t dndGetClusterId(SDnode *pDnode);
void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort);
void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet); void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet);
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg); void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg);
......
...@@ -57,8 +57,8 @@ typedef struct { ...@@ -57,8 +57,8 @@ typedef struct {
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
int32_t dropped; int32_t dropped;
int32_t clusterId;
uint32_t rebootTime; uint32_t rebootTime;
int64_t clusterId;
SEpSet mnodeEpSet; SEpSet mnodeEpSet;
char *file; char *file;
SHashObj *dnodeHash; SHashObj *dnodeHash;
......
...@@ -26,10 +26,10 @@ int32_t dndGetDnodeId(SDnode *pDnode) { ...@@ -26,10 +26,10 @@ int32_t dndGetDnodeId(SDnode *pDnode) {
return dnodeId; return dnodeId;
} }
int64_t dndGetClusterId(SDnode *pDnode) { int32_t dndGetClusterId(SDnode *pDnode) {
SDnodeMgmt *pMgmt = &pDnode->dmgmt; SDnodeMgmt *pMgmt = &pDnode->dmgmt;
taosRLockLatch(&pMgmt->latch); taosRLockLatch(&pMgmt->latch);
int64_t clusterId = pMgmt->clusterId; int32_t clusterId = pMgmt->clusterId;
taosRUnLockLatch(&pMgmt->latch); taosRUnLockLatch(&pMgmt->latch);
return clusterId; return clusterId;
} }
...@@ -190,78 +190,78 @@ static int32_t dndReadDnodes(SDnode *pDnode) { ...@@ -190,78 +190,78 @@ static int32_t dndReadDnodes(SDnode *pDnode) {
} }
cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId"); cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId");
if (!dnodeId || dnodeId->type != cJSON_String) { if (!dnodeId || dnodeId->type != cJSON_Number) {
dError("failed to read %s since dnodeId not found", pMgmt->file); dError("failed to read %s since dnodeId not found", pMgmt->file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pMgmt->dnodeId = atoi(dnodeId->valuestring); pMgmt->dnodeId = dnodeId->valueint;
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
if (!clusterId || clusterId->type != cJSON_String) { if (!clusterId || clusterId->type != cJSON_Number) {
dError("failed to read %s since clusterId not found", pMgmt->file); dError("failed to read %s since clusterId not found", pMgmt->file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pMgmt->clusterId = atoll(clusterId->valuestring); pMgmt->clusterId = clusterId->valueint;
cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
if (!dropped || dropped->type != cJSON_String) { if (!dropped || dropped->type != cJSON_Number) {
dError("failed to read %s since dropped not found", pMgmt->file); dError("failed to read %s since dropped not found", pMgmt->file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pMgmt->dropped = atoi(dropped->valuestring); pMgmt->dropped = dropped->valueint;
cJSON *dnodeInfos = cJSON_GetObjectItem(root, "dnodeInfos"); cJSON *dnodes = cJSON_GetObjectItem(root, "dnodes");
if (!dnodeInfos || dnodeInfos->type != cJSON_Array) { if (!dnodes || dnodes->type != cJSON_Array) {
dError("failed to read %s since dnodeInfos not found", pMgmt->file); dError("failed to read %s since dnodes not found", pMgmt->file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
int32_t dnodeInfosSize = cJSON_GetArraySize(dnodeInfos); int32_t numOfNodes = cJSON_GetArraySize(dnodes);
if (dnodeInfosSize <= 0) { if (numOfNodes <= 0) {
dError("failed to read %s since dnodeInfos size:%d invalid", pMgmt->file, dnodeInfosSize); dError("failed to read %s since numOfNodes:%d invalid", pMgmt->file, numOfNodes);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pMgmt->dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps)); pMgmt->dnodeEps = calloc(1, numOfNodes * sizeof(SDnodeEp) + sizeof(SDnodeEps));
if (pMgmt->dnodeEps == NULL) { if (pMgmt->dnodeEps == NULL) {
dError("failed to calloc dnodeEpList since %s", strerror(errno)); dError("failed to calloc dnodeEpList since %s", strerror(errno));
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pMgmt->dnodeEps->num = dnodeInfosSize; pMgmt->dnodeEps->num = numOfNodes;
for (int32_t i = 0; i < dnodeInfosSize; ++i) { for (int32_t i = 0; i < numOfNodes; ++i) {
cJSON *dnodeInfo = cJSON_GetArrayItem(dnodeInfos, i); cJSON *node = cJSON_GetArrayItem(dnodes, i);
if (dnodeInfo == NULL) break; if (node == NULL) break;
SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i]; SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i];
cJSON *dnodeId = cJSON_GetObjectItem(dnodeInfo, "dnodeId"); cJSON *dnodeId = cJSON_GetObjectItem(node, "id");
if (!dnodeId || dnodeId->type != cJSON_String) { if (!dnodeId || dnodeId->type != cJSON_Number) {
dError("failed to read %s, dnodeId not found", pMgmt->file); dError("failed to read %s, dnodeId not found", pMgmt->file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pDnodeEp->id = atoi(dnodeId->valuestring); pDnodeEp->id = dnodeId->valueint;
cJSON *isMnode = cJSON_GetObjectItem(dnodeInfo, "isMnode"); cJSON *dnodeFqdn = cJSON_GetObjectItem(node, "fqdn");
if (!isMnode || isMnode->type != cJSON_String) {
dError("failed to read %s, isMnode not found", pMgmt->file);
goto PRASE_DNODE_OVER;
}
pDnodeEp->isMnode = atoi(isMnode->valuestring);
cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn");
if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) { if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) {
dError("failed to read %s, dnodeFqdn not found", pMgmt->file); dError("failed to read %s, dnodeFqdn not found", pMgmt->file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
tstrncpy(pDnodeEp->fqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN); tstrncpy(pDnodeEp->fqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN);
cJSON *dnodePort = cJSON_GetObjectItem(dnodeInfo, "dnodePort"); cJSON *dnodePort = cJSON_GetObjectItem(node, "port");
if (!dnodePort || dnodePort->type != cJSON_String) { if (!dnodePort || dnodePort->type != cJSON_Number) {
dError("failed to read %s, dnodePort not found", pMgmt->file); dError("failed to read %s, dnodePort not found", pMgmt->file);
goto PRASE_DNODE_OVER; goto PRASE_DNODE_OVER;
} }
pDnodeEp->port = atoi(dnodePort->valuestring); pDnodeEp->port = dnodePort->valueint;
cJSON *isMnode = cJSON_GetObjectItem(node, "isMnode");
if (!isMnode || isMnode->type != cJSON_Number) {
dError("failed to read %s, isMnode not found", pMgmt->file);
goto PRASE_DNODE_OVER;
}
pDnodeEp->isMnode = isMnode->valueint;
} }
code = 0; code = 0;
...@@ -307,16 +307,16 @@ static int32_t dndWriteDnodes(SDnode *pDnode) { ...@@ -307,16 +307,16 @@ static int32_t dndWriteDnodes(SDnode *pDnode) {
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", pMgmt->dnodeId); len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pMgmt->dnodeId);
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pMgmt->clusterId); len += snprintf(content + len, maxLen - len, " \"clusterId\": %d,\n", pMgmt->clusterId);
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", pMgmt->dropped); len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pMgmt->dropped);
len += snprintf(content + len, maxLen - len, " \"dnodeInfos\": [{\n"); len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n");
for (int32_t i = 0; i < pMgmt->dnodeEps->num; ++i) { for (int32_t i = 0; i < pMgmt->dnodeEps->num; ++i) {
SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i]; SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i];
len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", pDnodeEp->id); len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pDnodeEp->id);
len += snprintf(content + len, maxLen - len, " \"isMnode\": \"%d\",\n", pDnodeEp->isMnode); len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pDnodeEp->fqdn);
len += snprintf(content + len, maxLen - len, " \"dnodeFqdn\": \"%s\",\n", pDnodeEp->fqdn); len += snprintf(content + len, maxLen - len, " \"port\": %u,\n", pDnodeEp->port);
len += snprintf(content + len, maxLen - len, " \"dnodePort\": \"%u\"\n", pDnodeEp->port); len += snprintf(content + len, maxLen - len, " \"isMnode\": %d\n", pDnodeEp->isMnode);
if (i < pMgmt->dnodeEps->num - 1) { if (i < pMgmt->dnodeEps->num - 1) {
len += snprintf(content + len, maxLen - len, " },{\n"); len += snprintf(content + len, maxLen - len, " },{\n");
} else { } else {
...@@ -344,23 +344,27 @@ static void dndSendStatusMsg(SDnode *pDnode) { ...@@ -344,23 +344,27 @@ static void dndSendStatusMsg(SDnode *pDnode) {
return; return;
} }
bool changed = false;
SDnodeMgmt *pMgmt = &pDnode->dmgmt; SDnodeMgmt *pMgmt = &pDnode->dmgmt;
taosRLockLatch(&pMgmt->latch); taosRLockLatch(&pMgmt->latch);
pStatus->sversion = htonl(pDnode->opt.sver); pStatus->sver = htonl(pDnode->opt.sver);
pStatus->dnodeId = htonl(pMgmt->dnodeId); pStatus->dnodeId = htonl(pMgmt->dnodeId);
pStatus->clusterId = htobe64(pMgmt->clusterId); pStatus->clusterId = htonl(pMgmt->clusterId);
pStatus->rebootTime = htonl(pMgmt->rebootTime); pStatus->rebootTime = htonl(pMgmt->rebootTime);
pStatus->numOfCores = htonl(pDnode->opt.numOfCores); pStatus->numOfCores = htons(pDnode->opt.numOfCores);
pStatus->numOfSupportMnodes = htons(pDnode->opt.numOfCores);
pStatus->numOfSupportVnodes = htons(pDnode->opt.numOfCores);
pStatus->numOfSupportQnodes = htons(pDnode->opt.numOfCores);
tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN); tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN);
pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval); pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval);
tstrncpy(pStatus->clusterCfg.timezone, pDnode->opt.timezone, TSDB_TIMEZONE_LEN); pStatus->clusterCfg.mnodeEqualVnodeNum = htonl(pDnode->opt.mnodeEqualVnodeNum);
tstrncpy(pStatus->clusterCfg.locale, pDnode->opt.locale, TSDB_LOCALE_LEN);
tstrncpy(pStatus->clusterCfg.charset, pDnode->opt.charset, TSDB_LOCALE_LEN);
pStatus->clusterCfg.checkTime = 0; pStatus->clusterCfg.checkTime = 0;
char timestr[32] = "1970-01-01 00:00:00.00"; char timestr[32] = "1970-01-01 00:00:00.00";
(void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); (void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
pStatus->clusterCfg.checkTime = htonl(pStatus->clusterCfg.checkTime);
tstrncpy(pStatus->clusterCfg.timezone, pDnode->opt.timezone, TSDB_TIMEZONE_LEN);
tstrncpy(pStatus->clusterCfg.locale, pDnode->opt.locale, TSDB_LOCALE_LEN);
tstrncpy(pStatus->clusterCfg.charset, pDnode->opt.charset, TSDB_LOCALE_LEN);
taosRUnLockLatch(&pMgmt->latch); taosRUnLockLatch(&pMgmt->latch);
dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads); dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads);
...@@ -373,7 +377,7 @@ static void dndSendStatusMsg(SDnode *pDnode) { ...@@ -373,7 +377,7 @@ static void dndSendStatusMsg(SDnode *pDnode) {
static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
SDnodeMgmt *pMgmt = &pDnode->dmgmt; SDnodeMgmt *pMgmt = &pDnode->dmgmt;
if (pMgmt->dnodeId == 0 || pMgmt->dropped != pCfg->dropped) { if (pMgmt->dnodeId == 0 || pMgmt->dropped != pCfg->dropped) {
dInfo("set dnodeId:%d clusterId:%" PRId64 " dropped:%d", pCfg->dnodeId, pCfg->clusterId, pCfg->dropped); dInfo("set dnodeId:%d clusterId:%d dropped:%d", pCfg->dnodeId, pCfg->clusterId, pCfg->dropped);
taosWLockLatch(&pMgmt->latch); taosWLockLatch(&pMgmt->latch);
pMgmt->dnodeId = pCfg->dnodeId; pMgmt->dnodeId = pCfg->dnodeId;
...@@ -414,7 +418,7 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { ...@@ -414,7 +418,7 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
SStatusRsp *pRsp = pMsg->pCont; SStatusRsp *pRsp = pMsg->pCont;
SDnodeCfg *pCfg = &pRsp->dnodeCfg; SDnodeCfg *pCfg = &pRsp->dnodeCfg;
pCfg->dnodeId = htonl(pCfg->dnodeId); pCfg->dnodeId = htonl(pCfg->dnodeId);
pCfg->clusterId = htobe64(pCfg->clusterId); pCfg->clusterId = htonl(pCfg->clusterId);
dndUpdateDnodeCfg(pDnode, pCfg); dndUpdateDnodeCfg(pDnode, pCfg);
if (pCfg->dropped) return; if (pCfg->dropped) return;
...@@ -434,6 +438,7 @@ static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { a ...@@ -434,6 +438,7 @@ static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { a
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); } static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); }
static void dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) { static void dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) {
dDebug("config msg is received");
SCfgDnodeMsg *pCfg = pMsg->pCont; SCfgDnodeMsg *pCfg = pMsg->pCont;
int32_t code = TSDB_CODE_OPS_NOT_SUPPORT; int32_t code = TSDB_CODE_OPS_NOT_SUPPORT;
...@@ -443,12 +448,12 @@ static void dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) { ...@@ -443,12 +448,12 @@ static void dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) {
} }
static void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg) { static void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg) {
dInfo("startup msg is received"); dDebug("startup msg is received");
SStartupMsg *pStartup = rpcMallocCont(sizeof(SStartupMsg)); SStartupMsg *pStartup = rpcMallocCont(sizeof(SStartupMsg));
dndGetStartup(pDnode, pStartup); dndGetStartup(pDnode, pStartup);
dInfo("startup msg is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); dDebug("startup msg is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStartup, .contLen = sizeof(SStartupMsg)}; SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStartup, .contLen = sizeof(SStartupMsg)};
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
...@@ -464,7 +469,7 @@ static void *dnodeThreadRoutine(void *param) { ...@@ -464,7 +469,7 @@ static void *dnodeThreadRoutine(void *param) {
pthread_testcancel(); pthread_testcancel();
if (dndGetStat(pDnode) == DND_STAT_RUNNING) { if (dndGetStat(pDnode) == DND_STAT_RUNNING) {
// dndSendStatusMsg(pDnode); dndSendStatusMsg(pDnode);
} }
} }
} }
......
...@@ -130,43 +130,43 @@ static int32_t dndReadMnodeFile(SDnode *pDnode) { ...@@ -130,43 +130,43 @@ static int32_t dndReadMnodeFile(SDnode *pDnode) {
} }
cJSON *deployed = cJSON_GetObjectItem(root, "deployed"); cJSON *deployed = cJSON_GetObjectItem(root, "deployed");
if (!deployed || deployed->type != cJSON_String) { if (!deployed || deployed->type != cJSON_Number) {
dError("failed to read %s since deployed not found", pMgmt->file); dError("failed to read %s since deployed not found", pMgmt->file);
goto PRASE_MNODE_OVER; goto PRASE_MNODE_OVER;
} }
pMgmt->deployed = atoi(deployed->valuestring); pMgmt->deployed = deployed->valueint;
cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
if (!dropped || dropped->type != cJSON_String) { if (!dropped || dropped->type != cJSON_Number) {
dError("failed to read %s since dropped not found", pMgmt->file); dError("failed to read %s since dropped not found", pMgmt->file);
goto PRASE_MNODE_OVER; goto PRASE_MNODE_OVER;
} }
pMgmt->dropped = atoi(dropped->valuestring); pMgmt->dropped = dropped->valueint;
cJSON *nodes = cJSON_GetObjectItem(root, "nodes"); cJSON *mnodes = cJSON_GetObjectItem(root, "mnodes");
if (!nodes || nodes->type != cJSON_Array) { if (!mnodes || mnodes->type != cJSON_Array) {
dError("failed to read %s since nodes not found", pMgmt->file); dError("failed to read %s since nodes not found", pMgmt->file);
goto PRASE_MNODE_OVER; goto PRASE_MNODE_OVER;
} }
pMgmt->replica = cJSON_GetArraySize(nodes); pMgmt->replica = cJSON_GetArraySize(mnodes);
if (pMgmt->replica <= 0 || pMgmt->replica > TSDB_MAX_REPLICA) { if (pMgmt->replica <= 0 || pMgmt->replica > TSDB_MAX_REPLICA) {
dError("failed to read %s since nodes size %d invalid", pMgmt->file, pMgmt->replica); dError("failed to read %s since mnodes size %d invalid", pMgmt->file, pMgmt->replica);
goto PRASE_MNODE_OVER; goto PRASE_MNODE_OVER;
} }
for (int32_t i = 0; i < pMgmt->replica; ++i) { for (int32_t i = 0; i < pMgmt->replica; ++i) {
cJSON *node = cJSON_GetArrayItem(nodes, i); cJSON *node = cJSON_GetArrayItem(mnodes, i);
if (node == NULL) break; if (node == NULL) break;
SReplica *pReplica = &pMgmt->replicas[i]; SReplica *pReplica = &pMgmt->replicas[i];
cJSON *id = cJSON_GetObjectItem(node, "id"); cJSON *id = cJSON_GetObjectItem(node, "id");
if (!id || id->type != cJSON_String || id->valuestring == NULL) { if (!id || id->type != cJSON_Number) {
dError("failed to read %s since id not found", pMgmt->file); dError("failed to read %s since id not found", pMgmt->file);
goto PRASE_MNODE_OVER; goto PRASE_MNODE_OVER;
} }
pReplica->id = atoi(id->valuestring); pReplica->id = id->valueint;
cJSON *fqdn = cJSON_GetObjectItem(node, "fqdn"); cJSON *fqdn = cJSON_GetObjectItem(node, "fqdn");
if (!fqdn || fqdn->type != cJSON_String || fqdn->valuestring == NULL) { if (!fqdn || fqdn->type != cJSON_String || fqdn->valuestring == NULL) {
...@@ -176,15 +176,15 @@ static int32_t dndReadMnodeFile(SDnode *pDnode) { ...@@ -176,15 +176,15 @@ static int32_t dndReadMnodeFile(SDnode *pDnode) {
tstrncpy(pReplica->fqdn, fqdn->valuestring, TSDB_FQDN_LEN); tstrncpy(pReplica->fqdn, fqdn->valuestring, TSDB_FQDN_LEN);
cJSON *port = cJSON_GetObjectItem(node, "port"); cJSON *port = cJSON_GetObjectItem(node, "port");
if (!port || port->type != cJSON_String || port->valuestring == NULL) { if (!port || port->type != cJSON_Number) {
dError("failed to read %s since port not found", pMgmt->file); dError("failed to read %s since port not found", pMgmt->file);
goto PRASE_MNODE_OVER; goto PRASE_MNODE_OVER;
} }
pReplica->port = atoi(port->valuestring); pReplica->port = port->valueint;
} }
code = 0; code = 0;
dInfo("succcessed to read file %s", pMgmt->file); dDebug("succcessed to read file %s, deployed:%d dropped:%d", pMgmt->file, pMgmt->deployed, pMgmt->dropped);
PRASE_MNODE_OVER: PRASE_MNODE_OVER:
if (content != NULL) free(content); if (content != NULL) free(content);
...@@ -213,15 +213,15 @@ static int32_t dndWriteMnodeFile(SDnode *pDnode) { ...@@ -213,15 +213,15 @@ static int32_t dndWriteMnodeFile(SDnode *pDnode) {
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"deployed\": \"%d\",\n", pMgmt->deployed); len += snprintf(content + len, maxLen - len, " \"deployed\": %d,\n", pMgmt->deployed);
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", pMgmt->dropped); len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pMgmt->dropped);
len += snprintf(content + len, maxLen - len, " \"nodes\": [{\n"); len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n");
for (int32_t i = 0; i < pMgmt->replica; ++i) { for (int32_t i = 0; i < pMgmt->replica; ++i) {
SReplica *pReplica = &pMgmt->replicas[i]; SReplica *pReplica = &pMgmt->replicas[i];
len += snprintf(content + len, maxLen - len, " \"id\": \"%d\",\n", pReplica->id); len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id);
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn);
len += snprintf(content + len, maxLen - len, " \"port\": \"%u\"\n", pReplica->port); len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port);
if (i < pMgmt->replica - 1) { if (i < pMgmt->replica - 1) {
len += snprintf(content + len, maxLen - len, " },{\n"); len += snprintf(content + len, maxLen - len, " },{\n");
} else { } else {
...@@ -241,7 +241,7 @@ static int32_t dndWriteMnodeFile(SDnode *pDnode) { ...@@ -241,7 +241,7 @@ static int32_t dndWriteMnodeFile(SDnode *pDnode) {
return -1; return -1;
} }
dInfo("successed to write %s", pMgmt->file); dInfo("successed to write %s, deployed:%d dropped:%d", pMgmt->file, pMgmt->deployed, pMgmt->dropped);
return 0; return 0;
} }
...@@ -289,7 +289,6 @@ static void dndStopMnodeWorker(SDnode *pDnode) { ...@@ -289,7 +289,6 @@ static void dndStopMnodeWorker(SDnode *pDnode) {
taosWLockLatch(&pMgmt->latch); taosWLockLatch(&pMgmt->latch);
pMgmt->deployed = 0; pMgmt->deployed = 0;
pMgmt->pMnode = NULL;
taosWUnLockLatch(&pMgmt->latch); taosWUnLockLatch(&pMgmt->latch);
while (pMgmt->refCount > 1) taosMsleep(10); while (pMgmt->refCount > 1) taosMsleep(10);
...@@ -332,6 +331,12 @@ static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) { ...@@ -332,6 +331,12 @@ static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) {
pOption->putMsgToApplyMsgFp = dndPutMsgIntoMnodeApplyQueue; pOption->putMsgToApplyMsgFp = dndPutMsgIntoMnodeApplyQueue;
pOption->dnodeId = dndGetDnodeId(pDnode); pOption->dnodeId = dndGetDnodeId(pDnode);
pOption->clusterId = dndGetClusterId(pDnode); pOption->clusterId = dndGetClusterId(pDnode);
pOption->sver = pDnode->opt.sver;
pOption->statusInterval = pDnode->opt.statusInterval;
pOption->mnodeEqualVnodeNum = pDnode->opt.mnodeEqualVnodeNum;
pOption->timezone = pDnode->opt.timezone;
pOption->charset = pDnode->opt.charset;
pOption->locale = pDnode->opt.locale;
} }
static void dndBuildMnodeDeployOption(SDnode *pDnode, SMnodeOpt *pOption) { static void dndBuildMnodeDeployOption(SDnode *pDnode, SMnodeOpt *pOption) {
...@@ -390,29 +395,34 @@ static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SC ...@@ -390,29 +395,34 @@ static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SC
static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) { static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) {
SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnodeMgmt *pMgmt = &pDnode->mmgmt;
int32_t code = dndStartMnodeWorker(pDnode);
if (code != 0) {
dError("failed to start mnode worker since %s", terrstr());
return code;
}
SMnode *pMnode = mndOpen(pDnode->dir.mnode, pOption); SMnode *pMnode = mndOpen(pDnode->dir.mnode, pOption);
if (pMnode == NULL) { if (pMnode == NULL) {
dError("failed to open mnode since %s", terrstr()); dError("failed to open mnode since %s", terrstr());
return -1;
}
pMgmt->deployed = 1;
int32_t code = dndWriteMnodeFile(pDnode);
if (code != 0) {
dError("failed to write mnode file since %s", terrstr());
code = terrno; code = terrno;
dndStopMnodeWorker(pDnode); pMgmt->deployed = 0;
mndClose(pMnode);
mndDestroy(pDnode->dir.mnode);
terrno = code; terrno = code;
return code; return -1;
} }
if (dndWriteMnodeFile(pDnode) != 0) { code = dndStartMnodeWorker(pDnode);
dError("failed to write mnode file since %s", terrstr()); if (code != 0) {
dError("failed to start mnode worker since %s", terrstr());
code = terrno; code = terrno;
pMgmt->deployed = 0;
dndStopMnodeWorker(pDnode); dndStopMnodeWorker(pDnode);
mndClose(pMnode); mndClose(pMnode);
mndDestroy(pDnode->dir.mnode); mndDestroy(pDnode->dir.mnode);
terrno = code; terrno = code;
return code; return -1;
} }
taosWLockLatch(&pMgmt->latch); taosWLockLatch(&pMgmt->latch);
...@@ -420,6 +430,7 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) { ...@@ -420,6 +430,7 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) {
pMgmt->deployed = 1; pMgmt->deployed = 1;
taosWUnLockLatch(&pMgmt->latch); taosWUnLockLatch(&pMgmt->latch);
dInfo("mnode open successfully");
return 0; return 0;
} }
...@@ -908,6 +919,7 @@ void dndCleanupMnode(SDnode *pDnode) { ...@@ -908,6 +919,7 @@ void dndCleanupMnode(SDnode *pDnode) {
dndStopMnodeWorker(pDnode); dndStopMnodeWorker(pDnode);
dndCleanupMnodeMgmtWorker(pDnode); dndCleanupMnodeMgmtWorker(pDnode);
tfree(pMgmt->file); tfree(pMgmt->file);
mndClose(pMgmt->pMnode);
dInfo("dnode-mnode is cleaned up"); dInfo("dnode-mnode is cleaned up");
} }
......
...@@ -58,6 +58,8 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { ...@@ -58,6 +58,8 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DNODE] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DNODE] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_MNODE] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_MNODE] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DB] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_DB] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DB] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_DROP_DB] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_USE_DB] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_USE_DB] = dndProcessMnodeWriteMsg;
...@@ -115,12 +117,12 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { ...@@ -115,12 +117,12 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP] = dndProcessMnodeWriteMsg;
// message from dnode to mnode // message from dnode to mnode
pMgmt->msgFp[TSDB_MSG_TYPE_AUTH] = dndProcessMnodeReadMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_RSP] = dndProcessDnodeRsp;
pMgmt->msgFp[TSDB_MSG_TYPE_GRANT] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_GRANT] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_GRANT_RSP] = dndProcessDnodeRsp; pMgmt->msgFp[TSDB_MSG_TYPE_GRANT_RSP] = dndProcessDnodeRsp;
pMgmt->msgFp[TSDB_MSG_TYPE_STATUS] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_STATUS] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_STATUS_RSP] = dndProcessDnodeRsp; pMgmt->msgFp[TSDB_MSG_TYPE_STATUS_RSP] = dndProcessDnodeRsp;
pMgmt->msgFp[TSDB_MSG_TYPE_AUTH] = dndProcessMnodeReadMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_AUTH_RSP] = dndProcessDnodeRsp;
} }
static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
...@@ -131,19 +133,20 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { ...@@ -131,19 +133,20 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
if (dndGetStat(pDnode) == DND_STAT_STOPPED) { if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
if (pMsg == NULL || pMsg->pCont == NULL) return; if (pMsg == NULL || pMsg->pCont == NULL) return;
dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pMsg->handle, taosMsg[msgType]); dTrace("RPC %p, rsp:%s app:%p is ignored since dnode is stopping", pMsg->handle, taosMsg[msgType], pMsg->ahandle);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
return; return;
} }
DndMsgFp fp = pMgmt->msgFp[msgType]; DndMsgFp fp = pMgmt->msgFp[msgType];
if (fp != NULL) { if (fp != NULL) {
dTrace("RPC %p, rsp:%s will be processed, code:%s", pMsg->handle, taosMsg[msgType], tstrerror(pMsg->code));
(*fp)(pDnode, pMsg, pEpSet); (*fp)(pDnode, pMsg, pEpSet);
dTrace("RPC %p, rsp:%s app:%p is processed, code:0x%0X", pMsg->handle, taosMsg[msgType], pMsg->ahandle,
pMsg->code & 0XFFFF);
} else { } else {
dError("RPC %p, rsp:%s not processed", pMsg->handle, taosMsg[msgType]); dError("RPC %p, rsp:%s app:%p not processed", pMsg->handle, taosMsg[msgType], pMsg->ahandle);
rpcFreeCont(pMsg->pCont);
} }
rpcFreeCont(pMsg->pCont);
} }
static int32_t dndInitClient(SDnode *pDnode) { static int32_t dndInitClient(SDnode *pDnode) {
...@@ -187,19 +190,19 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { ...@@ -187,19 +190,19 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
int32_t msgType = pMsg->msgType; int32_t msgType = pMsg->msgType;
if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) { if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) {
dTrace("RPC %p, network test req will be processed", pMsg->handle); dTrace("RPC %p, network test req, app:%p will be processed", pMsg->handle, pMsg->ahandle);
dndProcessDnodeReq(pDnode, pMsg, pEpSet); dndProcessDnodeReq(pDnode, pMsg, pEpSet);
return; return;
} }
if (dndGetStat(pDnode) == DND_STAT_STOPPED) { if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
dError("RPC %p, req:%s is ignored since dnode exiting", pMsg->handle, taosMsg[msgType]); dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, taosMsg[msgType], pMsg->ahandle);
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_EXITING}; SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_EXITING};
rpcSendResponse(&rspMsg); rpcSendResponse(&rspMsg);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
return; return;
} else if (dndGetStat(pDnode) != DND_STAT_RUNNING) { } else if (dndGetStat(pDnode) != DND_STAT_RUNNING) {
dError("RPC %p, req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]); dError("RPC %p, req:%s app:%p is ignored since dnode not running", pMsg->handle, taosMsg[msgType], pMsg->ahandle);
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY}; SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY};
rpcSendResponse(&rspMsg); rpcSendResponse(&rspMsg);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
...@@ -207,7 +210,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { ...@@ -207,7 +210,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
} }
if (pMsg->pCont == NULL) { if (pMsg->pCont == NULL) {
dTrace("RPC %p, req:%s not processed since content is null", pMsg->handle, taosMsg[msgType]); dTrace("RPC %p, req:%s app:%p not processed since content is null", pMsg->handle, taosMsg[msgType], pMsg->ahandle);
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN}; SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN};
rpcSendResponse(&rspMsg); rpcSendResponse(&rspMsg);
return; return;
...@@ -215,10 +218,10 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { ...@@ -215,10 +218,10 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
DndMsgFp fp = pMgmt->msgFp[msgType]; DndMsgFp fp = pMgmt->msgFp[msgType];
if (fp != NULL) { if (fp != NULL) {
dTrace("RPC %p, req:%s will be processed", pMsg->handle, taosMsg[msgType]); dTrace("RPC %p, req:%s app:%p will be processed", pMsg->handle, taosMsg[msgType], pMsg->ahandle);
(*fp)(pDnode, pMsg, pEpSet); (*fp)(pDnode, pMsg, pEpSet);
} else { } else {
dError("RPC %p, req:%s is not processed", pMsg->handle, taosMsg[msgType]); dError("RPC %p, req:%s app:%p is not processed since no handle", pMsg->handle, taosMsg[msgType], pMsg->ahandle);
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED}; SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED};
rpcSendResponse(&rspMsg); rpcSendResponse(&rspMsg);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
......
...@@ -38,7 +38,7 @@ typedef struct { ...@@ -38,7 +38,7 @@ typedef struct {
int32_t threadIndex; int32_t threadIndex;
pthread_t *pThreadId; pthread_t *pThreadId;
SVnodeObj *pVnodes; SVnodeObj *pVnodes;
SDnode *pDnode; SDnode * pDnode;
} SVnodeThread; } SVnodeThread;
static int32_t dndInitVnodeReadWorker(SDnode *pDnode); static int32_t dndInitVnodeReadWorker(SDnode *pDnode);
...@@ -73,7 +73,7 @@ void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEp ...@@ -73,7 +73,7 @@ void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEp
void dndProcessVnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); void dndProcessVnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SVnodeMsg *pMsg); static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SVnodeMsg *pMsg);
static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId); static SVnodeObj * dndAcquireVnode(SDnode *pDnode, int32_t vgId);
static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode); static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode);
static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, SVnode *pImpl); static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, SVnode *pImpl);
static void dndDropVnodeWrapper(SDnode *pDnode, SVnodeObj *pVnode); static void dndDropVnodeWrapper(SDnode *pDnode, SVnodeObj *pVnode);
...@@ -95,7 +95,7 @@ static int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg); ...@@ -95,7 +95,7 @@ static int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId) { static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId) {
SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodesMgmt *pMgmt = &pDnode->vmgmt;
SVnodeObj *pVnode = NULL; SVnodeObj * pVnode = NULL;
int32_t refCount = 0; int32_t refCount = 0;
taosRLockLatch(&pMgmt->latch); taosRLockLatch(&pMgmt->latch);
...@@ -128,7 +128,7 @@ static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode) { ...@@ -128,7 +128,7 @@ static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode) {
static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, SVnode *pImpl) { static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, SVnode *pImpl) {
SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodesMgmt *pMgmt = &pDnode->vmgmt;
SVnodeObj *pVnode = calloc(1, sizeof(SVnodeObj)); SVnodeObj * pVnode = calloc(1, sizeof(SVnodeObj));
if (pVnode == NULL) { if (pVnode == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
...@@ -208,7 +208,7 @@ static SVnodeObj **dndGetVnodesFromHash(SDnode *pDnode, int32_t *numOfVnodes) { ...@@ -208,7 +208,7 @@ static SVnodeObj **dndGetVnodesFromHash(SDnode *pDnode, int32_t *numOfVnodes) {
void *pIter = taosHashIterate(pMgmt->hash, NULL); void *pIter = taosHashIterate(pMgmt->hash, NULL);
while (pIter) { while (pIter) {
SVnodeObj **ppVnode = pIter; SVnodeObj **ppVnode = pIter;
SVnodeObj *pVnode = *ppVnode; SVnodeObj * pVnode = *ppVnode;
if (pVnode) { if (pVnode) {
num++; num++;
if (num < size) { if (num < size) {
...@@ -230,9 +230,9 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_ ...@@ -230,9 +230,9 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_
int32_t code = TSDB_CODE_DND_VNODE_READ_FILE_ERROR; int32_t code = TSDB_CODE_DND_VNODE_READ_FILE_ERROR;
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 30000; int32_t maxLen = 30000;
char *content = calloc(1, maxLen + 1); char * content = calloc(1, maxLen + 1);
cJSON *root = NULL; cJSON * root = NULL;
FILE *fp = NULL; FILE * fp = NULL;
char file[PATH_MAX + 20] = {0}; char file[PATH_MAX + 20] = {0};
SVnodeObj *pVnodes = NULL; SVnodeObj *pVnodes = NULL;
...@@ -277,7 +277,7 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_ ...@@ -277,7 +277,7 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_
} }
for (int32_t i = 0; i < vnodesNum; ++i) { for (int32_t i = 0; i < vnodesNum; ++i) {
cJSON *vnode = cJSON_GetArrayItem(vnodes, i); cJSON * vnode = cJSON_GetArrayItem(vnodes, i);
SVnodeObj *pVnode = &pVnodes[i]; SVnodeObj *pVnode = &pVnodes[i];
cJSON *vgId = cJSON_GetObjectItem(vnode, "vgId"); cJSON *vgId = cJSON_GetObjectItem(vnode, "vgId");
...@@ -321,7 +321,7 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode) { ...@@ -321,7 +321,7 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode) {
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 30000; int32_t maxLen = 30000;
char *content = calloc(1, maxLen + 1); char * content = calloc(1, maxLen + 1);
int32_t numOfVnodes = 0; int32_t numOfVnodes = 0;
SVnodeObj **pVnodes = dndGetVnodesFromHash(pDnode, &numOfVnodes); SVnodeObj **pVnodes = dndGetVnodesFromHash(pDnode, &numOfVnodes);
...@@ -403,8 +403,8 @@ static int32_t dndDropVnode(SDnode *pDnode, SVnodeObj *pVnode) { ...@@ -403,8 +403,8 @@ static int32_t dndDropVnode(SDnode *pDnode, SVnodeObj *pVnode) {
static void *dnodeOpenVnodeFunc(void *param) { static void *dnodeOpenVnodeFunc(void *param) {
SVnodeThread *pThread = param; SVnodeThread *pThread = param;
SDnode *pDnode = pThread->pDnode; SDnode * pDnode = pThread->pDnode;
SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodesMgmt * pMgmt = &pDnode->vmgmt;
dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum); dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
setThreadName("open-vnodes"); setThreadName("open-vnodes");
...@@ -527,6 +527,7 @@ static int32_t dndParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg ...@@ -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 ...@@ -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;
} }
...@@ -738,7 +740,7 @@ static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SVnodeMsg *pMsg) { ...@@ -738,7 +740,7 @@ static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SVnodeMsg *pMsg) {
static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) { static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) {
SVnodeMsg *pMsg = vnodeInitMsg(numOfMsgs); SVnodeMsg *pMsg = vnodeInitMsg(numOfMsgs);
SRpcMsg *pRpcMsg = NULL; SRpcMsg * pRpcMsg = NULL;
for (int32_t i = 0; i < numOfMsgs; ++i) { for (int32_t i = 0; i < numOfMsgs; ++i) {
taosGetQitem(qall, (void **)&pRpcMsg); taosGetQitem(qall, (void **)&pRpcMsg);
...@@ -895,6 +897,7 @@ static int32_t dndInitVnodeMgmtWorker(SDnode *pDnode) { ...@@ -895,6 +897,7 @@ static int32_t dndInitVnodeMgmtWorker(SDnode *pDnode) {
return -1; return -1;
} }
dDebug("vnode mgmt worker is initialized");
return 0; return 0;
} }
...@@ -903,6 +906,7 @@ static void dndCleanupVnodeMgmtWorker(SDnode *pDnode) { ...@@ -903,6 +906,7 @@ static void dndCleanupVnodeMgmtWorker(SDnode *pDnode) {
tWorkerFreeQueue(&pMgmt->mgmtPool, pMgmt->pMgmtQ); tWorkerFreeQueue(&pMgmt->mgmtPool, pMgmt->pMgmtQ);
tWorkerCleanup(&pMgmt->mgmtPool); tWorkerCleanup(&pMgmt->mgmtPool);
pMgmt->pMgmtQ = NULL; pMgmt->pMgmtQ = NULL;
dDebug("vnode mgmt worker is closed");
} }
static int32_t dndAllocVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode) { static int32_t dndAllocVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode) {
...@@ -963,6 +967,7 @@ static int32_t dndInitVnodeReadWorker(SDnode *pDnode) { ...@@ -963,6 +967,7 @@ static int32_t dndInitVnodeReadWorker(SDnode *pDnode) {
return -1; return -1;
} }
dDebug("vnode read worker is initialized");
return 0; return 0;
} }
...@@ -970,6 +975,7 @@ static void dndCleanupVnodeReadWorker(SDnode *pDnode) { ...@@ -970,6 +975,7 @@ static void dndCleanupVnodeReadWorker(SDnode *pDnode) {
SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodesMgmt *pMgmt = &pDnode->vmgmt;
tWorkerCleanup(&pMgmt->fetchPool); tWorkerCleanup(&pMgmt->fetchPool);
tWorkerCleanup(&pMgmt->queryPool); tWorkerCleanup(&pMgmt->queryPool);
dDebug("vnode close worker is initialized");
} }
static int32_t dndAllocVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode) { static int32_t dndAllocVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode) {
...@@ -1007,7 +1013,7 @@ static void dndFreeVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode) { ...@@ -1007,7 +1013,7 @@ static void dndFreeVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode) {
} }
static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) { static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) {
SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodesMgmt * pMgmt = &pDnode->vmgmt;
SMWorkerPool *pPool = &pMgmt->writePool; SMWorkerPool *pPool = &pMgmt->writePool;
pPool->name = "vnode-write"; pPool->name = "vnode-write";
pPool->max = tsNumOfCores; pPool->max = tsNumOfCores;
...@@ -1016,12 +1022,14 @@ static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) { ...@@ -1016,12 +1022,14 @@ static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) {
return -1; return -1;
} }
dDebug("vnode write worker is initialized");
return 0; return 0;
} }
static void dndCleanupVnodeWriteWorker(SDnode *pDnode) { static void dndCleanupVnodeWriteWorker(SDnode *pDnode) {
SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodesMgmt *pMgmt = &pDnode->vmgmt;
tMWorkerCleanup(&pMgmt->writePool); tMWorkerCleanup(&pMgmt->writePool);
dDebug("vnode write worker is closed");
} }
static int32_t dndAllocVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) { static int32_t dndAllocVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) {
...@@ -1046,7 +1054,7 @@ static int32_t dndInitVnodeSyncWorker(SDnode *pDnode) { ...@@ -1046,7 +1054,7 @@ static int32_t dndInitVnodeSyncWorker(SDnode *pDnode) {
if (maxThreads < 1) maxThreads = 1; if (maxThreads < 1) maxThreads = 1;
SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodesMgmt *pMgmt = &pDnode->vmgmt;
SMWorkerPool *pPool = &pMgmt->writePool; SMWorkerPool *pPool = &pMgmt->syncPool;
pPool->name = "vnode-sync"; pPool->name = "vnode-sync";
pPool->max = maxThreads; pPool->max = maxThreads;
if (tMWorkerInit(pPool) != 0) { if (tMWorkerInit(pPool) != 0) {
...@@ -1054,12 +1062,14 @@ static int32_t dndInitVnodeSyncWorker(SDnode *pDnode) { ...@@ -1054,12 +1062,14 @@ static int32_t dndInitVnodeSyncWorker(SDnode *pDnode) {
return -1; return -1;
} }
dDebug("vnode sync worker is initialized");
return 0; return 0;
} }
static void dndCleanupVnodeSyncWorker(SDnode *pDnode) { static void dndCleanupVnodeSyncWorker(SDnode *pDnode) {
SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodesMgmt *pMgmt = &pDnode->vmgmt;
tMWorkerCleanup(&pMgmt->syncPool); tMWorkerCleanup(&pMgmt->syncPool);
dDebug("vnode sync worker is closed");
} }
int32_t dndInitVnodes(SDnode *pDnode) { int32_t dndInitVnodes(SDnode *pDnode) {
...@@ -1111,12 +1121,12 @@ void dndGetVnodeLoads(SDnode *pDnode, SVnodeLoads *pLoads) { ...@@ -1111,12 +1121,12 @@ void dndGetVnodeLoads(SDnode *pDnode, SVnodeLoads *pLoads) {
pLoads->num = taosHashGetSize(pMgmt->hash); pLoads->num = taosHashGetSize(pMgmt->hash);
int32_t v = 0; int32_t v = 0;
void *pIter = taosHashIterate(pMgmt->hash, NULL); void * pIter = taosHashIterate(pMgmt->hash, NULL);
while (pIter) { while (pIter) {
SVnodeObj **ppVnode = pIter; SVnodeObj **ppVnode = pIter;
if (ppVnode == NULL || *ppVnode == NULL) continue; if (ppVnode == NULL || *ppVnode == NULL) continue;
SVnodeObj *pVnode = *ppVnode; SVnodeObj * pVnode = *ppVnode;
SVnodeLoad *pLoad = &pLoads->data[v++]; SVnodeLoad *pLoad = &pLoads->data[v++];
vnodeGetLoad(pVnode->pImpl, pLoad); vnodeGetLoad(pVnode->pImpl, pLoad);
......
...@@ -10,4 +10,5 @@ target_link_libraries( ...@@ -10,4 +10,5 @@ target_link_libraries(
PRIVATE sdb PRIVATE sdb
PRIVATE transport PRIVATE transport
PRIVATE cjson PRIVATE cjson
PRIVATE sync
) )
\ No newline at end of file
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "thash.h" #include "thash.h"
#include "cJSON.h" #include "cJSON.h"
#include "mnode.h" #include "mnode.h"
#include "sync.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -78,6 +79,28 @@ typedef enum { ...@@ -78,6 +79,28 @@ typedef enum {
typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy; typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;
typedef enum {
DND_STATUS_OFFLINE = 0,
DND_STATUS_READY = 1,
DND_STATUS_CREATING = 2,
DND_STATUS_DROPPING = 3
} EDndStatus;
typedef enum {
DND_REASON_ONLINE = 0,
DND_REASON_STATUS_MSG_TIMEOUT,
DND_REASON_STATUS_NOT_RECEIVED,
DND_REASON_VERSION_NOT_MATCH,
DND_REASON_DNODE_ID_NOT_MATCH,
DND_REASON_CLUSTER_ID_NOT_MATCH,
DND_REASON_MN_EQUAL_VN_NOT_MATCH,
DND_REASON_STATUS_INTERVAL_NOT_MATCH,
DND_REASON_TIME_ZONE_NOT_MATCH,
DND_REASON_LOCALE_NOT_MATCH,
DND_REASON_CHARSET_NOT_MATCH,
DND_REASON_OTHERS
} EDndReason;
typedef struct STrans { typedef struct STrans {
int32_t id; int32_t id;
ETrnStage stage; ETrnStage stage;
...@@ -92,7 +115,7 @@ typedef struct STrans { ...@@ -92,7 +115,7 @@ typedef struct STrans {
} STrans; } STrans;
typedef struct SClusterObj { typedef struct SClusterObj {
int64_t id; int32_t id;
char uid[TSDB_CLUSTER_ID_LEN]; char uid[TSDB_CLUSTER_ID_LEN];
int64_t createdTime; int64_t createdTime;
int64_t updateTime; int64_t updateTime;
...@@ -100,28 +123,31 @@ typedef struct SClusterObj { ...@@ -100,28 +123,31 @@ typedef struct SClusterObj {
typedef struct SDnodeObj { typedef struct SDnodeObj {
int32_t id; int32_t id;
int32_t vnodes;
int64_t createdTime; int64_t createdTime;
int64_t updateTime; int64_t updateTime;
int64_t lastAccess; int64_t rebootTime;
int64_t rebootTime; // time stamp for last reboot int32_t accessTimes;
int16_t numOfMnodes;
int16_t numOfVnodes;
int16_t numOfQnodes;
int16_t numOfSupportMnodes;
int16_t numOfSupportVnodes;
int16_t numOfSupportQnodes;
int16_t numOfCores;
EDndStatus status;
EDndReason offlineReason;
uint16_t port;
char fqdn[TSDB_FQDN_LEN]; char fqdn[TSDB_FQDN_LEN];
char ep[TSDB_EP_LEN]; char ep[TSDB_EP_LEN];
uint16_t port;
int16_t numOfCores; // from dnode status msg
int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode
int8_t status; // set in balance function
int8_t offlineReason;
} SDnodeObj; } SDnodeObj;
typedef struct SMnodeObj { typedef struct SMnodeObj {
int32_t id; int32_t id;
int8_t status;
int8_t role;
int32_t roleTerm;
int64_t roleTime;
int64_t createdTime; int64_t createdTime;
int64_t updateTime; int64_t updateTime;
ESyncState role;
int32_t roleTerm;
int64_t roleTime;
SDnodeObj *pDnode; SDnodeObj *pDnode;
} SMnodeObj; } SMnodeObj;
...@@ -273,25 +299,18 @@ typedef struct { ...@@ -273,25 +299,18 @@ typedef struct {
char payload[]; char payload[];
} SShowObj; } SShowObj;
typedef struct {
int32_t len;
void *rsp;
} SMnodeRsp;
typedef struct SMnodeMsg { typedef struct SMnodeMsg {
char user[TSDB_USER_LEN];
SMnode *pMnode; SMnode *pMnode;
void (*fp)(SMnodeMsg *pMsg, int32_t code);
SRpcConnInfo conn;
SUserObj *pUser;
int16_t received; int16_t received;
int16_t successed; int16_t successed;
int16_t expected; int16_t expected;
int16_t retry; int16_t retry;
int32_t code; int32_t code;
int64_t createdTime; int64_t createdTime;
SMnodeRsp rpcRsp;
SRpcMsg rpcMsg; SRpcMsg rpcMsg;
char pCont[]; int32_t contLen;
void *pCont;
} SMnodeMsg; } SMnodeMsg;
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -24,6 +24,8 @@ extern "C" { ...@@ -24,6 +24,8 @@ extern "C" {
int32_t mndInitDnode(SMnode *pMnode); int32_t mndInitDnode(SMnode *pMnode);
void mndCleanupDnode(SMnode *pMnode); void mndCleanupDnode(SMnode *pMnode);
SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId);
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -36,7 +36,7 @@ typedef struct { ...@@ -36,7 +36,7 @@ typedef struct {
typedef struct SMnode { typedef struct SMnode {
int32_t dnodeId; int32_t dnodeId;
int64_t clusterId; int32_t clusterId;
int8_t replica; int8_t replica;
int8_t selfIndex; int8_t selfIndex;
SReplica replicas[TSDB_MAX_REPLICA]; SReplica replicas[TSDB_MAX_REPLICA];
...@@ -50,12 +50,14 @@ typedef struct SMnode { ...@@ -50,12 +50,14 @@ typedef struct SMnode {
SendMsgToMnodeFp sendMsgToMnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp;
SendRedirectMsgFp sendRedirectMsgFp; SendRedirectMsgFp sendRedirectMsgFp;
PutMsgToMnodeQFp putMsgToApplyMsgFp; PutMsgToMnodeQFp putMsgToApplyMsgFp;
int32_t sver;
int32_t statusInterval;
int32_t mnodeEqualVnodeNum;
char *timezone;
char *locale;
char *charset;
} SMnode; } SMnode;
tmr_h mndGetTimer(SMnode *pMnode);
int32_t mndGetDnodeId(SMnode *pMnode);
int64_t mndGetClusterId(SMnode *pMnode);
void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg);
void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg); void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg);
void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg); void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg);
......
...@@ -24,8 +24,7 @@ extern "C" { ...@@ -24,8 +24,7 @@ extern "C" {
int32_t mndInitMnode(SMnode *pMnode); int32_t mndInitMnode(SMnode *pMnode);
void mndCleanupMnode(SMnode *pMnode); void mndCleanupMnode(SMnode *pMnode);
void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect); bool mndIsMnode(SMnode *pMnode, int32_t dnodeId);
void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -13,8 +13,8 @@ ...@@ -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_TRANSACTION_INT_H_ #ifndef _TD_MND_TRANS_H_
#define _TD_TRANSACTION_INT_H_ #define _TD_MND_TRANS_H_
#include "mndInt.h" #include "mndInt.h"
...@@ -44,4 +44,4 @@ SSdbRow *mndTransActionDecode(SSdbRaw *pRaw); ...@@ -44,4 +44,4 @@ SSdbRow *mndTransActionDecode(SSdbRaw *pRaw);
} }
#endif #endif
#endif /*_TD_TRANSACTION_INT_H_*/ #endif /*_TD_MND_TRANS_H_*/
...@@ -24,6 +24,8 @@ extern "C" { ...@@ -24,6 +24,8 @@ extern "C" {
int32_t mndInitUser(SMnode *pMnode); int32_t mndInitUser(SMnode *pMnode);
void mndCleanupUser(SMnode *pMnode); void mndCleanupUser(SMnode *pMnode);
SUserObj *mndAcquireUser(SMnode *pMnode, const char *userName);
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -44,6 +44,7 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) { ...@@ -44,6 +44,7 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
if (sver != SDB_ACCT_VER) { if (sver != SDB_ACCT_VER) {
mError("failed to decode acct since %s", terrstr());
terrno = TSDB_CODE_SDB_INVALID_DATA_VER; terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
return NULL; return NULL;
} }
...@@ -68,18 +69,30 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) { ...@@ -68,18 +69,30 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
return pRow; return pRow;
} }
static int32_t mnodeAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) { return 0; } static int32_t mnodeAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) {
mTrace("acct:%s, perform insert action", pAcct->acct);
memset(&pAcct->info, 0, sizeof(SAcctInfo));
return 0;
}
static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { return 0; } static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
mTrace("acct:%s, perform delete action", pAcct->acct);
return 0;
}
static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pSrcAcct, SAcctObj *pDstAcct) { static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pSrcAcct, SAcctObj *pDstAcct) {
SAcctObj tObj; mTrace("acct:%s, perform update action", pSrcAcct->acct);
int32_t len = (int32_t)((int8_t *)&tObj.info - (int8_t *)&tObj);
memcpy(pDstAcct, pSrcAcct, len); memcpy(pSrcAcct->acct, pDstAcct->acct, TSDB_USER_LEN);
pSrcAcct->createdTime = pDstAcct->createdTime;
pSrcAcct->updateTime = pDstAcct->updateTime;
pSrcAcct->acctId = pDstAcct->acctId;
pSrcAcct->status = pDstAcct->status;
pSrcAcct->cfg = pDstAcct->cfg;
return 0; return 0;
} }
static int32_t mnodeCreateDefaultAcct(SSdb *pSdb) { static int32_t mnodeCreateDefaultAcct(SMnode *pMnode) {
int32_t code = 0; int32_t code = 0;
SAcctObj acctObj = {0}; SAcctObj acctObj = {0};
...@@ -98,7 +111,8 @@ static int32_t mnodeCreateDefaultAcct(SSdb *pSdb) { ...@@ -98,7 +111,8 @@ static int32_t mnodeCreateDefaultAcct(SSdb *pSdb) {
if (pRaw == NULL) return -1; if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY); sdbSetRawStatus(pRaw, SDB_STATUS_READY);
return sdbWrite(pSdb, pRaw); mTrace("acct:%s, will be created while deploy sdb", acctObj.acct);
return sdbWrite(pMnode->pSdb, pRaw);
} }
int32_t mndInitAcct(SMnode *pMnode) { int32_t mndInitAcct(SMnode *pMnode) {
......
...@@ -14,8 +14,97 @@ ...@@ -14,8 +14,97 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "mndCluster.h"
#include "mndInt.h" #include "mndTrans.h"
#define SDB_CLUSTER_VER 1
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, SDB_CLUSTER_VER, sizeof(SClusterObj));
if (pRaw == NULL) return NULL;
int32_t dataPos = 0;
SDB_SET_INT32(pRaw, dataPos, pCluster->id);
SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime)
SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime)
SDB_SET_BINARY(pRaw, dataPos, pCluster->uid, TSDB_CLUSTER_ID_LEN)
return pRaw;
}
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
int8_t sver = 0;
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
if (sver != SDB_CLUSTER_VER) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
mError("failed to decode cluster since %s", terrstr());
return NULL;
}
SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj));
SClusterObj *pCluster = sdbGetRowObj(pRow);
if (pCluster == NULL) return NULL;
int32_t dataPos = 0;
SDB_GET_INT32(pRaw, pRow, dataPos, &pCluster->id)
SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->createdTime)
SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->updateTime)
SDB_GET_BINARY(pRaw, pRow, dataPos, pCluster->uid, TSDB_CLUSTER_ID_LEN)
return pRow;
}
static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster) {
mTrace("cluster:%d, perform insert action", pCluster->id);
return 0;
}
static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) {
mTrace("cluster:%d, perform delete action", pCluster->id);
return 0;
}
static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pSrcCluster, SClusterObj *pDstCluster) {
mTrace("cluster:%d, perform update action", pSrcCluster->id);
return 0;
}
static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
SClusterObj clusterObj = {0};
clusterObj.createdTime = taosGetTimestampMs();
clusterObj.updateTime = clusterObj.createdTime;
int32_t code = taosGetSystemUid(clusterObj.uid, TSDB_CLUSTER_ID_LEN);
if (code != 0) {
strcpy(clusterObj.uid, "tdengine2.0");
mError("failed to get uid from system, set to default val %s", clusterObj.uid);
} else {
mDebug("cluster:%d, uid is %s", clusterObj.id, clusterObj.uid);
}
clusterObj.id = MurmurHash3_32(clusterObj.uid, TSDB_CLUSTER_ID_LEN);
clusterObj.id = abs(clusterObj.id);
pMnode->clusterId = clusterObj.id;
SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj);
if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
mTrace("cluster:%d, will be created while deploy sdb", clusterObj.id);
return sdbWrite(pMnode->pSdb, pRaw);
}
int32_t mndInitCluster(SMnode *pMnode) {
SSdbTable table = {.sdbType = SDB_CLUSTER,
.keyType = SDB_KEY_INT32,
.deployFp = (SdbDeployFp)mndCreateDefaultCluster,
.encodeFp = (SdbEncodeFp)mndClusterActionEncode,
.decodeFp = (SdbDecodeFp)mndClusterActionDecode,
.insertFp = (SdbInsertFp)mndClusterActionInsert,
.updateFp = (SdbUpdateFp)mndClusterActionUpdate,
.deleteFp = (SdbDeleteFp)mndClusterActionDelete};
return sdbSetTable(pMnode->pSdb, table);
}
int32_t mndInitCluster(SMnode *pMnode) { return 0; }
void mndCleanupCluster(SMnode *pMnode) {} void mndCleanupCluster(SMnode *pMnode) {}
...@@ -14,8 +14,339 @@ ...@@ -14,8 +14,339 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "mndDnode.h"
#include "mndInt.h" #include "mndMnode.h"
#include "mndTrans.h"
#include "ttime.h"
#define SDB_DNODE_VER 1
static char *offlineReason[] = {
"",
"status msg timeout",
"status not received",
"version not match",
"dnodeId not match",
"clusterId not match",
"mnEqualVn not match",
"interval not match",
"timezone not match",
"locale not match",
"charset not match",
"unknown",
};
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, SDB_DNODE_VER, sizeof(SDnodeObj));
if (pRaw == NULL) return NULL;
int32_t dataPos = 0;
SDB_SET_INT32(pRaw, dataPos, pDnode->id);
SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime)
SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime)
SDB_SET_INT16(pRaw, dataPos, pDnode->port)
SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN)
SDB_SET_DATALEN(pRaw, dataPos);
return pRaw;
}
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
int8_t sver = 0;
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
if (sver != SDB_DNODE_VER) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
mError("failed to decode dnode since %s", terrstr());
return NULL;
}
SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj));
SDnodeObj *pDnode = sdbGetRowObj(pRow);
if (pDnode == NULL) return NULL;
int32_t dataPos = 0;
SDB_GET_INT32(pRaw, pRow, dataPos, &pDnode->id)
SDB_GET_INT64(pRaw, pRow, dataPos, &pDnode->createdTime)
SDB_GET_INT64(pRaw, pRow, dataPos, &pDnode->updateTime)
SDB_GET_INT16(pRaw, pRow, dataPos, &pDnode->port)
SDB_GET_BINARY(pRaw, pRow, dataPos, pDnode->fqdn, TSDB_FQDN_LEN)
return pRow;
}
static void mnodeResetDnode(SDnodeObj *pDnode) {
pDnode->rebootTime = 0;
pDnode->accessTimes = 0;
pDnode->numOfCores = 0;
pDnode->numOfMnodes = 0;
pDnode->numOfVnodes = 0;
pDnode->numOfQnodes = 0;
pDnode->numOfSupportMnodes = 0;
pDnode->numOfSupportVnodes = 0;
pDnode->numOfSupportQnodes = 0;
pDnode->status = DND_STATUS_OFFLINE;
pDnode->offlineReason = DND_REASON_STATUS_NOT_RECEIVED;
snprintf(pDnode->ep, TSDB_EP_LEN, "%s:%u", pDnode->fqdn, pDnode->port);
}
static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode) {
mTrace("dnode:%d, perform insert action", pDnode->id);
mnodeResetDnode(pDnode);
return 0;
}
static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
mTrace("dnode:%d, perform delete action", pDnode->id);
return 0;
}
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pSrcDnode, SDnodeObj *pDstDnode) {
mTrace("dnode:%d, perform update action", pSrcDnode->id);
pSrcDnode->id = pDstDnode->id;
pSrcDnode->createdTime = pDstDnode->createdTime;
pSrcDnode->updateTime = pDstDnode->updateTime;
pSrcDnode->port = pDstDnode->port;
memcpy(pSrcDnode->fqdn, pDstDnode->fqdn, TSDB_FQDN_LEN);
return 0;
}
static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
SDnodeObj dnodeObj = {0};
dnodeObj.id = 1;
dnodeObj.createdTime = taosGetTimestampMs();
dnodeObj.updateTime = dnodeObj.createdTime;
dnodeObj.port = pMnode->replicas[0].port;
memcpy(&dnodeObj.fqdn, pMnode->replicas[0].fqdn, TSDB_FQDN_LEN);
SSdbRaw *pRaw = mndDnodeActionEncode(&dnodeObj);
if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
mTrace("dnode:%d, will be created while deploy sdb", dnodeObj.id);
return sdbWrite(pMnode->pSdb, pRaw);
}
static SDnodeObj *mndAcquireDnodeByEp(SMnode *pMnode, char *pEpStr) {
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
while (1) {
SDnodeObj *pDnode = NULL;
pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
if (pIter == NULL) break;
if (strncasecmp(pEpStr, pDnode->ep, TSDB_EP_LEN) == 0) {
sdbCancelFetch(pSdb, pIter);
return pDnode;
}
}
return NULL;
}
static int32_t mndGetDnodeSize(SMnode *pMnode) {
SSdb *pSdb = pMnode->pSdb;
return sdbGetSize(pSdb, SDB_DNODE);
}
static void mndGetDnodeData(SMnode *pMnode, SDnodeEps *pEps, int32_t numOfEps) {
SSdb *pSdb = pMnode->pSdb;
int32_t i = 0;
void *pIter = NULL;
while (1) {
SDnodeObj *pDnode = NULL;
pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
if (pIter == NULL) break;
if (i >= numOfEps) {
sdbCancelFetch(pSdb, pIter);
break;
}
SDnodeEp *pEp = &pEps->eps[i];
pEp->id = htonl(pDnode->id);
pEp->port = htons(pDnode->port);
memcpy(pEp->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
pEp->isMnode = 0;
if (mndIsMnode(pMnode, pDnode->id)) {
pEp->isMnode = 1;
}
i++;
}
pEps->num = htonl(i);
}
static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
if (pCfg->mnodeEqualVnodeNum != pMnode->mnodeEqualVnodeNum) {
mError("\"mnodeEqualVnodeNum\"[%d - %d] cfg inconsistent", pCfg->mnodeEqualVnodeNum, pMnode->mnodeEqualVnodeNum);
return DND_REASON_MN_EQUAL_VN_NOT_MATCH;
}
if (pCfg->statusInterval != pMnode->statusInterval) {
mError("\"statusInterval\"[%d - %d] cfg inconsistent", pCfg->statusInterval, pMnode->statusInterval);
return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
}
int64_t checkTime = 0;
char timestr[32] = "1970-01-01 00:00:00.00";
(void)taosParseTime(timestr, &checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
if ((0 != strcasecmp(pCfg->timezone, pMnode->timezone)) && (checkTime != pCfg->checkTime)) {
mError("\"timezone\"[%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezone,
pCfg->checkTime, checkTime);
return DND_REASON_TIME_ZONE_NOT_MATCH;
}
if (0 != strcasecmp(pCfg->locale, pMnode->locale)) {
mError("\"locale\"[%s - %s] cfg parameters inconsistent", pCfg->locale, pMnode->locale);
return DND_REASON_LOCALE_NOT_MATCH;
}
if (0 != strcasecmp(pCfg->charset, pMnode->charset)) {
mError("\"charset\"[%s - %s] cfg parameters inconsistent.", pCfg->charset, pMnode->charset);
return DND_REASON_CHARSET_NOT_MATCH;
}
return 0;
}
static void mndParseStatusMsg(SStatusMsg *pStatus) {
pStatus->sver = htonl(pStatus->sver);
pStatus->dnodeId = htonl(pStatus->dnodeId);
pStatus->clusterId = htonl(pStatus->clusterId);
pStatus->rebootTime = htonl(pStatus->rebootTime);
pStatus->numOfCores = htons(pStatus->numOfCores);
pStatus->numOfSupportMnodes = htons(pStatus->numOfSupportMnodes);
pStatus->numOfSupportVnodes = htons(pStatus->numOfSupportVnodes);
pStatus->numOfSupportQnodes = htons(pStatus->numOfSupportQnodes);
pStatus->clusterCfg.statusInterval = htonl(pStatus->clusterCfg.statusInterval);
pStatus->clusterCfg.mnodeEqualVnodeNum = htonl(pStatus->clusterCfg.mnodeEqualVnodeNum);
pStatus->clusterCfg.checkTime = htobe64(pStatus->clusterCfg.checkTime);
}
static int32_t mndProcessStatusMsg(SMnode *pMnode, SMnodeMsg *pMsg) {
SStatusMsg *pStatus = pMsg->rpcMsg.pCont;
mndParseStatusMsg(pStatus);
SDnodeObj *pDnode = NULL;
if (pStatus->dnodeId == 0) {
pDnode = mndAcquireDnodeByEp(pMnode, pStatus->dnodeEp);
if (pDnode == NULL) {
mDebug("dnode:%s, not created yet", pStatus->dnodeEp);
return TSDB_CODE_MND_DNODE_NOT_EXIST;
}
} else {
pDnode = mndAcquireDnode(pMnode, pStatus->dnodeId);
if (pDnode == NULL) {
pDnode = mndAcquireDnodeByEp(pMnode, pStatus->dnodeEp);
if (pDnode != NULL && pDnode->status != DND_STATUS_READY) {
pDnode->offlineReason = DND_REASON_DNODE_ID_NOT_MATCH;
}
mError("dnode:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp);
mndReleaseDnode(pMnode, pDnode);
return TSDB_CODE_MND_DNODE_NOT_EXIST;
}
}
if (pStatus->sver != pMnode->sver) {
if (pDnode != NULL && pDnode->status != DND_STATUS_READY) {
pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH;
}
mndReleaseDnode(pMnode, pDnode);
mError("dnode:%d, status msg version:%d not match cluster:%d", pStatus->dnodeId, pStatus->sver, pMnode->sver);
return TSDB_CODE_MND_INVALID_MSG_VERSION;
}
if (pStatus->dnodeId == 0) {
mDebug("dnode:%d %s, first access, set clusterId %d", pDnode->id, pDnode->ep, pMnode->clusterId);
} else {
if (pStatus->clusterId != pMnode->clusterId) {
if (pDnode != NULL && pDnode->status != DND_STATUS_READY) {
pDnode->offlineReason = DND_REASON_CLUSTER_ID_NOT_MATCH;
}
mError("dnode:%d, clusterId %d not match exist %d", pDnode->id, pStatus->clusterId, pMnode->clusterId);
mndReleaseDnode(pMnode, pDnode);
return TSDB_CODE_MND_INVALID_CLUSTER_ID;
} else {
pDnode->accessTimes++;
mTrace("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes);
}
}
if (pDnode->status == DND_STATUS_OFFLINE) {
// Verify whether the cluster parameters are consistent when status change from offline to ready
int32_t ret = mndCheckClusterCfgPara(pMnode, &pStatus->clusterCfg);
if (0 != ret) {
pDnode->offlineReason = ret;
mError("dnode:%d, cluster cfg inconsistent since:%s", pDnode->id, offlineReason[ret]);
mndReleaseDnode(pMnode, pDnode);
return TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT;
}
mInfo("dnode:%d, from offline to online", pDnode->id);
}
pDnode->rebootTime = pStatus->rebootTime;
pDnode->numOfCores = pStatus->numOfCores;
pDnode->numOfSupportMnodes = pStatus->numOfSupportMnodes;
pDnode->numOfSupportVnodes = pStatus->numOfSupportVnodes;
pDnode->numOfSupportQnodes = pStatus->numOfSupportQnodes;
pDnode->status = DND_STATUS_READY;
int32_t numOfEps = mndGetDnodeSize(pMnode);
int32_t contLen = sizeof(SStatusRsp) + numOfEps * sizeof(SDnodeEp);
SStatusRsp *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) {
mndReleaseDnode(pMnode, pDnode);
return TSDB_CODE_OUT_OF_MEMORY;
}
pRsp->dnodeCfg.dnodeId = htonl(pDnode->id);
pRsp->dnodeCfg.dropped = 0;
pRsp->dnodeCfg.clusterId = htonl(pMnode->clusterId);
mndGetDnodeData(pMnode, &pRsp->dnodeEps, numOfEps);
pMsg->contLen = contLen;
pMsg->pCont = pRsp;
mndReleaseDnode(pMnode, pDnode);
return 0;
}
static int32_t mndProcessCreateDnodeMsg(SMnode *pMnode, SMnodeMsg *pMsg) { return 0; }
static int32_t mndProcessDropDnodeMsg(SMnode *pMnode, SMnodeMsg *pMsg) { return 0; }
static int32_t mndProcessConfigDnodeMsg(SMnode *pMnode, SMnodeMsg *pMsg) { return 0; }
int32_t mndInitDnode(SMnode *pMnode) {
SSdbTable table = {.sdbType = SDB_DNODE,
.keyType = SDB_KEY_INT32,
.deployFp = (SdbDeployFp)mndCreateDefaultDnode,
.encodeFp = (SdbEncodeFp)mndDnodeActionEncode,
.decodeFp = (SdbDecodeFp)mndDnodeActionDecode,
.insertFp = (SdbInsertFp)mndDnodeActionInsert,
.updateFp = (SdbUpdateFp)mndDnodeActionUpdate,
.deleteFp = (SdbDeleteFp)mndDnodeActionDelete};
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_DNODE, mndProcessCreateDnodeMsg);
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_DNODE, mndProcessDropDnodeMsg);
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CONFIG_DNODE, mndProcessConfigDnodeMsg);
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_STATUS, mndProcessStatusMsg);
return sdbSetTable(pMnode->pSdb, table);
}
int32_t mndInitDnode(SMnode *pMnode) { return 0; }
void mndCleanupDnode(SMnode *pMnode) {} void mndCleanupDnode(SMnode *pMnode) {}
SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId) {
SSdb *pSdb = pMnode->pSdb;
return sdbAcquire(pSdb, SDB_DNODE, &dnodeId);
}
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode) {
SSdb *pSdb = pMnode->pSdb;
sdbRelease(pSdb, pDnode);
}
...@@ -14,11 +14,125 @@ ...@@ -14,11 +14,125 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "mndTrans.h"
#include "mndInt.h"
#define SDB_MNODE_VER 1
static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pMnodeObj) {
SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, SDB_MNODE_VER, sizeof(SMnodeObj));
if (pRaw == NULL) return NULL;
int32_t dataPos = 0;
SDB_SET_INT32(pRaw, dataPos, pMnodeObj->id);
SDB_SET_INT64(pRaw, dataPos, pMnodeObj->createdTime)
SDB_SET_INT64(pRaw, dataPos, pMnodeObj->updateTime)
return pRaw;
}
static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) {
int8_t sver = 0;
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
if (sver != SDB_MNODE_VER) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
mError("failed to decode mnode since %s", terrstr());
return NULL;
}
SSdbRow *pRow = sdbAllocRow(sizeof(SMnodeObj));
SMnodeObj *pMnodeObj = sdbGetRowObj(pRow);
if (pMnodeObj == NULL) return NULL;
int32_t dataPos = 0;
SDB_GET_INT32(pRaw, pRow, dataPos, &pMnodeObj->id)
SDB_GET_INT64(pRaw, pRow, dataPos, &pMnodeObj->createdTime)
SDB_GET_INT64(pRaw, pRow, dataPos, &pMnodeObj->updateTime)
return pRow;
}
static void mnodeResetMnode(SMnodeObj *pMnodeObj) {
pMnodeObj->role = TAOS_SYNC_STATE_FOLLOWER;
pMnodeObj->roleTerm = 0;
pMnodeObj->roleTime = 0;
}
static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pMnodeObj) {
mTrace("mnode:%d, perform insert action", pMnodeObj->id);
pMnodeObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pMnodeObj->id);
if (pMnodeObj->pDnode == NULL) {
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
mError("mnode:%d, failed to perform insert action since %s", pMnodeObj->id, terrstr());
return -1;
}
mnodeResetMnode(pMnodeObj);
return 0;
}
static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pMnodeObj) {
mTrace("mnode:%d, perform delete action", pMnodeObj->id);
if (pMnodeObj->pDnode != NULL) {
sdbRelease(pSdb, pMnodeObj->pDnode);
pMnodeObj->pDnode = NULL;
}
return 0;
}
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pSrcMnode, SMnodeObj *pDstMnode) {
mTrace("mnode:%d, perform update action", pSrcMnode->id);
pSrcMnode->id = pDstMnode->id;
pSrcMnode->createdTime = pDstMnode->createdTime;
pSrcMnode->updateTime = pDstMnode->updateTime;
return 0;
}
static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
SMnodeObj mnodeObj = {0};
mnodeObj.id = 1;
mnodeObj.createdTime = taosGetTimestampMs();
mnodeObj.updateTime = mnodeObj.createdTime;
SSdbRaw *pRaw = mndMnodeActionEncode(&mnodeObj);
if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
mTrace("mnode:%d, will be created while deploy sdb", mnodeObj.id);
return sdbWrite(pMnode->pSdb, pRaw);
}
static int32_t mndProcessCreateMnodeMsg(SMnode *pMnode, SMnodeMsg *pMsg) { return 0; }
static int32_t mndProcessDropMnodeMsg(SMnode *pMnode, SMnodeMsg *pMsg) { return 0; }
int32_t mndInitMnode(SMnode *pMnode) {
SSdbTable table = {.sdbType = SDB_MNODE,
.keyType = SDB_KEY_INT32,
.deployFp = (SdbDeployFp)mndCreateDefaultMnode,
.encodeFp = (SdbEncodeFp)mndMnodeActionEncode,
.decodeFp = (SdbDecodeFp)mndMnodeActionDecode,
.insertFp = (SdbInsertFp)mndMnodeActionInsert,
.updateFp = (SdbUpdateFp)mndMnodeActionUpdate,
.deleteFp = (SdbDeleteFp)mndMnodeActionDelete};
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_MNODE, mndProcessCreateMnodeMsg);
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_MNODE, mndProcessDropMnodeMsg);
return sdbSetTable(pMnode->pSdb, table);
}
int32_t mndInitMnode(SMnode *pMnode) { return 0; }
void mndCleanupMnode(SMnode *pMnode) {} void mndCleanupMnode(SMnode *pMnode) {}
void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {} bool mndIsMnode(SMnode *pMnode, int32_t dnodeId) {
void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {} SSdb *pSdb = pMnode->pSdb;
\ No newline at end of file
SMnodeObj *pMnodeObj = sdbAcquire(pSdb, SDB_MNODE, &dnodeId);
if (pMnodeObj == NULL) {
return false;
}
sdbRelease(pSdb, pMnodeObj);
return true;
}
\ No newline at end of file
...@@ -203,9 +203,9 @@ static void mndSendTelemetryReport() { ...@@ -203,9 +203,9 @@ static void mndSendTelemetryReport() {
return; return;
} }
int64_t clusterId = mndGetClusterId(NULL); int32_t clusterId = 0;
char clusterIdStr[20] = {0}; char clusterIdStr[20] = {0};
snprintf(clusterIdStr, sizeof(clusterIdStr), "%" PRId64, clusterId); snprintf(clusterIdStr, sizeof(clusterIdStr), "%d", clusterId);
SBufferWriter bw = tbufInitWriter(NULL, false); SBufferWriter bw = tbufInitWriter(NULL, false);
mndBeginObject(&bw); mndBeginObject(&bw);
......
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mndSync.h" #include "mndSync.h"
#include "tkey.h"
#include "mndTrans.h" #include "mndTrans.h"
#include "tkey.h"
#define SDB_USER_VER 1 #define SDB_USER_VER 1
static SSdbRaw *mndUserActionEncode(SUserObj *pUser) { static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, SDB_USER_VER, sizeof(SAcctObj)); SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, SDB_USER_VER, sizeof(SUserObj));
if (pRaw == NULL) return NULL; if (pRaw == NULL) return NULL;
int32_t dataPos = 0; int32_t dataPos = 0;
...@@ -41,6 +41,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { ...@@ -41,6 +41,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
if (sver != SDB_USER_VER) { if (sver != SDB_USER_VER) {
mError("failed to decode user since %s", terrstr());
terrno = TSDB_CODE_SDB_INVALID_DATA_VER; terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
return NULL; return NULL;
} }
...@@ -61,15 +62,18 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { ...@@ -61,15 +62,18 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
} }
static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) { static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
mTrace("user:%s, perform insert action", pUser->user);
pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
if (pUser->prohibitDbHash == NULL) { if (pUser->prohibitDbHash == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
mError("user:%s, failed to perform insert action since %s", pUser->user, terrstr());
return -1; return -1;
} }
pUser->pAcct = sdbAcquire(pSdb, SDB_ACCT, pUser->acct); pUser->pAcct = sdbAcquire(pSdb, SDB_ACCT, pUser->acct);
if (pUser->pAcct == NULL) { if (pUser->pAcct == NULL) {
terrno = TSDB_CODE_MND_ACCT_NOT_EXIST; terrno = TSDB_CODE_MND_ACCT_NOT_EXIST;
mError("user:%s, failed to perform insert action since %s", pUser->user, terrstr());
return -1; return -1;
} }
...@@ -77,12 +81,13 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) { ...@@ -77,12 +81,13 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
} }
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
mTrace("user:%s, perform delete action", pUser->user);
if (pUser->prohibitDbHash) { if (pUser->prohibitDbHash) {
taosHashCleanup(pUser->prohibitDbHash); taosHashCleanup(pUser->prohibitDbHash);
pUser->prohibitDbHash = NULL; pUser->prohibitDbHash = NULL;
} }
if (pUser->acct != NULL) { if (pUser->pAcct != NULL) {
sdbRelease(pSdb, pUser->pAcct); sdbRelease(pSdb, pUser->pAcct);
pUser->pAcct = NULL; pUser->pAcct = NULL;
} }
...@@ -91,13 +96,17 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { ...@@ -91,13 +96,17 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
} }
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) { static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) {
SUserObj tObj; mTrace("user:%s, perform update action", pSrcUser->user);
int32_t len = (int32_t)((int8_t *)tObj.prohibitDbHash - (int8_t *)&tObj); memcpy(pSrcUser->user, pDstUser->user, TSDB_USER_LEN);
memcpy(pDstUser, pSrcUser, len); memcpy(pSrcUser->pass, pDstUser->pass, TSDB_KEY_LEN);
memcpy(pSrcUser->acct, pDstUser->acct, TSDB_USER_LEN);
pSrcUser->createdTime = pDstUser->createdTime;
pSrcUser->updateTime = pDstUser->updateTime;
pSrcUser->rootAuth = pDstUser->rootAuth;
return 0; return 0;
} }
static int32_t mndCreateDefaultUser(SSdb *pSdb, char *acct, char *user, char *pass) { static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char *pass) {
SUserObj userObj = {0}; SUserObj userObj = {0};
tstrncpy(userObj.user, user, TSDB_USER_LEN); tstrncpy(userObj.user, user, TSDB_USER_LEN);
tstrncpy(userObj.acct, acct, TSDB_USER_LEN); tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
...@@ -113,15 +122,16 @@ static int32_t mndCreateDefaultUser(SSdb *pSdb, char *acct, char *user, char *pa ...@@ -113,15 +122,16 @@ static int32_t mndCreateDefaultUser(SSdb *pSdb, char *acct, char *user, char *pa
if (pRaw == NULL) return -1; if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY); sdbSetRawStatus(pRaw, SDB_STATUS_READY);
return sdbWrite(pSdb, pRaw); mTrace("user:%s, will be created while deploy sdb", userObj.user);
return sdbWrite(pMnode->pSdb, pRaw);
} }
static int32_t mndCreateDefaultUsers(SSdb *pSdb) { static int32_t mndCreateDefaultUsers(SMnode *pMnode) {
if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { if (mndCreateDefaultUser(pMnode, TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
return -1; return -1;
} }
if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { if (mndCreateDefaultUser(pMnode, TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) {
return -1; return -1;
} }
...@@ -196,7 +206,7 @@ static int32_t mndProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) { ...@@ -196,7 +206,7 @@ static int32_t mndProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) {
return -1; return -1;
} }
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->conn.user); SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user);
if (pOperUser == NULL) { if (pOperUser == NULL) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("user:%s, failed to create since %s", pCreate->user, terrstr()); mError("user:%s, failed to create since %s", pCreate->user, terrstr());
...@@ -230,3 +240,14 @@ int32_t mndInitUser(SMnode *pMnode) { ...@@ -230,3 +240,14 @@ int32_t mndInitUser(SMnode *pMnode) {
} }
void mndCleanupUser(SMnode *pMnode) {} void mndCleanupUser(SMnode *pMnode) {}
SUserObj *mndAcquireUser(SMnode *pMnode, const char *userName) {
SSdb *pSdb = pMnode->pSdb;
return sdbAcquire(pSdb, SDB_USER, &userName);
}
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser) {
SSdb *pSdb = pMnode->pSdb;
sdbRelease(pSdb, pUser);
}
...@@ -32,30 +32,6 @@ ...@@ -32,30 +32,6 @@
#include "mndUser.h" #include "mndUser.h"
#include "mndVgroup.h" #include "mndVgroup.h"
int32_t mndGetDnodeId(SMnode *pMnode) {
if (pMnode != NULL) {
return pMnode->dnodeId;
}
return -1;
}
int64_t mndGetClusterId(SMnode *pMnode) {
if (pMnode != NULL) {
return pMnode->clusterId;
}
return -1;
}
tmr_h mndGetTimer(SMnode *pMnode) {
if (pMnode != NULL) {
return pMnode->timer;
}
return NULL;
}
void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) { if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) {
(*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg); (*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg);
...@@ -112,6 +88,7 @@ static int32_t mnodeCreateDir(SMnode *pMnode, const char *path) { ...@@ -112,6 +88,7 @@ static int32_t mnodeCreateDir(SMnode *pMnode, const char *path) {
static int32_t mndInitSdb(SMnode *pMnode) { static int32_t mndInitSdb(SMnode *pMnode) {
SSdbOpt opt = {0}; SSdbOpt opt = {0};
opt.path = pMnode->path; opt.path = pMnode->path;
opt.pMnode = pMnode;
pMnode->pSdb = sdbInit(&opt); pMnode->pSdb = sdbInit(&opt);
if (pMnode->pSdb == NULL) { if (pMnode->pSdb == NULL) {
...@@ -177,11 +154,11 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) { ...@@ -177,11 +154,11 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
if (pMnode->pSteps == NULL) return; if (pMnode->pSteps == NULL) return;
if (pos == -1) { if (pos == -1) {
pos = taosArrayGetSize(pMnode->pSteps); pos = taosArrayGetSize(pMnode->pSteps) - 1;
} }
for (int32_t s = pos; s >= 0; s--) { for (int32_t s = pos; s >= 0; s--) {
SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos); SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, s);
mDebug("step:%s will cleanup", pStep->name); mDebug("step:%s will cleanup", pStep->name);
if (pStep->cleanupFp != NULL) { if (pStep->cleanupFp != NULL) {
(*pStep->cleanupFp)(pMnode); (*pStep->cleanupFp)(pMnode);
...@@ -189,6 +166,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) { ...@@ -189,6 +166,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
} }
taosArrayClear(pMnode->pSteps); taosArrayClear(pMnode->pSteps);
taosArrayDestroy(pMnode->pSteps);
pMnode->pSteps = NULL; pMnode->pSteps = NULL;
} }
...@@ -225,15 +203,22 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { ...@@ -225,15 +203,22 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp;
pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp;
pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp;
pMnode->sver = pOption->sver;
pMnode->statusInterval = pOption->statusInterval;
pMnode->mnodeEqualVnodeNum = pOption->mnodeEqualVnodeNum;
pMnode->timezone = strdup(pOption->timezone);
pMnode->locale = strdup(pOption->locale);
pMnode->charset = strdup(pOption->charset);
if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL ||
pMnode->putMsgToApplyMsgFp == NULL) { pMnode->putMsgToApplyMsgFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0 ||
terrno = TSDB_CODE_MND_APP_ERROR; pMnode->statusInterval < 1 || pOption->mnodeEqualVnodeNum < 0) {
terrno = TSDB_CODE_MND_INVALID_OPTIONS;
return -1; return -1;
} }
if (pMnode->dnodeId < 0 || pMnode->clusterId < 0) { if (pMnode->timezone == NULL || pMnode->locale == NULL || pMnode->charset == NULL) {
terrno = TSDB_CODE_MND_APP_ERROR; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
} }
...@@ -259,8 +244,9 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { ...@@ -259,8 +244,9 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
} }
int32_t code = mnodeCreateDir(pMnode, path); int32_t code = mnodeCreateDir(pMnode, path);
if (mnodeCreateDir(pMnode, path) != 0) { if (code != 0) {
mError("failed to open mnode since %s", tstrerror(code)); code = terrno;
mError("failed to open mnode since %s", terrstr());
mndClose(pMnode); mndClose(pMnode);
terrno = code; terrno = code;
return NULL; return NULL;
...@@ -268,7 +254,8 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { ...@@ -268,7 +254,8 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
code = mndSetOptions(pMnode, pOption); code = mndSetOptions(pMnode, pOption);
if (code != 0) { if (code != 0) {
mError("failed to open mnode since %s", tstrerror(code)); code = terrno;
mError("failed to open mnode since %s", terrstr());
mndClose(pMnode); mndClose(pMnode);
terrno = code; terrno = code;
return NULL; return NULL;
...@@ -276,7 +263,8 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { ...@@ -276,7 +263,8 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
code = mndInitSteps(pMnode); code = mndInitSteps(pMnode);
if (code != 0) { if (code != 0) {
mError("failed to open mnode since %s", tstrerror(code)); code = terrno;
mError("failed to open mnode since %s", terrstr());
mndClose(pMnode); mndClose(pMnode);
terrno = code; terrno = code;
return NULL; return NULL;
...@@ -284,7 +272,8 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { ...@@ -284,7 +272,8 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
code = mndExecSteps(pMnode); code = mndExecSteps(pMnode);
if (code != 0) { if (code != 0) {
mError("failed to open mnode since %s", tstrerror(code)); code = terrno;
mError("failed to open mnode since %s", terrstr());
mndClose(pMnode); mndClose(pMnode);
terrno = code; terrno = code;
return NULL; return NULL;
...@@ -299,6 +288,9 @@ void mndClose(SMnode *pMnode) { ...@@ -299,6 +288,9 @@ void mndClose(SMnode *pMnode) {
mDebug("start to close mnode"); mDebug("start to close mnode");
mndCleanupSteps(pMnode, -1); mndCleanupSteps(pMnode, -1);
tfree(pMnode->path); tfree(pMnode->path);
tfree(pMnode->charset);
tfree(pMnode->locale);
tfree(pMnode->timezone);
tfree(pMnode); tfree(pMnode);
mDebug("mnode is closed"); mDebug("mnode is closed");
} }
...@@ -335,31 +327,36 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { ...@@ -335,31 +327,36 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg)); SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg));
if (pMsg == NULL) { if (pMsg == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
mError("failed to create msg since %s", terrstr());
return NULL; return NULL;
} }
if (rpcGetConnInfo(pRpcMsg->handle, &pMsg->conn) != 0) { SRpcConnInfo connInfo = {0};
if (rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) {
mndCleanupMsg(pMsg); mndCleanupMsg(pMsg);
mError("can not get user from conn:%p", pMsg->rpcMsg.handle);
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
mError("failed to create msg since %s", terrstr());
return NULL; return NULL;
} }
memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN);
pMsg->pMnode = pMnode;
pMsg->rpcMsg = *pRpcMsg; pMsg->rpcMsg = *pRpcMsg;
pMsg->createdTime = taosGetTimestampSec(); pMsg->createdTime = taosGetTimestampSec();
mTrace("msg:%p, is created", pMsg);
return pMsg; return pMsg;
} }
void mndCleanupMsg(SMnodeMsg *pMsg) { void mndCleanupMsg(SMnodeMsg *pMsg) {
if (pMsg->pUser != NULL) {
sdbRelease(pMsg->pMnode->pSdb, pMsg->pUser);
}
taosFreeQitem(pMsg); taosFreeQitem(pMsg);
mTrace("msg:%p, is destroyed", pMsg);
} }
void mndSendRsp(SMnodeMsg *pMsg, int32_t code) {} void mndSendRsp(SMnodeMsg *pMsg, int32_t code) {
SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .code = code};
rpcSendResponse(&rpcRsp);
}
static void mndProcessRpcMsg(SMnodeMsg *pMsg) { static void mndProcessRpcMsg(SMnodeMsg *pMsg) {
SMnode *pMnode = pMsg->pMnode; SMnode *pMnode = pMsg->pMnode;
...@@ -368,29 +365,34 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) { ...@@ -368,29 +365,34 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) {
void *ahandle = pMsg->rpcMsg.ahandle; void *ahandle = pMsg->rpcMsg.ahandle;
bool isReq = (msgType % 2 == 1); bool isReq = (msgType % 2 == 1);
mTrace("msg:%p, app:%p will be processed", pMsg, ahandle);
if (isReq && !mndIsMaster(pMnode)) { if (isReq && !mndIsMaster(pMnode)) {
code = TSDB_CODE_APP_NOT_READY; code = TSDB_CODE_APP_NOT_READY;
mDebug("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr());
goto PROCESS_RPC_END; goto PROCESS_RPC_END;
} }
if (isReq && pMsg->rpcMsg.pCont == NULL) { if (isReq && pMsg->rpcMsg.pCont == NULL) {
mError("msg:%p, app:%p type:%s content is null", pMsg, ahandle, taosMsg[msgType]);
code = TSDB_CODE_MND_INVALID_MSG_LEN; code = TSDB_CODE_MND_INVALID_MSG_LEN;
mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr());
goto PROCESS_RPC_END; goto PROCESS_RPC_END;
} }
MndMsgFp fp = pMnode->msgFp[msgType]; MndMsgFp fp = pMnode->msgFp[msgType];
if (fp == NULL) { if (fp == NULL) {
mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]);
code = TSDB_CODE_MSG_NOT_PROCESSED; code = TSDB_CODE_MSG_NOT_PROCESSED;
mError("msg:%p, app:%p failed to process since not handle", pMsg, ahandle);
goto PROCESS_RPC_END; goto PROCESS_RPC_END;
} }
code = (*fp)(pMnode, pMsg); code = (*fp)(pMnode, pMsg);
if (code != 0) { if (code != 0) {
code = terrno; code = terrno;
mError("msg:%p, app:%p type:%s failed to process since %s", pMsg, ahandle, taosMsg[msgType], terrstr()); mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr());
goto PROCESS_RPC_END; goto PROCESS_RPC_END;
} else {
mTrace("msg:%p, app:%p is processed", pMsg, ahandle);
} }
PROCESS_RPC_END: PROCESS_RPC_END:
...@@ -398,13 +400,13 @@ PROCESS_RPC_END: ...@@ -398,13 +400,13 @@ PROCESS_RPC_END:
if (code == TSDB_CODE_APP_NOT_READY) { if (code == TSDB_CODE_APP_NOT_READY) {
mndSendRedirectMsg(pMnode, &pMsg->rpcMsg); mndSendRedirectMsg(pMnode, &pMsg->rpcMsg);
} else if (code != 0) { } else if (code != 0) {
SRpcMsg rspMsg = {.handle = pMsg->rpcMsg.handle, .code = code}; SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .code = code};
rpcSendResponse(&rspMsg); rpcSendResponse(&rpcRsp);
} else { } else {
SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .contLen = pMsg->contLen, .pCont = pMsg->pCont};
rpcSendResponse(&rpcRsp);
} }
} }
mndCleanupMsg(pMsg);
} }
void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) { void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) {
......
...@@ -38,8 +38,8 @@ extern "C" { ...@@ -38,8 +38,8 @@ extern "C" {
typedef struct SSdbRaw { typedef struct SSdbRaw {
int8_t type; int8_t type;
int8_t sver;
int8_t status; int8_t status;
int8_t sver;
int8_t reserved; int8_t reserved;
int32_t dataLen; int32_t dataLen;
char pData[]; char pData[];
...@@ -53,6 +53,7 @@ typedef struct SSdbRow { ...@@ -53,6 +53,7 @@ typedef struct SSdbRow {
} SSdbRow; } SSdbRow;
typedef struct SSdb { typedef struct SSdb {
SMnode *pMnode;
char *currDir; char *currDir;
char *syncDir; char *syncDir;
char *tmpDir; char *tmpDir;
......
...@@ -27,7 +27,7 @@ SSdb *sdbInit(SSdbOpt *pOption) { ...@@ -27,7 +27,7 @@ SSdb *sdbInit(SSdbOpt *pOption) {
} }
char path[PATH_MAX + 100]; char path[PATH_MAX + 100];
snprintf(path, PATH_MAX + 100, "%s", pOption->path); snprintf(path, PATH_MAX + 100, "%s%sdata", pOption->path, TD_DIRSEP);
pSdb->currDir = strdup(path); pSdb->currDir = strdup(path);
snprintf(path, PATH_MAX + 100, "%s%ssync", pOption->path, TD_DIRSEP); snprintf(path, PATH_MAX + 100, "%s%ssync", pOption->path, TD_DIRSEP);
pSdb->syncDir = strdup(path); pSdb->syncDir = strdup(path);
...@@ -40,10 +40,11 @@ SSdb *sdbInit(SSdbOpt *pOption) { ...@@ -40,10 +40,11 @@ SSdb *sdbInit(SSdbOpt *pOption) {
return NULL; return NULL;
} }
for (int32_t i = 0; i < SDB_MAX; ++i) { for (ESdbType i = 0; i < SDB_MAX; ++i) {
taosInitRWLatch(&pSdb->locks[i]); taosInitRWLatch(&pSdb->locks[i]);
} }
pSdb->pMnode = pOption->pMnode;
mDebug("sdb init successfully"); mDebug("sdb init successfully");
return pSdb; return pSdb;
} }
...@@ -68,47 +69,67 @@ void sdbCleanup(SSdb *pSdb) { ...@@ -68,47 +69,67 @@ void sdbCleanup(SSdb *pSdb) {
tfree(pSdb->tmpDir); tfree(pSdb->tmpDir);
} }
for (int32_t i = 0; i < SDB_MAX; ++i) { for (ESdbType i = 0; i < SDB_MAX; ++i) {
SHashObj *hash = pSdb->hashObjs[i]; SHashObj *hash = pSdb->hashObjs[i];
if (hash != NULL) { if (hash == NULL) continue;
SdbDeleteFp deleteFp = pSdb->deleteFps[i];
SSdbRow **ppRow = taosHashIterate(hash, NULL);
while (ppRow != NULL) {
SSdbRow *pRow = *ppRow;
if (pRow == NULL) continue;
if (deleteFp != NULL) {
(*deleteFp)(pSdb, pRow->pObj);
}
sdbFreeRow(pRow);
ppRow = taosHashIterate(hash, ppRow);
}
}
for (ESdbType i = 0; i < SDB_MAX; ++i) {
SHashObj *hash = pSdb->hashObjs[i];
if (hash == NULL) continue;
taosHashClear(hash); taosHashClear(hash);
taosHashCleanup(hash); taosHashCleanup(hash);
}
pSdb->hashObjs[i] = NULL; pSdb->hashObjs[i] = NULL;
mTrace("sdb table:%d is cleaned up", i);
} }
free(pSdb);
mDebug("sdb is cleaned up"); mDebug("sdb is cleaned up");
} }
int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
ESdbType sdb = table.sdbType; ESdbType sdbType = table.sdbType;
pSdb->keyTypes[sdb] = table.keyType; EKeyType keyType = table.keyType;
pSdb->insertFps[sdb] = table.insertFp; pSdb->keyTypes[sdbType] = table.keyType;
pSdb->updateFps[sdb] = table.updateFp; pSdb->insertFps[sdbType] = table.insertFp;
pSdb->deleteFps[sdb] = table.deleteFp; pSdb->updateFps[sdbType] = table.updateFp;
pSdb->deployFps[sdb] = table.deployFp; pSdb->deleteFps[sdbType] = table.deleteFp;
pSdb->encodeFps[sdb] = table.encodeFp; pSdb->deployFps[sdbType] = table.deployFp;
pSdb->decodeFps[sdb] = table.decodeFp; pSdb->encodeFps[sdbType] = table.encodeFp;
pSdb->decodeFps[sdbType] = table.decodeFp;
for (int32_t i = 0; i < SDB_MAX; ++i) {
int32_t type; int32_t hashType = 0;
if (pSdb->keyTypes[i] == SDB_KEY_INT32) { if (keyType == SDB_KEY_INT32) {
type = TSDB_DATA_TYPE_INT; hashType = TSDB_DATA_TYPE_INT;
} else if (pSdb->keyTypes[i] == SDB_KEY_INT64) { } else if (keyType == SDB_KEY_INT64) {
type = TSDB_DATA_TYPE_BIGINT; hashType = TSDB_DATA_TYPE_BIGINT;
} else { } else {
type = TSDB_DATA_TYPE_BINARY; hashType = TSDB_DATA_TYPE_BINARY;
} }
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK); SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_NO_LOCK);
if (hash == NULL) { if (hash == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
} }
pSdb->hashObjs[i] = hash; pSdb->hashObjs[sdbType] = hash;
taosInitRWLatch(&pSdb->locks[i]); taosInitRWLatch(&pSdb->locks[sdbType]);
} mTrace("sdb table:%d is initialized", sdbType);
return 0; return 0;
} }
\ No newline at end of file
...@@ -42,11 +42,11 @@ static int32_t sdbCreateDir(SSdb *pSdb) { ...@@ -42,11 +42,11 @@ static int32_t sdbCreateDir(SSdb *pSdb) {
static int32_t sdbRunDeployFp(SSdb *pSdb) { static int32_t sdbRunDeployFp(SSdb *pSdb) {
mDebug("start to deploy sdb"); mDebug("start to deploy sdb");
for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) { for (ESdbType i = SDB_MAX - 1; i > SDB_START; --i) {
SdbDeployFp fp = pSdb->deployFps[i]; SdbDeployFp fp = pSdb->deployFps[i];
if (fp == NULL) continue; if (fp == NULL) continue;
if ((*fp)(pSdb) != 0) { if ((*fp)(pSdb->pMnode) != 0) {
mError("failed to deploy sdb:%d since %s", i, terrstr()); mError("failed to deploy sdb:%d since %s", i, terrstr());
return -1; return -1;
} }
...@@ -150,7 +150,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { ...@@ -150,7 +150,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
return -1; return -1;
} }
for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) { for (ESdbType i = SDB_MAX - 1; i > SDB_START; --i) {
SdbEncodeFp encodeFp = pSdb->encodeFps[i]; SdbEncodeFp encodeFp = pSdb->encodeFps[i];
if (encodeFp == NULL) continue; if (encodeFp == NULL) continue;
...@@ -173,6 +173,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { ...@@ -173,6 +173,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
if (taosWriteFile(fd, pRaw, writeLen) != writeLen) { if (taosWriteFile(fd, pRaw, writeLen) != writeLen) {
code = TAOS_SYSTEM_ERROR(terrno); code = TAOS_SYSTEM_ERROR(terrno);
taosHashCancelIterate(hash, ppRow); taosHashCancelIterate(hash, ppRow);
free(pRaw);
break; break;
} }
...@@ -180,6 +181,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { ...@@ -180,6 +181,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
if (taosWriteFile(fd, &cksum, sizeof(int32_t)) != sizeof(int32_t)) { if (taosWriteFile(fd, &cksum, sizeof(int32_t)) != sizeof(int32_t)) {
code = TAOS_SYSTEM_ERROR(terrno); code = TAOS_SYSTEM_ERROR(terrno);
taosHashCancelIterate(hash, ppRow); taosHashCancelIterate(hash, ppRow);
free(pRaw);
break; break;
} }
} else { } else {
...@@ -188,6 +190,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { ...@@ -188,6 +190,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
break; break;
} }
free(pRaw);
ppRow = taosHashIterate(hash, ppRow); ppRow = taosHashIterate(hash, ppRow);
} }
taosWUnLockLatch(pLock); taosWUnLockLatch(pLock);
......
...@@ -237,7 +237,15 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { ...@@ -237,7 +237,15 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
SRWLatch *pLock = &pSdb->locks[type]; SRWLatch *pLock = &pSdb->locks[type];
taosRLockLatch(pLock); taosRLockLatch(pLock);
SSdbRow **ppRow = taosHashIterate(hash, ppRow); if (pIter != NULL) {
SSdbRow *pLastRow = *(SSdbRow **)pIter;
int32_t ref = atomic_sub_fetch_32(&pLastRow->refCount, 1);
if (ref <= 0 && pLastRow->status == SDB_STATUS_DROPPED) {
sdbFreeRow(pLastRow);
}
}
SSdbRow **ppRow = taosHashIterate(hash, pIter);
while (ppRow != NULL) { while (ppRow != NULL) {
SSdbRow *pRow = *ppRow; SSdbRow *pRow = *ppRow;
if (pRow == NULL || pRow->status != SDB_STATUS_READY) { if (pRow == NULL || pRow->status != SDB_STATUS_READY) {
......
...@@ -61,6 +61,21 @@ int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) { ...@@ -61,6 +61,21 @@ int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
return 0; return 0;
} }
int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
if (pRaw == NULL) {
terrno = TSDB_CODE_INVALID_PTR;
return -1;
}
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
return -1;
}
*(int16_t *)(pRaw->pData + dataPos) = val;
return 0;
}
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) { int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
if (pRaw == NULL) { if (pRaw == NULL) {
terrno = TSDB_CODE_INVALID_PTR; terrno = TSDB_CODE_INVALID_PTR;
...@@ -146,6 +161,21 @@ int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) { ...@@ -146,6 +161,21 @@ int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
return 0; return 0;
} }
int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
if (pRaw == NULL) {
terrno = TSDB_CODE_INVALID_PTR;
return -1;
}
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
return -1;
}
*val = *(int16_t *)(pRaw->pData + dataPos);
return 0;
}
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) { int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
if (pRaw == NULL) { if (pRaw == NULL) {
terrno = TSDB_CODE_INVALID_PTR; terrno = TSDB_CODE_INVALID_PTR;
......
...@@ -19,5 +19,5 @@ target_link_libraries( ...@@ -19,5 +19,5 @@ target_link_libraries(
# test # test
if(${BUILD_TEST}) if(${BUILD_TEST})
add_subdirectory(test) # add_subdirectory(test)
endif(${BUILD_TEST}) endif(${BUILD_TEST})
\ No newline at end of file
...@@ -27,6 +27,7 @@ typedef struct SVBufPool SVBufPool; ...@@ -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
} }
......
...@@ -13,8 +13,8 @@ ...@@ -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 @@ ...@@ -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_*/
\ No newline at end of file \ No newline at end of file
...@@ -20,12 +20,14 @@ ...@@ -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" { ...@@ -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;
......
/*
* 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_*/
\ No newline at end of file
...@@ -16,23 +16,15 @@ ...@@ -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
} }
......
...@@ -21,6 +21,9 @@ extern "C" { ...@@ -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
......
...@@ -19,9 +19,12 @@ ...@@ -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 { ...@@ -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;
...@@ -59,8 +67,11 @@ typedef struct { ...@@ -59,8 +67,11 @@ typedef struct {
}; };
} SVMemAllocator; } SVMemAllocator;
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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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
}
}
\ No newline at end of file
...@@ -15,20 +15,20 @@ ...@@ -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));
} }
\ No newline at end of file
...@@ -15,27 +15,40 @@ ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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;
......
...@@ -12,3 +12,104 @@ ...@@ -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
}
\ No newline at end of file
...@@ -16,51 +16,84 @@ ...@@ -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;
}
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
#if 0 pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
int reqType; /* TODO */
size_t reqSize; /* TODO */ // ser request version
uint64_t reqVersion = 0; /* TODO */ void * pBuf = pMsg->pCont;
int code = 0; uint64_t ver = pVnode->state.processed++;
taosEncodeFixedU64(&pBuf, ver);
// Copy the request to vnode buffer
void *pReq = mMalloc(pVnode->inuse, reqSize); if (walWrite(pVnode->pWal, ver, pMsg->msgType, pMsg->pCont, pMsg->contLen) < 0) {
if (pReq == NULL) {
// TODO: handle error // TODO: handle error
} }
}
walFsync(pVnode->pWal, false);
memcpy(pReq, pMsg, reqSize); // Apply each request now
for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
SVnodeReq vReq;
// Apply the request
{
void *ptr = vnodeMalloc(pVnode, pMsg->contLen);
if (ptr == NULL) {
// TODO: handle error
}
// TODO: copy here need to be extended
memcpy(ptr, pMsg->pCont, pMsg->contLen);
// todo: change the interface here
uint64_t ver;
taosDecodeFixedU64(pMsg->pCont, &ver);
if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) {
// TODO: handle error
}
// Push the request to TQ so consumers can consume vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType);
tqPushMsg(pVnode->pTq, pReq, 0);
// Process the request switch (pMsg->msgType) {
switch (reqType) {
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 0;
}
return code; int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
#endif // TODO
return 0; return 0;
} }
......
...@@ -3,11 +3,173 @@ ...@@ -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);
} }
...@@ -13,8 +13,8 @@ ...@@ -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 @@ ...@@ -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_*/
\ No newline at end of file \ No newline at end of file
...@@ -34,7 +34,7 @@ typedef struct { ...@@ -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
......
...@@ -20,10 +20,10 @@ ...@@ -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" { ...@@ -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;
......
...@@ -28,7 +28,7 @@ typedef rocksdb_t meta_index_t; ...@@ -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
......
...@@ -13,8 +13,8 @@ ...@@ -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 @@ ...@@ -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_*/
\ No newline at end of file \ No newline at end of file
...@@ -18,8 +18,8 @@ ...@@ -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;
......
...@@ -15,20 +15,20 @@ ...@@ -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 ------------------------ */
\ No newline at end of file
...@@ -92,7 +92,7 @@ void metaCloseDB(SMeta *pMeta) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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;
} }
\ No newline at end of file
...@@ -47,7 +47,12 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */ ...@@ -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;
} }
\ No newline at end of file
...@@ -15,17 +15,14 @@ ...@@ -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) { ...@@ -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);
......
...@@ -15,21 +15,21 @@ ...@@ -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;
} }
......
...@@ -16,12 +16,12 @@ ...@@ -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 ...@@ -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 ...@@ -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
}
\ No newline at end of file
...@@ -40,17 +40,17 @@ void* tqSerializeBufItem(TqBufferItem* bufItem, void* ptr); ...@@ -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
} }
......
...@@ -28,7 +28,7 @@ extern "C" { ...@@ -28,7 +28,7 @@ extern "C" {
struct STsdb { struct STsdb {
char * path; char * path;
STsdbOptions options; STsdbCfg options;
SMemAllocatorFactory *pmaf; SMemAllocatorFactory *pmaf;
}; };
......
...@@ -20,10 +20,10 @@ ...@@ -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
} }
......
...@@ -15,12 +15,12 @@ ...@@ -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) { ...@@ -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));
......
...@@ -15,20 +15,20 @@ ...@@ -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)); }
\ No newline at end of file \ No newline at end of file
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
#ifndef __INDEX_FST_H__ #ifndef __INDEX_FST_H__
#define __INDEX_FST_H__ #define __INDEX_FST_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "tarray.h" #include "tarray.h"
#include "index_fst_util.h" #include "index_fst_util.h"
...@@ -34,6 +37,7 @@ typedef struct FstRange { ...@@ -34,6 +37,7 @@ typedef struct FstRange {
} FstRange; } FstRange;
typedef enum {GE, GT, LE, LT} RangeType;
typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State; typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State;
typedef enum {Ordered, OutOfOrdered, DuplicateKey} OrderType; typedef enum {Ordered, OutOfOrdered, DuplicateKey} OrderType;
...@@ -93,8 +97,11 @@ typedef struct FstBuilder { ...@@ -93,8 +97,11 @@ typedef struct FstBuilder {
FstBuilder *fstBuilderCreate(void *w, FstType ty); FstBuilder *fstBuilderCreate(void *w, FstType ty);
void fstBuilderDestroy(FstBuilder *b); void fstBuilderDestroy(FstBuilder *b);
void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in); void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in);
bool fstBuilderInsert(FstBuilder *b, FstSlice bs, Output in);
OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup); OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup);
void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate); void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate);
CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn); CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn);
...@@ -169,11 +176,6 @@ uint64_t fstStateFindInput(FstState *state, FstNode *node, uint8_t b, bool *null ...@@ -169,11 +176,6 @@ uint64_t fstStateFindInput(FstState *state, FstNode *node, uint8_t b, bool *null
#define FST_STATE_ONE_TRNAS_NEXT(node) (node->state.state == OneTransNext) #define FST_STATE_ONE_TRNAS_NEXT(node) (node->state.state == OneTransNext)
#define FST_STATE_ONE_TRNAS(node) (node->state.state == OneTrans) #define FST_STATE_ONE_TRNAS(node) (node->state.state == OneTrans)
#define FST_STATE_ANY_TRANS(node) (node->state.state == AnyTrans) #define FST_STATE_ANY_TRANS(node) (node->state.state == AnyTrans)
...@@ -272,7 +274,6 @@ FstNode* fstGetNode(Fst *fst, CompiledAddr); ...@@ -272,7 +274,6 @@ FstNode* fstGetNode(Fst *fst, CompiledAddr);
FstNode* fstGetRoot(Fst *fst); FstNode* fstGetRoot(Fst *fst);
FstType fstGetType(Fst *fst); FstType fstGetType(Fst *fst);
CompiledAddr fstGetRootAddr(Fst *fst); CompiledAddr fstGetRootAddr(Fst *fst);
Output fstEmptyFinalOutput(Fst *fst, bool *null); Output fstEmptyFinalOutput(Fst *fst, bool *null);
bool fstVerify(Fst *fst); bool fstVerify(Fst *fst);
...@@ -280,10 +281,6 @@ bool fstVerify(Fst *fst); ...@@ -280,10 +281,6 @@ bool fstVerify(Fst *fst);
//refactor this function //refactor this function
bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr); bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr);
typedef struct StreamState { typedef struct StreamState {
FstNode *node; FstNode *node;
uint64_t trans; uint64_t trans;
...@@ -310,10 +307,30 @@ typedef struct StreamWithStateResult { ...@@ -310,10 +307,30 @@ typedef struct StreamWithStateResult {
} StreamWithStateResult; } StreamWithStateResult;
StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *state); StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *state);
void swsResultDestroy(StreamWithStateResult *result);
typedef void* (*StreamCallback)(void *); typedef void* (*StreamCallback)(void *);
StreamWithState *streamWithStateCreate(Fst *fst, Automation *automation, FstBoundWithData *min, FstBoundWithData *max) ; StreamWithState *streamWithStateCreate(Fst *fst, Automation *automation, FstBoundWithData *min, FstBoundWithData *max) ;
void streamWithStateDestroy(StreamWithState *sws); void streamWithStateDestroy(StreamWithState *sws);
bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min); bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min);
StreamWithStateResult* streamWithStateNextWith(StreamWithState *sws, StreamCallback callback); StreamWithStateResult* streamWithStateNextWith(StreamWithState *sws, StreamCallback callback);
typedef struct FstStreamBuilder {
Fst *fst;
Automation *aut;
FstBoundWithData *min;
FstBoundWithData *max;
} FstStreamBuilder;
FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, Automation *aut);
// set up bound range
// refator, simple code by marco
FstStreamBuilder *fstStreamBuilderRange(FstStreamBuilder *b, FstSlice *val, RangeType type);
#ifdef __cplusplus
}
#endif
#endif #endif
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#ifndef __INDEX_FST_AUTAOMATION_H__ #ifndef __INDEX_FST_AUTAOMATION_H__
#define __INDEX_FST_AUTAOMATION_H__ #define __INDEX_FST_AUTAOMATION_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct AutomationCtx AutomationCtx; typedef struct AutomationCtx AutomationCtx;
typedef struct StartWith { typedef struct StartWith {
...@@ -42,6 +46,8 @@ typedef struct Automation { ...@@ -42,6 +46,8 @@ typedef struct Automation {
void *data; void *data;
} Automation; } Automation;
#ifdef __cplusplus
}
#endif
#endif #endif
#ifndef __INDEX_FST_COMM_H__ #ifndef __INDEX_FST_COMM_H__
#define __INDEX_FST_COMM_H__ #define __INDEX_FST_COMM_H__
extern const uint8_t COMMON_INPUTS[]; extern const uint8_t COMMON_INPUTS[];
extern char const COMMON_INPUTS_INV[]; extern char const COMMON_INPUTS_INV[];
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif #endif
...@@ -16,6 +16,38 @@ ...@@ -16,6 +16,38 @@
#ifndef __INDEX_FST_COUNTING_WRITER_H__ #ifndef __INDEX_FST_COUNTING_WRITER_H__
#define __INDEX_FST_COUNTING_WRITER_H__ #define __INDEX_FST_COUNTING_WRITER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "tfile.h"
#define DefaultMem 1024*1024
static char tmpFile[] = "/tmp/index";
typedef enum WriterType {TMemory, TFile} WriterType;
typedef struct WriterCtx {
int (*write)(struct WriterCtx *ctx, uint8_t *buf, int len);
int (*read)(struct WriterCtx *ctx, uint8_t *buf, int len);
int (*flush)(struct WriterCtx *ctx);
WriterType type;
union {
int fd;
void *mem;
};
int32_t offset;
int32_t limit;
} WriterCtx;
static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len);
static int writeCtxDoRead(WriterCtx *ctx, uint8_t *buf, int len);
static int writeCtxDoFlush(WriterCtx *ctx);
WriterCtx* writerCtxCreate(WriterType type);
void writerCtxDestroy(WriterCtx *w);
typedef uint32_t CheckSummer; typedef uint32_t CheckSummer;
...@@ -25,7 +57,7 @@ typedef struct FstCountingWriter { ...@@ -25,7 +57,7 @@ typedef struct FstCountingWriter {
CheckSummer summer; CheckSummer summer;
} FstCountingWriter; } FstCountingWriter;
uint64_t fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t bufLen); int fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t bufLen);
int fstCountingWriterFlush(FstCountingWriter *write); int fstCountingWriterFlush(FstCountingWriter *write);
...@@ -44,6 +76,10 @@ uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n); ...@@ -44,6 +76,10 @@ uint8_t fstCountingWriterPackUint(FstCountingWriter *writer, uint64_t n);
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr) #define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer) #define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
#ifdef __cplusplus
}
#endif
#endif #endif
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
#ifndef __INDEX_FST_NODE_H__ #ifndef __INDEX_FST_NODE_H__
#define __INDEX_FST_NODE_H__ #define __INDEX_FST_NODE_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "index_fst_util.h" #include "index_fst_util.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
...@@ -42,7 +46,12 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src); ...@@ -42,7 +46,12 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src);
void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src); void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src);
//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr); //bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr);
bool fstBuilderNodeEqual(FstBuilderNode *n1, FstBuilderNode *n2);
void fstBuilderNodeDestroy(FstBuilderNode *node); void fstBuilderNodeDestroy(FstBuilderNode *node);
#ifdef __cplusplus
}
#endif
#endif #endif
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#ifndef __FST_REGISTRY_H__ #ifndef __FST_REGISTRY_H__
#define __FST_REGISTRY_H__ #define __FST_REGISTRY_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "index_fst_util.h" #include "index_fst_util.h"
#include "tarray.h" #include "tarray.h"
#include "index_fst_node.h" #include "index_fst_node.h"
...@@ -59,4 +63,8 @@ void fstRegistryDestroy(FstRegistry *registry); ...@@ -59,4 +63,8 @@ void fstRegistryDestroy(FstRegistry *registry);
FstRegistryEntry* fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNode); FstRegistryEntry* fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNode);
void fstRegistryEntryDestroy(FstRegistryEntry *entry); void fstRegistryEntryDestroy(FstRegistryEntry *entry);
#ifdef __cplusplus
}
#endif
#endif #endif
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
#ifndef __INDEX_FST_UTIL_H__ #ifndef __INDEX_FST_UTIL_H__
#define __INDEX_FST_UTIL_H__ #define __INDEX_FST_UTIL_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "tarray.h" #include "tarray.h"
#include "index_fst_common.h" #include "index_fst_common.h"
...@@ -67,20 +71,30 @@ uint8_t packDeltaSize(CompiledAddr nodeAddr, CompiledAddr transAddr); ...@@ -67,20 +71,30 @@ uint8_t packDeltaSize(CompiledAddr nodeAddr, CompiledAddr transAddr);
CompiledAddr unpackDelta(char *data, uint64_t len, uint64_t nodeAddr); CompiledAddr unpackDelta(char *data, uint64_t len, uint64_t nodeAddr);
typedef struct FstString {
uint8_t *data;
uint32_t len;
int32_t ref;
} FstString;
typedef struct FstSlice { typedef struct FstSlice {
uint8_t *data; FstString *str;
uint64_t dLen;
int32_t start; int32_t start;
int32_t end; int32_t end;
} FstSlice; } FstSlice;
FstSlice fstSliceCopy(FstSlice *slice, int32_t start, int32_t end); FstSlice fstSliceCreate(uint8_t *data, uint64_t len);
FstSlice fstSliceCreate(uint8_t *data, uint64_t dLen); FstSlice fstSliceCopy(FstSlice *s, int32_t start, int32_t end);
bool fstSliceEmpty(FstSlice *slice); FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end);
int fstSliceCompare(FstSlice *a, FstSlice *b); bool fstSliceIsEmpty(FstSlice *s);
int fstSliceCompare(FstSlice *s1, FstSlice *s2);
void fstSliceDestroy(FstSlice *s);
uint8_t *fstSliceData(FstSlice *s, int32_t *sz);
#define FST_SLICE_LEN(s) ((s)->end - (s)->start + 1) #define FST_SLICE_LEN(s) (s->end - s->start + 1)
#ifdef __cplusplus
}
#endif
#endif #endif
...@@ -52,7 +52,7 @@ void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes *nodes, bool isFinal) { ...@@ -52,7 +52,7 @@ void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes *nodes, bool isFinal) {
FstBuilderNode *node = malloc(sizeof(FstBuilderNode)); FstBuilderNode *node = malloc(sizeof(FstBuilderNode));
node->isFinal = isFinal; node->isFinal = isFinal;
node->finalOutput = 0; node->finalOutput = 0;
node->trans = NULL; node->trans = taosArrayInit(16, sizeof(FstTransition));
FstBuilderNodeUnfinished un = {.node = node, .last = NULL}; FstBuilderNodeUnfinished un = {.node = node, .last = NULL};
taosArrayPush(nodes->stack, &un); taosArrayPush(nodes->stack, &un);
...@@ -92,7 +92,7 @@ void fstUnFinishedNodesTopLastFreeze(FstUnFinishedNodes *nodes, CompiledAddr add ...@@ -92,7 +92,7 @@ void fstUnFinishedNodesTopLastFreeze(FstUnFinishedNodes *nodes, CompiledAddr add
} }
void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output out) { void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output out) {
FstSlice *s = &bs; FstSlice *s = &bs;
if (s->data == NULL || s->dLen == 0 || s->start > s->end) { if (fstSliceIsEmpty(s)) {
return; return;
} }
size_t sz = taosArrayGetSize(nodes->stack) - 1; size_t sz = taosArrayGetSize(nodes->stack) - 1;
...@@ -104,18 +104,20 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output ...@@ -104,18 +104,20 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output
//FstLastTransition *trn = malloc(sizeof(FstLastTransition)); //FstLastTransition *trn = malloc(sizeof(FstLastTransition));
//trn->inp = s->data[s->start]; //trn->inp = s->data[s->start];
//trn->out = out; //trn->out = out;
un->last = fstLastTransitionCreate(s->data[s->start], out); int32_t len = 0;
uint8_t *data = fstSliceData(s, &len);
un->last = fstLastTransitionCreate(data[0], out);
for (uint64_t i = s->start; i <= s->end; i++) { for (uint64_t i = 0; i < len; i++) {
FstBuilderNode *n = malloc(sizeof(FstBuilderNode)); FstBuilderNode *n = malloc(sizeof(FstBuilderNode));
n->isFinal = false; n->isFinal = false;
n->finalOutput = 0; n->finalOutput = 0;
n->trans = NULL; n->trans = taosArrayInit(16, sizeof(FstTransition));
//FstLastTransition *trn = malloc(sizeof(FstLastTransition)); //FstLastTransition *trn = malloc(sizeof(FstLastTransition));
//trn->inp = s->data[i]; //trn->inp = s->data[i];
//trn->out = out; //trn->out = out;
FstLastTransition *trn = fstLastTransitionCreate(s->data[i], out); FstLastTransition *trn = fstLastTransitionCreate(data[i], out);
FstBuilderNodeUnfinished un = {.node = n, .last = trn}; FstBuilderNodeUnfinished un = {.node = n, .last = trn};
taosArrayPush(nodes->stack, &un); taosArrayPush(nodes->stack, &un);
...@@ -127,13 +129,13 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output ...@@ -127,13 +129,13 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output
uint64_t fstUnFinishedNodesFindCommPrefix(FstUnFinishedNodes *node, FstSlice bs) { uint64_t fstUnFinishedNodesFindCommPrefix(FstUnFinishedNodes *node, FstSlice bs) {
FstSlice *s = &bs; FstSlice *s = &bs;
size_t lsz = (size_t)(s->end - s->start + 1); // data len
size_t ssz = taosArrayGetSize(node->stack); // stack size size_t ssz = taosArrayGetSize(node->stack); // stack size
uint64_t count = 0; uint64_t count = 0;
int32_t lsz; // data len
uint8_t *data = fstSliceData(s, &lsz);
for (size_t i = 0; i < ssz && i < lsz; i++) { for (size_t i = 0; i < ssz && i < lsz; i++) {
FstBuilderNodeUnfinished *un = taosArrayGet(node->stack, i); FstBuilderNodeUnfinished *un = taosArrayGet(node->stack, i);
if (un->last->inp == s->data[s->start + i]) { if (un->last->inp == data[i]) {
count++; count++;
} else { } else {
break; break;
...@@ -153,7 +155,8 @@ uint64_t fstUnFinishedNodesFindCommPrefixAndSetOutput(FstUnFinishedNodes *node, ...@@ -153,7 +155,8 @@ uint64_t fstUnFinishedNodesFindCommPrefixAndSetOutput(FstUnFinishedNodes *node,
FstLastTransition *t = un->last; FstLastTransition *t = un->last;
uint64_t addPrefix = 0; uint64_t addPrefix = 0;
if (t && t->inp == s->data[s->start + i]) { uint8_t *data = fstSliceData(s, NULL);
if (t && t->inp == data[i]) {
uint64_t commPrefix = MIN(t->out, *out); uint64_t commPrefix = MIN(t->out, *out);
uint64_t tAddPrefix = t->out - commPrefix; uint64_t tAddPrefix = t->out - commPrefix;
(*out) = (*out) - commPrefix; (*out) = (*out) - commPrefix;
...@@ -164,7 +167,6 @@ uint64_t fstUnFinishedNodesFindCommPrefixAndSetOutput(FstUnFinishedNodes *node, ...@@ -164,7 +167,6 @@ uint64_t fstUnFinishedNodesFindCommPrefixAndSetOutput(FstUnFinishedNodes *node,
} }
if (addPrefix != 0) { if (addPrefix != 0) {
fstBuilderNodeUnfinishedAddOutputPrefix(un, addPrefix); fstBuilderNodeUnfinishedAddOutputPrefix(un, addPrefix);
} }
} }
return i; return i;
...@@ -176,7 +178,9 @@ FstState fstStateCreateFrom(FstSlice* slice, CompiledAddr addr) { ...@@ -176,7 +178,9 @@ FstState fstStateCreateFrom(FstSlice* slice, CompiledAddr addr) {
if (addr == EMPTY_ADDRESS) { if (addr == EMPTY_ADDRESS) {
return fs; return fs;
} }
uint8_t v = slice->data[addr];
uint8_t *data = fstSliceData(slice, NULL);
uint8_t v = data[addr];
uint8_t t = (v & 0b11000000) >> 6; uint8_t t = (v & 0b11000000) >> 6;
if (t == 0b11) { if (t == 0b11) {
fs.state = OneTransNext; fs.state = OneTransNext;
...@@ -376,7 +380,8 @@ uint8_t fstStateInput(FstState *s, FstNode *node) { ...@@ -376,7 +380,8 @@ uint8_t fstStateInput(FstState *s, FstNode *node) {
FstSlice *slice = &node->data; FstSlice *slice = &node->data;
bool null = false; bool null = false;
uint8_t inp = fstStateCommInput(s, &null); uint8_t inp = fstStateCommInput(s, &null);
return null == false ? inp : slice->data[slice->start - 1]; uint8_t *data = fstSliceData(slice, NULL);
return null == false ? inp : data[-1];
} }
uint8_t fstStateInputForAnyTrans(FstState *s, FstNode *node, uint64_t i) { uint8_t fstStateInputForAnyTrans(FstState *s, FstNode *node, uint64_t i) {
assert(s->state == AnyTrans); assert(s->state == AnyTrans);
...@@ -388,7 +393,9 @@ uint8_t fstStateInputForAnyTrans(FstState *s, FstNode *node, uint64_t i) { ...@@ -388,7 +393,9 @@ uint8_t fstStateInputForAnyTrans(FstState *s, FstNode *node, uint64_t i) {
- fstStateTransIndexSize(s, node->version, node->nTrans) - fstStateTransIndexSize(s, node->version, node->nTrans)
- i - i
- 1; // the output size - 1; // the output size
return slice->data[at];
uint8_t *data = fstSliceData(slice, NULL);
return data[at];
} }
// trans_addr // trans_addr
...@@ -406,7 +413,8 @@ CompiledAddr fstStateTransAddr(FstState *s, FstNode *node) { ...@@ -406,7 +413,8 @@ CompiledAddr fstStateTransAddr(FstState *s, FstNode *node) {
- tSizes; - tSizes;
// refactor error logic // refactor error logic
return unpackDelta(slice->data + slice->start + i, tSizes, node->end); uint8_t *data = fstSliceData(slice, NULL);
return unpackDelta(data +i, tSizes, node->end);
} }
} }
CompiledAddr fstStateTransAddrForAnyTrans(FstState *s, FstNode *node, uint64_t i) { CompiledAddr fstStateTransAddrForAnyTrans(FstState *s, FstNode *node, uint64_t i) {
...@@ -421,7 +429,8 @@ CompiledAddr fstStateTransAddrForAnyTrans(FstState *s, FstNode *node, uint64_t i ...@@ -421,7 +429,8 @@ CompiledAddr fstStateTransAddrForAnyTrans(FstState *s, FstNode *node, uint64_t i
- node->nTrans - node->nTrans
- (i * tSizes) - (i * tSizes)
- tSizes; - tSizes;
return unpackDelta(slice->data + slice->start + at, tSizes, node->end); uint8_t *data = fstSliceData(slice, NULL);
return unpackDelta(data + at, tSizes, node->end);
} }
// sizes // sizes
...@@ -434,7 +443,8 @@ PackSizes fstStateSizes(FstState *s, FstSlice *slice) { ...@@ -434,7 +443,8 @@ PackSizes fstStateSizes(FstState *s, FstSlice *slice) {
i = FST_SLICE_LEN(slice) - 1 - fstStateNtransLen(s) - 1; i = FST_SLICE_LEN(slice) - 1 - fstStateNtransLen(s) - 1;
} }
return (PackSizes)(slice->data[slice->start + i]); uint8_t *data = fstSliceData(slice, NULL);
return (PackSizes)(*(data +i));
} }
// Output // Output
Output fstStateOutput(FstState *s, FstNode *node) { Output fstStateOutput(FstState *s, FstNode *node) {
...@@ -452,7 +462,8 @@ Output fstStateOutput(FstState *s, FstNode *node) { ...@@ -452,7 +462,8 @@ Output fstStateOutput(FstState *s, FstNode *node) {
- 1 - 1
- tSizes - tSizes
- oSizes; - oSizes;
return unpackUint64(slice->data + slice->start + i, oSizes); uint8_t *data = fstSliceData(slice, NULL);
return unpackUint64(data + i, oSizes);
} }
Output fstStateOutputForAnyTrans(FstState *s, FstNode *node, uint64_t i) { Output fstStateOutputForAnyTrans(FstState *s, FstNode *node, uint64_t i) {
...@@ -469,7 +480,9 @@ Output fstStateOutputForAnyTrans(FstState *s, FstNode *node, uint64_t i) { ...@@ -469,7 +480,9 @@ Output fstStateOutputForAnyTrans(FstState *s, FstNode *node, uint64_t i) {
- fstStateTotalTransSize(s, node->version, node->sizes, node->nTrans) - fstStateTotalTransSize(s, node->version, node->sizes, node->nTrans)
- (i * oSizes) - (i * oSizes)
- oSizes; - oSizes;
return unpackUint64(slice->data + slice->start + at, oSizes);
uint8_t *data = fstSliceData(slice, NULL);
return unpackUint64(data + at, oSizes);
} }
// anyTrans specify function // anyTrans specify function
...@@ -523,7 +536,10 @@ uint64_t fstStateNtrans(FstState *s, FstSlice *slice) { ...@@ -523,7 +536,10 @@ uint64_t fstStateNtrans(FstState *s, FstSlice *slice) {
if (null != true) { if (null != true) {
return n; return n;
} }
n = slice->data[slice->end - 1]; // data[data.len() - 2] int32_t len;
uint8_t *data = fstSliceData(slice, &len);
n = data[len - 2];
//n = data[slice->end - 1]; // data[data.len() - 2]
return n == 1 ? 256: n; // // "1" is never a normal legal value here, because if there, // is only 1 transition, then it is encoded in the state byte return n == 1 ? 256: n; // // "1" is never a normal legal value here, because if there, // is only 1 transition, then it is encoded in the state byte
} }
Output fstStateFinalOutput(FstState *s, uint64_t version, FstSlice *slice, PackSizes sizes, uint64_t nTrans) { Output fstStateFinalOutput(FstState *s, uint64_t version, FstSlice *slice, PackSizes sizes, uint64_t nTrans) {
...@@ -538,7 +554,8 @@ Output fstStateFinalOutput(FstState *s, uint64_t version, FstSlice *slice, Pack ...@@ -538,7 +554,8 @@ Output fstStateFinalOutput(FstState *s, uint64_t version, FstSlice *slice, Pack
- fstStateTotalTransSize(s, version, sizes, nTrans) - fstStateTotalTransSize(s, version, sizes, nTrans)
- (nTrans * oSizes) - (nTrans * oSizes)
- oSizes; - oSizes;
return unpackUint64(slice->data + slice->start + at, (uint8_t)oSizes); uint8_t *data = fstSliceData(slice, NULL);
return unpackUint64(data + at, (uint8_t)oSizes);
} }
uint64_t fstStateFindInput(FstState *s, FstNode *node, uint8_t b, bool *null) { uint64_t fstStateFindInput(FstState *s, FstNode *node, uint8_t b, bool *null) {
...@@ -549,7 +566,10 @@ uint64_t fstStateFindInput(FstState *s, FstNode *node, uint8_t b, bool *null) { ...@@ -549,7 +566,10 @@ uint64_t fstStateFindInput(FstState *s, FstNode *node, uint8_t b, bool *null) {
- fstStateNtransLen(s) - fstStateNtransLen(s)
- 1 // pack size - 1 // pack size
- fstStateTransIndexSize(s, node->version, node->nTrans); - fstStateTransIndexSize(s, node->version, node->nTrans);
uint64_t i = slice->data[slice->start + at + b]; int32_t dlen = 0;
uint8_t *data = fstSliceData(slice, &dlen);
uint64_t i = data[at + b];
//uint64_t i = slice->data[slice->start + at + b];
if (i >= node->nTrans) { if (i >= node->nTrans) {
*null = true; *null = true;
} }
...@@ -561,8 +581,13 @@ uint64_t fstStateFindInput(FstState *s, FstNode *node, uint8_t b, bool *null) { ...@@ -561,8 +581,13 @@ uint64_t fstStateFindInput(FstState *s, FstNode *node, uint8_t b, bool *null) {
- node->nTrans; - node->nTrans;
uint64_t end = start + node->nTrans; uint64_t end = start + node->nTrans;
uint64_t len = end - start; uint64_t len = end - start;
int32_t dlen = 0;
uint8_t *data = fstSliceData(slice, &dlen);
for(int i = 0; i < len; i++) { for(int i = 0; i < len; i++) {
uint8_t v = slice->data[slice->start + i]; //uint8_t v = slice->data[slice->start + i];
////slice->data[slice->start + i];
uint8_t v = data[i];
if (v == b) { if (v == b) {
return node->nTrans - i - 1; // bug return node->nTrans - i - 1; // bug
} }
...@@ -635,6 +660,7 @@ static const char *fstNodeState(FstNode *node) { ...@@ -635,6 +660,7 @@ static const char *fstNodeState(FstNode *node) {
void fstNodeDestroy(FstNode *node) { void fstNodeDestroy(FstNode *node) {
fstSliceDestroy(&node->data);
free(node); free(node);
} }
FstTransitions* fstNodeTransitions(FstNode *node) { FstTransitions* fstNodeTransitions(FstNode *node) {
...@@ -774,18 +800,18 @@ bool fstBuilderInsert(FstBuilder *b, FstSlice bs, Output in) { ...@@ -774,18 +800,18 @@ bool fstBuilderInsert(FstBuilder *b, FstSlice bs, Output in) {
void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) { void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
FstSlice *s = &bs; FstSlice *s = &bs;
if (fstSliceEmpty(s)) { if (fstSliceIsEmpty(s)) {
b->len = 1; b->len = 1;
fstUnFinishedNodesSetRootOutput(b->unfinished, in); fstUnFinishedNodesSetRootOutput(b->unfinished, in);
return; return;
} }
Output out;
//if (in != 0) { //if let Some(in) = in //if (in != 0) { //if let Some(in) = in
// prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out); // prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
//} else { //} else {
// prefixLen = fstUnFinishedNodesFindCommPrefix(b->unfinished, bs); // prefixLen = fstUnFinishedNodesFindCommPrefix(b->unfinished, bs);
// out = 0; // out = 0;
//} //}
Output out;
uint64_t prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out); uint64_t prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out);
if (prefixLen == FST_SLICE_LEN(s)) { if (prefixLen == FST_SLICE_LEN(s)) {
...@@ -798,12 +824,13 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) { ...@@ -798,12 +824,13 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) {
FstSlice sub = fstSliceCopy(s, prefixLen, s->end); FstSlice sub = fstSliceCopy(s, prefixLen, s->end);
fstUnFinishedNodesAddSuffix(b->unfinished, sub, out); fstUnFinishedNodesAddSuffix(b->unfinished, sub, out);
fstSliceDestroy(&sub);
return; return;
} }
OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) { OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup) {
FstSlice *input = &bs; FstSlice *input = &bs;
if (fstSliceEmpty(&b->last)) { if (fstSliceIsEmpty(&b->last)) {
// deep copy or not // deep copy or not
b->last = fstSliceCopy(&bs, input->start, input->end); b->last = fstSliceCopy(&bs, input->start, input->end);
} else { } else {
...@@ -829,7 +856,7 @@ void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate) { ...@@ -829,7 +856,7 @@ void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate) {
} }
addr = fstBuilderCompile(b, n); addr = fstBuilderCompile(b, n);
assert(addr != NONE_ADDRESS); assert(addr != NONE_ADDRESS);
fstBuilderNodeDestroy(n); //fstBuilderNodeDestroy(n);
} }
fstUnFinishedNodesTopLastFreeze(b->unfinished, addr); fstUnFinishedNodesTopLastFreeze(b->unfinished, addr);
return; return;
...@@ -888,7 +915,7 @@ void fstBuilderFinish(FstBuilder *b) { ...@@ -888,7 +915,7 @@ void fstBuilderFinish(FstBuilder *b) {
FstSlice fstNodeAsSlice(FstNode *node) { FstSlice fstNodeAsSlice(FstNode *node) {
FstSlice *slice = &node->data; FstSlice *slice = &node->data;
FstSlice s = fstSliceCopy(slice, slice->end, slice->dLen - 1); FstSlice s = fstSliceCopy(slice, slice->end, FST_SLICE_LEN(slice) - 1);
return s; return s;
} }
...@@ -929,12 +956,13 @@ void fstBuilderNodeUnfinishedAddOutputPrefix(FstBuilderNodeUnfinished *unNode, O ...@@ -929,12 +956,13 @@ void fstBuilderNodeUnfinishedAddOutputPrefix(FstBuilderNodeUnfinished *unNode, O
} }
Fst* fstCreate(FstSlice *slice) { Fst* fstCreate(FstSlice *slice) {
char *buf = slice->data; int32_t slen;
uint64_t skip = 0; char *buf = fstSliceData(slice, &slen);
uint64_t len = slice->dLen; if (slen < 36) {
if (len < 36) {
return NULL; return NULL;
} }
uint64_t len = slen;
uint64_t skip = 0;
uint64_t version; uint64_t version;
taosDecodeFixedU64(buf, &version); taosDecodeFixedU64(buf, &version);
...@@ -992,8 +1020,10 @@ void fstDestroy(Fst *fst) { ...@@ -992,8 +1020,10 @@ void fstDestroy(Fst *fst) {
bool fstGet(Fst *fst, FstSlice *b, Output *out) { bool fstGet(Fst *fst, FstSlice *b, Output *out) {
FstNode *root = fstGetRoot(fst); FstNode *root = fstGetRoot(fst);
Output tOut = 0; Output tOut = 0;
for (uint32_t i = 0; i < b->dLen; i++) { int32_t len;
uint8_t inp = b->data[i]; uint8_t *data = fstSliceData(b, &len);
for (uint32_t i = 0; i < len; i++) {
uint8_t inp = data[i];
Output res = 0; Output res = 0;
bool null = fstNodeFindInput(root, inp, &res); bool null = fstNodeFindInput(root, inp, &res);
if (null) { return false; } if (null) { return false; }
...@@ -1046,9 +1076,10 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) { ...@@ -1046,9 +1076,10 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) {
bool fstVerify(Fst *fst) { bool fstVerify(Fst *fst) {
uint32_t checkSum = fst->meta->checkSum; uint32_t checkSum = fst->meta->checkSum;
FstSlice *data = fst->data; int32_t len;
uint8_t *data = fstSliceData(fst->data, &len);
TSCKSUM initSum = 0; TSCKSUM initSum = 0;
if (!taosCheckChecksumWhole(data->data, data->dLen)) { if (!taosCheckChecksumWhole(data, len)) {
return false; return false;
} }
return true; return true;
...@@ -1059,8 +1090,13 @@ FstBoundWithData* fstBoundStateCreate(FstBound type, FstSlice *data) { ...@@ -1059,8 +1090,13 @@ FstBoundWithData* fstBoundStateCreate(FstBound type, FstSlice *data) {
FstBoundWithData *b = calloc(1, sizeof(FstBoundWithData)); FstBoundWithData *b = calloc(1, sizeof(FstBoundWithData));
if (b == NULL) { return NULL; } if (b == NULL) { return NULL; }
b->type = type; if (data != NULL) {
b->data = fstSliceCopy(data, data->start, data->end); b->data = fstSliceCopy(data, data->start, data->end);
} else {
b->data = fstSliceCreate(NULL, 0);
}
b->type = type;
return b; return b;
} }
...@@ -1078,7 +1114,7 @@ bool fstBoundWithDataIsEmpty(FstBoundWithData *bound) { ...@@ -1078,7 +1114,7 @@ bool fstBoundWithDataIsEmpty(FstBoundWithData *bound) {
if (bound->type == Unbounded) { if (bound->type == Unbounded) {
return true; return true;
} else { } else {
return fstSliceEmpty(&bound->data); return fstSliceIsEmpty(&bound->data);
} }
} }
...@@ -1145,8 +1181,10 @@ bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) { ...@@ -1145,8 +1181,10 @@ bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) {
Output out = 0; Output out = 0;
void* autState = sws->aut->start(); void* autState = sws->aut->start();
for (uint32_t i = 0; i < key->dLen; i++) { int32_t len;
uint8_t b = key->data[i]; uint8_t *data = fstSliceData(key, &len);
for (uint32_t i = 0; i < len; i++) {
uint8_t b = data[i];
uint64_t res = 0; uint64_t res = 0;
bool null = fstNodeFindInput(node, b, &res); bool null = fstNodeFindInput(node, b, &res);
if (null == false) { if (null == false) {
...@@ -1262,12 +1300,16 @@ StreamWithStateResult *streamWithStateNextWith(StreamWithState *sws, StreamCallb ...@@ -1262,12 +1300,16 @@ StreamWithStateResult *streamWithStateNextWith(StreamWithState *sws, StreamCallb
if (fstBoundWithDataExceededBy(sws->endAt, &slice)) { if (fstBoundWithDataExceededBy(sws->endAt, &slice)) {
taosArrayDestroyEx(sws->stack, streamStateDestroy); taosArrayDestroyEx(sws->stack, streamStateDestroy);
sws->stack = (SArray *)taosArrayInit(256, sizeof(StreamState)); sws->stack = (SArray *)taosArrayInit(256, sizeof(StreamState));
fstSliceDestroy(&slice);
return NULL; return NULL;
} }
if (FST_NODE_IS_FINAL(nextNode) && isMatch) { if (FST_NODE_IS_FINAL(nextNode) && isMatch) {
FstOutput fOutput = {.null = false, out = out + FST_NODE_FINAL_OUTPUT(nextNode)}; FstOutput fOutput = {.null = false, .out = out + FST_NODE_FINAL_OUTPUT(nextNode)};
return swsResultCreate(&slice, fOutput , tState); StreamWithStateResult *result = swsResultCreate(&slice, fOutput , tState);
fstSliceDestroy(&slice);
return result;
} }
fstSliceDestroy(&slice);
} }
return NULL; return NULL;
...@@ -1277,14 +1319,19 @@ StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *sta ...@@ -1277,14 +1319,19 @@ StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *sta
StreamWithStateResult *result = calloc(1, sizeof(StreamWithStateResult)); StreamWithStateResult *result = calloc(1, sizeof(StreamWithStateResult));
if (result == NULL) { return NULL; } if (result == NULL) { return NULL; }
FstSlice slice = fstSliceCopy(data, 0, data->dLen - 1); result->data = fstSliceCopy(data, 0, FST_SLICE_LEN(data) - 1);
result->data = slice;
result->out = fOut; result->out = fOut;
result->state = state; result->state = state;
return result; return result;
}
void swsResultDestroy(StreamWithStateResult *result) {
if (NULL == result) { return; }
fstSliceDestroy(&result->data);
free(result);
} }
void streamStateDestroy(void *s) { void streamStateDestroy(void *s) {
if (NULL == s) { return; } if (NULL == s) { return; }
StreamState *ss = (StreamState *)s; StreamState *ss = (StreamState *)s;
...@@ -1293,5 +1340,44 @@ void streamStateDestroy(void *s) { ...@@ -1293,5 +1340,44 @@ void streamStateDestroy(void *s) {
//free(s->autoState); //free(s->autoState);
} }
FstStreamBuilder *fstStreamBuilderCreate(Fst *fst, Automation *aut) {
FstStreamBuilder *b = calloc(1, sizeof(FstStreamBuilder));
if (NULL == b) { return NULL; }
b->fst = fst;
b->aut = aut;
b->min = fstBoundStateCreate(Unbounded, NULL);
b->max = fstBoundStateCreate(Unbounded, NULL);
return b;
}
void fstStreamBuilderDestroy(FstStreamBuilder *b) {
fstSliceDestroy(&b->min->data);
fstSliceDestroy(&b->max->data);
free(b);
}
FstStreamBuilder *fstStreamBuilderRange(FstStreamBuilder *b, FstSlice *val, RangeType type) {
if (b == NULL) { return NULL; }
if (type == GE) {
b->min->type = Included;
fstSliceDestroy(&(b->min->data));
b->min->data = fstSliceDeepCopy(val, 0, FST_SLICE_LEN(val) - 1);
} else if (type == GT) {
b->min->type = Excluded;
fstSliceDestroy(&(b->min->data));
b->min->data = fstSliceDeepCopy(val, 0, FST_SLICE_LEN(val) - 1);
} else if (type == LE) {
b->max->type = Included;
fstSliceDestroy(&(b->max->data));
b->max->data = fstSliceDeepCopy(val, 0, FST_SLICE_LEN(val) - 1);
} else if (type == LT) {
b->max->type = Excluded;
fstSliceDestroy(&(b->max->data));
b->max->data = fstSliceDeepCopy(val, 0, FST_SLICE_LEN(val) - 1);
}
return b;
}
...@@ -12,3 +12,4 @@ ...@@ -12,3 +12,4 @@
* 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/>.
*/ */
...@@ -16,24 +16,88 @@ ...@@ -16,24 +16,88 @@
#include "index_fst_util.h" #include "index_fst_util.h"
#include "index_fst_counting_writer.h" #include "index_fst_counting_writer.h"
static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len) {
if (ctx->offset + len > ctx->limit) {
return -1;
}
if (ctx->type == TFile) {
assert(len != tfWrite(ctx->fd, buf, len));
} else {
memcpy(ctx->mem + ctx->offset, buf, len);
}
ctx->offset += len;
return len;
}
static int writeCtxDoRead(WriterCtx *ctx, uint8_t *buf, int len) {
if (ctx->type == TFile) {
tfRead(ctx->fd, buf, len);
} else {
memcpy(buf, ctx->mem + ctx->offset, len);
}
ctx->offset += len;
return 1;
}
static int writeCtxDoFlush(WriterCtx *ctx) {
if (ctx->type == TFile) {
//tfFlush(ctx->fd);
} else {
// do nothing
}
return 1;
}
WriterCtx* writerCtxCreate(WriterType type) {
WriterCtx *ctx = calloc(1, sizeof(WriterCtx));
if (ctx == NULL) { return NULL; }
ctx->type == type;
if (ctx->type == TFile) {
ctx->fd = tfOpenCreateWriteAppend(tmpFile);
} else if (ctx->type == TMemory) {
ctx->mem = calloc(1, DefaultMem * sizeof(uint8_t));
}
ctx->write = writeCtxDoWrite;
ctx->read = writeCtxDoRead;
ctx->flush = writeCtxDoFlush;
ctx->offset = 0;
ctx->limit = DefaultMem;
return ctx;
}
void writerCtxDestroy(WriterCtx *ctx) {
if (ctx->type == TMemory) {
free(ctx->mem);
} else {
tfClose(ctx->fd);
}
free(ctx);
}
FstCountingWriter *fstCountingWriterCreate(void *wrt) { FstCountingWriter *fstCountingWriterCreate(void *wrt) {
FstCountingWriter *cw = calloc(1, sizeof(FstCountingWriter)); FstCountingWriter *cw = calloc(1, sizeof(FstCountingWriter));
if (cw == NULL) { return NULL; } if (cw == NULL) { return NULL; }
cw->wrt = wrt; cw->wrt = (void *)(writerCtxCreate(TFile));
return cw; return cw;
} }
void fstCountingWriterDestroy(FstCountingWriter *cw) { void fstCountingWriterDestroy(FstCountingWriter *cw) {
// free wrt object: close fd or free mem // free wrt object: close fd or free mem
writerCtxDestroy((WriterCtx *)(cw->wrt));
free(cw); free(cw);
} }
uint64_t fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t bufLen) { int fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t bufLen) {
if (write == NULL) { return 0; } if (write == NULL) { return 0; }
// update checksum // update checksum
// write data to file/socket or mem // write data to file/socket or mem
WriterCtx *ctx = write->wrt;
write->count += bufLen; int nWrite = ctx->write(ctx, buf, bufLen);
write->count += nWrite;
return bufLen; return bufLen;
} }
...@@ -41,6 +105,8 @@ uint32_t fstCountingWriterMaskedCheckSum(FstCountingWriter *write) { ...@@ -41,6 +105,8 @@ uint32_t fstCountingWriterMaskedCheckSum(FstCountingWriter *write) {
return 0; return 0;
} }
int fstCountingWriterFlush(FstCountingWriter *write) { int fstCountingWriterFlush(FstCountingWriter *write) {
WriterCtx *ctx = write->wrt;
ctx->flush(ctx);
//write->wtr->flush //write->wtr->flush
return 1; return 1;
} }
......
...@@ -18,7 +18,7 @@ FstBuilderNode *fstBuilderNodeDefault() { ...@@ -18,7 +18,7 @@ FstBuilderNode *fstBuilderNodeDefault() {
FstBuilderNode *bn = malloc(sizeof(FstBuilderNode)); FstBuilderNode *bn = malloc(sizeof(FstBuilderNode));
bn->isFinal = false; bn->isFinal = false;
bn->finalOutput = 0; bn->finalOutput = 0;
bn->trans = NULL; bn->trans = taosArrayInit(16, sizeof(FstTransition));
return bn; return bn;
} }
void fstBuilderNodeDestroy(FstBuilderNode *node) { void fstBuilderNodeDestroy(FstBuilderNode *node) {
...@@ -27,6 +27,25 @@ void fstBuilderNodeDestroy(FstBuilderNode *node) { ...@@ -27,6 +27,25 @@ void fstBuilderNodeDestroy(FstBuilderNode *node) {
taosArrayDestroy(node->trans); taosArrayDestroy(node->trans);
free(node); free(node);
} }
bool fstBuilderNodeEqual(FstBuilderNode *n1, FstBuilderNode *n2) {
if (n1 == n2) { return true; }
if (n1->isFinal != n2->isFinal ||
n1->finalOutput != n2->finalOutput ||
taosArrayGetSize(n1->trans) != taosArrayGetSize(n2->trans)) {
return false;
}
size_t sz = taosArrayGetSize(n1->trans);
for (size_t i = 0; i < sz; i++) {
FstTransition *t1 = taosArrayGet(n1->trans, i);
FstTransition *t2 = taosArrayGet(n2->trans, i);
if (t1->inp != t2->inp || t1->out != t2->out || t1->addr != t2->addr) {
return false;
}
}
return true;
}
FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src) { FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src) {
FstBuilderNode *node = malloc(sizeof(FstBuilderNode)); FstBuilderNode *node = malloc(sizeof(FstBuilderNode));
if (node == NULL) { return NULL; } if (node == NULL) { return NULL; }
...@@ -53,12 +72,17 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) { ...@@ -53,12 +72,17 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) {
dst->isFinal = src->isFinal; dst->isFinal = src->isFinal;
dst->finalOutput = src->finalOutput; dst->finalOutput = src->finalOutput;
// avoid mem leak //release free avoid mem leak
taosArrayDestroy(dst->trans); taosArrayDestroy(dst->trans);
dst->trans = src->trans; size_t sz = taosArrayGetSize(src->trans);
src->trans = NULL; dst->trans = taosArrayInit(sz, sizeof(FstTransition));
for (size_t i = 0; i < sz; i++) {
FstTransition *trn = taosArrayGet(src->trans, i);
taosArrayPush(dst->trans, trn);
}
} }
//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) { //bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) {
//size_t sz = taosArrayGetSize(b->trans); //size_t sz = taosArrayGetSize(b->trans);
......
...@@ -112,7 +112,7 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo ...@@ -112,7 +112,7 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
if (end - start == 1) { if (end - start == 1) {
FstRegistryCell *cell = taosArrayGet(registry->table, start); FstRegistryCell *cell = taosArrayGet(registry->table, start);
//cell->isNode && //cell->isNode &&
if (cell->addr != NONE_ADDRESS && cell->node == bNode) { if (cell->addr != NONE_ADDRESS && fstBuilderNodeEqual(cell->node, bNode)) {
entry->state = FOUND; entry->state = FOUND;
entry->addr = cell->addr ; entry->addr = cell->addr ;
return entry; return entry;
...@@ -123,13 +123,13 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo ...@@ -123,13 +123,13 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
} }
} else if (end - start == 2) { } else if (end - start == 2) {
FstRegistryCell *cell1 = taosArrayGet(registry->table, start); FstRegistryCell *cell1 = taosArrayGet(registry->table, start);
if (cell1->addr != NONE_ADDRESS && cell1->node == bNode) { if (cell1->addr != NONE_ADDRESS && fstBuilderNodeEqual(cell1->node, bNode)) {
entry->state = FOUND; entry->state = FOUND;
entry->addr = cell1->addr; entry->addr = cell1->addr;
return entry; return entry;
} }
FstRegistryCell *cell2 = taosArrayGet(registry->table, start + 1); FstRegistryCell *cell2 = taosArrayGet(registry->table, start + 1);
if (cell2->addr != NONE_ADDRESS && cell2->node == bNode) { if (cell2->addr != NONE_ADDRESS && fstBuilderNodeEqual(cell2->node, bNode)) {
entry->state = FOUND; entry->state = FOUND;
entry->addr = cell2->addr; entry->addr = cell2->addr;
// must swap here // must swap here
...@@ -147,7 +147,7 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo ...@@ -147,7 +147,7 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo
uint32_t i = start; uint32_t i = start;
for (; i < end; i++) { for (; i < end; i++) {
FstRegistryCell *cell = (FstRegistryCell *)taosArrayGet(registry->table, i); FstRegistryCell *cell = (FstRegistryCell *)taosArrayGet(registry->table, i);
if (cell->addr != NONE_ADDRESS && cell->node == bNode) { if (cell->addr != NONE_ADDRESS && fstBuilderNodeEqual(cell->node, bNode)) {
entry->state = FOUND; entry->state = FOUND;
entry->addr = cell->addr; entry->addr = cell->addr;
fstRegistryCellPromote(registry->table, i, start); fstRegistryCellPromote(registry->table, i, start);
......
...@@ -91,42 +91,87 @@ CompiledAddr unpackDelta(char *data, uint64_t len, uint64_t nodeAddr) { ...@@ -91,42 +91,87 @@ CompiledAddr unpackDelta(char *data, uint64_t len, uint64_t nodeAddr) {
} }
// fst slice func // fst slice func
FstSlice fstSliceCreate(uint8_t *data, uint64_t dLen) { //
FstSlice slice = {.data = data, .dLen = dLen, .start = 0, .end = dLen - 1};
return slice; FstSlice fstSliceCreate(uint8_t *data, uint64_t len) {
FstString *str = (FstString *)malloc(sizeof(FstString));
str->ref = 1;
str->len = len;
str->data = malloc(len * sizeof(uint8_t));
memcpy(str->data, data, len);
FstSlice s = {.str = str, .start = 0, .end = len - 1};
return s;
} }
// just shallow copy // just shallow copy
FstSlice fstSliceCopy(FstSlice *slice, int32_t start, int32_t end) { FstSlice fstSliceCopy(FstSlice *s, int32_t start, int32_t end) {
FstSlice t; FstString *str = s->str;
if (start >= slice->dLen || end >= slice->dLen || start > end) { str->ref++;
t.data = NULL; //uint8_t *buf = fstSliceData(s, &alen);
//start = buf + start - (buf - s->start);
//end = buf + end - (buf - s->start);
FstSlice t = {.str = str, .start = start + s->start, .end = end + s->start};
return t; return t;
}; }
FstSlice fstSliceDeepCopy(FstSlice *s, int32_t start, int32_t end) {
int32_t tlen = end - start + 1;
int32_t slen;
uint8_t *data = fstSliceData(s, &slen);
assert(tlen <= slen);
uint8_t *buf = malloc(sizeof(uint8_t) * tlen);
memcpy(buf, data + start, tlen);
FstString *str = malloc(sizeof(FstString));
str->data = buf;
str->len = tlen;
str->ref = 1;
FstSlice ans;
ans.str = str;
ans.start = 0;
ans.end = tlen - 1;
return ans;
}
bool fstSliceIsEmpty(FstSlice *s) {
return s->str == NULL || s->str->len == 0 || s->start < 0 || s->end < 0;
}
t.data = slice->data; uint8_t *fstSliceData(FstSlice *s, int32_t *size) {
t.dLen = slice->dLen; FstString *str = s->str;
t.start = start; if (size != NULL) {
t.end = end; *size = s->end - s->start + 1;
return t; }
return str->data + s->start;
} }
bool fstSliceEmpty(FstSlice *slice) { void fstSliceDestroy(FstSlice *s) {
return slice->data == NULL || slice->dLen <= 0; FstString *str = s->str;
str->ref--;
if (str->ref <= 0) {
free(str->data);
free(str);
s->str = NULL;
}
} }
int fstSliceCompare(FstSlice *a, FstSlice *b) { int fstSliceCompare(FstSlice *a, FstSlice *b) {
int32_t aLen = (a->end - a->start + 1); int32_t alen, blen;
int32_t bLen = (b->end - b->start + 1); uint8_t *aBuf = fstSliceData(a, &alen);
int32_t mLen = (aLen < bLen ? aLen : bLen); uint8_t *bBuf = fstSliceData(b, &blen);
for (int i = 0; i < mLen; i++) {
uint8_t x = a->data[i + a->start]; uint32_t i, j;
uint8_t y = b->data[i + b->start]; for (i = 0, j = 0; i < alen && j < blen; i++, j++) {
if (x == y) { continue; } uint8_t x = aBuf[i];
uint8_t y = bBuf[j];
if (x == y) { continue;}
else if (x < y) { return -1; } else if (x < y) { return -1; }
else { return 1; } else { return 1; };
} }
if (aLen == bLen) { return 0; } if (i < alen) { return 1; }
else if (aLen < bLen) { return -1; } else if (j < blen) { return -1; }
else { return 1; } else { return 0; }
} }
......
add_executable(indexTest "") add_executable(indexTest "")
target_sources(indexTest target_sources(indexTest
PRIVATE PRIVATE
"../src/index.c"
"indexTests.cpp" "indexTests.cpp"
) )
target_include_directories ( indexTest target_include_directories ( indexTest
......
...@@ -3,58 +3,84 @@ ...@@ -3,58 +3,84 @@
#include <iostream> #include <iostream>
#include "index.h" #include "index.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_fst.h"
#include "index_fst_util.h"
#include "index_fst_counting_writer.h"
//TEST(IndexTest, index_create_test) {
// SIndexOpts *opts = indexOptsCreate();
// SIndex *index = indexOpen(opts, "./test");
// if (index == NULL) {
// std::cout << "index open failed" << std::endl;
// }
//
//
// // write
// for (int i = 0; i < 100000; i++) {
// SIndexMultiTerm* terms = indexMultiTermCreate();
// std::string val = "field";
//
// indexMultiTermAdd(terms, "tag1", strlen("tag1"), val.c_str(), val.size());
//
// val.append(std::to_string(i));
// indexMultiTermAdd(terms, "tag2", strlen("tag2"), val.c_str(), val.size());
//
// val.insert(0, std::to_string(i));
// indexMultiTermAdd(terms, "tag3", strlen("tag3"), val.c_str(), val.size());
//
// val.append("const");
// indexMultiTermAdd(terms, "tag4", strlen("tag4"), val.c_str(), val.size());
//
//
// indexPut(index, terms, i);
// indexMultiTermDestroy(terms);
// }
//
//
// // query
// SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST);
//
// indexMultiTermQueryAdd(multiQuery, "tag1", strlen("tag1"), "field", strlen("field"), QUERY_PREFIX);
// indexMultiTermQueryAdd(multiQuery, "tag3", strlen("tag3"), "0field0", strlen("0field0"), QUERY_TERM);
//
// SArray *result = (SArray *)taosArrayInit(10, sizeof(int));
// indexSearch(index, multiQuery, result);
//
// std::cout << "taos'size : " << taosArrayGetSize(result) << std::endl;
// for (int i = 0; i < taosArrayGetSize(result); i++) {
// int *v = (int *)taosArrayGet(result, i);
// std::cout << "value --->" << *v << std::endl;
// }
// // add more test case
// indexMultiTermQueryDestroy(multiQuery);
//
// indexOptsDestroy(opts);
// indexClose(index);
// //
//}
int main(int argc, char** argv) {
std::string str("abc");
FstSlice key = fstSliceCreate((uint8_t *)str.c_str(), str.size());
Output val = 10;
std::string str1("bcd");
FstSlice key1 = fstSliceCreate((uint8_t *)str1.c_str(), str1.size());
Output val2 = 10;
FstBuilder *b = fstBuilderCreate(NULL, 1);
fstBuilderInsert(b, key, val);
fstBuilderInsert(b, key1, val2);
fstBuilderFinish(b);
fstBuilderDestroy(b);
fstSliceDestroy(&key);
return 1;
}
//TEST(IndexFstBuilder, IndexFstInput) {
//
//}
TEST(IndexTest, index_create_test) {
SIndexOpts *opts = indexOptsCreate();
SIndex *index = indexOpen(opts, "./test");
if (index == NULL) {
std::cout << "index open failed" << std::endl;
}
// write
for (int i = 0; i < 100000; i++) {
SIndexMultiTerm* terms = indexMultiTermCreate();
std::string val = "field";
indexMultiTermAdd(terms, "tag1", strlen("tag1"), val.c_str(), val.size());
val.append(std::to_string(i));
indexMultiTermAdd(terms, "tag2", strlen("tag2"), val.c_str(), val.size());
val.insert(0, std::to_string(i));
indexMultiTermAdd(terms, "tag3", strlen("tag3"), val.c_str(), val.size());
val.append("const");
indexMultiTermAdd(terms, "tag4", strlen("tag4"), val.c_str(), val.size());
indexPut(index, terms, i);
indexMultiTermDestroy(terms);
}
// query
SIndexMultiTermQuery *multiQuery = indexMultiTermQueryCreate(MUST);
indexMultiTermQueryAdd(multiQuery, "tag1", strlen("tag1"), "field", strlen("field"), QUERY_PREFIX);
indexMultiTermQueryAdd(multiQuery, "tag3", strlen("tag3"), "0field0", strlen("0field0"), QUERY_TERM);
SArray *result = (SArray *)taosArrayInit(10, sizeof(int));
indexSearch(index, multiQuery, result);
std::cout << "taos'size : " << taosArrayGetSize(result) << std::endl;
for (int i = 0; i < taosArrayGetSize(result); i++) {
int *v = (int *)taosArrayGet(result, i);
std::cout << "value --->" << *v << std::endl;
}
// add more test case
indexMultiTermQueryDestroy(multiQuery);
indexOptsDestroy(opts);
indexClose(index);
//
}
...@@ -252,14 +252,14 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) { ...@@ -252,14 +252,14 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); } void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); }
bool taosGetSystemUid(char *uid) { int32_t taosGetSystemUid(char *uid, int32_t uidlen) {
GUID guid; GUID guid;
CoCreateGuid(&guid); CoCreateGuid(&guid);
sprintf(uid, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], sprintf(uid, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0],
guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
return true; return 0;
} }
char *taosGetCmdlineByPID(int pid) { return ""; } char *taosGetCmdlineByPID(int pid) { return ""; }
...@@ -452,12 +452,12 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { ...@@ -452,12 +452,12 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) {
} }
} }
bool taosGetSystemUid(char *uid) { int32_t taosGetSystemUid(char *uid, int32_t uidlen) {
uuid_t uuid = {0}; uuid_t uuid = {0};
uuid_generate(uuid); uuid_generate(uuid);
// it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null
uuid_unparse_lower(uuid, uid); uuid_unparse_lower(uuid, uid);
return true; return 0;
} }
char *taosGetCmdlineByPID(int pid) { char *taosGetCmdlineByPID(int pid) {
...@@ -1070,13 +1070,13 @@ void taosSetCoreDump(bool enable) { ...@@ -1070,13 +1070,13 @@ void taosSetCoreDump(bool enable) {
#endif #endif
} }
bool taosGetSystemUid(char *uid, int32_t uidlen) { int32_t taosGetSystemUid(char *uid, int32_t uidlen) {
int fd; int fd;
int len = 0; int len = 0;
fd = open("/proc/sys/kernel/random/uuid", 0); fd = open("/proc/sys/kernel/random/uuid", 0);
if (fd < 0) { if (fd < 0) {
return false; return -1;
} else { } else {
len = read(fd, uid, uidlen); len = read(fd, uid, uidlen);
close(fd); close(fd);
...@@ -1084,9 +1084,10 @@ bool taosGetSystemUid(char *uid, int32_t uidlen) { ...@@ -1084,9 +1084,10 @@ bool taosGetSystemUid(char *uid, int32_t uidlen) {
if (len >= 36) { if (len >= 36) {
uid[36] = 0; uid[36] = 0;
return true; return 0;
} }
return false;
return -1;
} }
char *taosGetCmdlineByPID(int pid) { char *taosGetCmdlineByPID(int pid) {
......
...@@ -130,7 +130,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, "Message not processed ...@@ -130,7 +130,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, "Message not processed
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_IN_PROGRESS, "Message is progressing") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_IN_PROGRESS, "Message is progressing")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_NEED_REPROCESSED, "Message need to be reprocessed") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACTION_NEED_REPROCESSED, "Message need to be reprocessed")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_RIGHTS, "Insufficient privilege for operation") TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_RIGHTS, "Insufficient privilege for operation")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_APP_ERROR, "Unexpected generic error in mnode") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_OPTIONS, "Invalid mnode options")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONNECTION, "Invalid message connection") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONNECTION, "Invalid message connection")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_VERSION, "Incompatible protocol version") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_VERSION, "Incompatible protocol version")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_LEN, "Invalid message length") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_MSG_LEN, "Invalid message length")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册