提交 ad55c1a7 编写于 作者: S shenglian zhou

Merge branch 'develop' into feature/td-4647-2

...@@ -13,3 +13,6 @@ ...@@ -13,3 +13,6 @@
[submodule "deps/jemalloc"] [submodule "deps/jemalloc"]
path = deps/jemalloc path = deps/jemalloc
url = https://github.com/jemalloc/jemalloc url = https://github.com/jemalloc/jemalloc
[submodule "deps/TSZ"]
path = deps/TSZ
url = https://github.com/taosdata/TSZ.git
...@@ -91,3 +91,12 @@ SET(TD_MEMORY_SANITIZER FALSE) ...@@ -91,3 +91,12 @@ SET(TD_MEMORY_SANITIZER FALSE)
IF (${MEMORY_SANITIZER} MATCHES "true") IF (${MEMORY_SANITIZER} MATCHES "true")
SET(TD_MEMORY_SANITIZER TRUE) SET(TD_MEMORY_SANITIZER TRUE)
ENDIF () ENDIF ()
IF (${TSZ_ENABLED} MATCHES "true")
# define add
MESSAGE(STATUS "build with TSZ enabled")
ADD_DEFINITIONS(-DTD_TSZ)
set(VAR_TSZ "TSZ" CACHE INTERNAL "global variant tsz" )
ELSE()
set(VAR_TSZ "" CACHE INTERNAL "global variant empty" )
ENDIF()
...@@ -15,7 +15,6 @@ ADD_SUBDIRECTORY(cJson) ...@@ -15,7 +15,6 @@ ADD_SUBDIRECTORY(cJson)
ADD_SUBDIRECTORY(wepoll) ADD_SUBDIRECTORY(wepoll)
ADD_SUBDIRECTORY(MsvcLibX) ADD_SUBDIRECTORY(MsvcLibX)
ADD_SUBDIRECTORY(rmonotonic) ADD_SUBDIRECTORY(rmonotonic)
ADD_SUBDIRECTORY(lua) ADD_SUBDIRECTORY(lua)
IF (TD_LINUX AND TD_MQTT) IF (TD_LINUX AND TD_MQTT)
...@@ -38,3 +37,7 @@ IF (TD_LINUX_64 AND JEMALLOC_ENABLED) ...@@ -38,3 +37,7 @@ IF (TD_LINUX_64 AND JEMALLOC_ENABLED)
BUILD_COMMAND ${MAKE} BUILD_COMMAND ${MAKE}
) )
ENDIF () ENDIF ()
IF (${TSZ_ENABLED} MATCHES "true")
ADD_SUBDIRECTORY(TSZ)
ENDIF()
\ No newline at end of file
Subproject commit 0ca5b15a8eac40327dd737be52c926fa5675712c
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
static SBnThread tsBnThread; static SBnThread tsBnThread;
static void *bnThreadFunc(void *arg) { static void *bnThreadFunc(void *arg) {
setThreadName("bnThreadd");
while (1) { while (1) {
pthread_mutex_lock(&tsBnThread.mutex); pthread_mutex_lock(&tsBnThread.mutex);
if (tsBnThread.stop) { if (tsBnThread.stop) {
......
...@@ -11,7 +11,7 @@ IF (TD_LINUX) ...@@ -11,7 +11,7 @@ IF (TD_LINUX)
# set the static lib name # set the static lib name
ADD_LIBRARY(taos_static STATIC ${SRC}) ADD_LIBRARY(taos_static STATIC ${SRC})
TARGET_LINK_LIBRARIES(taos_static common query trpc tutil pthread m rt) TARGET_LINK_LIBRARIES(taos_static common query trpc tutil pthread m rt ${VAR_TSZ})
SET_TARGET_PROPERTIES(taos_static PROPERTIES OUTPUT_NAME "taos_static") SET_TARGET_PROPERTIES(taos_static PROPERTIES OUTPUT_NAME "taos_static")
SET_TARGET_PROPERTIES(taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(taos_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
......
...@@ -108,7 +108,9 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le ...@@ -108,7 +108,9 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, SName* name, STableMeta* pTableMeta, STableDataBlocks** dataBlocks); int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, SName* name, STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta); void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta);
void tscSortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf);
int tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo); int tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo);
int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows);
void tscDestroyBoundColumnInfo(SParsedDataColInfo* pColInfo); void tscDestroyBoundColumnInfo(SParsedDataColInfo* pColInfo);
void doRetrieveSubqueryData(SSchedMsg *pMsg); void doRetrieveSubqueryData(SSchedMsg *pMsg);
......
...@@ -138,7 +138,8 @@ typedef struct STableDataBlocks { ...@@ -138,7 +138,8 @@ typedef struct STableDataBlocks {
uint32_t size; uint32_t size;
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache
char *pData; char *pData;
bool cloned;
SParsedDataColInfo boundColumnInfo; SParsedDataColInfo boundColumnInfo;
// for parameter ('?') binding // for parameter ('?') binding
...@@ -159,6 +160,7 @@ typedef struct SInsertStatementParam { ...@@ -159,6 +160,7 @@ typedef struct SInsertStatementParam {
SHashObj *pTableBlockHashList; // data block for each table SHashObj *pTableBlockHashList; // data block for each table
SArray *pDataBlocks; // SArray<STableDataBlocks*>. Merged submit block for each vgroup SArray *pDataBlocks; // SArray<STableDataBlocks*>. Merged submit block for each vgroup
int8_t schemaAttached; // denote if submit block is built with table schema or not int8_t schemaAttached; // denote if submit block is built with table schema or not
uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
STagData tagData; // NOTE: pTagData->data is used as a variant length array STagData tagData; // NOTE: pTagData->data is used as a variant length array
int32_t batchSize; // for parameter ('?') binding and batch processing int32_t batchSize; // for parameter ('?') binding and batch processing
...@@ -170,6 +172,14 @@ typedef struct SInsertStatementParam { ...@@ -170,6 +172,14 @@ typedef struct SInsertStatementParam {
char *sql; // current sql statement position char *sql; // current sql statement position
} SInsertStatementParam; } SInsertStatementParam;
typedef enum {
PAYLOAD_TYPE_KV = 0,
PAYLOAD_TYPE_RAW = 1,
} EPayloadType;
#define IS_RAW_PAYLOAD(t) \
(((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
// TODO extract sql parser supporter // TODO extract sql parser supporter
typedef struct { typedef struct {
int command; int command;
...@@ -428,4 +438,4 @@ int32_t getExtendedRowSize(STableComInfo *tinfo); ...@@ -428,4 +438,4 @@ int32_t getExtendedRowSize(STableComInfo *tinfo);
} }
#endif #endif
#endif #endif
\ No newline at end of file
...@@ -7,11 +7,16 @@ taos_connect_auth ...@@ -7,11 +7,16 @@ taos_connect_auth
taos_close taos_close
taos_stmt_init taos_stmt_init
taos_stmt_prepare taos_stmt_prepare
taos_stmt_set_tbname_tags
taos_stmt_set_tbname
taos_stmt_is_insert
taos_stmt_num_params
taos_stmt_bind_param taos_stmt_bind_param
taos_stmt_add_batch taos_stmt_add_batch
taos_stmt_execute taos_stmt_execute
taos_stmt_use_result taos_stmt_use_result
taos_stmt_close taos_stmt_close
taos_stmt_errstr
taos_query taos_query
taos_fetch_row taos_fetch_row
taos_result_precision taos_result_precision
...@@ -37,6 +42,4 @@ taos_consume ...@@ -37,6 +42,4 @@ taos_consume
taos_unsubscribe taos_unsubscribe
taos_open_stream taos_open_stream
taos_close_stream taos_close_stream
taos_fetch_block
taos_load_table_info taos_load_table_info
...@@ -425,7 +425,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -425,7 +425,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
case TSDB_DATA_TYPE_BOOL: { // bool case TSDB_DATA_TYPE_BOOL: { // bool
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_BOOL), TYPE_BYTES[TSDB_DATA_TYPE_BOOL], tOffset); getNullValue(TSDB_DATA_TYPE_BOOL), TYPE_BYTES[TSDB_DATA_TYPE_BOOL], tOffset);
} else { } else {
if ((pToken->type == TK_BOOL || pToken->type == TK_STRING) && (pToken->n != 0)) { if ((pToken->type == TK_BOOL || pToken->type == TK_STRING) && (pToken->n != 0)) {
if (strncmp(pToken->z, "true", pToken->n) == 0) { if (strncmp(pToken->z, "true", pToken->n) == 0) {
...@@ -459,7 +459,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -459,7 +459,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_TINYINT), TYPE_BYTES[TSDB_DATA_TYPE_TINYINT], tOffset); getNullValue(TSDB_DATA_TYPE_TINYINT), TYPE_BYTES[TSDB_DATA_TYPE_TINYINT], tOffset);
} else { } else {
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true); ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -479,7 +479,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -479,7 +479,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_UTINYINT), TYPE_BYTES[TSDB_DATA_TYPE_UTINYINT], tOffset); getNullValue(TSDB_DATA_TYPE_UTINYINT), TYPE_BYTES[TSDB_DATA_TYPE_UTINYINT], tOffset);
} else { } else {
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false); ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -499,7 +499,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -499,7 +499,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_SMALLINT), TYPE_BYTES[TSDB_DATA_TYPE_SMALLINT], tOffset); getNullValue(TSDB_DATA_TYPE_SMALLINT), TYPE_BYTES[TSDB_DATA_TYPE_SMALLINT], tOffset);
} else { } else {
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true); ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -520,7 +520,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -520,7 +520,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = *sizeAppend =
tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_USMALLINT), TYPE_BYTES[TSDB_DATA_TYPE_USMALLINT], tOffset); getNullValue(TSDB_DATA_TYPE_USMALLINT), TYPE_BYTES[TSDB_DATA_TYPE_USMALLINT], tOffset);
} else { } else {
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false); ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -540,7 +540,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -540,7 +540,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_INT:
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_INT), TYPE_BYTES[TSDB_DATA_TYPE_INT], tOffset); getNullValue(TSDB_DATA_TYPE_INT), TYPE_BYTES[TSDB_DATA_TYPE_INT], tOffset);
} else { } else {
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true); ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -560,7 +560,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -560,7 +560,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UINT:
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_UINT), TYPE_BYTES[TSDB_DATA_TYPE_UINT], tOffset); getNullValue(TSDB_DATA_TYPE_UINT), TYPE_BYTES[TSDB_DATA_TYPE_UINT], tOffset);
} else { } else {
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false); ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -580,7 +580,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -580,7 +580,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_BIGINT), TYPE_BYTES[TSDB_DATA_TYPE_BIGINT], tOffset); getNullValue(TSDB_DATA_TYPE_BIGINT), TYPE_BYTES[TSDB_DATA_TYPE_BIGINT], tOffset);
} else { } else {
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true); ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, true);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -598,7 +598,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -598,7 +598,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_UBIGINT:
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_UBIGINT), TYPE_BYTES[TSDB_DATA_TYPE_UBIGINT], tOffset); getNullValue(TSDB_DATA_TYPE_UBIGINT), TYPE_BYTES[TSDB_DATA_TYPE_UBIGINT], tOffset);
} else { } else {
ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false); ret = tStrToInteger(pToken->z, pToken->type, pToken->n, &iv, false);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
...@@ -639,7 +639,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -639,7 +639,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
if (isNullStr(pToken)) { if (isNullStr(pToken)) {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_DOUBLE), TYPE_BYTES[TSDB_DATA_TYPE_DOUBLE], tOffset); getNullValue(TSDB_DATA_TYPE_DOUBLE), TYPE_BYTES[TSDB_DATA_TYPE_DOUBLE], tOffset);
} else { } else {
double dv; double dv;
if (TK_ILLEGAL == tscToDouble(pToken, &dv, &endptr)) { if (TK_ILLEGAL == tscToDouble(pToken, &dv, &endptr)) {
...@@ -661,7 +661,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -661,7 +661,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
if (pToken->type == TK_NULL) { if (pToken->type == TK_NULL) {
payloadColSetId(payload, pSchema->colId); payloadColSetId(payload, pSchema->colId);
payloadColSetType(payload, pSchema->type); payloadColSetType(payload, pSchema->type);
memcpy(POINTER_SHIFT(payloadStart, tOffset), tdGetNullVal(TSDB_DATA_TYPE_BINARY), VARSTR_HEADER_SIZE + CHAR_BYTES); memcpy(POINTER_SHIFT(payloadStart, tOffset), getNullValue(TSDB_DATA_TYPE_BINARY), VARSTR_HEADER_SIZE + CHAR_BYTES);
*sizeAppend = (TDRowLenT)(VARSTR_HEADER_SIZE + CHAR_BYTES); *sizeAppend = (TDRowLenT)(VARSTR_HEADER_SIZE + CHAR_BYTES);
} else { // too long values will return invalid sql, not be truncated automatically } else { // too long values will return invalid sql, not be truncated automatically
if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) { // todo refactor if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) { // todo refactor
...@@ -684,7 +684,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -684,7 +684,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
if (pToken->type == TK_NULL) { if (pToken->type == TK_NULL) {
payloadColSetId(payload, pSchema->colId); payloadColSetId(payload, pSchema->colId);
payloadColSetType(payload, pSchema->type); payloadColSetType(payload, pSchema->type);
memcpy(POINTER_SHIFT(payloadStart,tOffset), tdGetNullVal(TSDB_DATA_TYPE_NCHAR), VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); memcpy(POINTER_SHIFT(payloadStart,tOffset), getNullValue(TSDB_DATA_TYPE_NCHAR), VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE);
*sizeAppend = (TDRowLenT)(VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); *sizeAppend = (TDRowLenT)(VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE);
} else { } else {
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
...@@ -716,7 +716,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay ...@@ -716,7 +716,7 @@ static int32_t tsParseOneColumnKV(SSchema *pSchema, SStrToken *pToken, char *pay
*kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP]); *kvRowColLen += (TDRowLenT)(sizeof(SColIdx) + TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP]);
} else { } else {
*sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type, *sizeAppend = tsSetPayloadColValue(payloadStart, payload, pSchema->colId, pSchema->type,
tdGetNullVal(TSDB_DATA_TYPE_TIMESTAMP), getNullValue(TSDB_DATA_TYPE_TIMESTAMP),
TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], tOffset); TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], tOffset);
} }
} else { } else {
...@@ -1056,7 +1056,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3 ...@@ -1056,7 +1056,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows) { int32_t FORCE_INLINE tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows) {
pBlocks->tid = pTableMeta->id.tid; pBlocks->tid = pTableMeta->id.tid;
pBlocks->uid = pTableMeta->id.uid; pBlocks->uid = pTableMeta->id.uid;
pBlocks->sversion = pTableMeta->sversion; pBlocks->sversion = pTableMeta->sversion;
...@@ -1069,9 +1069,8 @@ int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_ ...@@ -1069,9 +1069,8 @@ int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_
} }
} }
#if 0
// data block is disordered, sort it in ascending order // data block is disordered, sort it in ascending order
static void tscSortRemoveDataBlockDupRowsOld(STableDataBlocks *dataBuf) { void tscSortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) {
SSubmitBlk *pBlocks = (SSubmitBlk *)dataBuf->pData; SSubmitBlk *pBlocks = (SSubmitBlk *)dataBuf->pData;
// size is less than the total size, since duplicated rows may be removed yet. // size is less than the total size, since duplicated rows may be removed yet.
...@@ -1114,7 +1113,6 @@ static void tscSortRemoveDataBlockDupRowsOld(STableDataBlocks *dataBuf) { ...@@ -1114,7 +1113,6 @@ static void tscSortRemoveDataBlockDupRowsOld(STableDataBlocks *dataBuf) {
dataBuf->prevTS = INT64_MIN; dataBuf->prevTS = INT64_MIN;
} }
#endif
// data block is disordered, sort it in ascending order // data block is disordered, sort it in ascending order
int tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKeyInfo) { int tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKeyInfo) {
......
...@@ -47,6 +47,7 @@ typedef struct SNormalStmt { ...@@ -47,6 +47,7 @@ typedef struct SNormalStmt {
typedef struct SMultiTbStmt { typedef struct SMultiTbStmt {
bool nameSet; bool nameSet;
bool tagSet; bool tagSet;
bool subSet;
uint64_t currentUid; uint64_t currentUid;
char *sqlstr; char *sqlstr;
uint32_t tbNum; uint32_t tbNum;
...@@ -54,6 +55,7 @@ typedef struct SMultiTbStmt { ...@@ -54,6 +55,7 @@ typedef struct SMultiTbStmt {
SStrToken stbname; SStrToken stbname;
SStrToken values; SStrToken values;
SArray *tags; SArray *tags;
STableDataBlocks *lastBlock;
SHashObj *pTableHash; SHashObj *pTableHash;
SHashObj *pTableBlockHashList; // data block for each table SHashObj *pTableBlockHashList; // data block for each table
} SMultiTbStmt; } SMultiTbStmt;
...@@ -291,7 +293,6 @@ static char* normalStmtBuildSql(STscStmt* stmt) { ...@@ -291,7 +293,6 @@ static char* normalStmtBuildSql(STscStmt* stmt) {
return taosStringBuilderGetResult(&sb, NULL); return taosStringBuilderGetResult(&sb, NULL);
} }
#if 0
static int fillColumnsNull(STableDataBlocks* pBlock, int32_t rowNum) { static int fillColumnsNull(STableDataBlocks* pBlock, int32_t rowNum) {
SParsedDataColInfo* spd = &pBlock->boundColumnInfo; SParsedDataColInfo* spd = &pBlock->boundColumnInfo;
int32_t offset = 0; int32_t offset = 0;
...@@ -319,129 +320,8 @@ static int fillColumnsNull(STableDataBlocks* pBlock, int32_t rowNum) { ...@@ -319,129 +320,8 @@ static int fillColumnsNull(STableDataBlocks* pBlock, int32_t rowNum) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
#endif
/**
* input:
* - schema:
* - payload:
* - spd:
* output:
* - pBlock with data block replaced by K-V format
*/
static int refactorPayload(STableDataBlocks* pBlock, int32_t rowNum) {
SParsedDataColInfo* spd = &pBlock->boundColumnInfo;
SSchema* schema = (SSchema*)pBlock->pTableMeta->schema;
SMemRowHelper* pHelper = &pBlock->rowHelper;
STableMeta* pTableMeta = pBlock->pTableMeta;
STableComInfo tinfo = tscGetTableInfo(pTableMeta);
int code = TSDB_CODE_SUCCESS;
int32_t extendedRowSize = getExtendedRowSize(&tinfo);
TDRowTLenT destPayloadSize = sizeof(SSubmitBlk);
ASSERT(pHelper->allNullLen >= 8);
TDRowTLenT destAllocSize = sizeof(SSubmitBlk) + rowNum * extendedRowSize;
SSubmitBlk* pDestBlock = tcalloc(destAllocSize, 1);
if (pDestBlock == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
memcpy(pDestBlock, pBlock->pData, sizeof(SSubmitBlk));
char* destPayload = (char*)pDestBlock + sizeof(SSubmitBlk);
char* srcPayload = (char*)pBlock->pData + sizeof(SSubmitBlk);
for (int n = 0; n < rowNum; ++n) {
payloadSetNCols(destPayload, spd->numOfBound);
TDRowTLenT dataRowLen = pHelper->allNullLen;
TDRowTLenT kvRowLen = TD_MEM_ROW_KV_VER_SIZE + sizeof(SColIdx) * spd->numOfBound;
TDRowTLenT payloadValOffset = payloadValuesOffset(destPayload); // rely on payloadNCols
TDRowLenT colValOffset = 0;
char* kvPrimaryKeyStart = destPayload + PAYLOAD_HEADER_LEN; // primaryKey in 1st column tuple
char* kvStart = kvPrimaryKeyStart + PAYLOAD_COL_HEAD_LEN; // the column tuple behind the primaryKey
for (int32_t i = 0; i < spd->numOfBound; ++i) {
int32_t colIndex = spd->boundedColumns[i];
ASSERT(spd->cols[colIndex].hasVal);
char* start = srcPayload + spd->cols[colIndex].offset;
SSchema* pSchema = &schema[colIndex]; // get colId here
bool isPrimaryKey = (colIndex == PRIMARYKEY_TIMESTAMP_COL_INDEX);
// the primary key locates in 1st column
if (!IS_DATA_COL_ORDERED(spd->orderStatus)) {
ASSERT(spd->colIdxInfo != NULL);
if (!isPrimaryKey) {
kvStart = POINTER_SHIFT(kvPrimaryKeyStart, spd->colIdxInfo[i].finalIdx * PAYLOAD_COL_HEAD_LEN);
} else {
ASSERT(spd->colIdxInfo[i].finalIdx == 0);
}
}
if (isPrimaryKey) {
payloadColSetId(kvPrimaryKeyStart, pSchema->colId);
payloadColSetType(kvPrimaryKeyStart, pSchema->type);
payloadColSetOffset(kvPrimaryKeyStart, colValOffset);
memcpy(POINTER_SHIFT(destPayload, payloadValOffset + colValOffset), start, TYPE_BYTES[pSchema->type]);
colValOffset += TYPE_BYTES[pSchema->type];
kvRowLen += TYPE_BYTES[pSchema->type];
} else {
payloadColSetId(kvStart, pSchema->colId);
payloadColSetType(kvStart, pSchema->type);
payloadColSetOffset(kvStart, colValOffset);
if (IS_VAR_DATA_TYPE(pSchema->type)) {
varDataCopy(POINTER_SHIFT(destPayload, payloadValOffset + colValOffset), start);
colValOffset += varDataTLen(start);
kvRowLen += varDataTLen(start);
if (pSchema->type == TSDB_DATA_TYPE_BINARY) {
dataRowLen += (varDataLen(start) - CHAR_BYTES);
} else if (pSchema->type == TSDB_DATA_TYPE_NCHAR) {
dataRowLen += (varDataLen(start) - TSDB_NCHAR_SIZE);
} else {
ASSERT(0);
}
} else {
memcpy(POINTER_SHIFT(destPayload, payloadValOffset + colValOffset), start, TYPE_BYTES[pSchema->type]);
colValOffset += TYPE_BYTES[pSchema->type];
kvRowLen += TYPE_BYTES[pSchema->type];
}
if (IS_DATA_COL_ORDERED(spd->orderStatus)) {
kvStart += PAYLOAD_COL_HEAD_LEN; // move to next column
}
}
} // end of column
if (kvRowLen < dataRowLen) {
payloadSetType(destPayload, SMEM_ROW_KV);
} else {
payloadSetType(destPayload, SMEM_ROW_DATA);
}
ASSERT(colValOffset <= TSDB_MAX_BYTES_PER_ROW);
TDRowTLenT len = payloadValOffset + colValOffset;
payloadSetTLen(destPayload, len);
// next loop
srcPayload += pBlock->rowSize;
destPayload += len;
destPayloadSize += len;
} // end of row
ASSERT(destPayloadSize <= destAllocSize);
tfree(pBlock->pData);
pBlock->pData = (char*)pDestBlock;
pBlock->nAllocSize = destAllocSize;
pBlock->size = destPayloadSize;
return code;
}
#if 0
int32_t fillTablesColumnsNull(SSqlObj* pSql) { int32_t fillTablesColumnsNull(SSqlObj* pSql) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
...@@ -464,93 +344,12 @@ int32_t fillTablesColumnsNull(SSqlObj* pSql) { ...@@ -464,93 +344,12 @@ int32_t fillTablesColumnsNull(SSqlObj* pSql) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
#endif
/**
* check and sort
*/
static int initPayloadEnv(STableDataBlocks* pBlock, int32_t rowNum) {
SParsedDataColInfo* spd = &pBlock->boundColumnInfo;
if (spd->orderStatus != ORDER_STATUS_UNKNOWN) {
return TSDB_CODE_SUCCESS;
}
bool isOrdered = true;
int32_t lastColIdx = -1;
for (int32_t i = 0; i < spd->numOfBound; ++i) {
ASSERT(spd->cols[i].hasVal);
int32_t colIdx = spd->boundedColumns[i];
if (isOrdered) {
if (lastColIdx > colIdx) {
isOrdered = false;
break;
} else {
lastColIdx = colIdx;
}
}
}
spd->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED;
if (isOrdered) {
spd->colIdxInfo = NULL;
} else {
spd->colIdxInfo = calloc(spd->numOfBound, sizeof(SBoundIdxInfo));
if (spd->colIdxInfo == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
SBoundIdxInfo* pColIdx = spd->colIdxInfo;
for (uint16_t i = 0; i < spd->numOfBound; ++i) {
pColIdx[i].schemaColIdx = (uint16_t)spd->boundedColumns[i];
pColIdx[i].boundIdx = i;
}
qsort(pColIdx, spd->numOfBound, sizeof(SBoundIdxInfo), schemaIdxCompar);
for (uint16_t i = 0; i < spd->numOfBound; ++i) {
pColIdx[i].finalIdx = i;
}
qsort(pColIdx, spd->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar);
}
return TSDB_CODE_SUCCESS;
}
/**
* Refactor the raw payload structure to K-V format as the in tsParseOneRow()
*/
int32_t fillTablesPayload(SSqlObj* pSql) {
SSqlCmd* pCmd = &pSql->cmd;
int code = TSDB_CODE_SUCCESS;
STableDataBlocks** p = taosHashIterate(pCmd->insertParam.pTableBlockHashList, NULL);
STableDataBlocks* pOneTableBlock = *p;
while (pOneTableBlock) {
SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData;
if (pBlocks->numOfRows > 0) { ////////////////////////////////////////////////////////////////////////////////
initSMemRowHelper(&pOneTableBlock->rowHelper, tscGetTableSchema(pOneTableBlock->pTableMeta), // functions for insertion statement preparation
tscGetNumOfColumns(pOneTableBlock->pTableMeta), 0); static FORCE_INLINE int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, TAOS_BIND* bind, int32_t colNum) {
if ((code = initPayloadEnv(pOneTableBlock, pBlocks->numOfRows)) != TSDB_CODE_SUCCESS) {
return code;
}
if ((code = refactorPayload(pOneTableBlock, pBlocks->numOfRows)) != TSDB_CODE_SUCCESS) {
return code;
};
}
p = taosHashIterate(pCmd->insertParam.pTableBlockHashList, p);
if (p == NULL) {
break;
}
pOneTableBlock = *p;
}
return code;
}
////////////////////////////////////////////////////////////////////////////////
// functions for insertion statement preparation
static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, TAOS_BIND* bind, int32_t colNum) {
if (bind->is_null != NULL && *(bind->is_null)) { if (bind->is_null != NULL && *(bind->is_null)) {
setNull(data + param->offset, param->type, param->bytes); setNull(data + param->offset, param->type, param->bytes);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -949,25 +748,25 @@ int32_t fillTablesPayload(SSqlObj* pSql) { ...@@ -949,25 +748,25 @@ int32_t fillTablesPayload(SSqlObj* pSql) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
size = 1; *(uint8_t *)(data + param->offset) = *(uint8_t *)bind->buffer;
break; break;
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_USMALLINT:
size = 2; *(uint16_t *)(data + param->offset) = *(uint16_t *)bind->buffer;
break; break;
case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_INT:
case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UINT:
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
size = 4; *(uint32_t *)(data + param->offset) = *(uint32_t *)bind->buffer;
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_UBIGINT:
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
size = 8; *(uint64_t *)(data + param->offset) = *(uint64_t *)bind->buffer;
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
...@@ -993,7 +792,6 @@ int32_t fillTablesPayload(SSqlObj* pSql) { ...@@ -993,7 +792,6 @@ int32_t fillTablesPayload(SSqlObj* pSql) {
return TSDB_CODE_TSC_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
memcpy(data + param->offset, bind->buffer, size);
if (param->offset == 0) { if (param->offset == 0) {
if (tsCheckTimestamp(pBlock, data + param->offset) != TSDB_CODE_SUCCESS) { if (tsCheckTimestamp(pBlock, data + param->offset) != TSDB_CODE_SUCCESS) {
tscError("invalid timestamp"); tscError("invalid timestamp");
...@@ -1004,6 +802,58 @@ int32_t fillTablesPayload(SSqlObj* pSql) { ...@@ -1004,6 +802,58 @@ int32_t fillTablesPayload(SSqlObj* pSql) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t insertStmtGenLastBlock(STableDataBlocks** lastBlock, STableDataBlocks* pBlock) {
*lastBlock = (STableDataBlocks*)malloc(sizeof(STableDataBlocks));
memcpy(*lastBlock, pBlock, sizeof(STableDataBlocks));
(*lastBlock)->cloned = true;
(*lastBlock)->pData = NULL;
(*lastBlock)->ordered = true;
(*lastBlock)->prevTS = INT64_MIN;
(*lastBlock)->size = sizeof(SSubmitBlk);
(*lastBlock)->tsSource = -1;
return TSDB_CODE_SUCCESS;
}
static int32_t insertStmtGenBlock(STscStmt* pStmt, STableDataBlocks** pBlock, STableMeta* pTableMeta, SName* name) {
int32_t code = 0;
if (pStmt->mtb.lastBlock == NULL) {
tscError("no previous data block");
return TSDB_CODE_TSC_APP_ERROR;
}
int32_t msize = tscGetTableMetaSize(pTableMeta);
int32_t tsize = sizeof(STableDataBlocks) + msize;
void *t = malloc(tsize);
*pBlock = t;
memcpy(*pBlock, pStmt->mtb.lastBlock, sizeof(STableDataBlocks));
t = (char *)t + sizeof(STableDataBlocks);
(*pBlock)->pTableMeta = t;
memcpy((*pBlock)->pTableMeta, pTableMeta, msize);
(*pBlock)->pData = malloc((*pBlock)->nAllocSize);
(*pBlock)->vgId = (*pBlock)->pTableMeta->vgId;
tNameAssign(&(*pBlock)->tableName, name);
SSubmitBlk* blk = (SSubmitBlk*)(*pBlock)->pData;
memset(blk, 0, sizeof(*blk));
code = tsSetBlockInfo(blk, pTableMeta, 0);
if (code != TSDB_CODE_SUCCESS) {
STMT_RET(code);
}
return TSDB_CODE_SUCCESS;
}
static int doBindBatchParam(STableDataBlocks* pBlock, SParamInfo* param, TAOS_MULTI_BIND* bind, int32_t rowNum) { static int doBindBatchParam(STableDataBlocks* pBlock, SParamInfo* param, TAOS_MULTI_BIND* bind, int32_t rowNum) {
if (bind->buffer_type != param->type || !isValidDataType(param->type)) { if (bind->buffer_type != param->type || !isValidDataType(param->type)) {
...@@ -1309,12 +1159,9 @@ static int insertStmtExecute(STscStmt* stmt) { ...@@ -1309,12 +1159,9 @@ static int insertStmtExecute(STscStmt* stmt) {
pBlk->uid = pTableMeta->id.uid; pBlk->uid = pTableMeta->id.uid;
pBlk->tid = pTableMeta->id.tid; pBlk->tid = pTableMeta->id.tid;
int code = fillTablesPayload(stmt->pSql); fillTablesColumnsNull(stmt->pSql);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
code = tscMergeTableDataBlocks(&stmt->pSql->cmd.insertParam, false); int code = tscMergeTableDataBlocks(&stmt->pSql->cmd.insertParam, false);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
} }
...@@ -1378,7 +1225,7 @@ static void insertBatchClean(STscStmt* pStmt) { ...@@ -1378,7 +1225,7 @@ static void insertBatchClean(STscStmt* pStmt) {
static int insertBatchStmtExecute(STscStmt* pStmt) { static int insertBatchStmtExecute(STscStmt* pStmt) {
int32_t code = 0; int32_t code = 0;
if(pStmt->mtb.nameSet == false) { if(pStmt->mtb.nameSet == false) {
tscError("0x%"PRIx64" no table name set", pStmt->pSql->self); tscError("0x%"PRIx64" no table name set", pStmt->pSql->self);
return invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no table name set"); return invalidOperationMsg(tscGetErrorMsgPayload(&pStmt->pSql->cmd), "no table name set");
...@@ -1391,7 +1238,7 @@ static int insertBatchStmtExecute(STscStmt* pStmt) { ...@@ -1391,7 +1238,7 @@ static int insertBatchStmtExecute(STscStmt* pStmt) {
return TSDB_CODE_TSC_APP_ERROR; return TSDB_CODE_TSC_APP_ERROR;
} }
fillTablesPayload(pStmt->pSql); fillTablesColumnsNull(pStmt->pSql);
if ((code = tscMergeTableDataBlocks(&pStmt->pSql->cmd.insertParam, false)) != TSDB_CODE_SUCCESS) { if ((code = tscMergeTableDataBlocks(&pStmt->pSql->cmd.insertParam, false)) != TSDB_CODE_SUCCESS) {
return code; return code;
...@@ -1433,11 +1280,11 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { ...@@ -1433,11 +1280,11 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) {
pStmt->mtb.tbname = sToken; pStmt->mtb.tbname = sToken;
pStmt->mtb.nameSet = false; pStmt->mtb.nameSet = false;
if (pStmt->mtb.pTableHash == NULL) { if (pStmt->mtb.pTableHash == NULL) {
pStmt->mtb.pTableHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); pStmt->mtb.pTableHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false);
} }
if (pStmt->mtb.pTableBlockHashList == NULL) { if (pStmt->mtb.pTableBlockHashList == NULL) {
pStmt->mtb.pTableBlockHashList = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); pStmt->mtb.pTableBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
} }
pStmt->mtb.tagSet = true; pStmt->mtb.tagSet = true;
...@@ -1728,6 +1575,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { ...@@ -1728,6 +1575,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) { int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) {
STscStmt* pStmt = (STscStmt*)stmt; STscStmt* pStmt = (STscStmt*)stmt;
int32_t code = 0;
if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) {
STMT_RET(TSDB_CODE_TSC_DISCONNECTED); STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
...@@ -1765,6 +1613,9 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1765,6 +1613,9 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
SSubmitBlk* pBlk = (SSubmitBlk*) (*t1)->pData; SSubmitBlk* pBlk = (SSubmitBlk*) (*t1)->pData;
pCmd->batchSize = pBlk->numOfRows; pCmd->batchSize = pBlk->numOfRows;
if (pBlk->numOfRows == 0) {
(*t1)->prevTS = INT64_MIN;
}
tsSetBlockInfo(pBlk, (*t1)->pTableMeta, pBlk->numOfRows); tsSetBlockInfo(pBlk, (*t1)->pTableMeta, pBlk->numOfRows);
...@@ -1774,6 +1625,51 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1774,6 +1625,51 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
STMT_RET(TSDB_CODE_SUCCESS); STMT_RET(TSDB_CODE_SUCCESS);
} }
if (pStmt->mtb.subSet && taosHashGetSize(pStmt->mtb.pTableHash) > 0) {
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0);
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
char sTableName[TSDB_TABLE_FNAME_LEN];
strncpy(sTableName, pTableMeta->sTableName, sizeof(sTableName));
SStrToken tname = {0};
tname.type = TK_STRING;
tname.z = (char *)name;
tname.n = (uint32_t)strlen(name);
SName fullname = {0};
tscSetTableFullName(&fullname, &tname, pSql);
memcpy(&pTableMetaInfo->name, &fullname, sizeof(fullname));
code = tscGetTableMeta(pSql, pTableMetaInfo);
if (code != TSDB_CODE_SUCCESS) {
STMT_RET(code);
}
pTableMeta = pTableMetaInfo->pTableMeta;
if (strcmp(sTableName, pTableMeta->sTableName)) {
tscError("0x%"PRIx64" only tables belongs to one stable is allowed", pSql->self);
STMT_RET(TSDB_CODE_TSC_APP_ERROR);
}
STableDataBlocks* pBlock = NULL;
insertStmtGenBlock(pStmt, &pBlock, pTableMeta, &pTableMetaInfo->name);
pCmd->batchSize = 0;
pStmt->mtb.currentUid = pTableMeta->id.uid;
pStmt->mtb.tbNum++;
taosHashPut(pCmd->insertParam.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES);
taosHashPut(pStmt->mtb.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES);
taosHashPut(pStmt->mtb.pTableHash, name, strlen(name), (char*) &pTableMeta->id.uid, sizeof(pTableMeta->id.uid));
tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid);
STMT_RET(TSDB_CODE_SUCCESS);
}
if (pStmt->mtb.tagSet) { if (pStmt->mtb.tagSet) {
pStmt->mtb.tbname = tscReplaceStrToken(&pSql->sqlstr, &pStmt->mtb.tbname, name); pStmt->mtb.tbname = tscReplaceStrToken(&pSql->sqlstr, &pStmt->mtb.tbname, name);
} else { } else {
...@@ -1802,7 +1698,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1802,7 +1698,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
pCmd->insertParam.pTableBlockHashList = hashList; pCmd->insertParam.pTableBlockHashList = hashList;
} }
int32_t code = tsParseSql(pStmt->pSql, true); code = tsParseSql(pStmt->pSql, true);
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
// wait for the callback function to post the semaphore // wait for the callback function to post the semaphore
tsem_wait(&pStmt->pSql->rspSem); tsem_wait(&pStmt->pSql->rspSem);
...@@ -1830,6 +1726,10 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1830,6 +1726,10 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
taosHashPut(pStmt->mtb.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES); taosHashPut(pStmt->mtb.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES);
taosHashPut(pStmt->mtb.pTableHash, name, strlen(name), (char*) &pTableMeta->id.uid, sizeof(pTableMeta->id.uid)); taosHashPut(pStmt->mtb.pTableHash, name, strlen(name), (char*) &pTableMeta->id.uid, sizeof(pTableMeta->id.uid));
if (pStmt->mtb.lastBlock == NULL) {
insertStmtGenLastBlock(&pStmt->mtb.lastBlock, pBlock);
}
tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid); tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid);
} }
...@@ -1837,7 +1737,17 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1837,7 +1737,17 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
} }
int taos_stmt_set_sub_tbname(TAOS_STMT* stmt, const char* name) {
STscStmt* pStmt = (STscStmt*)stmt;
pStmt->mtb.subSet = true;
return taos_stmt_set_tbname_tags(stmt, name, NULL);
}
int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
STscStmt* pStmt = (STscStmt*)stmt;
pStmt->mtb.subSet = false;
return taos_stmt_set_tbname_tags(stmt, name, NULL); return taos_stmt_set_tbname_tags(stmt, name, NULL);
} }
...@@ -1861,6 +1771,7 @@ int taos_stmt_close(TAOS_STMT* stmt) { ...@@ -1861,6 +1771,7 @@ int taos_stmt_close(TAOS_STMT* stmt) {
if (pStmt->pSql && pStmt->pSql->res.code != 0) { if (pStmt->pSql && pStmt->pSql->res.code != 0) {
rmMeta = true; rmMeta = true;
} }
tscDestroyDataBlock(pStmt->mtb.lastBlock, rmMeta);
pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->mtb.pTableBlockHashList, rmMeta); pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->mtb.pTableBlockHashList, rmMeta);
taosHashCleanup(pStmt->pSql->cmd.insertParam.pTableBlockHashList); taosHashCleanup(pStmt->pSql->cmd.insertParam.pTableBlockHashList);
pStmt->pSql->cmd.insertParam.pTableBlockHashList = NULL; pStmt->pSql->cmd.insertParam.pTableBlockHashList = NULL;
...@@ -1895,6 +1806,8 @@ int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) { ...@@ -1895,6 +1806,8 @@ int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) {
pStmt->last = STMT_BIND; pStmt->last = STMT_BIND;
tscDebug("tableId:%" PRIu64 ", try to bind one row", pStmt->mtb.currentUid);
STMT_RET(insertStmtBindParam(pStmt, bind)); STMT_RET(insertStmtBindParam(pStmt, bind));
} else { } else {
STMT_RET(normalStmtBindParam(pStmt, bind)); STMT_RET(normalStmtBindParam(pStmt, bind));
...@@ -2014,6 +1927,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) { ...@@ -2014,6 +1927,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) {
pStmt->last = STMT_EXECUTE; pStmt->last = STMT_EXECUTE;
pStmt->pSql->cmd.insertParam.payloadType = PAYLOAD_TYPE_RAW;
if (pStmt->multiTbInsert) { if (pStmt->multiTbInsert) {
ret = insertBatchStmtExecute(pStmt); ret = insertBatchStmtExecute(pStmt);
} else { } else {
......
...@@ -8037,6 +8037,28 @@ static void freeElem(void* p) { ...@@ -8037,6 +8037,28 @@ static void freeElem(void* p) {
tfree(*(char**)p); tfree(*(char**)p);
} }
int32_t tnameComparFn(const void* p1, const void* p2) {
SName* pn1 = (SName*)p1;
SName* pn2 = (SName*)p2;
int32_t ret = strncmp(pn1->acctId, pn2->acctId, tListLen(pn1->acctId));
if (ret != 0) {
return ret > 0? 1:-1;
} else {
ret = strncmp(pn1->dbname, pn2->dbname, tListLen(pn1->dbname));
if (ret != 0) {
return ret > 0? 1:-1;
} else {
ret = strncmp(pn1->tname, pn2->tname, tListLen(pn1->tname));
if (ret != 0) {
return ret > 0? 1:-1;
} else {
return 0;
}
}
}
}
int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
...@@ -8091,6 +8113,9 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -8091,6 +8113,9 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
plist = taosArrayInit(4, POINTER_BYTES); plist = taosArrayInit(4, POINTER_BYTES);
pVgroupList = taosArrayInit(4, POINTER_BYTES); pVgroupList = taosArrayInit(4, POINTER_BYTES);
taosArraySort(tableNameList, tnameComparFn);
taosArrayRemoveDuplicate(tableNameList, tnameComparFn, NULL);
size_t numOfTables = taosArrayGetSize(tableNameList); size_t numOfTables = taosArrayGetSize(tableNameList);
for (int32_t i = 0; i < numOfTables; ++i) { for (int32_t i = 0; i < numOfTables; ++i) {
SName* pname = taosArrayGet(tableNameList, i); SName* pname = taosArrayGet(tableNameList, i);
...@@ -8111,8 +8136,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -8111,8 +8136,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
continue; continue;
} }
} else if (pTableMeta->tableType == TSDB_SUPER_TABLE) { } else if (pTableMeta->tableType == TSDB_SUPER_TABLE) {
// the vgroup list of a super table is not kept in local buffer, so here need retrieve it // the vgroup list of super table is not kept in local buffer, so here need retrieve it from the mnode each time
// from the mnode each time
char* t = strdup(name); char* t = strdup(name);
taosArrayPush(pVgroupList, &t); taosArrayPush(pVgroupList, &t);
} }
...@@ -8139,6 +8163,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -8139,6 +8163,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (pInfo->funcs) { if (pInfo->funcs) {
funcSize = taosArrayGetSize(pInfo->funcs); funcSize = taosArrayGetSize(pInfo->funcs);
} }
if (funcSize > 0) { if (funcSize > 0) {
for (size_t i = 0; i < funcSize; ++i) { for (size_t i = 0; i < funcSize; ++i) {
SStrToken* t = taosArrayGet(pInfo->funcs, i); SStrToken* t = taosArrayGet(pInfo->funcs, i);
......
...@@ -1315,8 +1315,7 @@ void tscFreeQueryInfo(SSqlCmd* pCmd, bool removeMeta) { ...@@ -1315,8 +1315,7 @@ void tscFreeQueryInfo(SSqlCmd* pCmd, bool removeMeta) {
return; return;
} }
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); SQueryInfo* pQueryInfo = pCmd->pQueryInfo;
while(pQueryInfo != NULL) { while(pQueryInfo != NULL) {
SQueryInfo* p = pQueryInfo->sibling; SQueryInfo* p = pQueryInfo->sibling;
...@@ -1518,12 +1517,6 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) { ...@@ -1518,12 +1517,6 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) {
} }
tfree(pDataBlock->pData); tfree(pDataBlock->pData);
tfree(pDataBlock->params);
// free the refcount for metermeta
if (pDataBlock->pTableMeta != NULL) {
tfree(pDataBlock->pTableMeta);
}
if (removeMeta) { if (removeMeta) {
char name[TSDB_TABLE_FNAME_LEN] = {0}; char name[TSDB_TABLE_FNAME_LEN] = {0};
...@@ -1532,7 +1525,17 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) { ...@@ -1532,7 +1525,17 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) {
taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN)); taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
} }
tscDestroyBoundColumnInfo(&pDataBlock->boundColumnInfo); if (!pDataBlock->cloned) {
tfree(pDataBlock->params);
// free the refcount for metermeta
if (pDataBlock->pTableMeta != NULL) {
tfree(pDataBlock->pTableMeta);
}
tscDestroyBoundColumnInfo(&pDataBlock->boundColumnInfo);
}
tfree(pDataBlock); tfree(pDataBlock);
} }
...@@ -1598,7 +1601,7 @@ void freeUdfInfo(SUdfInfo* pUdfInfo) { ...@@ -1598,7 +1601,7 @@ void freeUdfInfo(SUdfInfo* pUdfInfo) {
taosCloseDll(pUdfInfo->handle); taosCloseDll(pUdfInfo->handle);
} }
// todo refactor
void* tscDestroyUdfArrayList(SArray* pUdfList) { void* tscDestroyUdfArrayList(SArray* pUdfList) {
if (pUdfList == NULL) { if (pUdfList == NULL) {
return NULL; return NULL;
...@@ -1711,12 +1714,14 @@ int32_t tscCreateDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOff ...@@ -1711,12 +1714,14 @@ int32_t tscCreateDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOff
dataBuf->nAllocSize = dataBuf->headerSize * 2; dataBuf->nAllocSize = dataBuf->headerSize * 2;
} }
dataBuf->pData = calloc(1, dataBuf->nAllocSize); //dataBuf->pData = calloc(1, dataBuf->nAllocSize);
dataBuf->pData = malloc(dataBuf->nAllocSize);
if (dataBuf->pData == NULL) { if (dataBuf->pData == NULL) {
tscError("failed to allocated memory, reason:%s", strerror(errno)); tscError("failed to allocated memory, reason:%s", strerror(errno));
tfree(dataBuf); tfree(dataBuf);
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
memset(dataBuf->pData, 0, sizeof(SSubmitBlk));
//Here we keep the tableMeta to avoid it to be remove by other threads. //Here we keep the tableMeta to avoid it to be remove by other threads.
dataBuf->pTableMeta = tscTableMetaDup(pTableMeta); dataBuf->pTableMeta = tscTableMetaDup(pTableMeta);
...@@ -1813,14 +1818,14 @@ static SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) { ...@@ -1813,14 +1818,14 @@ static SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) {
p = payloadNextCol(p); p = payloadNextCol(p);
++i; ++i;
} else { } else {
tdAppendColVal(trow, tdGetNullVal(pSchema[j].type), pSchema[j].type, toffset); tdAppendColVal(trow, getNullValue(pSchema[j].type), pSchema[j].type, toffset);
toffset += TYPE_BYTES[pSchema[j].type]; toffset += TYPE_BYTES[pSchema[j].type];
++j; ++j;
} }
} }
while (j < nCols) { while (j < nCols) {
tdAppendColVal(trow, tdGetNullVal(pSchema[j].type), pSchema[j].type, toffset); tdAppendColVal(trow, getNullValue(pSchema[j].type), pSchema[j].type, toffset);
toffset += TYPE_BYTES[pSchema[j].type]; toffset += TYPE_BYTES[pSchema[j].type];
++j; ++j;
} }
...@@ -1860,7 +1865,8 @@ static SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) { ...@@ -1860,7 +1865,8 @@ static SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) {
} }
// Erase the empty space reserved for binary data // Erase the empty space reserved for binary data
static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bool includeSchema, SBlockKeyTuple *blkKeyTuple) { static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SInsertStatementParam* insertParam,
SBlockKeyTuple* blkKeyTuple) {
// TODO: optimize this function, handle the case while binary is not presented // TODO: optimize this function, handle the case while binary is not presented
STableMeta* pTableMeta = pTableDataBlock->pTableMeta; STableMeta* pTableMeta = pTableDataBlock->pTableMeta;
STableComInfo tinfo = tscGetTableInfo(pTableMeta); STableComInfo tinfo = tscGetTableInfo(pTableMeta);
...@@ -1873,7 +1879,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo ...@@ -1873,7 +1879,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo
int32_t flen = 0; // original total length of row int32_t flen = 0; // original total length of row
// schema needs to be included into the submit data block // schema needs to be included into the submit data block
if (includeSchema) { if (insertParam->schemaAttached) {
int32_t numOfCols = tscGetNumOfColumns(pTableDataBlock->pTableMeta); int32_t numOfCols = tscGetNumOfColumns(pTableDataBlock->pTableMeta);
for(int32_t j = 0; j < numOfCols; ++j) { for(int32_t j = 0; j < numOfCols; ++j) {
STColumn* pCol = (STColumn*) pDataBlock; STColumn* pCol = (STColumn*) pDataBlock;
...@@ -1900,18 +1906,38 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo ...@@ -1900,18 +1906,38 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo
pBlock->dataLen = 0; pBlock->dataLen = 0;
int32_t numOfRows = htons(pBlock->numOfRows); int32_t numOfRows = htons(pBlock->numOfRows);
SMemRowBuilder rowBuilder; if (IS_RAW_PAYLOAD(insertParam->payloadType)) {
rowBuilder.pSchema = pSchema; for (int32_t i = 0; i < numOfRows; ++i) {
rowBuilder.sversion = pTableMeta->sversion; SMemRow memRow = (SMemRow)pDataBlock;
rowBuilder.flen = flen; memRowSetType(memRow, SMEM_ROW_DATA);
rowBuilder.nCols = tinfo.numOfColumns; SDataRow trow = memRowDataBody(memRow);
rowBuilder.pDataBlock = pDataBlock; dataRowSetLen(trow, (uint16_t)(TD_DATA_ROW_HEAD_SIZE + flen));
rowBuilder.pSubmitBlk = pBlock; dataRowSetVersion(trow, pTableMeta->sversion);
rowBuilder.buf = p;
int toffset = 0;
for (int32_t j = 0; j < tinfo.numOfColumns; j++) {
tdAppendColVal(trow, p, pSchema[j].type, toffset);
toffset += TYPE_BYTES[pSchema[j].type];
p += pSchema[j].bytes;
}
pDataBlock = (char*)pDataBlock + memRowTLen(memRow);
pBlock->dataLen += memRowTLen(memRow);
}
} else {
SMemRowBuilder rowBuilder;
rowBuilder.pSchema = pSchema;
rowBuilder.sversion = pTableMeta->sversion;
rowBuilder.flen = flen;
rowBuilder.nCols = tinfo.numOfColumns;
rowBuilder.pDataBlock = pDataBlock;
rowBuilder.pSubmitBlk = pBlock;
rowBuilder.buf = p;
for (int32_t i = 0; i < numOfRows; ++i) { for (int32_t i = 0; i < numOfRows; ++i) {
rowBuilder.buf = (blkKeyTuple + i)->payloadAddr; rowBuilder.buf = (blkKeyTuple + i)->payloadAddr;
tdGenMemRowFromBuilder(&rowBuilder); tdGenMemRowFromBuilder(&rowBuilder);
}
} }
int32_t len = pBlock->dataLen + pBlock->schemaLen; int32_t len = pBlock->dataLen + pBlock->schemaLen;
...@@ -1936,16 +1962,14 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) { ...@@ -1936,16 +1962,14 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) {
static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeBlockMap) { static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeBlockMap) {
pInsertParam->numOfTables = (int32_t) taosHashGetSize(pInsertParam->pTableBlockHashList); pInsertParam->numOfTables = (int32_t) taosHashGetSize(pInsertParam->pTableBlockHashList);
if (pInsertParam->pTableNameList == NULL) { if (pInsertParam->pTableNameList == NULL) {
pInsertParam->pTableNameList = calloc(pInsertParam->numOfTables, POINTER_BYTES); pInsertParam->pTableNameList = malloc(pInsertParam->numOfTables * POINTER_BYTES);
} else {
memset(pInsertParam->pTableNameList, 0, pInsertParam->numOfTables * POINTER_BYTES);
} }
STableDataBlocks **p1 = taosHashIterate(pInsertParam->pTableBlockHashList, NULL); STableDataBlocks **p1 = taosHashIterate(pInsertParam->pTableBlockHashList, NULL);
int32_t i = 0; int32_t i = 0;
while(p1) { while(p1) {
STableDataBlocks* pBlocks = *p1; STableDataBlocks* pBlocks = *p1;
tfree(pInsertParam->pTableNameList[i]); //tfree(pInsertParam->pTableNameList[i]);
pInsertParam->pTableNameList[i++] = tNameDup(&pBlocks->tableName); pInsertParam->pTableNameList[i++] = tNameDup(&pBlocks->tableName);
p1 = taosHashIterate(pInsertParam->pTableBlockHashList, p1); p1 = taosHashIterate(pInsertParam->pTableBlockHashList, p1);
...@@ -1959,6 +1983,7 @@ static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeB ...@@ -1959,6 +1983,7 @@ static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeB
int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBlockMap) { int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBlockMap) {
const int INSERT_HEAD_SIZE = sizeof(SMsgDesc) + sizeof(SSubmitMsg); const int INSERT_HEAD_SIZE = sizeof(SMsgDesc) + sizeof(SSubmitMsg);
int code = 0; int code = 0;
bool isRawPayload = IS_RAW_PAYLOAD(pInsertParam->payloadType);
void* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); void* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES); SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES);
...@@ -1967,7 +1992,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl ...@@ -1967,7 +1992,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
STableDataBlocks* pOneTableBlock = *p; STableDataBlocks* pOneTableBlock = *p;
SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock
while(pOneTableBlock) { while(pOneTableBlock) {
SSubmitBlk* pBlocks = (SSubmitBlk*) pOneTableBlock->pData; SSubmitBlk* pBlocks = (SSubmitBlk*) pOneTableBlock->pData;
if (pBlocks->numOfRows > 0) { if (pBlocks->numOfRows > 0) {
...@@ -1988,14 +2013,12 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl ...@@ -1988,14 +2013,12 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize + sizeof(STColumn) * tscGetNumOfColumns(pOneTableBlock->pTableMeta); int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize + sizeof(STColumn) * tscGetNumOfColumns(pOneTableBlock->pTableMeta);
if (dataBuf->nAllocSize < destSize) { if (dataBuf->nAllocSize < destSize) {
while (dataBuf->nAllocSize < destSize) { dataBuf->nAllocSize = (uint32_t)(destSize * 1.5);
dataBuf->nAllocSize = (uint32_t)(dataBuf->nAllocSize * 1.5);
}
char* tmp = realloc(dataBuf->pData, dataBuf->nAllocSize); char* tmp = realloc(dataBuf->pData, dataBuf->nAllocSize);
if (tmp != NULL) { if (tmp != NULL) {
dataBuf->pData = tmp; dataBuf->pData = tmp;
memset(dataBuf->pData + dataBuf->size, 0, dataBuf->nAllocSize - dataBuf->size); //memset(dataBuf->pData + dataBuf->size, 0, dataBuf->nAllocSize - dataBuf->size);
} else { // failed to allocate memory, free already allocated memory and return error code } else { // failed to allocate memory, free already allocated memory and return error code
tscError("0x%"PRIx64" failed to allocate memory for merging submit block, size:%d", pInsertParam->objectId, dataBuf->nAllocSize); tscError("0x%"PRIx64" failed to allocate memory for merging submit block, size:%d", pInsertParam->objectId, dataBuf->nAllocSize);
...@@ -2008,21 +2031,29 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl ...@@ -2008,21 +2031,29 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
} }
} }
if ((code = tscSortRemoveDataBlockDupRows(pOneTableBlock, &blkKeyInfo)) != 0) { if (isRawPayload) {
taosHashCleanup(pVnodeDataBlockHashList); tscSortRemoveDataBlockDupRowsRaw(pOneTableBlock);
tscDestroyBlockArrayList(pVnodeDataBlockList); char* ekey = (char*)pBlocks->data + pOneTableBlock->rowSize * (pBlocks->numOfRows - 1);
tfree(dataBuf->pData);
tfree(blkKeyInfo.pKeyTuple);
return code;
}
ASSERT(blkKeyInfo.pKeyTuple != NULL && pBlocks->numOfRows > 0);
SBlockKeyTuple* pLastKeyTuple = blkKeyInfo.pKeyTuple + pBlocks->numOfRows - 1; tscDebug("0x%" PRIx64 " name:%s, tid:%d rows:%d sversion:%d skey:%" PRId64 ", ekey:%" PRId64,
tscDebug("0x%" PRIx64 " name:%s, tid:%d rows:%d sversion:%d skey:%" PRId64 ", ekey:%" PRId64, pInsertParam->objectId, tNameGetTableName(&pOneTableBlock->tableName), pBlocks->tid,
pInsertParam->objectId, tNameGetTableName(&pOneTableBlock->tableName), pBlocks->tid, pBlocks->numOfRows, pBlocks->numOfRows, pBlocks->sversion, GET_INT64_VAL(pBlocks->data), GET_INT64_VAL(ekey));
pBlocks->sversion, blkKeyInfo.pKeyTuple->skey, pLastKeyTuple->skey); } else {
if ((code = tscSortRemoveDataBlockDupRows(pOneTableBlock, &blkKeyInfo)) != 0) {
taosHashCleanup(pVnodeDataBlockHashList);
tscDestroyBlockArrayList(pVnodeDataBlockList);
tfree(dataBuf->pData);
tfree(blkKeyInfo.pKeyTuple);
return code;
}
ASSERT(blkKeyInfo.pKeyTuple != NULL && pBlocks->numOfRows > 0);
SBlockKeyTuple* pLastKeyTuple = blkKeyInfo.pKeyTuple + pBlocks->numOfRows - 1;
tscDebug("0x%" PRIx64 " name:%s, tid:%d rows:%d sversion:%d skey:%" PRId64 ", ekey:%" PRId64,
pInsertParam->objectId, tNameGetTableName(&pOneTableBlock->tableName), pBlocks->tid,
pBlocks->numOfRows, pBlocks->sversion, blkKeyInfo.pKeyTuple->skey, pLastKeyTuple->skey);
}
int32_t len = pBlocks->numOfRows * (pOneTableBlock->rowSize + expandSize) + sizeof(STColumn) * tscGetNumOfColumns(pOneTableBlock->pTableMeta); int32_t len = pBlocks->numOfRows * (pOneTableBlock->rowSize + expandSize) + sizeof(STColumn) * tscGetNumOfColumns(pOneTableBlock->pTableMeta);
pBlocks->tid = htonl(pBlocks->tid); pBlocks->tid = htonl(pBlocks->tid);
...@@ -2032,7 +2063,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl ...@@ -2032,7 +2063,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
pBlocks->schemaLen = 0; pBlocks->schemaLen = 0;
// erase the empty space reserved for binary data // erase the empty space reserved for binary data
int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, pInsertParam->schemaAttached, blkKeyInfo.pKeyTuple); int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, pInsertParam, blkKeyInfo.pKeyTuple);
assert(finalLen <= len); assert(finalLen <= len);
dataBuf->size += (finalLen + sizeof(SSubmitBlk)); dataBuf->size += (finalLen + sizeof(SSubmitBlk));
...@@ -3097,6 +3128,7 @@ void tscInitQueryInfo(SQueryInfo* pQueryInfo) { ...@@ -3097,6 +3128,7 @@ void tscInitQueryInfo(SQueryInfo* pQueryInfo) {
int32_t tscAddQueryInfo(SSqlCmd* pCmd) { int32_t tscAddQueryInfo(SSqlCmd* pCmd) {
assert(pCmd != NULL); assert(pCmd != NULL);
SQueryInfo* pQueryInfo = calloc(1, sizeof(SQueryInfo)); SQueryInfo* pQueryInfo = calloc(1, sizeof(SQueryInfo));
if (pQueryInfo == NULL) { if (pQueryInfo == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
...@@ -3889,7 +3921,7 @@ bool tscIsUpdateQuery(SSqlObj* pSql) { ...@@ -3889,7 +3921,7 @@ bool tscIsUpdateQuery(SSqlObj* pSql) {
} }
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
return ((pCmd->command >= TSDB_SQL_INSERT && pCmd->command <= TSDB_SQL_DROP_DNODE) || TSDB_SQL_USE_DB == pCmd->command); return ((pCmd->command >= TSDB_SQL_INSERT && pCmd->command <= TSDB_SQL_DROP_DNODE) || TSDB_SQL_RESET_CACHE == pCmd->command || TSDB_SQL_USE_DB == pCmd->command);
} }
char* tscGetSqlStr(SSqlObj* pSql) { char* tscGetSqlStr(SSqlObj* pSql) {
...@@ -4079,17 +4111,21 @@ void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp) { ...@@ -4079,17 +4111,21 @@ void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp) {
//backup the total number of result first //backup the total number of result first
int64_t num = pRes->numOfTotal + pRes->numOfClauseTotal; int64_t num = pRes->numOfTotal + pRes->numOfClauseTotal;
// DON't free final since it may be recoreded and used later in APP // DON't free final since it may be recoreded and used later in APP
TAOS_FIELD* finalBk = pRes->final; TAOS_FIELD* finalBk = pRes->final;
pRes->final = NULL; pRes->final = NULL;
tscFreeSqlResult(pSql); tscFreeSqlResult(pSql);
pRes->final = finalBk; pRes->final = finalBk;
pRes->numOfTotal = num; pRes->numOfTotal = num;
for(int32_t i = 0; i < pSql->subState.numOfSub; ++i) {
taos_free_result(pSql->pSubs[i]);
}
tfree(pSql->pSubs); tfree(pSql->pSubs);
pSql->subState.numOfSub = 0; pSql->subState.numOfSub = 0;
pSql->fp = fp; pSql->fp = fp;
tscDebug("0x%"PRIx64" try data in the next subclause", pSql->self); tscDebug("0x%"PRIx64" try data in the next subclause", pSql->self);
...@@ -4350,7 +4386,7 @@ STableMeta* tscTableMetaDup(STableMeta* pTableMeta) { ...@@ -4350,7 +4386,7 @@ STableMeta* tscTableMetaDup(STableMeta* pTableMeta) {
assert(pTableMeta != NULL); assert(pTableMeta != NULL);
size_t size = tscGetTableMetaSize(pTableMeta); size_t size = tscGetTableMetaSize(pTableMeta);
STableMeta* p = calloc(1, size); STableMeta* p = malloc(size);
memcpy(p, pTableMeta, size); memcpy(p, pTableMeta, size);
return p; return p;
} }
...@@ -4729,6 +4765,20 @@ int32_t nameComparFn(const void* n1, const void* n2) { ...@@ -4729,6 +4765,20 @@ int32_t nameComparFn(const void* n1, const void* n2) {
} }
} }
static void freeContent(void* p) {
char* ptr = *(char**)p;
tfree(ptr);
}
static int32_t contCompare(const void* p1, const void* p2) {
int32_t ret = strcmp(p1, p2);
if (ret == 0) {
return 0;
} else {
return ret > 0 ? 1:-1;
}
}
int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t length, SArray* pNameArray) { int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t length, SArray* pNameArray) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
...@@ -4776,32 +4826,7 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt ...@@ -4776,32 +4826,7 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt
} }
taosArraySort(pNameArray, nameComparFn); taosArraySort(pNameArray, nameComparFn);
taosArrayRemoveDuplicate(pNameArray, contCompare, freeContent);
int32_t pos = 0;
for(int32_t i = 1; i < len; ++i) {
char** p1 = taosArrayGet(pNameArray, pos);
char** p2 = taosArrayGet(pNameArray, i);
if (strcmp(*p1, *p2) == 0) {
// do nothing
} else {
if (pos + 1 != i) {
char* p = taosArrayGetP(pNameArray, pos + 1);
tfree(p);
taosArraySet(pNameArray, pos + 1, p2);
pos += 1;
} else {
pos += 1;
}
}
}
for(int32_t i = pos + 1; i < pNameArray->size; ++i) {
char* p = taosArrayGetP(pNameArray, i);
tfree(p);
}
pNameArray->size = pos + 1;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -24,35 +24,6 @@ ...@@ -24,35 +24,6 @@
extern "C" { extern "C" {
#endif #endif
#pragma pack(push, 1)
typedef struct {
VarDataLenT len;
uint8_t data;
} SBinaryNullT;
typedef struct {
VarDataLenT len;
uint32_t data;
} SNCharNullT;
#pragma pack(pop)
extern const uint8_t BoolNull;
extern const uint8_t TinyintNull;
extern const uint16_t SmallintNull;
extern const uint32_t IntNull;
extern const uint64_t BigintNull;
extern const uint64_t TimestampNull;
extern const uint8_t UTinyintNull;
extern const uint16_t USmallintNull;
extern const uint32_t UIntNull;
extern const uint64_t UBigintNull;
extern const uint32_t FloatNull;
extern const uint64_t DoubleNull;
extern const SBinaryNullT BinaryNull;
extern const SNCharNullT NcharNull;
const void *tdGetNullVal(int8_t type);
#define STR_TO_VARSTR(x, str) \ #define STR_TO_VARSTR(x, str) \
do { \ do { \
VarDataLenT __len = (VarDataLenT)strlen(str); \ VarDataLenT __len = (VarDataLenT)strlen(str); \
...@@ -287,7 +258,7 @@ void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints); ...@@ -287,7 +258,7 @@ void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints);
// Get the data pointer from a column-wised data // Get the data pointer from a column-wised data
static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int row) { static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int row) {
if (isAllRowsNull(pCol)) { if (isAllRowsNull(pCol)) {
return tdGetNullVal(pCol->type); return getNullValue(pCol->type);
} }
if (IS_VAR_DATA_TYPE(pCol->type)) { if (IS_VAR_DATA_TYPE(pCol->type)) {
return POINTER_SHIFT(pCol->pData, pCol->dataOff[row]); return POINTER_SHIFT(pCol->pData, pCol->dataOff[row]);
......
...@@ -205,6 +205,16 @@ extern int32_t wDebugFlag; ...@@ -205,6 +205,16 @@ extern int32_t wDebugFlag;
extern int32_t cqDebugFlag; extern int32_t cqDebugFlag;
extern int32_t debugFlag; extern int32_t debugFlag;
#ifdef TD_TSZ
// lossy
extern char lossyColumns[];
extern double fPrecision;
extern double dPrecision;
extern uint32_t maxIntervals;
extern uint32_t intervals;
extern char Compressor[];
#endif
typedef struct { typedef struct {
char dir[TSDB_FILENAME_LEN]; char dir[TSDB_FILENAME_LEN];
int level; int level;
......
...@@ -18,21 +18,6 @@ ...@@ -18,21 +18,6 @@
#include "tcoding.h" #include "tcoding.h"
#include "wchar.h" #include "wchar.h"
const uint8_t BoolNull = TSDB_DATA_BOOL_NULL;
const uint8_t TinyintNull = TSDB_DATA_TINYINT_NULL;
const uint16_t SmallintNull = TSDB_DATA_SMALLINT_NULL;
const uint32_t IntNull = TSDB_DATA_INT_NULL;
const uint64_t BigintNull = TSDB_DATA_BIGINT_NULL;
const uint64_t TimestampNull = TSDB_DATA_BIGINT_NULL;
const uint8_t UTinyintNull = TSDB_DATA_UTINYINT_NULL;
const uint16_t USmallintNull = TSDB_DATA_USMALLINT_NULL;
const uint32_t UIntNull = TSDB_DATA_UINT_NULL;
const uint64_t UBigintNull = TSDB_DATA_UBIGINT_NULL;
const uint32_t FloatNull = TSDB_DATA_FLOAT_NULL;
const uint64_t DoubleNull = TSDB_DATA_DOUBLE_NULL;
const SBinaryNullT BinaryNull = {1, TSDB_DATA_BINARY_NULL};
const SNCharNullT NcharNull = {4, TSDB_DATA_NCHAR_NULL};
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2, static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
int limit2, int tRows); int limit2, int tRows);
...@@ -453,7 +438,7 @@ static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols ...@@ -453,7 +438,7 @@ static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols
SDataCol *pDataCol = &(pCols->cols[dcol]); SDataCol *pDataCol = &(pCols->cols[dcol]);
if (rcol >= schemaNCols(pSchema)) { if (rcol >= schemaNCols(pSchema)) {
// dataColSetNullAt(pDataCol, pCols->numOfRows); // dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal(pDataCol, tdGetNullVal(pDataCol->type), pCols->numOfRows, pCols->maxPoints); dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
dcol++; dcol++;
continue; continue;
} }
...@@ -468,7 +453,7 @@ static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols ...@@ -468,7 +453,7 @@ static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols
rcol++; rcol++;
} else { } else {
// dataColSetNullAt(pDataCol, pCols->numOfRows); // dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal(pDataCol, tdGetNullVal(pDataCol->type), pCols->numOfRows, pCols->maxPoints); dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
dcol++; dcol++;
} }
} }
...@@ -498,7 +483,7 @@ static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCo ...@@ -498,7 +483,7 @@ static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCo
SDataCol *pDataCol = &(pCols->cols[dcol]); SDataCol *pDataCol = &(pCols->cols[dcol]);
if (rcol >= nRowCols || rcol >= schemaNCols(pSchema)) { if (rcol >= nRowCols || rcol >= schemaNCols(pSchema)) {
// dataColSetNullAt(pDataCol, pCols->numOfRows); // dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal(pDataCol, tdGetNullVal(pDataCol->type), pCols->numOfRows, pCols->maxPoints); dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
++dcol; ++dcol;
continue; continue;
} }
...@@ -514,7 +499,7 @@ static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCo ...@@ -514,7 +499,7 @@ static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCo
++rcol; ++rcol;
} else { } else {
// dataColSetNullAt(pDataCol, pCols->numOfRows); // dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal(pDataCol, tdGetNullVal(pDataCol->type), pCols->numOfRows, pCols->maxPoints); dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
++dcol; ++dcol;
} }
} }
...@@ -799,40 +784,4 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) { ...@@ -799,40 +784,4 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) {
memcpy(kvRowValues(row), pBuilder->buf, pBuilder->size); memcpy(kvRowValues(row), pBuilder->buf, pBuilder->size);
return row; return row;
}
const void *tdGetNullVal(int8_t type) {
switch (type) {
case TSDB_DATA_TYPE_BOOL:
return &BoolNull;
case TSDB_DATA_TYPE_TINYINT:
return &TinyintNull;
case TSDB_DATA_TYPE_SMALLINT:
return &SmallintNull;
case TSDB_DATA_TYPE_INT:
return &IntNull;
case TSDB_DATA_TYPE_BIGINT:
return &BigintNull;
case TSDB_DATA_TYPE_FLOAT:
return &FloatNull;
case TSDB_DATA_TYPE_DOUBLE:
return &DoubleNull;
case TSDB_DATA_TYPE_BINARY:
return &BinaryNull;
case TSDB_DATA_TYPE_TIMESTAMP:
return &TimestampNull;
case TSDB_DATA_TYPE_NCHAR:
return &NcharNull;
case TSDB_DATA_TYPE_UTINYINT:
return &UTinyintNull;
case TSDB_DATA_TYPE_USMALLINT:
return &USmallintNull;
case TSDB_DATA_TYPE_UINT:
return &UIntNull;
case TSDB_DATA_TYPE_UBIGINT:
return &UBigintNull;
default:
ASSERT(0);
return NULL;
}
} }
\ No newline at end of file
...@@ -244,6 +244,19 @@ int32_t tsdbDebugFlag = 131; ...@@ -244,6 +244,19 @@ int32_t tsdbDebugFlag = 131;
int32_t cqDebugFlag = 131; int32_t cqDebugFlag = 131;
int32_t fsDebugFlag = 135; int32_t fsDebugFlag = 135;
#ifdef TD_TSZ
//
// lossy compress 6
//
char lossyColumns[32] = ""; // "float|double" means all float and double columns can be lossy compressed. set empty can close lossy compress.
// below option can take effect when tsLossyColumns not empty
double fPrecision = 1E-8; // float column precision
double dPrecision = 1E-16; // double column precision
uint32_t maxIntervals = 500; // max intervals
uint32_t intervals = 100; // intervals
char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESSOR
#endif
int32_t (*monStartSystemFp)() = NULL; int32_t (*monStartSystemFp)() = NULL;
void (*monStopSystemFp)() = NULL; void (*monStopSystemFp)() = NULL;
void (*monExecuteSQLFp)(char *sql) = NULL; void (*monExecuteSQLFp)(char *sql) = NULL;
...@@ -1517,6 +1530,62 @@ static void doInitGlobalConfig(void) { ...@@ -1517,6 +1530,62 @@ static void doInitGlobalConfig(void) {
cfg.ptrLength = tListLen(tsTempDir); cfg.ptrLength = tListLen(tsTempDir);
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
#ifdef TD_TSZ
// lossy compress
cfg.option = "lossyColumns";
cfg.ptr = lossyColumns;
cfg.valType = TAOS_CFG_VTYPE_STRING;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 0;
cfg.maxValue = 0;
cfg.ptrLength = tListLen(lossyColumns);
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "fPrecision";
cfg.ptr = &fPrecision;
cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = MIN_FLOAT;
cfg.maxValue = MAX_FLOAT;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "dPrecision";
cfg.ptr = &dPrecision;
cfg.valType = TAOS_CFG_VTYPE_DOUBLE;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = MIN_FLOAT;
cfg.maxValue = MAX_FLOAT;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "maxIntervals";
cfg.ptr = &maxIntervals;
cfg.valType = TAOS_CFG_VTYPE_INT32;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 0;
cfg.maxValue = 65536;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "intervals";
cfg.ptr = &intervals;
cfg.valType = TAOS_CFG_VTYPE_INT32;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 0;
cfg.maxValue = 65536;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
#endif
} }
void taosInitGlobalCfg() { void taosInitGlobalCfg() {
......
...@@ -306,7 +306,7 @@ bool tIsValidName(const SName* name) { ...@@ -306,7 +306,7 @@ bool tIsValidName(const SName* name) {
SName* tNameDup(const SName* name) { SName* tNameDup(const SName* name) {
assert(name != NULL); assert(name != NULL);
SName* p = calloc(1, sizeof(SName)); SName* p = malloc(sizeof(SName));
memcpy(p, name, sizeof(SName)); memcpy(p, name, sizeof(SName));
return p; return p;
} }
......
...@@ -492,30 +492,32 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems) { ...@@ -492,30 +492,32 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems) {
} }
} }
static uint8_t nullBool = TSDB_DATA_BOOL_NULL; static uint8_t nullBool = TSDB_DATA_BOOL_NULL;
static uint8_t nullTinyInt = TSDB_DATA_TINYINT_NULL; static uint8_t nullTinyInt = TSDB_DATA_TINYINT_NULL;
static uint16_t nullSmallInt = TSDB_DATA_SMALLINT_NULL; static uint16_t nullSmallInt = TSDB_DATA_SMALLINT_NULL;
static uint32_t nullInt = TSDB_DATA_INT_NULL; static uint32_t nullInt = TSDB_DATA_INT_NULL;
static uint64_t nullBigInt = TSDB_DATA_BIGINT_NULL; static uint64_t nullBigInt = TSDB_DATA_BIGINT_NULL;
static uint32_t nullFloat = TSDB_DATA_FLOAT_NULL; static uint32_t nullFloat = TSDB_DATA_FLOAT_NULL;
static uint64_t nullDouble = TSDB_DATA_DOUBLE_NULL; static uint64_t nullDouble = TSDB_DATA_DOUBLE_NULL;
static uint8_t nullTinyIntu = TSDB_DATA_UTINYINT_NULL; static uint8_t nullTinyIntu = TSDB_DATA_UTINYINT_NULL;
static uint16_t nullSmallIntu = TSDB_DATA_USMALLINT_NULL; static uint16_t nullSmallIntu = TSDB_DATA_USMALLINT_NULL;
static uint32_t nullIntu = TSDB_DATA_UINT_NULL; static uint32_t nullIntu = TSDB_DATA_UINT_NULL;
static uint64_t nullBigIntu = TSDB_DATA_UBIGINT_NULL; static uint64_t nullBigIntu = TSDB_DATA_UBIGINT_NULL;
static SBinaryNullT nullBinary = {1, TSDB_DATA_BINARY_NULL};
static union { static SNCharNullT nullNchar = {4, TSDB_DATA_NCHAR_NULL};
tstr str;
char pad[sizeof(tstr) + 4]; // static union {
} nullBinary = {.str = {.len = 1}}, nullNchar = {.str = {.len = 4}}; // tstr str;
// char pad[sizeof(tstr) + 4];
static void *nullValues[] = { // } nullBinary = {.str = {.len = 1}}, nullNchar = {.str = {.len = 4}};
static const void *nullValues[] = {
&nullBool, &nullTinyInt, &nullSmallInt, &nullInt, &nullBigInt, &nullBool, &nullTinyInt, &nullSmallInt, &nullInt, &nullBigInt,
&nullFloat, &nullDouble, &nullBinary, &nullBigInt, &nullNchar, &nullFloat, &nullDouble, &nullBinary, &nullBigInt, &nullNchar,
&nullTinyIntu, &nullSmallIntu, &nullIntu, &nullBigIntu, &nullTinyIntu, &nullSmallIntu, &nullIntu, &nullBigIntu,
}; };
void *getNullValue(int32_t type) { const void *getNullValue(int32_t type) {
assert(type >= TSDB_DATA_TYPE_BOOL && type <= TSDB_DATA_TYPE_UBIGINT); assert(type >= TSDB_DATA_TYPE_BOOL && type <= TSDB_DATA_TYPE_UBIGINT);
return nullValues[type - 1]; return nullValues[type - 1];
} }
......
...@@ -37,13 +37,6 @@ ...@@ -37,13 +37,6 @@
<maven.test.jvmargs></maven.test.jvmargs> <maven.test.jvmargs></maven.test.jvmargs>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<!-- for restful -->
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
...@@ -52,12 +45,18 @@ ...@@ -52,12 +45,18 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.58</version> <version>1.2.76</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>30.0-jre</version> <version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -171,11 +171,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -171,11 +171,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
// do nothing // do nothing
} }
@Override private void checkResultSetTypeAndResultSetConcurrency(int resultSetType, int resultSetConcurrency) throws SQLException {
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
switch (resultSetType) { switch (resultSetType) {
case ResultSet.TYPE_FORWARD_ONLY: case ResultSet.TYPE_FORWARD_ONLY:
break; break;
...@@ -194,7 +190,14 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -194,7 +190,14 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
default: default:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
} }
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
checkResultSetTypeAndResultSetConcurrency(resultSetType, resultSetConcurrency);
return createStatement(); return createStatement();
} }
...@@ -203,24 +206,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -203,24 +206,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
if (isClosed()) if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
switch (resultSetType) { checkResultSetTypeAndResultSetConcurrency(resultSetType, resultSetConcurrency);
case ResultSet.TYPE_FORWARD_ONLY:
break;
case ResultSet.TYPE_SCROLL_INSENSITIVE:
case ResultSet.TYPE_SCROLL_SENSITIVE:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
default:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
switch (resultSetConcurrency) {
case ResultSet.CONCUR_READ_ONLY:
break;
case ResultSet.CONCUR_UPDATABLE:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
default:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
return prepareStatement(sql); return prepareStatement(sql);
} }
......
...@@ -326,7 +326,7 @@ public class EmptyResultSet implements ResultSet { ...@@ -326,7 +326,7 @@ public class EmptyResultSet implements ResultSet {
@Override @Override
public int getFetchDirection() throws SQLException { public int getFetchDirection() throws SQLException {
return 0; return ResultSet.FETCH_FORWARD;
} }
@Override @Override
...@@ -341,12 +341,12 @@ public class EmptyResultSet implements ResultSet { ...@@ -341,12 +341,12 @@ public class EmptyResultSet implements ResultSet {
@Override @Override
public int getType() throws SQLException { public int getType() throws SQLException {
return 0; return ResultSet.TYPE_FORWARD_ONLY;
} }
@Override @Override
public int getConcurrency() throws SQLException { public int getConcurrency() throws SQLException {
return 0; return ResultSet.CONCUR_READ_ONLY;
} }
@Override @Override
...@@ -746,7 +746,7 @@ public class EmptyResultSet implements ResultSet { ...@@ -746,7 +746,7 @@ public class EmptyResultSet implements ResultSet {
@Override @Override
public int getHoldability() throws SQLException { public int getHoldability() throws SQLException {
return 0; return ResultSet.CLOSE_CURSORS_AT_COMMIT;
} }
@Override @Override
......
...@@ -40,7 +40,7 @@ public class TSDBErrorNumbers { ...@@ -40,7 +40,7 @@ public class TSDBErrorNumbers {
public static final int ERROR_JNI_FETCH_END = 0x2358; // fetch to the end of resultSet public static final int ERROR_JNI_FETCH_END = 0x2358; // fetch to the end of resultSet
public static final int ERROR_JNI_OUT_OF_MEMORY = 0x2359; // JNI alloc memory failed public static final int ERROR_JNI_OUT_OF_MEMORY = 0x2359; // JNI alloc memory failed
private static final Set<Integer> errorNumbers = new HashSet(); private static final Set<Integer> errorNumbers = new HashSet<>();
static { static {
errorNumbers.add(ERROR_CONNECTION_CLOSED); errorNumbers.add(ERROR_CONNECTION_CLOSED);
......
...@@ -61,7 +61,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { ...@@ -61,7 +61,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
return; return;
// parse row data // parse row data
for (int rowIndex = 0; rowIndex < data.size(); rowIndex++) { for (int rowIndex = 0; rowIndex < data.size(); rowIndex++) {
List<Object> row = new ArrayList(); List<Object> row = new ArrayList<>();
JSONArray jsonRow = data.getJSONArray(rowIndex); JSONArray jsonRow = data.getJSONArray(rowIndex);
for (int colIndex = 0; colIndex < this.metaData.getColumnCount(); colIndex++) { for (int colIndex = 0; colIndex < this.metaData.getColumnCount(); colIndex++) {
row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).taos_type)); row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).taos_type));
......
...@@ -9,6 +9,7 @@ import org.apache.http.client.protocol.HttpClientContext; ...@@ -9,6 +9,7 @@ import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeaderElementIterator; import org.apache.http.message.BasicHeaderElementIterator;
...@@ -34,7 +35,11 @@ public class HttpClientPoolUtil { ...@@ -34,7 +35,11 @@ public class HttpClientPoolUtil {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE); connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE);
connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL); connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL);
httpClient = HttpClients.custom().setKeepAliveStrategy(DEFAULT_KEEP_ALIVE_STRATEGY).setConnectionManager(connectionManager).build(); httpClient = HttpClients.custom()
.setKeepAliveStrategy(DEFAULT_KEEP_ALIVE_STRATEGY)
.setConnectionManager(connectionManager)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
} }
} }
......
...@@ -4,14 +4,14 @@ public class OSUtils { ...@@ -4,14 +4,14 @@ public class OSUtils {
private static final String OS = System.getProperty("os.name").toLowerCase(); private static final String OS = System.getProperty("os.name").toLowerCase();
public static boolean isWindows() { public static boolean isWindows() {
return OS.indexOf("win") >= 0; return OS.contains("win");
} }
public static boolean isMac() { public static boolean isMac() {
return OS.indexOf("mac") >= 0; return OS.contains("mac");
} }
public static boolean isLinux() { public static boolean isLinux() {
return OS.indexOf("nux") >= 0; return OS.contains("nux");
} }
} }
...@@ -16,7 +16,7 @@ package com.taosdata.jdbc.utils; ...@@ -16,7 +16,7 @@ package com.taosdata.jdbc.utils;
public class SqlSyntaxValidator { public class SqlSyntaxValidator {
private static final String[] SQL = {"select", "insert", "import", "create", "use", "alter", "drop", "set", "show", "describe"}; private static final String[] SQL = {"select", "insert", "import", "create", "use", "alter", "drop", "set", "show", "describe", "reset"};
private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set"}; private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set"};
private static final String[] querySQL = {"select", "show", "describe"}; private static final String[] querySQL = {"select", "show", "describe"};
...@@ -61,29 +61,11 @@ public class SqlSyntaxValidator { ...@@ -61,29 +61,11 @@ public class SqlSyntaxValidator {
public static boolean isUseSql(String sql) { public static boolean isUseSql(String sql) {
return sql.trim().toLowerCase().startsWith("use"); return sql.trim().toLowerCase().startsWith("use");
// || sql.trim().toLowerCase().matches("create\\s*database.*") || sql.toLowerCase().toLowerCase().matches("drop\\s*database.*");
}
public static boolean isShowSql(String sql) {
return sql.trim().toLowerCase().startsWith("show");
}
public static boolean isDescribeSql(String sql) {
return sql.trim().toLowerCase().startsWith("describe");
}
public static boolean isInsertSql(String sql) {
return sql.trim().toLowerCase().startsWith("insert") || sql.trim().toLowerCase().startsWith("import");
} }
public static boolean isSelectSql(String sql) { public static boolean isSelectSql(String sql) {
return sql.trim().toLowerCase().startsWith("select"); return sql.trim().toLowerCase().startsWith("select");
} }
public static boolean isShowDatabaseSql(String sql) {
return sql.trim().toLowerCase().matches("show\\s*databases");
}
} }
...@@ -7,9 +7,9 @@ import java.util.concurrent.atomic.AtomicLong; ...@@ -7,9 +7,9 @@ import java.util.concurrent.atomic.AtomicLong;
public class TaosInfo implements TaosInfoMBean { public class TaosInfo implements TaosInfoMBean {
private static volatile TaosInfo instance; private static volatile TaosInfo instance;
private AtomicLong connect_open = new AtomicLong(); private final AtomicLong connect_open = new AtomicLong();
private AtomicLong connect_close = new AtomicLong(); private final AtomicLong connect_close = new AtomicLong();
private AtomicLong statement_count = new AtomicLong(); private final AtomicLong statement_count = new AtomicLong();
static { static {
try { try {
......
...@@ -22,8 +22,7 @@ import java.util.stream.IntStream; ...@@ -22,8 +22,7 @@ import java.util.stream.IntStream;
public class Utils { public class Utils {
private static Pattern ptn = Pattern.compile(".*?'"); private static final Pattern ptn = Pattern.compile(".*?'");
private static final DateTimeFormatter milliSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSS").toFormatter(); private static final DateTimeFormatter milliSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSS").toFormatter();
private static final DateTimeFormatter microSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").toFormatter(); private static final DateTimeFormatter microSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").toFormatter();
private static final DateTimeFormatter nanoSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS").toFormatter(); private static final DateTimeFormatter nanoSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS").toFormatter();
...@@ -74,7 +73,7 @@ public class Utils { ...@@ -74,7 +73,7 @@ public class Utils {
public static String escapeSingleQuota(String origin) { public static String escapeSingleQuota(String origin) {
Matcher m = ptn.matcher(origin); Matcher m = ptn.matcher(origin);
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int end = 0; int end = 0;
while (m.find()) { while (m.find()) {
end = m.end(); end = m.end();
...@@ -87,7 +86,7 @@ public class Utils { ...@@ -87,7 +86,7 @@ public class Utils {
sb.append(seg); sb.append(seg);
} }
} else { // len > 1 } else { // len > 1
sb.append(seg.substring(0, seg.length() - 2)); sb.append(seg, 0, seg.length() - 2);
char lastcSec = seg.charAt(seg.length() - 2); char lastcSec = seg.charAt(seg.length() - 2);
if (lastcSec == '\\') { if (lastcSec == '\\') {
sb.append("\\'"); sb.append("\\'");
...@@ -195,7 +194,7 @@ public class Utils { ...@@ -195,7 +194,7 @@ public class Utils {
public static String formatTimestamp(Timestamp timestamp) { public static String formatTimestamp(Timestamp timestamp) {
int nanos = timestamp.getNanos(); int nanos = timestamp.getNanos();
if (nanos % 1000000l != 0) if (nanos % 1000000L != 0)
return timestamp.toLocalDateTime().format(microSecFormatter); return timestamp.toLocalDateTime().format(microSecFormatter);
return timestamp.toLocalDateTime().format(milliSecFormatter); return timestamp.toLocalDateTime().format(milliSecFormatter);
} }
......
...@@ -5,7 +5,6 @@ import org.junit.Assert; ...@@ -5,7 +5,6 @@ import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import javax.management.OperationsException;
import java.sql.*; import java.sql.*;
import java.util.Properties; import java.util.Properties;
......
package com.taosdata.jdbc; package com.taosdata.jdbc;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLWarning; import java.sql.SQLWarning;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.lang.management.ManagementFactory; import static org.junit.Assert.assertEquals;
import java.lang.management.RuntimeMXBean; import static org.junit.Assert.assertTrue;
import java.lang.management.ThreadMXBean;
public class TSDBJNIConnectorTest { public class TSDBJNIConnectorTest {
......
package com.taosdata.jdbc; package com.taosdata.jdbc;
import com.taosdata.jdbc.rs.RestfulParameterMetaData;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
......
...@@ -2,7 +2,6 @@ package com.taosdata.jdbc; ...@@ -2,7 +2,6 @@ package com.taosdata.jdbc;
import org.junit.*; import org.junit.*;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -26,7 +25,7 @@ public class TSDBPreparedStatementTest { ...@@ -26,7 +25,7 @@ public class TSDBPreparedStatementTest {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setTimestamp(1, new Timestamp(ts));
pstmt_insert.setInt(2, 2); pstmt_insert.setInt(2, 2);
pstmt_insert.setLong(3, 3l); pstmt_insert.setLong(3, 3L);
pstmt_insert.setFloat(4, 3.14f); pstmt_insert.setFloat(4, 3.14f);
pstmt_insert.setDouble(5, 3.1415); pstmt_insert.setDouble(5, 3.1415);
pstmt_insert.setShort(6, (short) 6); pstmt_insert.setShort(6, (short) 6);
...@@ -53,8 +52,8 @@ public class TSDBPreparedStatementTest { ...@@ -53,8 +52,8 @@ public class TSDBPreparedStatementTest {
Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); Assert.assertEquals(ts, rs.getTimestamp(1).getTime());
Assert.assertEquals(2, rs.getInt(2)); Assert.assertEquals(2, rs.getInt(2));
Assert.assertEquals(2, rs.getInt("f1")); Assert.assertEquals(2, rs.getInt("f1"));
Assert.assertEquals(3l, rs.getLong(3)); Assert.assertEquals(3L, rs.getLong(3));
Assert.assertEquals(3l, rs.getLong("f2")); Assert.assertEquals(3L, rs.getLong("f2"));
Assert.assertEquals(3.14f, rs.getFloat(4), 0.0); Assert.assertEquals(3.14f, rs.getFloat(4), 0.0);
Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0); Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0);
Assert.assertEquals(3.1415, rs.getDouble(5), 0.0); Assert.assertEquals(3.1415, rs.getDouble(5), 0.0);
...@@ -312,14 +311,14 @@ public class TSDBPreparedStatementTest { ...@@ -312,14 +311,14 @@ public class TSDBPreparedStatementTest {
Random r = new Random(); Random r = new Random();
s.setTableName("weather_test"); s.setTableName("weather_test");
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
int random = 10 + r.nextInt(5); int random = 10 + r.nextInt(5);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s2.add(null); s2.add(null);
...@@ -330,7 +329,7 @@ public class TSDBPreparedStatementTest { ...@@ -330,7 +329,7 @@ public class TSDBPreparedStatementTest {
s.setNString(1, s2, 4); s.setNString(1, s2, 4);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<Float> s3 = new ArrayList<Float>(); ArrayList<Float> s3 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s3.add(null); s3.add(null);
...@@ -341,7 +340,7 @@ public class TSDBPreparedStatementTest { ...@@ -341,7 +340,7 @@ public class TSDBPreparedStatementTest {
s.setFloat(2, s3); s.setFloat(2, s3);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<Double> s4 = new ArrayList<Double>(); ArrayList<Double> s4 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s4.add(null); s4.add(null);
...@@ -352,7 +351,7 @@ public class TSDBPreparedStatementTest { ...@@ -352,7 +351,7 @@ public class TSDBPreparedStatementTest {
s.setDouble(3, s4); s.setDouble(3, s4);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<Long> ts2 = new ArrayList<Long>(); ArrayList<Long> ts2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
ts2.add(null); ts2.add(null);
...@@ -379,13 +378,13 @@ public class TSDBPreparedStatementTest { ...@@ -379,13 +378,13 @@ public class TSDBPreparedStatementTest {
if (i % random == 0) { if (i % random == 0) {
sb.add(null); sb.add(null);
} else { } else {
sb.add(i % 2 == 0 ? true : false); sb.add(i % 2 == 0);
} }
} }
s.setBoolean(6, sb); s.setBoolean(6, sb);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<String> s5 = new ArrayList<String>(); ArrayList<String> s5 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s5.add(null); s5.add(null);
...@@ -424,14 +423,14 @@ public class TSDBPreparedStatementTest { ...@@ -424,14 +423,14 @@ public class TSDBPreparedStatementTest {
Random r = new Random(); Random r = new Random();
s.setTableName("weather_test"); s.setTableName("weather_test");
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
int random = 10 + r.nextInt(5); int random = 10 + r.nextInt(5);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s2.add(null); s2.add(null);
...@@ -442,7 +441,7 @@ public class TSDBPreparedStatementTest { ...@@ -442,7 +441,7 @@ public class TSDBPreparedStatementTest {
s.setNString(1, s2, 4); s.setNString(1, s2, 4);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<String> s3 = new ArrayList<String>(); ArrayList<String> s3 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s3.add(null); s3.add(null);
...@@ -471,7 +470,7 @@ public class TSDBPreparedStatementTest { ...@@ -471,7 +470,7 @@ public class TSDBPreparedStatementTest {
public void bindDataWithSingleTagTest() throws SQLException { public void bindDataWithSingleTagTest() throws SQLException {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
String types[] = new String[]{"tinyint", "smallint", "int", "bigint", "bool", "float", "double", "binary(10)", "nchar(10)"}; String[] types = new String[]{"tinyint", "smallint", "int", "bigint", "bool", "float", "double", "binary(10)", "nchar(10)"};
for (String type : types) { for (String type : types) {
stmt.execute("drop table if exists weather_test"); stmt.execute("drop table if exists weather_test");
...@@ -510,21 +509,21 @@ public class TSDBPreparedStatementTest { ...@@ -510,21 +509,21 @@ public class TSDBPreparedStatementTest {
} }
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
int random = 10 + r.nextInt(5); int random = 10 + r.nextInt(5);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
s2.add("分支" + i % 4); s2.add("分支" + i % 4);
} }
s.setNString(1, s2, 10); s.setNString(1, s2, 10);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<String> s3 = new ArrayList<String>(); ArrayList<String> s3 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
s3.add("test" + i % 4); s3.add("test" + i % 4);
} }
...@@ -561,13 +560,13 @@ public class TSDBPreparedStatementTest { ...@@ -561,13 +560,13 @@ public class TSDBPreparedStatementTest {
s.setTagString(1, "test"); s.setTagString(1, "test");
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
s2.add("test" + i % 4); s2.add("test" + i % 4);
} }
...@@ -788,7 +787,7 @@ public class TSDBPreparedStatementTest { ...@@ -788,7 +787,7 @@ public class TSDBPreparedStatementTest {
public void setBigDecimal() throws SQLException { public void setBigDecimal() throws SQLException {
// given // given
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
BigDecimal bigDecimal = new BigDecimal(3.14444); BigDecimal bigDecimal = new BigDecimal("3.14444");
// when // when
pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setTimestamp(1, new Timestamp(ts));
...@@ -999,7 +998,7 @@ public class TSDBPreparedStatementTest { ...@@ -999,7 +998,7 @@ public class TSDBPreparedStatementTest {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setTimestamp(1, new Timestamp(ts));
pstmt_insert.setInt(2, 2); pstmt_insert.setInt(2, 2);
pstmt_insert.setLong(3, 3l); pstmt_insert.setLong(3, 3L);
pstmt_insert.setFloat(4, 3.14f); pstmt_insert.setFloat(4, 3.14f);
pstmt_insert.setDouble(5, 3.1415); pstmt_insert.setDouble(5, 3.1415);
pstmt_insert.setShort(6, (short) 6); pstmt_insert.setShort(6, (short) 6);
......
...@@ -95,13 +95,13 @@ public class TSDBResultSetTest { ...@@ -95,13 +95,13 @@ public class TSDBResultSetTest {
@Test @Test
public void getBigDecimal() throws SQLException { public void getBigDecimal() throws SQLException {
BigDecimal f1 = rs.getBigDecimal("f1"); BigDecimal f1 = rs.getBigDecimal("f1");
Assert.assertEquals(1609430400000l, f1.longValue()); Assert.assertEquals(1609430400000L, f1.longValue());
BigDecimal f2 = rs.getBigDecimal("f2"); BigDecimal f2 = rs.getBigDecimal("f2");
Assert.assertEquals(1, f2.intValue()); Assert.assertEquals(1, f2.intValue());
BigDecimal f3 = rs.getBigDecimal("f3"); BigDecimal f3 = rs.getBigDecimal("f3");
Assert.assertEquals(100l, f3.longValue()); Assert.assertEquals(100L, f3.longValue());
BigDecimal f4 = rs.getBigDecimal("f4"); BigDecimal f4 = rs.getBigDecimal("f4");
Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f); Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f);
...@@ -125,13 +125,13 @@ public class TSDBResultSetTest { ...@@ -125,13 +125,13 @@ public class TSDBResultSetTest {
Assert.assertEquals(1, Ints.fromByteArray(f2)); Assert.assertEquals(1, Ints.fromByteArray(f2));
byte[] f3 = rs.getBytes("f3"); byte[] f3 = rs.getBytes("f3");
Assert.assertEquals(100l, Longs.fromByteArray(f3)); Assert.assertEquals(100L, Longs.fromByteArray(f3));
byte[] f4 = rs.getBytes("f4"); byte[] f4 = rs.getBytes("f4");
Assert.assertEquals(3.1415f, Float.valueOf(new String(f4)), 0.000000f); Assert.assertEquals(3.1415f, Float.parseFloat(new String(f4)), 0.000000f);
byte[] f5 = rs.getBytes("f5"); byte[] f5 = rs.getBytes("f5");
Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f); Assert.assertEquals(3.1415926, Double.parseDouble(new String(f5)), 0.000000f);
byte[] f6 = rs.getBytes("f6"); byte[] f6 = rs.getBytes("f6");
Assert.assertTrue(Arrays.equals("abc".getBytes(), f6)); Assert.assertTrue(Arrays.equals("abc".getBytes(), f6));
...@@ -223,7 +223,7 @@ public class TSDBResultSetTest { ...@@ -223,7 +223,7 @@ public class TSDBResultSetTest {
Object f3 = rs.getObject("f3"); Object f3 = rs.getObject("f3");
Assert.assertEquals(Long.class, f3.getClass()); Assert.assertEquals(Long.class, f3.getClass());
Assert.assertEquals(100l, f3); Assert.assertEquals(100L, f3);
Object f4 = rs.getObject("f4"); Object f4 = rs.getObject("f4");
Assert.assertEquals(Float.class, f4.getClass()); Assert.assertEquals(Float.class, f4.getClass());
...@@ -421,7 +421,7 @@ public class TSDBResultSetTest { ...@@ -421,7 +421,7 @@ public class TSDBResultSetTest {
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
public void updateLong() throws SQLException { public void updateLong() throws SQLException {
rs.updateLong(1, 1l); rs.updateLong(1, 1L);
} }
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
......
...@@ -3,12 +3,13 @@ package com.taosdata.jdbc.cases; ...@@ -3,12 +3,13 @@ package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.TSDBDriver;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.IOException;
import java.sql.*; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties; import java.util.Properties;
public class BadLocaleSettingTest { public class BadLocaleSettingTest {
......
package com.taosdata.jdbc.cases; package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.TSDBDriver;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -9,13 +10,13 @@ import java.util.Properties; ...@@ -9,13 +10,13 @@ import java.util.Properties;
public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { public class ConnectMultiTaosdByRestfulWithDifferentTokenTest {
private static String host1 = "192.168.17.156"; private static final String host1 = "192.168.17.156";
private static String user1 = "root"; private static final String user1 = "root";
private static String password1 = "tqueue"; private static final String password1 = "tqueue";
private Connection conn1; private Connection conn1;
private static String host2 = "192.168.17.82"; private static final String host2 = "192.168.17.82";
private static String user2 = "root"; private static final String user2 = "root";
private static String password2 = "taosdata"; private static final String password2 = "taosdata";
private Connection conn2; private Connection conn2;
@Test @Test
...@@ -30,6 +31,7 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { ...@@ -30,6 +31,7 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest {
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
ResultSet rs = stmt.executeQuery("select server_status()"); ResultSet rs = stmt.executeQuery("select server_status()");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
Assert.assertNotNull(meta);
while (rs.next()) { while (rs.next()) {
} }
} catch (SQLException e) { } catch (SQLException e) {
......
...@@ -13,7 +13,7 @@ import java.util.Properties; ...@@ -13,7 +13,7 @@ import java.util.Properties;
public class DriverAutoloadTest { public class DriverAutoloadTest {
private Properties properties; private Properties properties;
private String host = "127.0.0.1"; private final String host = "127.0.0.1";
@Test @Test
public void testRestful() throws SQLException { public void testRestful() throws SQLException {
......
...@@ -13,9 +13,9 @@ import java.util.Random; ...@@ -13,9 +13,9 @@ import java.util.Random;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class InsertDbwithoutUseDbTest { public class InsertDbwithoutUseDbTest {
private static String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Properties properties; private static Properties properties;
private static Random random = new Random(System.currentTimeMillis()); private static final Random random = new Random(System.currentTimeMillis());
@Test @Test
public void case001() throws ClassNotFoundException, SQLException { public void case001() throws ClassNotFoundException, SQLException {
......
...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterJniTest { ...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterJniTest {
private static final String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Connection conn; private static Connection conn;
private static String dbName = "spec_char_test"; private static final String dbName = "spec_char_test";
private static String tbname1 = "test"; private static final String tbname1 = "test";
private static String tbname2 = "weather"; private static final String tbname2 = "weather";
private static String special_character_str_1 = "$asd$$fsfsf$"; private static final String special_character_str_1 = "$asd$$fsfsf$";
private static String special_character_str_2 = "\\\\asdfsfsf\\\\"; private static final String special_character_str_2 = "\\\\asdfsfsf\\\\";
private static String special_character_str_3 = "\\\\asdfsfsf\\"; private static final String special_character_str_3 = "\\\\asdfsfsf\\";
private static String special_character_str_4 = "?asd??fsf?sf?"; private static final String special_character_str_4 = "?asd??fsf?sf?";
private static String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$"; private static final String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$";
@Test @Test
public void testCase01() throws SQLException { public void testCase01() throws SQLException {
......
...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterRestfulTest { ...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterRestfulTest {
private static final String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Connection conn; private static Connection conn;
private static String dbName = "spec_char_test"; private static final String dbName = "spec_char_test";
private static String tbname1 = "test"; private static final String tbname1 = "test";
private static String tbname2 = "weather"; private static final String tbname2 = "weather";
private static String special_character_str_1 = "$asd$$fsfsf$"; private static final String special_character_str_1 = "$asd$$fsfsf$";
private static String special_character_str_2 = "\\\\asdfsfsf\\\\"; private static final String special_character_str_2 = "\\\\asdfsfsf\\\\";
private static String special_character_str_3 = "\\\\asdfsfsf\\"; private static final String special_character_str_3 = "\\\\asdfsfsf\\";
private static String special_character_str_4 = "?asd??fsf?sf?"; private static final String special_character_str_4 = "?asd??fsf?sf?";
private static String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$"; private static final String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$";
@Test @Test
public void testCase01() throws SQLException { public void testCase01() throws SQLException {
......
...@@ -8,13 +8,13 @@ import java.util.Properties; ...@@ -8,13 +8,13 @@ import java.util.Properties;
public class InvalidResultSetPointerTest { public class InvalidResultSetPointerTest {
private static String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static final String dbName = "test"; private static final String dbName = "test";
private static final String stbName = "stb"; private static final String stbName = "stb";
private static final String tbName = "tb"; private static final String tbName = "tb";
private static Connection connection; private static Connection connection;
private static int numOfSTb = 30000; private static final int numOfSTb = 30000;
private static int numOfTb = 3; private static final int numOfTb = 3;
private static int numOfThreads = 100; private static int numOfThreads = 100;
@Test @Test
...@@ -74,7 +74,7 @@ public class InvalidResultSetPointerTest { ...@@ -74,7 +74,7 @@ public class InvalidResultSetPointerTest {
b = numOfSTb % numOfThreads; b = numOfSTb % numOfThreads;
} }
multiThreadingClass instance[] = new multiThreadingClass[numOfThreads]; multiThreadingClass[] instance = new multiThreadingClass[numOfThreads];
int last = 0; int last = 0;
for (int i = 0; i < numOfThreads; i++) { for (int i = 0; i < numOfThreads; i++) {
......
...@@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit; ...@@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit;
public class MultiThreadsWithSameStatementTest { public class MultiThreadsWithSameStatementTest {
private static class Service {
private class Service {
public Connection conn; public Connection conn;
public Statement stmt; public Statement stmt;
......
package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
public class ResetQueryCacheTest {
static Connection connection;
static Statement statement;
static String host = "127.0.0.1";
@Before
public void init() {
try {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
statement = connection.createStatement();
} catch (SQLException e) {
return;
}
}
@Test
public void testResetQueryCache() throws SQLException {
String resetSql = "reset query cache";
statement.execute(resetSql);
}
@After
public void close() {
try {
if (statement != null)
statement.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
...@@ -16,9 +16,9 @@ import static org.junit.Assert.assertEquals; ...@@ -16,9 +16,9 @@ import static org.junit.Assert.assertEquals;
public class StableTest { public class StableTest {
private static Connection connection; private static Connection connection;
private static String dbName = "test"; private static final String dbName = "test";
private static String stbName = "st"; private static final String stbName = "st";
private static String host = "127.0.0.1"; private static final String host = "127.0.0.1";
@BeforeClass @BeforeClass
public static void createDatabase() { public static void createDatabase() {
......
...@@ -25,7 +25,7 @@ public class TaosInfoMonitorTest { ...@@ -25,7 +25,7 @@ public class TaosInfoMonitorTest {
return null; return null;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
connectionList.stream().forEach(conn -> { connectionList.forEach(conn -> {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("show databases"); ResultSet rs = stmt.executeQuery("show databases");
while (rs.next()) { while (rs.next()) {
...@@ -37,7 +37,7 @@ public class TaosInfoMonitorTest { ...@@ -37,7 +37,7 @@ public class TaosInfoMonitorTest {
} }
}); });
connectionList.stream().forEach(conn -> { connectionList.forEach(conn -> {
try { try {
conn.close(); conn.close();
TimeUnit.MILLISECONDS.sleep(100); TimeUnit.MILLISECONDS.sleep(100);
......
...@@ -22,7 +22,7 @@ public class TimestampPrecisionInNanoInJniTest { ...@@ -22,7 +22,7 @@ public class TimestampPrecisionInNanoInJniTest {
private static final long timestamp3 = (timestamp1 + 10) * 1000_000 + 123456; private static final long timestamp3 = (timestamp1 + 10) * 1000_000 + 123456;
private static final Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); private static final Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
private static final String date1 = format.format(new Date(timestamp1)); private static final String date1 = format.format(new Date(timestamp1));
private static final String date4 = format.format(new Date(timestamp1 + 10l)); private static final String date4 = format.format(new Date(timestamp1 + 10L));
private static final String date2 = date1 + "123455"; private static final String date2 = date1 + "123455";
private static final String date3 = date4 + "123456"; private static final String date3 = date4 + "123456";
......
...@@ -44,7 +44,7 @@ public class UnsignedNumberJniTest { ...@@ -44,7 +44,7 @@ public class UnsignedNumberJniTest {
Assert.assertEquals(127, rs.getByte(2)); Assert.assertEquals(127, rs.getByte(2));
Assert.assertEquals(32767, rs.getShort(3)); Assert.assertEquals(32767, rs.getShort(3));
Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807l, rs.getLong(5)); Assert.assertEquals(9223372036854775807L, rs.getLong(5));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -45,7 +45,7 @@ public class UnsignedNumberRestfulTest { ...@@ -45,7 +45,7 @@ public class UnsignedNumberRestfulTest {
Assert.assertEquals(127, rs.getByte(2)); Assert.assertEquals(127, rs.getByte(2));
Assert.assertEquals(32767, rs.getShort(3)); Assert.assertEquals(32767, rs.getShort(3));
Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807l, rs.getLong(5)); Assert.assertEquals(9223372036854775807L, rs.getLong(5));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -95,13 +95,13 @@ public class RestfulResultSetTest { ...@@ -95,13 +95,13 @@ public class RestfulResultSetTest {
public void getBigDecimal() throws SQLException { public void getBigDecimal() throws SQLException {
BigDecimal f1 = rs.getBigDecimal("f1"); BigDecimal f1 = rs.getBigDecimal("f1");
long actual = (f1 == null) ? 0 : f1.longValue(); long actual = (f1 == null) ? 0 : f1.longValue();
Assert.assertEquals(1609430400000l, actual); Assert.assertEquals(1609430400000L, actual);
BigDecimal f2 = rs.getBigDecimal("f2"); BigDecimal f2 = rs.getBigDecimal("f2");
Assert.assertEquals(1, f2.intValue()); Assert.assertEquals(1, f2.intValue());
BigDecimal f3 = rs.getBigDecimal("f3"); BigDecimal f3 = rs.getBigDecimal("f3");
Assert.assertEquals(100l, f3.longValue()); Assert.assertEquals(100L, f3.longValue());
BigDecimal f4 = rs.getBigDecimal("f4"); BigDecimal f4 = rs.getBigDecimal("f4");
Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f); Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f);
...@@ -125,13 +125,13 @@ public class RestfulResultSetTest { ...@@ -125,13 +125,13 @@ public class RestfulResultSetTest {
Assert.assertEquals(1, Ints.fromByteArray(f2)); Assert.assertEquals(1, Ints.fromByteArray(f2));
byte[] f3 = rs.getBytes("f3"); byte[] f3 = rs.getBytes("f3");
Assert.assertEquals(100l, Longs.fromByteArray(f3)); Assert.assertEquals(100L, Longs.fromByteArray(f3));
byte[] f4 = rs.getBytes("f4"); byte[] f4 = rs.getBytes("f4");
Assert.assertEquals(3.1415f, Float.valueOf(new String(f4)), 0.000000f); Assert.assertEquals(3.1415f, Float.parseFloat(new String(f4)), 0.000000f);
byte[] f5 = rs.getBytes("f5"); byte[] f5 = rs.getBytes("f5");
Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f); Assert.assertEquals(3.1415926, Double.parseDouble(new String(f5)), 0.000000f);
byte[] f6 = rs.getBytes("f6"); byte[] f6 = rs.getBytes("f6");
Assert.assertEquals("abc", new String(f6)); Assert.assertEquals("abc", new String(f6));
...@@ -222,7 +222,7 @@ public class RestfulResultSetTest { ...@@ -222,7 +222,7 @@ public class RestfulResultSetTest {
Object f3 = rs.getObject("f3"); Object f3 = rs.getObject("f3");
Assert.assertEquals(Long.class, f3.getClass()); Assert.assertEquals(Long.class, f3.getClass());
Assert.assertEquals(100l, f3); Assert.assertEquals(100L, f3);
Object f4 = rs.getObject("f4"); Object f4 = rs.getObject("f4");
Assert.assertEquals(Float.class, f4.getClass()); Assert.assertEquals(Float.class, f4.getClass());
...@@ -434,7 +434,7 @@ public class RestfulResultSetTest { ...@@ -434,7 +434,7 @@ public class RestfulResultSetTest {
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
public void updateLong() throws SQLException { public void updateLong() throws SQLException {
rs.updateLong(1, 1l); rs.updateLong(1, 1L);
} }
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
......
...@@ -10,17 +10,17 @@ public class OSUtilsTest { ...@@ -10,17 +10,17 @@ public class OSUtilsTest {
@Test @Test
public void inWindows() { public void inWindows() {
Assert.assertEquals(OS.indexOf("win") >= 0, OSUtils.isWindows()); Assert.assertEquals(OS.contains("win"), OSUtils.isWindows());
} }
@Test @Test
public void isMac() { public void isMac() {
Assert.assertEquals(OS.indexOf("mac") >= 0, OSUtils.isMac()); Assert.assertEquals(OS.contains("mac"), OSUtils.isMac());
} }
@Test @Test
public void isLinux() { public void isLinux() {
Assert.assertEquals(OS.indexOf("nux") >= 0, OSUtils.isLinux()); Assert.assertEquals(OS.contains("nux"), OSUtils.isLinux());
} }
@Before @Before
......
...@@ -21,47 +21,4 @@ public class TimestampUtil { ...@@ -21,47 +21,4 @@ public class TimestampUtil {
SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat); SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat);
return sdf.format(new Date(time)); return sdf.format(new Date(time));
} }
public static class TimeTuple {
public Long start;
public Long end;
public Long timeGap;
TimeTuple(long start, long end, long timeGap) {
this.start = start;
this.end = end;
this.timeGap = timeGap;
}
}
public static TimeTuple range(long start, long timeGap, long size) {
long now = System.currentTimeMillis();
if (timeGap < 1)
timeGap = 1;
if (start == 0)
start = now - size * timeGap;
// 如果size小于1异常
if (size < 1)
throw new IllegalArgumentException("size less than 1.");
// 如果timeGap为1,已经超长,需要前移start
if (start + size > now) {
start = now - size;
return new TimeTuple(start, now, 1);
}
long end = start + (long) (timeGap * size);
if (end > now) {
//压缩timeGap
end = now;
double gap = (end - start) / (size * 1.0f);
if (gap < 1.0f) {
timeGap = 1;
start = end - size;
} else {
timeGap = (long) gap;
end = start + (long) (timeGap * size);
}
}
return new TimeTuple(start, end, timeGap);
}
} }
...@@ -3,8 +3,6 @@ package com.taosdata.jdbc.utils; ...@@ -3,8 +3,6 @@ package com.taosdata.jdbc.utils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream; import java.util.stream.Stream;
public class UtilsTest { public class UtilsTest {
...@@ -19,14 +17,14 @@ public class UtilsTest { ...@@ -19,14 +17,14 @@ public class UtilsTest {
Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news); Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news);
// given // given
s = "\'''''a\\'"; s = "'''''a\\'";
// when // when
news = Utils.escapeSingleQuota(s); news = Utils.escapeSingleQuota(s);
// then // then
Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news); Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news);
// given // given
s = "\'\'\'\''a\\'"; s = "'''''a\\'";
// when // when
news = Utils.escapeSingleQuota(s); news = Utils.escapeSingleQuota(s);
// then // then
......
...@@ -490,9 +490,9 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) { ...@@ -490,9 +490,9 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
for (int32_t i = 0; i < pSchema->numOfCols; i++) { for (int32_t i = 0; i < pSchema->numOfCols; i++) {
STColumn *c = pSchema->columns + i; STColumn *c = pSchema->columns + i;
void* val = row[i]; void *val = row[i];
if (val == NULL) { if (val == NULL) {
val = getNullValue(c->type); val = (void *)getNullValue(c->type);
} else if (c->type == TSDB_DATA_TYPE_BINARY) { } else if (c->type == TSDB_DATA_TYPE_BINARY) {
val = ((char*)val) - sizeof(VarDataLenT); val = ((char*)val) - sizeof(VarDataLenT);
} else if (c->type == TSDB_DATA_TYPE_NCHAR) { } else if (c->type == TSDB_DATA_TYPE_NCHAR) {
......
...@@ -150,6 +150,8 @@ static void *dnodeProcessMPeerQueue(void *param) { ...@@ -150,6 +150,8 @@ static void *dnodeProcessMPeerQueue(void *param) {
SMnodeMsg *pPeerMsg; SMnodeMsg *pPeerMsg;
int32_t type; int32_t type;
void * unUsed; void * unUsed;
setThreadName("dnodeMPeerQ");
while (1) { while (1) {
if (taosReadQitemFromQset(tsMPeerQset, &type, (void **)&pPeerMsg, &unUsed) == 0) { if (taosReadQitemFromQset(tsMPeerQset, &type, (void **)&pPeerMsg, &unUsed) == 0) {
......
...@@ -155,6 +155,8 @@ static void *dnodeProcessMReadQueue(void *param) { ...@@ -155,6 +155,8 @@ static void *dnodeProcessMReadQueue(void *param) {
int32_t type; int32_t type;
void * unUsed; void * unUsed;
setThreadName("dnodeMReadQ");
while (1) { while (1) {
if (taosReadQitemFromQset(tsMReadQset, &type, (void **)&pRead, &unUsed) == 0) { if (taosReadQitemFromQset(tsMReadQset, &type, (void **)&pRead, &unUsed) == 0) {
dDebug("qset:%p, mnode read got no message from qset, exiting", tsMReadQset); dDebug("qset:%p, mnode read got no message from qset, exiting", tsMReadQset);
......
...@@ -168,7 +168,9 @@ static void *dnodeProcessMWriteQueue(void *param) { ...@@ -168,7 +168,9 @@ static void *dnodeProcessMWriteQueue(void *param) {
SMnodeMsg *pWrite; SMnodeMsg *pWrite;
int32_t type; int32_t type;
void * unUsed; void * unUsed;
setThreadName("dnodeMWriteQ");
while (1) { while (1) {
if (taosReadQitemFromQset(tsMWriteQset, &type, (void **)&pWrite, &unUsed) == 0) { if (taosReadQitemFromQset(tsMWriteQset, &type, (void **)&pWrite, &unUsed) == 0) {
dDebug("qset:%p, mnode write got no message from qset, exiting", tsMWriteQset); dDebug("qset:%p, mnode write got no message from qset, exiting", tsMWriteQset);
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "module.h" #include "module.h"
#include "qScript.h" #include "qScript.h"
#include "mnode.h" #include "mnode.h"
#include "tscompression.h"
#if !defined(_MODULE) || !defined(_TD_LINUX) #if !defined(_MODULE) || !defined(_TD_LINUX)
int32_t moduleStart() { return 0; } int32_t moduleStart() { return 0; }
...@@ -236,6 +237,12 @@ static void dnodeCheckDataDirOpenned(char *dir) { ...@@ -236,6 +237,12 @@ static void dnodeCheckDataDirOpenned(char *dir) {
} }
static int32_t dnodeInitStorage() { static int32_t dnodeInitStorage() {
#ifdef TD_TSZ
// compress module init
tsCompressInit();
#endif
// storage module init
if (tsDiskCfgNum == 1 && dnodeCreateDir(tsDataDir) < 0) { if (tsDiskCfgNum == 1 && dnodeCreateDir(tsDataDir) < 0) {
dError("failed to create dir: %s, reason: %s", tsDataDir, strerror(errno)); dError("failed to create dir: %s, reason: %s", tsDataDir, strerror(errno));
return -1; return -1;
...@@ -311,7 +318,15 @@ static int32_t dnodeInitStorage() { ...@@ -311,7 +318,15 @@ static int32_t dnodeInitStorage() {
return 0; return 0;
} }
static void dnodeCleanupStorage() { tfsDestroy(); } static void dnodeCleanupStorage() {
// storage destroy
tfsDestroy();
#ifdef TD_TSZ
// compress destroy
tsCompressExit();
#endif
}
bool dnodeIsFirstDeploy() { bool dnodeIsFirstDeploy() {
return strcmp(tsFirst, tsLocalEp) == 0; return strcmp(tsFirst, tsLocalEp) == 0;
......
...@@ -245,6 +245,8 @@ static void* telemetryThread(void* param) { ...@@ -245,6 +245,8 @@ static void* telemetryThread(void* param) {
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
end.tv_sec += 300; // wait 5 minutes before send first report end.tv_sec += 300; // wait 5 minutes before send first report
setThreadName("telemetryThrd");
while (!tsExit) { while (!tsExit) {
int r = 0; int r = 0;
struct timespec ts = end; struct timespec ts = end;
......
...@@ -103,6 +103,8 @@ static void *dnodeProcessMgmtQueue(void *wparam) { ...@@ -103,6 +103,8 @@ static void *dnodeProcessMgmtQueue(void *wparam) {
int32_t qtype; int32_t qtype;
void * handle; void * handle;
setThreadName("dnodeMgmtQ");
while (1) { while (1) {
if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pMgmt, &handle) == 0) { if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pMgmt, &handle) == 0) {
dDebug("qdnode mgmt got no message from qset:%p, , exit", pPool->qset); dDebug("qdnode mgmt got no message from qset:%p, , exit", pPool->qset);
......
...@@ -118,6 +118,11 @@ static void *dnodeProcessReadQueue(void *wparam) { ...@@ -118,6 +118,11 @@ static void *dnodeProcessReadQueue(void *wparam) {
SVReadMsg * pRead; SVReadMsg * pRead;
int32_t qtype; int32_t qtype;
void * pVnode; void * pVnode;
char name[16];
memset(name, 0, 16);
snprintf(name, 16, "%s-dnReadQ", pPool->name);
setThreadName(name);
while (1) { while (1) {
if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pRead, &pVnode) == 0) { if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pRead, &pVnode) == 0) {
......
...@@ -191,6 +191,8 @@ static void *dnodeProcessVWriteQueue(void *wparam) { ...@@ -191,6 +191,8 @@ static void *dnodeProcessVWriteQueue(void *wparam) {
taosBlockSIGPIPE(); taosBlockSIGPIPE();
dDebug("dnode vwrite worker:%d is running", pWorker->workerId); dDebug("dnode vwrite worker:%d is running", pWorker->workerId);
setThreadName("dnodeWriteQ");
while (1) { while (1) {
numOfMsgs = taosReadAllQitemsFromQset(pWorker->qset, pWorker->qall, &pVnode); numOfMsgs = taosReadAllQitemsFromQset(pWorker->qset, pWorker->qall, &pVnode);
if (numOfMsgs == 0) { if (numOfMsgs == 0) {
......
...@@ -91,6 +91,8 @@ static void *dnodeOpenVnode(void *param) { ...@@ -91,6 +91,8 @@ static void *dnodeOpenVnode(void *param) {
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("dnodeOpenVnode");
for (int32_t v = 0; v < pThread->vnodeNum; ++v) { for (int32_t v = 0; v < pThread->vnodeNum; ++v) {
int32_t vgId = pThread->vnodeList[v]; int32_t vgId = pThread->vnodeList[v];
snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", vgId, tsOpenVnodes, tsTotalVnodes); snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", vgId, tsOpenVnodes, tsTotalVnodes);
......
...@@ -72,6 +72,7 @@ DLL_EXPORT int taos_init(); ...@@ -72,6 +72,7 @@ DLL_EXPORT int taos_init();
DLL_EXPORT void taos_cleanup(void); DLL_EXPORT void taos_cleanup(void);
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
DLL_EXPORT void taos_close(TAOS *taos); DLL_EXPORT void taos_close(TAOS *taos);
const char *taos_data_type(int type); const char *taos_data_type(int type);
...@@ -110,21 +111,23 @@ typedef struct TAOS_MULTI_BIND { ...@@ -110,21 +111,23 @@ typedef struct TAOS_MULTI_BIND {
} TAOS_MULTI_BIND; } TAOS_MULTI_BIND;
TAOS_STMT *taos_stmt_init(TAOS *taos);
int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length); DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags); DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name); DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags);
int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert); DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name);
int taos_stmt_num_params(TAOS_STMT *stmt, int *nums); DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT* stmt, const char* name);
DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes); int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind); DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind);
int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind); int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind);
int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int colIdx); int taos_stmt_bind_single_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int colIdx);
int taos_stmt_add_batch(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt);
int taos_stmt_execute(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt);
TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt); DLL_EXPORT TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt);
int taos_stmt_close(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
char * taos_stmt_errstr(TAOS_STMT *stmt); DLL_EXPORT char * taos_stmt_errstr(TAOS_STMT *stmt);
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res); DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
...@@ -139,10 +142,10 @@ DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int n ...@@ -139,10 +142,10 @@ DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int n
DLL_EXPORT void taos_stop_query(TAOS_RES *res); DLL_EXPORT void taos_stop_query(TAOS_RES *res);
DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col); DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows); DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
int taos_validate_sql(TAOS *taos, const char *sql); DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
int* taos_fetch_lengths(TAOS_RES *res); DLL_EXPORT int* taos_fetch_lengths(TAOS_RES *res);
// TAOS_RES *taos_list_tables(TAOS *mysql, const char *wild); // TAOS_RES *taos_list_tables(TAOS *mysql, const char *wild);
// TAOS_RES *taos_list_dbs(TAOS *mysql, const char *wild); // TAOS_RES *taos_list_dbs(TAOS *mysql, const char *wild);
......
...@@ -20,6 +20,18 @@ typedef struct tstr { ...@@ -20,6 +20,18 @@ typedef struct tstr {
char data[]; char data[];
} tstr; } tstr;
#pragma pack(push, 1)
typedef struct {
VarDataLenT len;
uint8_t data;
} SBinaryNullT;
typedef struct {
VarDataLenT len;
uint32_t data;
} SNCharNullT;
#pragma pack(pop)
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT) #define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
#define varDataLen(v) ((VarDataLenT *)(v))[0] #define varDataLen(v) ((VarDataLenT *)(v))[0]
...@@ -182,7 +194,7 @@ bool isValidDataType(int32_t type); ...@@ -182,7 +194,7 @@ bool isValidDataType(int32_t type);
void setVardataNull(char* val, int32_t type); void setVardataNull(char* val, int32_t type);
void setNull(char *val, int32_t type, int32_t bytes); void setNull(char *val, int32_t type, int32_t bytes);
void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems); void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems);
void *getNullValue(int32_t type); const void *getNullValue(int32_t type);
void assignVal(char *val, const char *src, int32_t len, int32_t type); void assignVal(char *val, const char *src, int32_t len, int32_t type);
void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf); void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf);
......
...@@ -4,3 +4,4 @@ PROJECT(TDengine) ...@@ -4,3 +4,4 @@ PROJECT(TDengine)
ADD_SUBDIRECTORY(shell) ADD_SUBDIRECTORY(shell)
ADD_SUBDIRECTORY(taosdemo) ADD_SUBDIRECTORY(taosdemo)
ADD_SUBDIRECTORY(taosdump) ADD_SUBDIRECTORY(taosdump)
ADD_SUBDIRECTORY(taospack)
...@@ -104,6 +104,8 @@ static void shellFreeTbnames() { ...@@ -104,6 +104,8 @@ static void shellFreeTbnames() {
static void *shellCheckThreadFp(void *arg) { static void *shellCheckThreadFp(void *arg) {
ShellThreadObj *pThread = (ShellThreadObj *)arg; ShellThreadObj *pThread = (ShellThreadObj *)arg;
setThreadName("shellCheckThrd");
int32_t interval = tbNum / pThread->totalThreads + 1; int32_t interval = tbNum / pThread->totalThreads + 1;
int32_t start = pThread->threadIndex * interval; int32_t start = pThread->threadIndex * interval;
int32_t end = (pThread->threadIndex + 1) * interval; int32_t end = (pThread->threadIndex + 1) * interval;
......
...@@ -336,6 +336,8 @@ void *shellLoopQuery(void *arg) { ...@@ -336,6 +336,8 @@ void *shellLoopQuery(void *arg) {
TAOS *con = (TAOS *)arg; TAOS *con = (TAOS *)arg;
setThreadName("shellLoopQuery");
pthread_cleanup_push(cleanup_handler, NULL); pthread_cleanup_push(cleanup_handler, NULL);
char *command = malloc(MAX_COMMAND_SIZE); char *command = malloc(MAX_COMMAND_SIZE);
......
...@@ -223,6 +223,8 @@ static void shellSourceFile(TAOS *con, char *fptr) { ...@@ -223,6 +223,8 @@ static void shellSourceFile(TAOS *con, char *fptr) {
void* shellImportThreadFp(void *arg) void* shellImportThreadFp(void *arg)
{ {
ShellThreadObj *pThread = (ShellThreadObj*)arg; ShellThreadObj *pThread = (ShellThreadObj*)arg;
setThreadName("shellImportThrd");
for (int f = 0; f < shellSQLFileNum; ++f) { for (int f = 0; f < shellSQLFileNum; ++f) {
if (f % pThread->totalThreads == pThread->threadIndex) { if (f % pThread->totalThreads == pThread->threadIndex) {
char *SQLFileName = shellSQLFiles[f]; char *SQLFileName = shellSQLFiles[f];
......
...@@ -336,6 +336,8 @@ void *shellLoopQuery(void *arg) { ...@@ -336,6 +336,8 @@ void *shellLoopQuery(void *arg) {
TAOS *con = (TAOS *)arg; TAOS *con = (TAOS *)arg;
setThreadName("shellLoopQuery");
pthread_cleanup_push(cleanup_handler, NULL); pthread_cleanup_push(cleanup_handler, NULL);
char *command = malloc(MAX_COMMAND_SIZE); char *command = malloc(MAX_COMMAND_SIZE);
......
...@@ -26,6 +26,8 @@ void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { ...@@ -26,6 +26,8 @@ void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) {
} }
void *cancelHandler(void *arg) { void *cancelHandler(void *arg) {
setThreadName("cancelHandler");
while(1) { while(1) {
if (tsem_wait(&cancelSem) != 0) { if (tsem_wait(&cancelSem) != 0) {
taosMsleep(10); taosMsleep(10);
......
此差异已折叠。
...@@ -1474,6 +1474,8 @@ static void* taosDumpOutWorkThreadFp(void *arg) ...@@ -1474,6 +1474,8 @@ static void* taosDumpOutWorkThreadFp(void *arg)
STableRecord tableRecord; STableRecord tableRecord;
int fd; int fd;
setThreadName("dumpOutWorkThrd");
char tmpBuf[4096] = {0}; char tmpBuf[4096] = {0};
sprintf(tmpBuf, ".tables.tmp.%d", pThread->threadIndex); sprintf(tmpBuf, ".tables.tmp.%d", pThread->threadIndex);
fd = open(tmpBuf, O_RDWR | O_CREAT, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH); fd = open(tmpBuf, O_RDWR | O_CREAT, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH);
...@@ -2571,6 +2573,8 @@ static int taosDumpInOneFile(TAOS* taos, FILE* fp, char* fcharset, ...@@ -2571,6 +2573,8 @@ static int taosDumpInOneFile(TAOS* taos, FILE* fp, char* fcharset,
static void* taosDumpInWorkThreadFp(void *arg) static void* taosDumpInWorkThreadFp(void *arg)
{ {
SThreadParaObj *pThread = (SThreadParaObj*)arg; SThreadParaObj *pThread = (SThreadParaObj*)arg;
setThreadName("dumpInWorkThrd");
for (int32_t f = 0; f < g_tsSqlFileNum; ++f) { for (int32_t f = 0; f < g_tsSqlFileNum; ++f) {
if (f % pThread->totalThreads == pThread->threadIndex) { if (f % pThread->totalThreads == pThread->threadIndex) {
char *SQLFileName = g_tsDumpInSqlFiles[f]; char *SQLFileName = g_tsDumpInSqlFiles[f];
......
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
INCLUDE_DIRECTORIES(inc)
IF (TD_LINUX)
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(taospack ${SRC})
TARGET_LINK_LIBRARIES(taospack os tutil tsdb ${VAR_TSZ})
ELSEIF (TD_WINDOWS)
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(taospack ${SRC})
TARGET_LINK_LIBRARIES(taospack)
ELSEIF (TD_DARWIN)
# MAC
AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(taospack ${SRC})
TARGET_LINK_LIBRARIES(taospack os tutil tsdb)
ENDIF ()
\ No newline at end of file
此差异已折叠。
...@@ -1113,6 +1113,7 @@ static void *sdbWorkerFp(void *pWorker) { ...@@ -1113,6 +1113,7 @@ static void *sdbWorkerFp(void *pWorker) {
void * unUsed; void * unUsed;
taosBlockSIGPIPE(); taosBlockSIGPIPE();
setThreadName("sdbWorker");
while (1) { while (1) {
int32_t numOfMsgs = taosReadAllQitemsFromQset(tsSdbWQset, tsSdbWQall, &unUsed); int32_t numOfMsgs = taosReadAllQitemsFromQset(tsSdbWQset, tsSdbWQall, &unUsed);
......
...@@ -210,6 +210,25 @@ extern "C" { ...@@ -210,6 +210,25 @@ extern "C" {
#define PRIzu "zu" #define PRIzu "zu"
#endif #endif
#if defined(_TD_LINUX_64) || defined(_TD_LINUX_32) || defined(_TD_MIPS_64) || defined(_TD_ARM_32) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64)
#if defined(_TD_DARWIN_64)
// MacOS
#if !defined(_GNU_SOURCE)
#define setThreadName(name) do { pthread_setname_np((name)); } while (0)
#else
// pthread_setname_np not defined
#define setThreadName(name)
#endif
#else
// Linux, length of name must <= 16 (the last '\0' included)
#define setThreadName(name) do { prctl(PR_SET_NAME, (name)); } while (0)
#endif
#else
// Windows
#define setThreadName(name)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -85,6 +85,7 @@ extern "C" { ...@@ -85,6 +85,7 @@ extern "C" {
#include <sys/eventfd.h> #include <sys/eventfd.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/sendfile.h> #include <sys/sendfile.h>
#include <sys/prctl.h>
#if !(defined(_ALPINE)) #if !(defined(_ALPINE))
#include <error.h> #include <error.h>
......
...@@ -41,6 +41,8 @@ static semaphore_t sem_exit; ...@@ -41,6 +41,8 @@ static semaphore_t sem_exit;
static void* sem_thread_routine(void *arg) { static void* sem_thread_routine(void *arg) {
(void)arg; (void)arg;
setThreadName("sem_thrd");
sem_port = mach_task_self(); sem_port = mach_task_self();
kern_return_t ret = semaphore_create(sem_port, &sem_exit, SYNC_POLICY_FIFO, 0); kern_return_t ret = semaphore_create(sem_port, &sem_exit, SYNC_POLICY_FIFO, 0);
if (ret != KERN_SUCCESS) { if (ret != KERN_SUCCESS) {
......
...@@ -32,6 +32,7 @@ static volatile int timer_stop = 0; ...@@ -32,6 +32,7 @@ static volatile int timer_stop = 0;
static void* timer_routine(void *arg) { static void* timer_routine(void *arg) {
(void)arg; (void)arg;
setThreadName("timer");
int r = 0; int r = 0;
struct timespec to = {0}; struct timespec to = {0};
......
...@@ -38,6 +38,8 @@ static void *taosProcessAlarmSignal(void *tharg) { ...@@ -38,6 +38,8 @@ static void *taosProcessAlarmSignal(void *tharg) {
struct sigevent sevent = {{0}}; struct sigevent sevent = {{0}};
setThreadName("alarmSignal");
#ifdef _ALPINE #ifdef _ALPINE
sevent.sigev_notify = SIGEV_THREAD; sevent.sigev_notify = SIGEV_THREAD;
sevent.sigev_value.sival_int = syscall(__NR_gettid); sevent.sigev_value.sival_int = syscall(__NR_gettid);
......
...@@ -100,6 +100,7 @@ typedef enum HTTP_PARSER_STATE { ...@@ -100,6 +100,7 @@ typedef enum HTTP_PARSER_STATE {
HTTP_PARSER_CHUNK, HTTP_PARSER_CHUNK,
HTTP_PARSER_END, HTTP_PARSER_END,
HTTP_PARSER_ERROR, HTTP_PARSER_ERROR,
HTTP_PARSER_OPTIONAL_SP
} HTTP_PARSER_STATE; } HTTP_PARSER_STATE;
typedef enum HTTP_AUTH_TYPE { typedef enum HTTP_AUTH_TYPE {
......
...@@ -744,6 +744,15 @@ static int32_t httpParserOnSp(HttpParser *parser, HTTP_PARSER_STATE state, const ...@@ -744,6 +744,15 @@ static int32_t httpParserOnSp(HttpParser *parser, HTTP_PARSER_STATE state, const
return ok; return ok;
} }
static int32_t httpParserOnOptionalSp(HttpParser *parser, HTTP_PARSER_STATE state, const char c, int32_t *again) {
int32_t ok = 0;
if (c != ' ') {
*again = 1;
httpPopStack(parser);
}
return ok;
}
static int32_t httpParserOnStatusCode(HttpParser *parser, HTTP_PARSER_STATE state, const char c, int32_t *again) { static int32_t httpParserOnStatusCode(HttpParser *parser, HTTP_PARSER_STATE state, const char c, int32_t *again) {
HttpContext *pContext = parser->pContext; HttpContext *pContext = parser->pContext;
int32_t ok = 0; int32_t ok = 0;
...@@ -867,7 +876,7 @@ static int32_t httpParserOnHeader(HttpParser *parser, HTTP_PARSER_STATE state, c ...@@ -867,7 +876,7 @@ static int32_t httpParserOnHeader(HttpParser *parser, HTTP_PARSER_STATE state, c
} }
httpPushStack(parser, HTTP_PARSER_CRLF); httpPushStack(parser, HTTP_PARSER_CRLF);
httpPushStack(parser, HTTP_PARSER_HEADER_VAL); httpPushStack(parser, HTTP_PARSER_HEADER_VAL);
httpPushStack(parser, HTTP_PARSER_SP); httpPushStack(parser, HTTP_PARSER_OPTIONAL_SP);
httpPushStack(parser, HTTP_PARSER_HEADER_KEY); httpPushStack(parser, HTTP_PARSER_HEADER_KEY);
break; break;
} }
...@@ -1061,6 +1070,10 @@ static int32_t httpParseChar(HttpParser *parser, const char c, int32_t *again) { ...@@ -1061,6 +1070,10 @@ static int32_t httpParseChar(HttpParser *parser, const char c, int32_t *again) {
ok = httpParserOnSp(parser, state, c, again); ok = httpParserOnSp(parser, state, c, again);
break; break;
} }
if (state == HTTP_PARSER_OPTIONAL_SP) {
ok = httpParserOnOptionalSp(parser, state, c, again);
break;
}
if (state == HTTP_PARSER_STATUS_CODE) { if (state == HTTP_PARSER_STATUS_CODE) {
ok = httpParserOnStatusCode(parser, state, c, again); ok = httpParserOnStatusCode(parser, state, c, again);
break; break;
......
...@@ -70,6 +70,8 @@ static void *httpProcessResultQueue(void *param) { ...@@ -70,6 +70,8 @@ static void *httpProcessResultQueue(void *param) {
int32_t type; int32_t type;
void * unUsed; void * unUsed;
setThreadName("httpResultQ");
while (1) { while (1) {
if (taosReadQitemFromQset(tsHttpQset, &type, (void **)&pMsg, &unUsed) == 0) { if (taosReadQitemFromQset(tsHttpQset, &type, (void **)&pMsg, &unUsed) == 0) {
httpDebug("qset:%p, http queue got no message from qset, exiting", tsHttpQset); httpDebug("qset:%p, http queue got no message from qset, exiting", tsHttpQset);
......
...@@ -117,6 +117,7 @@ static void httpProcessHttpData(void *param) { ...@@ -117,6 +117,7 @@ static void httpProcessHttpData(void *param) {
int32_t fdNum; int32_t fdNum;
taosSetMaskSIGPIPE(); taosSetMaskSIGPIPE();
setThreadName("httpData");
while (1) { while (1) {
struct epoll_event events[HTTP_MAX_EVENTS]; struct epoll_event events[HTTP_MAX_EVENTS];
...@@ -208,6 +209,7 @@ static void *httpAcceptHttpConnection(void *arg) { ...@@ -208,6 +209,7 @@ static void *httpAcceptHttpConnection(void *arg) {
int32_t totalFds = 0; int32_t totalFds = 0;
taosSetMaskSIGPIPE(); taosSetMaskSIGPIPE();
setThreadName("httpAcceptConn");
pServer->fd = taosOpenTcpServerSocket(pServer->serverIp, pServer->serverPort); pServer->fd = taosOpenTcpServerSocket(pServer->serverIp, pServer->serverPort);
......
...@@ -114,6 +114,7 @@ int32_t monStartSystem() { ...@@ -114,6 +114,7 @@ int32_t monStartSystem() {
static void *monThreadFunc(void *param) { static void *monThreadFunc(void *param) {
monDebug("starting to initialize monitor module ..."); monDebug("starting to initialize monitor module ...");
setThreadName("monThrd");
while (1) { while (1) {
static int32_t accessTimes = 0; static int32_t accessTimes = 0;
......
...@@ -100,6 +100,8 @@ void mqttPublishCallback(void** unused, struct mqtt_response_publish* published) ...@@ -100,6 +100,8 @@ void mqttPublishCallback(void** unused, struct mqtt_response_publish* published)
} }
void* mqttClientRefresher(void* client) { void* mqttClientRefresher(void* client) {
setThreadName("mqttCliRefresh");
while (tsMqttIsRuning) { while (tsMqttIsRuning) {
mqtt_sync((struct mqtt_client*)client); mqtt_sync((struct mqtt_client*)client);
taosMsleep(100); taosMsleep(100);
...@@ -141,4 +143,4 @@ void mqttReconnectClient(struct mqtt_client* client, void** unused) { ...@@ -141,4 +143,4 @@ void mqttReconnectClient(struct mqtt_client* client, void** unused) {
mqtt_reinit(client, sockfd, tsMqttStatus.sendbuf, tsMqttStatus.sendbufsz, tsMqttStatus.recvbuf, tsMqttStatus.recvbufsz); mqtt_reinit(client, sockfd, tsMqttStatus.sendbuf, tsMqttStatus.sendbufsz, tsMqttStatus.recvbuf, tsMqttStatus.recvbufsz);
mqtt_connect(client, tsMqttClientId, NULL, NULL, 0, tsMqttUser, tsMqttPass, MQTT_CONNECT_CLEAN_SESSION, 400); mqtt_connect(client, tsMqttClientId, NULL, NULL, 0, tsMqttUser, tsMqttPass, MQTT_CONNECT_CLEAN_SESSION, 400);
mqtt_subscribe(client, tsMqttTopic, 0); mqtt_subscribe(client, tsMqttTopic, 0);
} }
\ No newline at end of file
...@@ -242,6 +242,7 @@ static void *taosAcceptTcpConnection(void *arg) { ...@@ -242,6 +242,7 @@ static void *taosAcceptTcpConnection(void *arg) {
pServerObj = (SServerObj *)arg; pServerObj = (SServerObj *)arg;
tDebug("%s TCP server is ready, ip:0x%x:%hu", pServerObj->label, pServerObj->ip, pServerObj->port); tDebug("%s TCP server is ready, ip:0x%x:%hu", pServerObj->label, pServerObj->ip, pServerObj->port);
setThreadName("acceptTcpConn");
while (1) { while (1) {
socklen_t addrlen = sizeof(caddr); socklen_t addrlen = sizeof(caddr);
...@@ -528,6 +529,11 @@ static void *taosProcessTcpData(void *param) { ...@@ -528,6 +529,11 @@ static void *taosProcessTcpData(void *param) {
SFdObj *pFdObj; SFdObj *pFdObj;
struct epoll_event events[maxEvents]; struct epoll_event events[maxEvents];
SRecvInfo recvInfo; SRecvInfo recvInfo;
char name[16];
memset(name, 0, sizeof(name));
snprintf(name, 16, "%s-tcpData", pThreadObj->label);
setThreadName(name);
while (1) { while (1) {
int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, TAOS_EPOLL_WAIT_TIME); int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, TAOS_EPOLL_WAIT_TIME);
......
...@@ -195,6 +195,8 @@ static void *taosRecvUdpData(void *param) { ...@@ -195,6 +195,8 @@ static void *taosRecvUdpData(void *param) {
tDebug("%s UDP thread is created, index:%d", pConn->label, pConn->index); tDebug("%s UDP thread is created, index:%d", pConn->label, pConn->index);
char *msg = pConn->buffer; char *msg = pConn->buffer;
setThreadName("recvUdpData");
while (1) { while (1) {
dataLen = recvfrom(pConn->fd, pConn->buffer, RPC_MAX_UDP_SIZE, 0, (struct sockaddr *)&sourceAdd, &addLen); dataLen = recvfrom(pConn->fd, pConn->buffer, RPC_MAX_UDP_SIZE, 0, (struct sockaddr *)&sourceAdd, &addLen);
if (dataLen <= 0) { if (dataLen <= 0) {
......
...@@ -47,6 +47,8 @@ static int tcount = 0; ...@@ -47,6 +47,8 @@ static int tcount = 0;
static void *sendRequest(void *param) { static void *sendRequest(void *param) {
SInfo *pInfo = (SInfo *)param; SInfo *pInfo = (SInfo *)param;
SRpcMsg rpcMsg = {0}; SRpcMsg rpcMsg = {0};
setThreadName("sendCliReq");
tDebug("thread:%d, start to send request", pInfo->index); tDebug("thread:%d, start to send request", pInfo->index);
......
...@@ -39,8 +39,10 @@ static int terror = 0; ...@@ -39,8 +39,10 @@ static int terror = 0;
static void *sendRequest(void *param) { static void *sendRequest(void *param) {
SInfo *pInfo = (SInfo *)param; SInfo *pInfo = (SInfo *)param;
SRpcMsg rpcMsg, rspMsg; SRpcMsg rpcMsg, rspMsg;
setThreadName("sendSrvReq");
tDebug("thread:%d, start to send request", pInfo->index); tDebug("thread:%d, start to send request", pInfo->index);
while ( pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) { while ( pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) {
......
...@@ -263,6 +263,7 @@ static int32_t syncRestoreDataStepByStep(SSyncPeer *pPeer) { ...@@ -263,6 +263,7 @@ static int32_t syncRestoreDataStepByStep(SSyncPeer *pPeer) {
} }
void *syncRestoreData(void *param) { void *syncRestoreData(void *param) {
setThreadName("syncRestoreData");
int64_t rid = (int64_t)param; int64_t rid = (int64_t)param;
SSyncPeer *pPeer = syncAcquirePeer(rid); SSyncPeer *pPeer = syncAcquirePeer(rid);
if (pPeer == NULL) { if (pPeer == NULL) {
......
...@@ -415,6 +415,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) { ...@@ -415,6 +415,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) {
} }
void *syncRetrieveData(void *param) { void *syncRetrieveData(void *param) {
setThreadName("syncRetrievData");
int64_t rid = (int64_t)param; int64_t rid = (int64_t)param;
SSyncPeer *pPeer = syncAcquirePeer(rid); SSyncPeer *pPeer = syncAcquirePeer(rid);
if (pPeer == NULL) { if (pPeer == NULL) {
......
...@@ -195,6 +195,8 @@ static void *syncProcessTcpData(void *param) { ...@@ -195,6 +195,8 @@ static void *syncProcessTcpData(void *param) {
SConnObj * pConn = NULL; SConnObj * pConn = NULL;
struct epoll_event events[maxEvents]; struct epoll_event events[maxEvents];
setThreadName("syncTcpData");
void *buffer = malloc(pInfo->bufferSize); void *buffer = malloc(pInfo->bufferSize);
taosBlockSIGPIPE(); taosBlockSIGPIPE();
...@@ -257,6 +259,7 @@ static void *syncAcceptPeerTcpConnection(void *argv) { ...@@ -257,6 +259,7 @@ static void *syncAcceptPeerTcpConnection(void *argv) {
SPoolInfo *pInfo = &pPool->info; SPoolInfo *pInfo = &pPool->info;
taosBlockSIGPIPE(); taosBlockSIGPIPE();
setThreadName("acceptTcpConn");
while (1) { while (1) {
struct sockaddr_in clientAddr; struct sockaddr_in clientAddr;
......
...@@ -48,6 +48,8 @@ void *sendRequest(void *param) { ...@@ -48,6 +48,8 @@ void *sendRequest(void *param) {
SInfo * pInfo = (SInfo *)param; SInfo * pInfo = (SInfo *)param;
SRpcMsg rpcMsg = {0}; SRpcMsg rpcMsg = {0};
setThreadName("sendCliReq");
uDebug("thread:%d, start to send request", pInfo->index); uDebug("thread:%d, start to send request", pInfo->index);
while (pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) { while (pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) {
......
...@@ -178,6 +178,8 @@ void *processWriteQueue(void *param) { ...@@ -178,6 +178,8 @@ void *processWriteQueue(void *param) {
int type; int type;
void *item; void *item;
setThreadName("writeQ");
while (1) { while (1) {
int ret = taosReadQitem(qhandle, &type, &item); int ret = taosReadQitem(qhandle, &type, &item);
if (ret <= 0) { if (ret <= 0) {
......
...@@ -158,6 +158,8 @@ static void *tsdbLoopCommit(void *arg) { ...@@ -158,6 +158,8 @@ static void *tsdbLoopCommit(void *arg) {
STsdbRepo * pRepo = NULL; STsdbRepo * pRepo = NULL;
TSDB_REQ_T req; TSDB_REQ_T req;
setThreadName("tsdbCommit");
while (true) { while (true) {
pthread_mutex_lock(&(pQueue->lock)); pthread_mutex_lock(&(pQueue->lock));
...@@ -208,4 +210,4 @@ void tsdbDecCommitRef(int vgId) { ...@@ -208,4 +210,4 @@ void tsdbDecCommitRef(int vgId) {
int refCount = atomic_sub_fetch_32(&tsCommitQueue.refCount, 1); int refCount = atomic_sub_fetch_32(&tsCommitQueue.refCount, 1);
pthread_cond_broadcast(&(tsCommitQueue.queueNotEmpty)); pthread_cond_broadcast(&(tsCommitQueue.queueNotEmpty));
tsdbDebug("vgId:%d, dec commit queue ref to %d", vgId, refCount); tsdbDebug("vgId:%d, dec commit queue ref to %d", vgId, refCount);
} }
\ No newline at end of file
...@@ -787,7 +787,7 @@ static char *getTagIndexKey(const void *pData) { ...@@ -787,7 +787,7 @@ static char *getTagIndexKey(const void *pData) {
void * res = tdGetKVRowValOfCol(pTable->tagVal, pCol->colId); void * res = tdGetKVRowValOfCol(pTable->tagVal, pCol->colId);
if (res == NULL) { if (res == NULL) {
// treat the column as NULL if we cannot find it // treat the column as NULL if we cannot find it
res = getNullValue(pCol->type); res = (char*)getNullValue(pCol->type);
} }
return res; return res;
} }
......
...@@ -3085,7 +3085,7 @@ int32_t checkForCachedLastRow(STsdbQueryHandle* pQueryHandle, STableGroupInfo *g ...@@ -3085,7 +3085,7 @@ int32_t checkForCachedLastRow(STsdbQueryHandle* pQueryHandle, STableGroupInfo *g
} }
// update the tsdb query time range // update the tsdb query time range
if (pQueryHandle->cachelastrow) { if (pQueryHandle->cachelastrow != TSDB_CACHED_TYPE_NONE) {
pQueryHandle->window = TSWINDOW_INITIALIZER; pQueryHandle->window = TSWINDOW_INITIALIZER;
pQueryHandle->checkFiles = false; pQueryHandle->checkFiles = false;
pQueryHandle->activeIndex = -1; // start from -1 pQueryHandle->activeIndex = -1; // start from -1
...@@ -3117,6 +3117,7 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { ...@@ -3117,6 +3117,7 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) {
STimeWindow window = {INT64_MAX, INT64_MIN}; STimeWindow window = {INT64_MAX, INT64_MIN};
int32_t totalNumOfTable = 0; int32_t totalNumOfTable = 0;
SArray* emptyGroup = taosArrayInit(16, sizeof(int32_t));
// NOTE: starts from the buffer in case of descending timestamp order check data blocks // NOTE: starts from the buffer in case of descending timestamp order check data blocks
size_t numOfGroups = taosArrayGetSize(groupList->pGroupList); size_t numOfGroups = taosArrayGetSize(groupList->pGroupList);
...@@ -3159,27 +3160,30 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { ...@@ -3159,27 +3160,30 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) {
} }
} }
taosArrayClear(pGroup);
// more than one table in each group, only one table left for each group // more than one table in each group, only one table left for each group
if (keyInfo.pTable != NULL) { if (keyInfo.pTable != NULL) {
totalNumOfTable++; totalNumOfTable++;
taosArrayPush(pGroup, &keyInfo); if (taosArrayGetSize(pGroup) == 1) {
} else { // do nothing
} else {
taosArrayClear(pGroup);
taosArrayPush(pGroup, &keyInfo);
}
} else { // mark all the empty groups, and remove it later
taosArrayDestroy(pGroup); taosArrayDestroy(pGroup);
taosArrayPush(emptyGroup, &j);
taosArrayRemove(groupList->pGroupList, j);
numOfGroups -= 1;
j -= 1;
} }
} }
// window does not being updated, so set the original // window does not being updated, so set the original
if (window.skey == INT64_MAX && window.ekey == INT64_MIN) { if (window.skey == INT64_MAX && window.ekey == INT64_MIN) {
window = TSWINDOW_INITIALIZER; window = TSWINDOW_INITIALIZER;
assert(totalNumOfTable == 0 && taosArrayGetSize(groupList->pGroupList) == 0); assert(totalNumOfTable == 0 && taosArrayGetSize(groupList->pGroupList) == numOfGroups);
} }
taosArrayRemoveBatch(groupList->pGroupList, TARRAY_GET_START(emptyGroup), (int32_t) taosArrayGetSize(emptyGroup));
taosArrayDestroy(emptyGroup);
groupList->numOfTables = totalNumOfTable; groupList->numOfTables = totalNumOfTable;
return window; return window;
} }
......
...@@ -4,13 +4,18 @@ PROJECT(TDengine) ...@@ -4,13 +4,18 @@ PROJECT(TDengine)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sync/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sync/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/rmonotonic/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/rmonotonic/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/TSZ/sz/include)
AUX_SOURCE_DIRECTORY(src SRC) AUX_SOURCE_DIRECTORY(src SRC)
ADD_LIBRARY(tutil ${SRC}) ADD_LIBRARY(tutil ${SRC})
TARGET_LINK_LIBRARIES(tutil pthread os lz4 z rmonotonic)
TARGET_LINK_LIBRARIES(tutil pthread os lz4 z rmonotonic ${VAR_TSZ} )
IF (TD_LINUX) IF (TD_LINUX)
TARGET_LINK_LIBRARIES(tutil m rt) TARGET_LINK_LIBRARIES(tutil m rt)
# ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tests)
FIND_PATH(ICONV_INCLUDE_EXIST iconv.h /usr/include/ /usr/local/include/) FIND_PATH(ICONV_INCLUDE_EXIST iconv.h /usr/include/ /usr/local/include/)
IF (ICONV_INCLUDE_EXIST) IF (ICONV_INCLUDE_EXIST)
...@@ -36,4 +41,4 @@ ENDIF() ...@@ -36,4 +41,4 @@ ENDIF()
IF (TD_STORAGE) IF (TD_STORAGE)
TARGET_LINK_LIBRARIES(tutil storage) TARGET_LINK_LIBRARIES(tutil storage)
ENDIF () ENDIF ()
\ No newline at end of file
...@@ -52,6 +52,22 @@ void* taosArrayInit(size_t size, size_t elemSize); ...@@ -52,6 +52,22 @@ void* taosArrayInit(size_t size, size_t elemSize);
*/ */
void *taosArrayAddBatch(SArray *pArray, const void *pData, int nEles); void *taosArrayAddBatch(SArray *pArray, const void *pData, int nEles);
/**
*
* @param pArray
* @param pData position array list
* @param numOfElems the number of removed position
*/
void taosArrayRemoveBatch(SArray *pArray, const int32_t* pData, int32_t numOfElems);
/**
*
* @param pArray
* @param comparFn
* @param fp
*/
void taosArrayRemoveDuplicate(SArray *pArray, __compar_fn_t comparFn, void (*fp)(void*));
/** /**
* add all element from the source array list into the destination * add all element from the source array list into the destination
* @param pArray * @param pArray
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册