Merge branch 'develop' into hotfix/TD-919
This commit is contained in:
commit
9ad7844da9
Binary file not shown.
|
@ -28,10 +28,10 @@ extern int32_t tscEmbedded;
|
||||||
#define tscFatal(...) { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
#define tscFatal(...) { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
||||||
#define tscError(...) { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
#define tscError(...) { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
||||||
#define tscWarn(...) { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
#define tscWarn(...) { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
||||||
#define tscInfo(...) { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC INFO ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
#define tscInfo(...) { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }}
|
||||||
#define tscDebug(...) { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC DEBUG ", cDebugFlag, __VA_ARGS__); }}
|
#define tscDebug(...) { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }}
|
||||||
#define tscTrace(...) { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC TRACE ", cDebugFlag, __VA_ARGS__); }}
|
#define tscTrace(...) { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }}
|
||||||
#define tscDebugL(...){ if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC DEBUG ", cDebugFlag, __VA_ARGS__); }}
|
#define tscDebugL(...){ if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", cDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
#define jniFatal(...) { if (jniDebugFlag & DEBUG_FATAL) { taosPrintLog("JNI FATAL ", tscEmbedded ? 255 : jniDebugFlag, __VA_ARGS__); }}
|
#define jniFatal(...) { if (jniDebugFlag & DEBUG_FATAL) { taosPrintLog("JNI FATAL ", tscEmbedded ? 255 : jniDebugFlag, __VA_ARGS__); }}
|
||||||
#define jniError(...) { if (jniDebugFlag & DEBUG_ERROR) { taosPrintLog("JNI ERROR ", tscEmbedded ? 255 : jniDebugFlag, __VA_ARGS__); }}
|
#define jniError(...) { if (jniDebugFlag & DEBUG_ERROR) { taosPrintLog("JNI ERROR ", tscEmbedded ? 255 : jniDebugFlag, __VA_ARGS__); }}
|
||||||
#define jniWarn(...) { if (jniDebugFlag & DEBUG_WARN) { taosPrintLog("JNI WARN ", tscEmbedded ? 255 : jniDebugFlag, __VA_ARGS__); }}
|
#define jniWarn(...) { if (jniDebugFlag & DEBUG_WARN) { taosPrintLog("JNI WARN ", tscEmbedded ? 255 : jniDebugFlag, __VA_ARGS__); }}
|
||||||
#define jniInfo(...) { if (jniDebugFlag & DEBUG_INFO) { taosPrintLog("JNI INFO ", tscEmbedded ? 255 : jniDebugFlag, __VA_ARGS__); }}
|
#define jniInfo(...) { if (jniDebugFlag & DEBUG_INFO) { taosPrintLog("JNI ", tscEmbedded ? 255 : jniDebugFlag, __VA_ARGS__); }}
|
||||||
#define jniDebug(...) { if (jniDebugFlag & DEBUG_DEBUG) { taosPrintLog("JNI DEBUG ", jniDebugFlag, __VA_ARGS__); }}
|
#define jniDebug(...) { if (jniDebugFlag & DEBUG_DEBUG) { taosPrintLog("JNI ", jniDebugFlag, __VA_ARGS__); }}
|
||||||
#define jniTrace(...) { if (jniDebugFlag & DEBUG_TRACE) { taosPrintLog("JNI TRACE ", jniDebugFlag, __VA_ARGS__); }}
|
#define jniTrace(...) { if (jniDebugFlag & DEBUG_TRACE) { taosPrintLog("JNI ", jniDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
int __init = 0;
|
int __init = 0;
|
||||||
|
|
||||||
|
|
|
@ -478,6 +478,8 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
tscDebug("%p redo parse sql string to build submit block", pSql);
|
tscDebug("%p redo parse sql string to build submit block", pSql);
|
||||||
|
|
||||||
pCmd->parseFinished = false;
|
pCmd->parseFinished = false;
|
||||||
|
tscResetSqlCmdObj(pCmd);
|
||||||
|
|
||||||
code = tsParseSql(pSql, true);
|
code = tsParseSql(pSql, true);
|
||||||
|
|
||||||
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||||
|
@ -492,7 +494,23 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
*/
|
*/
|
||||||
pSql->fp = pSql->fetchFp; // restore the fp
|
pSql->fp = pSql->fetchFp; // restore the fp
|
||||||
tscHandleInsertRetry(pSql);
|
tscHandleInsertRetry(pSql);
|
||||||
} else {// in case of other query type, continue
|
} else if (pCmd->command == TSDB_SQL_SELECT) { // in case of other query type, continue
|
||||||
|
tscDebug("%p redo parse sql string and proceed", pSql);
|
||||||
|
//tscDebug("before %p fp:%p, fetchFp:%p", pSql, pSql->fp, pSql->fetchFp);
|
||||||
|
pCmd->parseFinished = false;
|
||||||
|
tscResetSqlCmdObj(pCmd);
|
||||||
|
|
||||||
|
//tscDebug("after %p fp:%p, fetchFp:%p", pSql, pSql->fp, pSql->fetchFp);
|
||||||
|
code = tsParseSql(pSql, true);
|
||||||
|
|
||||||
|
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
|
||||||
|
return;
|
||||||
|
} else if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
|
tscProcessSql(pSql);
|
||||||
|
} else { // in all other cases, simple retry
|
||||||
tscProcessSql(pSql);
|
tscProcessSql(pSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4962,6 +4962,7 @@ static void setCreateDBOption(SCMCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
||||||
pMsg->commitTime = htonl(pCreateDb->commitTime);
|
pMsg->commitTime = htonl(pCreateDb->commitTime);
|
||||||
pMsg->minRowsPerFileBlock = htonl(pCreateDb->minRowsPerBlock);
|
pMsg->minRowsPerFileBlock = htonl(pCreateDb->minRowsPerBlock);
|
||||||
pMsg->maxRowsPerFileBlock = htonl(pCreateDb->maxRowsPerBlock);
|
pMsg->maxRowsPerFileBlock = htonl(pCreateDb->maxRowsPerBlock);
|
||||||
|
pMsg->fsyncPeriod = htonl(pCreateDb->fsyncPeriod);
|
||||||
pMsg->compression = pCreateDb->compressionLevel;
|
pMsg->compression = pCreateDb->compressionLevel;
|
||||||
pMsg->walLevel = (char)pCreateDb->walLevel;
|
pMsg->walLevel = (char)pCreateDb->walLevel;
|
||||||
pMsg->replications = pCreateDb->replica;
|
pMsg->replications = pCreateDb->replica;
|
||||||
|
@ -5529,6 +5530,13 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate) {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val = htonl(pCreate->fsyncPeriod);
|
||||||
|
if (val != -1 && (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option fsyncPeriod: %d valid range: [%d, %d]", val,
|
||||||
|
TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD);
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
||||||
|
}
|
||||||
|
|
||||||
if (pCreate->compression != -1 &&
|
if (pCreate->compression != -1 &&
|
||||||
(pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) {
|
(pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) {
|
||||||
snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression,
|
snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression,
|
||||||
|
|
|
@ -246,21 +246,31 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
|
||||||
rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
} else {
|
} else {
|
||||||
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
if (rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID ||
|
// if (rpcMsg->code != TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||||
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
// if (pCmd->command == TSDB_SQL_CONNECT) {
|
||||||
if (pCmd->command == TSDB_SQL_CONNECT) {
|
// rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
// rpcFreeCont(rpcMsg->pCont);
|
||||||
rpcFreeCont(rpcMsg->pCont);
|
// return;
|
||||||
return;
|
// }
|
||||||
} else if (pCmd->command == TSDB_SQL_HB) {
|
|
||||||
rpcMsg->code = TSDB_CODE_RPC_NOT_READY;
|
|
||||||
rpcFreeCont(rpcMsg->pCont);
|
|
||||||
return;
|
|
||||||
} else if (pCmd->command == TSDB_SQL_META) {
|
|
||||||
// get table meta query will not retry, do nothing
|
|
||||||
} else {
|
|
||||||
tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry);
|
|
||||||
|
|
||||||
|
// if (pCmd->command == TSDB_SQL_HB) {
|
||||||
|
// rpcMsg->code = TSDB_CODE_RPC_NOT_READY;
|
||||||
|
// rpcFreeCont(rpcMsg->pCont);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (pCmd->command == TSDB_SQL_META || pCmd->command == TSDB_SQL_DESCRIBE_TABLE ||
|
||||||
|
// pCmd->command == TSDB_SQL_STABLEVGROUP || pCmd->command == TSDB_SQL_SHOW ||
|
||||||
|
// pCmd->command == TSDB_SQL_RETRIEVE) {
|
||||||
|
// // get table meta/vgroup query will not retry, do nothing
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
if ((pCmd->command == TSDB_SQL_SELECT || pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_INSERT ||
|
||||||
|
pCmd->command == TSDB_SQL_UPDATE_TAGS_VAL) &&
|
||||||
|
(rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID ||
|
||||||
|
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE)) {
|
||||||
|
tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry);
|
||||||
// set the flag to denote that sql string needs to be re-parsed and build submit block with table schema
|
// set the flag to denote that sql string needs to be re-parsed and build submit block with table schema
|
||||||
if (rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
if (rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE) {
|
||||||
pSql->cmd.submitSchema = 1;
|
pSql->cmd.submitSchema = 1;
|
||||||
|
@ -281,7 +291,6 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pRes->rspLen = 0;
|
pRes->rspLen = 0;
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,19 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
TAOS *taos_connect_c(const char *ip, uint8_t ipLen, const char *user, uint8_t userLen,
|
||||||
|
const char *pass, uint8_t passLen, const char *db, uint8_t dbLen, uint16_t port) {
|
||||||
|
char ipBuf[TSDB_EP_LEN] = {0};
|
||||||
|
char userBuf[TSDB_USER_LEN] = {0};
|
||||||
|
char passBuf[TSDB_PASSWORD_LEN] = {0};
|
||||||
|
char dbBuf[TSDB_DB_NAME_LEN] = {0};
|
||||||
|
strncpy(ipBuf, ip, MIN(TSDB_EP_LEN - 1, ipLen));
|
||||||
|
strncpy(userBuf, user, MIN(TSDB_USER_LEN - 1, userLen));
|
||||||
|
strncpy(passBuf, pass, MIN(TSDB_PASSWORD_LEN - 1,passLen));
|
||||||
|
strncpy(dbBuf, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
|
||||||
|
return taos_connect(ipBuf, userBuf, passBuf, dbBuf, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
|
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
|
||||||
void *param, void **taos) {
|
void *param, void **taos) {
|
||||||
|
@ -249,7 +262,14 @@ TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) {
|
||||||
tsem_wait(&pSql->rspSem);
|
tsem_wait(&pSql->rspSem);
|
||||||
return pSql;
|
return pSql;
|
||||||
}
|
}
|
||||||
|
TAOS_RES* taos_query_c(TAOS *taos, const char *sqlstr, uint32_t sqlLen) {
|
||||||
|
char* buf = malloc(sqlLen + 1);
|
||||||
|
buf[sqlLen] = 0;
|
||||||
|
strncpy(buf, sqlstr, sqlLen);
|
||||||
|
TAOS_RES *res = taos_query(taos, buf);
|
||||||
|
free(buf);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
int taos_result_precision(TAOS_RES *res) {
|
int taos_result_precision(TAOS_RES *res) {
|
||||||
SSqlObj *pSql = (SSqlObj *)res;
|
SSqlObj *pSql = (SSqlObj *)res;
|
||||||
if (pSql == NULL || pSql->signature != pSql) return 0;
|
if (pSql == NULL || pSql->signature != pSql) return 0;
|
||||||
|
|
|
@ -80,6 +80,7 @@ extern int16_t tsCommitTime; // seconds
|
||||||
extern int32_t tsTimePrecision;
|
extern int32_t tsTimePrecision;
|
||||||
extern int16_t tsCompression;
|
extern int16_t tsCompression;
|
||||||
extern int16_t tsWAL;
|
extern int16_t tsWAL;
|
||||||
|
extern int32_t tsFsyncPeriod;
|
||||||
extern int32_t tsReplications;
|
extern int32_t tsReplications;
|
||||||
|
|
||||||
// balance
|
// balance
|
||||||
|
|
|
@ -28,12 +28,12 @@ extern int32_t tscEmbedded;
|
||||||
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL INFO ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||||
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL DEBUG ", uDebugFlag, __VA_ARGS__); }}
|
#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
|
||||||
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL TRACE ", uDebugFlag, __VA_ARGS__); }}
|
#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
|
#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
|
||||||
#define pPrint(...) { taosPrintLog("APP INFO ", 255, __VA_ARGS__); }
|
#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); }
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -384,11 +384,13 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdResetDataCols(SDataCols *pCols) {
|
void tdResetDataCols(SDataCols *pCols) {
|
||||||
|
if (pCols != NULL) {
|
||||||
pCols->numOfRows = 0;
|
pCols->numOfRows = 0;
|
||||||
for (int i = 0; i < pCols->maxCols; i++) {
|
for (int i = 0; i < pCols->maxCols; i++) {
|
||||||
dataColReset(pCols->cols + i);
|
dataColReset(pCols->cols + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols) {
|
void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols) {
|
||||||
ASSERT(dataColsKeyLast(pCols) < dataRowKey(row));
|
ASSERT(dataColsKeyLast(pCols) < dataRowKey(row));
|
||||||
|
|
|
@ -110,6 +110,7 @@ int16_t tsCommitTime = TSDB_DEFAULT_COMMIT_TIME; // seconds
|
||||||
int32_t tsTimePrecision = TSDB_DEFAULT_PRECISION;
|
int32_t tsTimePrecision = TSDB_DEFAULT_PRECISION;
|
||||||
int16_t tsCompression = TSDB_DEFAULT_COMP_LEVEL;
|
int16_t tsCompression = TSDB_DEFAULT_COMP_LEVEL;
|
||||||
int16_t tsWAL = TSDB_DEFAULT_WAL_LEVEL;
|
int16_t tsWAL = TSDB_DEFAULT_WAL_LEVEL;
|
||||||
|
int32_t tsFsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD;
|
||||||
int32_t tsReplications = TSDB_DEFAULT_DB_REPLICA_OPTION;
|
int32_t tsReplications = TSDB_DEFAULT_DB_REPLICA_OPTION;
|
||||||
int32_t tsMaxVgroupsPerDb = 0;
|
int32_t tsMaxVgroupsPerDb = 0;
|
||||||
int32_t tsMinTablePerVnode = 100;
|
int32_t tsMinTablePerVnode = 100;
|
||||||
|
@ -193,7 +194,7 @@ int32_t monitorDebugFlag = 131;
|
||||||
int32_t qDebugFlag = 131;
|
int32_t qDebugFlag = 131;
|
||||||
int32_t rpcDebugFlag = 131;
|
int32_t rpcDebugFlag = 131;
|
||||||
int32_t uDebugFlag = 131;
|
int32_t uDebugFlag = 131;
|
||||||
int32_t debugFlag = 131;
|
int32_t debugFlag = 0;
|
||||||
int32_t sDebugFlag = 135;
|
int32_t sDebugFlag = 135;
|
||||||
int32_t wDebugFlag = 135;
|
int32_t wDebugFlag = 135;
|
||||||
int32_t tsdbDebugFlag = 131;
|
int32_t tsdbDebugFlag = 131;
|
||||||
|
@ -201,7 +202,7 @@ int32_t tsdbDebugFlag = 131;
|
||||||
static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT;
|
static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT;
|
||||||
|
|
||||||
void taosSetAllDebugFlag() {
|
void taosSetAllDebugFlag() {
|
||||||
for (int32_t i = 0; i < tsGlobalConfigNum; ++i) {
|
if (debugFlag != 0) {
|
||||||
mDebugFlag = debugFlag;
|
mDebugFlag = debugFlag;
|
||||||
sdbDebugFlag = debugFlag;
|
sdbDebugFlag = debugFlag;
|
||||||
dDebugFlag = debugFlag;
|
dDebugFlag = debugFlag;
|
||||||
|
@ -218,9 +219,9 @@ void taosSetAllDebugFlag() {
|
||||||
wDebugFlag = debugFlag;
|
wDebugFlag = debugFlag;
|
||||||
tsdbDebugFlag = debugFlag;
|
tsdbDebugFlag = debugFlag;
|
||||||
qDebugFlag = debugFlag;
|
qDebugFlag = debugFlag;
|
||||||
}
|
|
||||||
uInfo("all debug flag are set to %d", debugFlag);
|
uInfo("all debug flag are set to %d", debugFlag);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool taosCfgDynamicOptions(char *msg) {
|
bool taosCfgDynamicOptions(char *msg) {
|
||||||
char *option, *value;
|
char *option, *value;
|
||||||
|
@ -715,6 +716,16 @@ static void doInitGlobalConfig() {
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
|
cfg.option = "fsync";
|
||||||
|
cfg.ptr = &tsFsyncPeriod;
|
||||||
|
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||||
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
||||||
|
cfg.minValue = TSDB_MIN_FSYNC_PERIOD;
|
||||||
|
cfg.maxValue = TSDB_MAX_FSYNC_PERIOD;
|
||||||
|
cfg.ptrLength = 0;
|
||||||
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
cfg.option = "replica";
|
cfg.option = "replica";
|
||||||
cfg.ptr = &tsReplications;
|
cfg.ptr = &tsReplications;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class BatchInsertTest extends BaseTest {
|
||||||
|
|
||||||
|
static Connection connection = null;
|
||||||
|
static Statement statement = null;
|
||||||
|
static String dbName = "test";
|
||||||
|
static String stbName = "meters";
|
||||||
|
static String host = "localhost";
|
||||||
|
static int numOfTables = 30;
|
||||||
|
final static int numOfRecordsPerTable = 1000;
|
||||||
|
static long ts = 1496732686000l;
|
||||||
|
final static String tablePrefix = "t";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void createDatabase() throws SQLException {
|
||||||
|
try {
|
||||||
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||||
|
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/" + "?user=root&password=taosdata"
|
||||||
|
, properties);
|
||||||
|
|
||||||
|
statement = connection.createStatement();
|
||||||
|
statement.executeUpdate("drop database if exists " + dbName);
|
||||||
|
statement.executeUpdate("create database if not exists " + dbName);
|
||||||
|
statement.executeUpdate("use " + dbName);
|
||||||
|
|
||||||
|
String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))";
|
||||||
|
statement.executeUpdate(createTableSql);
|
||||||
|
|
||||||
|
for(int i = 0; i < numOfTables; i++) {
|
||||||
|
String loc = i % 2 == 0 ? "beijing" : "shanghai";
|
||||||
|
String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')";
|
||||||
|
statement.executeUpdate(createSubTalbesSql);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBatchInsert() throws SQLException{
|
||||||
|
|
||||||
|
ExecutorService executorService = Executors.newFixedThreadPool(numOfTables);
|
||||||
|
|
||||||
|
for (int i = 0; i < numOfTables; i++) {
|
||||||
|
final int index = i;
|
||||||
|
executorService.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
Statement statement = connection.createStatement(); // get statement
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("INSERT INTO " + tablePrefix + index + " VALUES");
|
||||||
|
Random rand = new Random();
|
||||||
|
for (int j = 1; j <= numOfRecordsPerTable; j++) {
|
||||||
|
sb.append("(" + (ts + j) + ", ");
|
||||||
|
sb.append(rand.nextInt(100) + ", ");
|
||||||
|
sb.append(rand.nextInt(100) + ", ");
|
||||||
|
sb.append(rand.nextInt(100) + ")");
|
||||||
|
}
|
||||||
|
statement.addBatch(sb.toString());
|
||||||
|
statement.executeBatch();
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
System.out.println("Thread " + index + " takes " + (endTime - startTime) + " microseconds");
|
||||||
|
connection.commit();
|
||||||
|
statement.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
executorService.shutdown();
|
||||||
|
|
||||||
|
try {
|
||||||
|
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement statement = connection.createStatement();
|
||||||
|
ResultSet rs = statement.executeQuery("select * from meters");
|
||||||
|
int num = 0;
|
||||||
|
while (rs.next()) {
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
assertEquals(num, numOfTables * numOfRecordsPerTable);
|
||||||
|
rs.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void close() throws Exception {
|
||||||
|
statement.close();
|
||||||
|
connection.close();
|
||||||
|
Thread.sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -27,9 +27,9 @@ extern int32_t dDebugFlag;
|
||||||
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); }}
|
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); }}
|
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }}
|
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }}
|
||||||
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND INFO ", 255, __VA_ARGS__); }}
|
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", 255, __VA_ARGS__); }}
|
||||||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND DEBUG ", dDebugFlag, __VA_ARGS__); }}
|
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND TRACE ", dDebugFlag, __VA_ARGS__); }}
|
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ static void *dnodeProcessMgmtQueue(void *param);
|
||||||
static int32_t dnodeOpenVnodes();
|
static int32_t dnodeOpenVnodes();
|
||||||
static void dnodeCloseVnodes();
|
static void dnodeCloseVnodes();
|
||||||
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *pMsg);
|
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *pMsg);
|
||||||
|
static int32_t dnodeProcessAlterVnodeMsg(SRpcMsg *pMsg);
|
||||||
static int32_t dnodeProcessDropVnodeMsg(SRpcMsg *pMsg);
|
static int32_t dnodeProcessDropVnodeMsg(SRpcMsg *pMsg);
|
||||||
static int32_t dnodeProcessAlterStreamMsg(SRpcMsg *pMsg);
|
static int32_t dnodeProcessAlterStreamMsg(SRpcMsg *pMsg);
|
||||||
static int32_t dnodeProcessConfigDnodeMsg(SRpcMsg *pMsg);
|
static int32_t dnodeProcessConfigDnodeMsg(SRpcMsg *pMsg);
|
||||||
|
@ -79,6 +80,7 @@ static int32_t (*dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *pMsg);
|
||||||
|
|
||||||
int32_t dnodeInitMgmt() {
|
int32_t dnodeInitMgmt() {
|
||||||
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = dnodeProcessCreateVnodeMsg;
|
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = dnodeProcessCreateVnodeMsg;
|
||||||
|
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = dnodeProcessAlterVnodeMsg;
|
||||||
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = dnodeProcessDropVnodeMsg;
|
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = dnodeProcessDropVnodeMsg;
|
||||||
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = dnodeProcessAlterStreamMsg;
|
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = dnodeProcessAlterStreamMsg;
|
||||||
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE] = dnodeProcessConfigDnodeMsg;
|
dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE] = dnodeProcessConfigDnodeMsg;
|
||||||
|
@ -388,7 +390,7 @@ static void dnodeCloseVnodes() {
|
||||||
dInfo("total vnodes:%d are all closed", numOfVnodes);
|
dInfo("total vnodes:%d are all closed", numOfVnodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) {
|
static void* dnodeParseVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
SMDCreateVnodeMsg *pCreate = rpcMsg->pCont;
|
SMDCreateVnodeMsg *pCreate = rpcMsg->pCont;
|
||||||
pCreate->cfg.vgId = htonl(pCreate->cfg.vgId);
|
pCreate->cfg.vgId = htonl(pCreate->cfg.vgId);
|
||||||
pCreate->cfg.cfgVersion = htonl(pCreate->cfg.cfgVersion);
|
pCreate->cfg.cfgVersion = htonl(pCreate->cfg.cfgVersion);
|
||||||
|
@ -401,20 +403,42 @@ static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
pCreate->cfg.daysToKeep = htonl(pCreate->cfg.daysToKeep);
|
pCreate->cfg.daysToKeep = htonl(pCreate->cfg.daysToKeep);
|
||||||
pCreate->cfg.minRowsPerFileBlock = htonl(pCreate->cfg.minRowsPerFileBlock);
|
pCreate->cfg.minRowsPerFileBlock = htonl(pCreate->cfg.minRowsPerFileBlock);
|
||||||
pCreate->cfg.maxRowsPerFileBlock = htonl(pCreate->cfg.maxRowsPerFileBlock);
|
pCreate->cfg.maxRowsPerFileBlock = htonl(pCreate->cfg.maxRowsPerFileBlock);
|
||||||
|
pCreate->cfg.fsyncPeriod = htonl(pCreate->cfg.fsyncPeriod);
|
||||||
pCreate->cfg.commitTime = htonl(pCreate->cfg.commitTime);
|
pCreate->cfg.commitTime = htonl(pCreate->cfg.commitTime);
|
||||||
|
|
||||||
for (int32_t j = 0; j < pCreate->cfg.replications; ++j) {
|
for (int32_t j = 0; j < pCreate->cfg.replications; ++j) {
|
||||||
pCreate->nodes[j].nodeId = htonl(pCreate->nodes[j].nodeId);
|
pCreate->nodes[j].nodeId = htonl(pCreate->nodes[j].nodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pCreate;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
|
SMDCreateVnodeMsg *pCreate = dnodeParseVnodeMsg(rpcMsg);
|
||||||
|
|
||||||
void *pVnode = vnodeAcquireVnode(pCreate->cfg.vgId);
|
void *pVnode = vnodeAcquireVnode(pCreate->cfg.vgId);
|
||||||
if (pVnode != NULL) {
|
if (pVnode != NULL) {
|
||||||
dDebug("vgId:%d, already exist, processed as alter msg", pCreate->cfg.vgId);
|
dDebug("vgId:%d, already exist, return success", pCreate->cfg.vgId);
|
||||||
int32_t code = vnodeAlter(pVnode, pCreate);
|
vnodeRelease(pVnode);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
} else {
|
||||||
|
dDebug("vgId:%d, create vnode msg is received", pCreate->cfg.vgId);
|
||||||
|
return vnodeCreate(pCreate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dnodeProcessAlterVnodeMsg(SRpcMsg *rpcMsg) {
|
||||||
|
SMDAlterVnodeMsg *pAlter = dnodeParseVnodeMsg(rpcMsg);
|
||||||
|
|
||||||
|
void *pVnode = vnodeAcquireVnode(pAlter->cfg.vgId);
|
||||||
|
if (pVnode != NULL) {
|
||||||
|
dDebug("vgId:%d, alter vnode msg is received", pAlter->cfg.vgId);
|
||||||
|
int32_t code = vnodeAlter(pVnode, pAlter);
|
||||||
vnodeRelease(pVnode);
|
vnodeRelease(pVnode);
|
||||||
return code;
|
return code;
|
||||||
} else {
|
} else {
|
||||||
return vnodeCreate(pCreate);
|
dError("vgId:%d, vnode not exist, can't alter it", pAlter->cfg.vgId);
|
||||||
|
return TSDB_CODE_VND_INVALID_VGROUP_ID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ int32_t dnodeInitServer() {
|
||||||
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = dnodeDispatchToVnodeWriteQueue;
|
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = dnodeDispatchToVnodeWriteQueue;
|
||||||
|
|
||||||
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = dnodeDispatchToMgmtQueue;
|
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = dnodeDispatchToMgmtQueue;
|
||||||
|
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = dnodeDispatchToMgmtQueue;
|
||||||
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = dnodeDispatchToMgmtQueue;
|
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = dnodeDispatchToMgmtQueue;
|
||||||
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = dnodeDispatchToMgmtQueue;
|
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = dnodeDispatchToMgmtQueue;
|
||||||
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE] = dnodeDispatchToMgmtQueue;
|
dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE] = dnodeDispatchToMgmtQueue;
|
||||||
|
|
|
@ -135,7 +135,7 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
|
|
||||||
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
|
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
|
||||||
if (signum == SIGUSR1) {
|
if (signum == SIGUSR1) {
|
||||||
taosCfgDynamicOptions("debugFlag 151");
|
taosCfgDynamicOptions("debugFlag 143");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (signum == SIGUSR2) {
|
if (signum == SIGUSR2) {
|
||||||
|
|
|
@ -67,6 +67,8 @@ DLL_EXPORT void taos_init();
|
||||||
DLL_EXPORT void taos_cleanup();
|
DLL_EXPORT void taos_cleanup();
|
||||||
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_c(const char *ip, uint8_t ipLen, const char *user, uint8_t userLen,
|
||||||
|
const char *pass, uint8_t passLen, const char *db, uint8_t dbLen, uint16_t port);
|
||||||
DLL_EXPORT void taos_close(TAOS *taos);
|
DLL_EXPORT void taos_close(TAOS *taos);
|
||||||
|
|
||||||
typedef struct TAOS_BIND {
|
typedef struct TAOS_BIND {
|
||||||
|
@ -88,6 +90,7 @@ TAOS_RES * taos_stmt_use_result(TAOS_STMT *stmt);
|
||||||
int taos_stmt_close(TAOS_STMT *stmt);
|
int taos_stmt_close(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_RES *taos_query_c(TAOS *taos, const char *sql, uint32_t sqlLen);
|
||||||
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
||||||
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||||
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
||||||
|
|
|
@ -332,6 +332,10 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
|
||||||
#define TSDB_MAX_WAL_LEVEL 2
|
#define TSDB_MAX_WAL_LEVEL 2
|
||||||
#define TSDB_DEFAULT_WAL_LEVEL 1
|
#define TSDB_DEFAULT_WAL_LEVEL 1
|
||||||
|
|
||||||
|
#define TSDB_MIN_FSYNC_PERIOD 0
|
||||||
|
#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond
|
||||||
|
#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second
|
||||||
|
|
||||||
#define TSDB_MIN_DB_REPLICA_OPTION 1
|
#define TSDB_MIN_DB_REPLICA_OPTION 1
|
||||||
#define TSDB_MAX_DB_REPLICA_OPTION 3
|
#define TSDB_MAX_DB_REPLICA_OPTION 3
|
||||||
#define TSDB_DEFAULT_DB_REPLICA_OPTION 1
|
#define TSDB_DEFAULT_DB_REPLICA_OPTION 1
|
||||||
|
|
|
@ -54,6 +54,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_CREATE_TABLE, "create-table" )
|
||||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_DROP_TABLE, "drop-table" )
|
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_DROP_TABLE, "drop-table" )
|
||||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_ALTER_TABLE, "alter-table" )
|
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_ALTER_TABLE, "alter-table" )
|
||||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_CREATE_VNODE, "create-vnode" )
|
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_CREATE_VNODE, "create-vnode" )
|
||||||
|
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_ALTER_VNODE, "alter-vnode" )
|
||||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_DROP_VNODE, "drop-vnode" )
|
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_DROP_VNODE, "drop-vnode" )
|
||||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_DROP_STABLE, "drop-stable" )
|
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_DROP_STABLE, "drop-stable" )
|
||||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_ALTER_STREAM, "alter-stream" )
|
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_ALTER_STREAM, "alter-stream" )
|
||||||
|
@ -515,6 +516,7 @@ typedef struct {
|
||||||
int32_t minRowsPerFileBlock;
|
int32_t minRowsPerFileBlock;
|
||||||
int32_t maxRowsPerFileBlock;
|
int32_t maxRowsPerFileBlock;
|
||||||
int32_t commitTime;
|
int32_t commitTime;
|
||||||
|
int32_t fsyncPeriod;
|
||||||
uint8_t precision; // time resolution
|
uint8_t precision; // time resolution
|
||||||
int8_t compression;
|
int8_t compression;
|
||||||
int8_t walLevel;
|
int8_t walLevel;
|
||||||
|
@ -608,6 +610,7 @@ typedef struct {
|
||||||
int32_t minRowsPerFileBlock;
|
int32_t minRowsPerFileBlock;
|
||||||
int32_t maxRowsPerFileBlock;
|
int32_t maxRowsPerFileBlock;
|
||||||
int32_t commitTime;
|
int32_t commitTime;
|
||||||
|
int32_t fsyncPeriod;
|
||||||
int8_t precision;
|
int8_t precision;
|
||||||
int8_t compression;
|
int8_t compression;
|
||||||
int8_t walLevel;
|
int8_t walLevel;
|
||||||
|
@ -626,7 +629,7 @@ typedef struct {
|
||||||
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN];
|
||||||
SMDVnodeCfg cfg;
|
SMDVnodeCfg cfg;
|
||||||
SMDVnodeDesc nodes[TSDB_MAX_REPLICA];
|
SMDVnodeDesc nodes[TSDB_MAX_REPLICA];
|
||||||
} SMDCreateVnodeMsg;
|
} SMDCreateVnodeMsg, SMDAlterVnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char tableId[TSDB_TABLE_ID_LEN];
|
char tableId[TSDB_TABLE_ID_LEN];
|
||||||
|
|
|
@ -110,117 +110,117 @@
|
||||||
#define TK_BLOCKS 92
|
#define TK_BLOCKS 92
|
||||||
#define TK_CTIME 93
|
#define TK_CTIME 93
|
||||||
#define TK_WAL 94
|
#define TK_WAL 94
|
||||||
#define TK_COMP 95
|
#define TK_FSYNC 95
|
||||||
#define TK_PRECISION 96
|
#define TK_COMP 96
|
||||||
#define TK_LP 97
|
#define TK_PRECISION 97
|
||||||
#define TK_RP 98
|
#define TK_LP 98
|
||||||
#define TK_TAGS 99
|
#define TK_RP 99
|
||||||
#define TK_USING 100
|
#define TK_TAGS 100
|
||||||
#define TK_AS 101
|
#define TK_USING 101
|
||||||
#define TK_COMMA 102
|
#define TK_AS 102
|
||||||
#define TK_NULL 103
|
#define TK_COMMA 103
|
||||||
#define TK_SELECT 104
|
#define TK_NULL 104
|
||||||
#define TK_UNION 105
|
#define TK_SELECT 105
|
||||||
#define TK_ALL 106
|
#define TK_UNION 106
|
||||||
#define TK_FROM 107
|
#define TK_ALL 107
|
||||||
#define TK_VARIABLE 108
|
#define TK_FROM 108
|
||||||
#define TK_INTERVAL 109
|
#define TK_VARIABLE 109
|
||||||
#define TK_FILL 110
|
#define TK_INTERVAL 110
|
||||||
#define TK_SLIDING 111
|
#define TK_FILL 111
|
||||||
#define TK_ORDER 112
|
#define TK_SLIDING 112
|
||||||
#define TK_BY 113
|
#define TK_ORDER 113
|
||||||
#define TK_ASC 114
|
#define TK_BY 114
|
||||||
#define TK_DESC 115
|
#define TK_ASC 115
|
||||||
#define TK_GROUP 116
|
#define TK_DESC 116
|
||||||
#define TK_HAVING 117
|
#define TK_GROUP 117
|
||||||
#define TK_LIMIT 118
|
#define TK_HAVING 118
|
||||||
#define TK_OFFSET 119
|
#define TK_LIMIT 119
|
||||||
#define TK_SLIMIT 120
|
#define TK_OFFSET 120
|
||||||
#define TK_SOFFSET 121
|
#define TK_SLIMIT 121
|
||||||
#define TK_WHERE 122
|
#define TK_SOFFSET 122
|
||||||
#define TK_NOW 123
|
#define TK_WHERE 123
|
||||||
#define TK_RESET 124
|
#define TK_NOW 124
|
||||||
#define TK_QUERY 125
|
#define TK_RESET 125
|
||||||
#define TK_ADD 126
|
#define TK_QUERY 126
|
||||||
#define TK_COLUMN 127
|
#define TK_ADD 127
|
||||||
#define TK_TAG 128
|
#define TK_COLUMN 128
|
||||||
#define TK_CHANGE 129
|
#define TK_TAG 129
|
||||||
#define TK_SET 130
|
#define TK_CHANGE 130
|
||||||
#define TK_KILL 131
|
#define TK_SET 131
|
||||||
#define TK_CONNECTION 132
|
#define TK_KILL 132
|
||||||
#define TK_STREAM 133
|
#define TK_CONNECTION 133
|
||||||
#define TK_COLON 134
|
#define TK_STREAM 134
|
||||||
#define TK_ABORT 135
|
#define TK_COLON 135
|
||||||
#define TK_AFTER 136
|
#define TK_ABORT 136
|
||||||
#define TK_ATTACH 137
|
#define TK_AFTER 137
|
||||||
#define TK_BEFORE 138
|
#define TK_ATTACH 138
|
||||||
#define TK_BEGIN 139
|
#define TK_BEFORE 139
|
||||||
#define TK_CASCADE 140
|
#define TK_BEGIN 140
|
||||||
#define TK_CLUSTER 141
|
#define TK_CASCADE 141
|
||||||
#define TK_CONFLICT 142
|
#define TK_CLUSTER 142
|
||||||
#define TK_COPY 143
|
#define TK_CONFLICT 143
|
||||||
#define TK_DEFERRED 144
|
#define TK_COPY 144
|
||||||
#define TK_DELIMITERS 145
|
#define TK_DEFERRED 145
|
||||||
#define TK_DETACH 146
|
#define TK_DELIMITERS 146
|
||||||
#define TK_EACH 147
|
#define TK_DETACH 147
|
||||||
#define TK_END 148
|
#define TK_EACH 148
|
||||||
#define TK_EXPLAIN 149
|
#define TK_END 149
|
||||||
#define TK_FAIL 150
|
#define TK_EXPLAIN 150
|
||||||
#define TK_FOR 151
|
#define TK_FAIL 151
|
||||||
#define TK_IGNORE 152
|
#define TK_FOR 152
|
||||||
#define TK_IMMEDIATE 153
|
#define TK_IGNORE 153
|
||||||
#define TK_INITIALLY 154
|
#define TK_IMMEDIATE 154
|
||||||
#define TK_INSTEAD 155
|
#define TK_INITIALLY 155
|
||||||
#define TK_MATCH 156
|
#define TK_INSTEAD 156
|
||||||
#define TK_KEY 157
|
#define TK_MATCH 157
|
||||||
#define TK_OF 158
|
#define TK_KEY 158
|
||||||
#define TK_RAISE 159
|
#define TK_OF 159
|
||||||
#define TK_REPLACE 160
|
#define TK_RAISE 160
|
||||||
#define TK_RESTRICT 161
|
#define TK_REPLACE 161
|
||||||
#define TK_ROW 162
|
#define TK_RESTRICT 162
|
||||||
#define TK_STATEMENT 163
|
#define TK_ROW 163
|
||||||
#define TK_TRIGGER 164
|
#define TK_STATEMENT 164
|
||||||
#define TK_VIEW 165
|
#define TK_TRIGGER 165
|
||||||
#define TK_COUNT 166
|
#define TK_VIEW 166
|
||||||
#define TK_SUM 167
|
#define TK_COUNT 167
|
||||||
#define TK_AVG 168
|
#define TK_SUM 168
|
||||||
#define TK_MIN 169
|
#define TK_AVG 169
|
||||||
#define TK_MAX 170
|
#define TK_MIN 170
|
||||||
#define TK_FIRST 171
|
#define TK_MAX 171
|
||||||
#define TK_LAST 172
|
#define TK_FIRST 172
|
||||||
#define TK_TOP 173
|
#define TK_LAST 173
|
||||||
#define TK_BOTTOM 174
|
#define TK_TOP 174
|
||||||
#define TK_STDDEV 175
|
#define TK_BOTTOM 175
|
||||||
#define TK_PERCENTILE 176
|
#define TK_STDDEV 176
|
||||||
#define TK_APERCENTILE 177
|
#define TK_PERCENTILE 177
|
||||||
#define TK_LEASTSQUARES 178
|
#define TK_APERCENTILE 178
|
||||||
#define TK_HISTOGRAM 179
|
#define TK_LEASTSQUARES 179
|
||||||
#define TK_DIFF 180
|
#define TK_HISTOGRAM 180
|
||||||
#define TK_SPREAD 181
|
#define TK_DIFF 181
|
||||||
#define TK_TWA 182
|
#define TK_SPREAD 182
|
||||||
#define TK_INTERP 183
|
#define TK_TWA 183
|
||||||
#define TK_LAST_ROW 184
|
#define TK_INTERP 184
|
||||||
#define TK_RATE 185
|
#define TK_LAST_ROW 185
|
||||||
#define TK_IRATE 186
|
#define TK_RATE 186
|
||||||
#define TK_SUM_RATE 187
|
#define TK_IRATE 187
|
||||||
#define TK_SUM_IRATE 188
|
#define TK_SUM_RATE 188
|
||||||
#define TK_AVG_RATE 189
|
#define TK_SUM_IRATE 189
|
||||||
#define TK_AVG_IRATE 190
|
#define TK_AVG_RATE 190
|
||||||
#define TK_TBID 191
|
#define TK_AVG_IRATE 191
|
||||||
#define TK_SEMI 192
|
#define TK_TBID 192
|
||||||
#define TK_NONE 193
|
#define TK_SEMI 193
|
||||||
#define TK_PREV 194
|
#define TK_NONE 194
|
||||||
#define TK_LINEAR 195
|
#define TK_PREV 195
|
||||||
#define TK_IMPORT 196
|
#define TK_LINEAR 196
|
||||||
#define TK_METRIC 197
|
#define TK_IMPORT 197
|
||||||
#define TK_TBNAME 198
|
#define TK_METRIC 198
|
||||||
#define TK_JOIN 199
|
#define TK_TBNAME 199
|
||||||
#define TK_METRICS 200
|
#define TK_JOIN 200
|
||||||
#define TK_STABLE 201
|
#define TK_METRICS 201
|
||||||
#define TK_INSERT 202
|
#define TK_STABLE 202
|
||||||
#define TK_INTO 203
|
#define TK_INSERT 203
|
||||||
#define TK_VALUES 204
|
#define TK_INTO 204
|
||||||
|
#define TK_VALUES 205
|
||||||
|
|
||||||
#define TK_SPACE 300
|
#define TK_SPACE 300
|
||||||
#define TK_COMMENT 301
|
#define TK_COMMENT 301
|
||||||
|
|
|
@ -35,6 +35,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t walLevel; // wal level
|
int8_t walLevel; // wal level
|
||||||
|
int32_t fsyncPeriod; // millisecond
|
||||||
int8_t wals; // number of WAL files;
|
int8_t wals; // number of WAL files;
|
||||||
int8_t keep; // keep the wal file when closed
|
int8_t keep; // keep the wal file when closed
|
||||||
} SWalCfg;
|
} SWalCfg;
|
||||||
|
|
|
@ -179,8 +179,8 @@ static struct argp_option options[] = {
|
||||||
{"start-time", 'S', "START_TIME", 0, "Start time to dump.", 3},
|
{"start-time", 'S', "START_TIME", 0, "Start time to dump.", 3},
|
||||||
{"end-time", 'E', "END_TIME", 0, "End time to dump.", 3},
|
{"end-time", 'E', "END_TIME", 0, "End time to dump.", 3},
|
||||||
{"data-batch", 'N', "DATA_BATCH", 0, "Number of data point per insert statement. Default is 1.", 3},
|
{"data-batch", 'N', "DATA_BATCH", 0, "Number of data point per insert statement. Default is 1.", 3},
|
||||||
{"table-batch", 'T', "TABLE_BATCH", 0, "Number of table dumpout into one output file. Default is 1.", 3},
|
{"table-batch", 't', "TABLE_BATCH", 0, "Number of table dumpout into one output file. Default is 1.", 3},
|
||||||
{"thread_num", 't', "THREAD_NUM", 0, "Number of thread for dump in file. Default is 5.", 3},
|
{"thread_num", 'T', "THREAD_NUM", 0, "Number of thread for dump in file. Default is 5.", 3},
|
||||||
{"allow-sys", 'a', 0, 0, "Allow to dump sys database", 3},
|
{"allow-sys", 'a', 0, 0, "Allow to dump sys database", 3},
|
||||||
{0}};
|
{0}};
|
||||||
|
|
||||||
|
@ -304,10 +304,10 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||||
case 'N':
|
case 'N':
|
||||||
arguments->data_batch = atoi(arg);
|
arguments->data_batch = atoi(arg);
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 't':
|
||||||
arguments->table_batch = atoi(arg);
|
arguments->table_batch = atoi(arg);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 'T':
|
||||||
arguments->thread_num = atoi(arg);
|
arguments->thread_num = atoi(arg);
|
||||||
break;
|
break;
|
||||||
case OPT_ABORT:
|
case OPT_ABORT:
|
||||||
|
@ -406,7 +406,7 @@ int main(int argc, char *argv[]) {
|
||||||
printf("password: %s\n", tsArguments.password);
|
printf("password: %s\n", tsArguments.password);
|
||||||
printf("port: %u\n", tsArguments.port);
|
printf("port: %u\n", tsArguments.port);
|
||||||
printf("cversion: %s\n", tsArguments.cversion);
|
printf("cversion: %s\n", tsArguments.cversion);
|
||||||
printf("mysqlFlag: %d", tsArguments.mysqlFlag);
|
printf("mysqlFlag: %d\n", tsArguments.mysqlFlag);
|
||||||
printf("outpath: %s\n", tsArguments.outpath);
|
printf("outpath: %s\n", tsArguments.outpath);
|
||||||
printf("inpath: %s\n", tsArguments.inpath);
|
printf("inpath: %s\n", tsArguments.inpath);
|
||||||
printf("encode: %s\n", tsArguments.encode);
|
printf("encode: %s\n", tsArguments.encode);
|
||||||
|
@ -821,7 +821,7 @@ _exit_failure:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon) {
|
int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon, bool isSuperTable) {
|
||||||
TAOS_ROW row = NULL;
|
TAOS_ROW row = NULL;
|
||||||
TAOS_RES *tmpResult = NULL;
|
TAOS_RES *tmpResult = NULL;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -832,6 +832,13 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* tbuf = (char *)malloc(COMMAND_SIZE);
|
||||||
|
if (tbuf == NULL) {
|
||||||
|
fprintf(stderr, "failed to allocate memory\n");
|
||||||
|
free(tempCommand);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(tempCommand, "describe %s", table);
|
sprintf(tempCommand, "describe %s", table);
|
||||||
|
|
||||||
tmpResult = taos_query(taosCon, tempCommand);
|
tmpResult = taos_query(taosCon, tempCommand);
|
||||||
|
@ -862,6 +869,92 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon) {
|
||||||
taos_free_result(tmpResult);
|
taos_free_result(tmpResult);
|
||||||
tmpResult = NULL;
|
tmpResult = NULL;
|
||||||
|
|
||||||
|
if (isSuperTable) {
|
||||||
|
free(tempCommand);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if chidl-table have tag, using select tagName from table to get tagValue
|
||||||
|
for (int i = 0 ; i < count; i++) {
|
||||||
|
if (strcmp(tableDes->cols[i].note, "TAG") != 0) continue;
|
||||||
|
|
||||||
|
|
||||||
|
sprintf(tempCommand, "select %s from %s", tableDes->cols[i].field, table);
|
||||||
|
|
||||||
|
tmpResult = taos_query(taosCon, tempCommand);
|
||||||
|
code = taos_errno(tmpResult);
|
||||||
|
if (code != 0) {
|
||||||
|
fprintf(stderr, "failed to run command %s\n", tempCommand);
|
||||||
|
free(tempCommand);
|
||||||
|
taos_free_result(tmpResult);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fields = taos_fetch_fields(tmpResult);
|
||||||
|
|
||||||
|
row = taos_fetch_row(tmpResult);
|
||||||
|
if (NULL == row) {
|
||||||
|
fprintf(stderr, " fetch failed to run command %s\n", tempCommand);
|
||||||
|
free(tempCommand);
|
||||||
|
taos_free_result(tmpResult);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (fields[0].type) {
|
||||||
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
|
sprintf(tableDes->cols[i].note, "%d", ((((int)(*((char *)row[0]))) == 1) ? 1 : 0));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
|
sprintf(tableDes->cols[i].note, "%d", (int)(*((char *)row[0])));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
sprintf(tableDes->cols[i].note, "%d", (int)(*((short *)row[0])));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_INT:
|
||||||
|
sprintf(tableDes->cols[i].note, "%d", *((int *)row[0]));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
|
sprintf(tableDes->cols[i].note, "%" PRId64 "", *((int64_t *)row[0]));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
|
sprintf(tableDes->cols[i].note, "%f", GET_FLOAT_VAL(row[0]));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
sprintf(tableDes->cols[i].note, "%f", GET_DOUBLE_VAL(row[0]));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_BINARY:
|
||||||
|
tableDes->cols[i].note[0] = '\'';
|
||||||
|
converStringToReadable((char *)row[0], fields[0].bytes, tbuf, COMMAND_SIZE);
|
||||||
|
char* pstr = stpcpy(&(tableDes->cols[i].note[1]), tbuf);
|
||||||
|
*(pstr++) = '\'';
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
|
convertNCharToReadable((char *)row[0], fields[0].bytes, tbuf, COMMAND_SIZE);
|
||||||
|
sprintf(tableDes->cols[i].note, "\'%s\'", tbuf);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
sprintf(tableDes->cols[i].note, "%" PRId64 "", *(int64_t *)row[0]);
|
||||||
|
#if 0
|
||||||
|
if (!arguments->mysqlFlag) {
|
||||||
|
sprintf(tableDes->cols[i].note, "%" PRId64 "", *(int64_t *)row[0]);
|
||||||
|
} else {
|
||||||
|
char buf[64] = "\0";
|
||||||
|
int64_t ts = *((int64_t *)row[0]);
|
||||||
|
time_t tt = (time_t)(ts / 1000);
|
||||||
|
struct tm *ptm = localtime(&tt);
|
||||||
|
strftime(buf, 64, "%y-%m-%d %H:%M:%S", ptm);
|
||||||
|
sprintf(tableDes->cols[i].note, "\'%s.%03d\'", buf, (int)(ts % 1000));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
taos_free_result(tmpResult);
|
||||||
|
tmpResult = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
free(tempCommand);
|
free(tempCommand);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
@ -886,23 +979,25 @@ int32_t taosDumpTable(char *table, char *metric, struct arguments *arguments, FI
|
||||||
memset(tableDes, 0, sizeof(STableDef) + sizeof(SColDes) * TSDB_MAX_COLUMNS);
|
memset(tableDes, 0, sizeof(STableDef) + sizeof(SColDes) * TSDB_MAX_COLUMNS);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
count = taosGetTableDes(table, tableDes, taosCon);
|
count = taosGetTableDes(table, tableDes, taosCon, false);
|
||||||
|
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
free(tableDes);
|
free(tableDes);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create child-table using super-table
|
||||||
taosDumpCreateMTableClause(tableDes, metric, count, fp);
|
taosDumpCreateMTableClause(tableDes, metric, count, fp);
|
||||||
|
|
||||||
} else { // dump table definition
|
} else { // dump table definition
|
||||||
count = taosGetTableDes(table, tableDes, taosCon);
|
count = taosGetTableDes(table, tableDes, taosCon, false);
|
||||||
|
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
free(tableDes);
|
free(tableDes);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create normal-table or super-table
|
||||||
taosDumpCreateTableClause(tableDes, count, fp);
|
taosDumpCreateTableClause(tableDes, count, fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1033,7 +1128,7 @@ int32_t taosDumpStable(char *table, FILE *fp, TAOS* taosCon) {
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
count = taosGetTableDes(table, tableDes, taosCon);
|
count = taosGetTableDes(table, tableDes, taosCon, true);
|
||||||
|
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
free(tableDes);
|
free(tableDes);
|
||||||
|
@ -1083,7 +1178,6 @@ int32_t taosDumpCreateSuperTableClause(TAOS* taosCon, char* dbName, FILE *fp)
|
||||||
taos_free_result(tmpResult);
|
taos_free_result(tmpResult);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
taos_free_result(tmpResult);
|
|
||||||
|
|
||||||
TAOS_FIELD *fields = taos_fetch_fields(tmpResult);
|
TAOS_FIELD *fields = taos_fetch_fields(tmpResult);
|
||||||
|
|
||||||
|
@ -1291,14 +1385,16 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols
|
||||||
if (counter != count_temp) {
|
if (counter != count_temp) {
|
||||||
if (strcasecmp(tableDes->cols[counter].type, "binary") == 0 ||
|
if (strcasecmp(tableDes->cols[counter].type, "binary") == 0 ||
|
||||||
strcasecmp(tableDes->cols[counter].type, "nchar") == 0) {
|
strcasecmp(tableDes->cols[counter].type, "nchar") == 0) {
|
||||||
pstr += sprintf(pstr, ", \'%s\'", tableDes->cols[counter].note);
|
//pstr += sprintf(pstr, ", \'%s\'", tableDes->cols[counter].note);
|
||||||
|
pstr += sprintf(pstr, ", %s", tableDes->cols[counter].note);
|
||||||
} else {
|
} else {
|
||||||
pstr += sprintf(pstr, ", %s", tableDes->cols[counter].note);
|
pstr += sprintf(pstr, ", %s", tableDes->cols[counter].note);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (strcasecmp(tableDes->cols[counter].type, "binary") == 0 ||
|
if (strcasecmp(tableDes->cols[counter].type, "binary") == 0 ||
|
||||||
strcasecmp(tableDes->cols[counter].type, "nchar") == 0) {
|
strcasecmp(tableDes->cols[counter].type, "nchar") == 0) {
|
||||||
pstr += sprintf(pstr, "\'%s\'", tableDes->cols[counter].note);
|
//pstr += sprintf(pstr, "\'%s\'", tableDes->cols[counter].note);
|
||||||
|
pstr += sprintf(pstr, "%s", tableDes->cols[counter].note);
|
||||||
} else {
|
} else {
|
||||||
pstr += sprintf(pstr, "%s", tableDes->cols[counter].note);
|
pstr += sprintf(pstr, "%s", tableDes->cols[counter].note);
|
||||||
}
|
}
|
||||||
|
@ -1363,7 +1459,7 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
numFields = taos_field_count(taosCon);
|
numFields = taos_field_count(tmpResult);
|
||||||
assert(numFields > 0);
|
assert(numFields > 0);
|
||||||
TAOS_FIELD *fields = taos_fetch_fields(tmpResult);
|
TAOS_FIELD *fields = taos_fetch_fields(tmpResult);
|
||||||
tbuf = (char *)malloc(COMMAND_SIZE);
|
tbuf = (char *)malloc(COMMAND_SIZE);
|
||||||
|
@ -2015,6 +2111,7 @@ int taosDumpInOneFile(TAOS * taos, FILE* fp, char* fcharset, char* encode, c
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(cmd + cmd_len, line, read_len);
|
memcpy(cmd + cmd_len, line, read_len);
|
||||||
|
cmd[read_len + cmd_len]= '\0';
|
||||||
if (queryDB(taos, cmd)) {
|
if (queryDB(taos, cmd)) {
|
||||||
fprintf(stderr, "error sql: linenu:%d, file:%s\n", lineNo, fileName);
|
fprintf(stderr, "error sql: linenu:%d, file:%s\n", lineNo, fileName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ static int32_t saveVnodeCfg(SVnodeObj *pVnode, char* cfgFile)
|
||||||
len += snprintf(content + len, maxLen - len, " \"precision\": %d,\n", pVnode->tsdbCfg.precision);
|
len += snprintf(content + len, maxLen - len, " \"precision\": %d,\n", pVnode->tsdbCfg.precision);
|
||||||
len += snprintf(content + len, maxLen - len, " \"compression\": %d,\n", pVnode->tsdbCfg.compression);
|
len += snprintf(content + len, maxLen - len, " \"compression\": %d,\n", pVnode->tsdbCfg.compression);
|
||||||
len += snprintf(content + len, maxLen - len, " \"walLevel\": %d,\n", pVnode->walCfg.walLevel);
|
len += snprintf(content + len, maxLen - len, " \"walLevel\": %d,\n", pVnode->walCfg.walLevel);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"fsync\": %d,\n", pVnode->walCfg.fsyncPeriod);
|
||||||
len += snprintf(content + len, maxLen - len, " \"replica\": %d,\n", pVnode->syncCfg.replica);
|
len += snprintf(content + len, maxLen - len, " \"replica\": %d,\n", pVnode->syncCfg.replica);
|
||||||
len += snprintf(content + len, maxLen - len, " \"wals\": %d,\n", pVnode->walCfg.wals);
|
len += snprintf(content + len, maxLen - len, " \"wals\": %d,\n", pVnode->walCfg.wals);
|
||||||
len += snprintf(content + len, maxLen - len, " \"quorum\": %d,\n", pVnode->syncCfg.quorum);
|
len += snprintf(content + len, maxLen - len, " \"quorum\": %d,\n", pVnode->syncCfg.quorum);
|
||||||
|
@ -212,6 +213,13 @@ static int32_t readVnodeCfg(SVnodeObj *pVnode, char* cfgFile)
|
||||||
}
|
}
|
||||||
pVnode->walCfg.walLevel = (int8_t) walLevel->valueint;
|
pVnode->walCfg.walLevel = (int8_t) walLevel->valueint;
|
||||||
|
|
||||||
|
cJSON *fsyncPeriod = cJSON_GetObjectItem(root, "fsync");
|
||||||
|
if (!fsyncPeriod || fsyncPeriod->type != cJSON_Number) {
|
||||||
|
printf("vgId:%d, failed to read vnode cfg, fsyncPeriod not found\n", pVnode->vgId);
|
||||||
|
goto PARSE_OVER;
|
||||||
|
}
|
||||||
|
pVnode->walCfg.fsyncPeriod = fsyncPeriod->valueint;
|
||||||
|
|
||||||
cJSON *wals = cJSON_GetObjectItem(root, "wals");
|
cJSON *wals = cJSON_GetObjectItem(root, "wals");
|
||||||
if (!wals || wals->type != cJSON_Number) {
|
if (!wals || wals->type != cJSON_Number) {
|
||||||
printf("vgId:%d, failed to read vnode cfg, wals not found\n", pVnode->vgId);
|
printf("vgId:%d, failed to read vnode cfg, wals not found\n", pVnode->vgId);
|
||||||
|
|
|
@ -160,6 +160,7 @@ typedef struct {
|
||||||
int32_t minRowsPerFileBlock;
|
int32_t minRowsPerFileBlock;
|
||||||
int32_t maxRowsPerFileBlock;
|
int32_t maxRowsPerFileBlock;
|
||||||
int32_t commitTime;
|
int32_t commitTime;
|
||||||
|
int32_t fsyncPeriod;
|
||||||
int8_t precision;
|
int8_t precision;
|
||||||
int8_t compression;
|
int8_t compression;
|
||||||
int8_t walLevel;
|
int8_t walLevel;
|
||||||
|
|
|
@ -30,16 +30,16 @@ extern int32_t sdbDebugFlag;
|
||||||
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
|
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
|
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
|
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
|
||||||
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND INFO ", 255, __VA_ARGS__); }}
|
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }}
|
||||||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND DEBUG ", mDebugFlag, __VA_ARGS__); }}
|
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND TRACE ", mDebugFlag, __VA_ARGS__); }}
|
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define sdbFatal(...) { if (sdbDebugFlag & DEBUG_FATAL) { taosPrintLog("SDB FATAL ", 255, __VA_ARGS__); }}
|
#define sdbFatal(...) { if (sdbDebugFlag & DEBUG_FATAL) { taosPrintLog("SDB FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define sdbError(...) { if (sdbDebugFlag & DEBUG_ERROR) { taosPrintLog("SDB ERROR ", 255, __VA_ARGS__); }}
|
#define sdbError(...) { if (sdbDebugFlag & DEBUG_ERROR) { taosPrintLog("SDB ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define sdbWarn(...) { if (sdbDebugFlag & DEBUG_WARN) { taosPrintLog("SDB WARN ", 255, __VA_ARGS__); }}
|
#define sdbWarn(...) { if (sdbDebugFlag & DEBUG_WARN) { taosPrintLog("SDB WARN ", 255, __VA_ARGS__); }}
|
||||||
#define sdbInfo(...) { if (sdbDebugFlag & DEBUG_INFO) { taosPrintLog("SDB INFO ", 255, __VA_ARGS__); }}
|
#define sdbInfo(...) { if (sdbDebugFlag & DEBUG_INFO) { taosPrintLog("SDB ", 255, __VA_ARGS__); }}
|
||||||
#define sdbDebug(...) { if (sdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("SDB DEBUG ", sdbDebugFlag, __VA_ARGS__); }}
|
#define sdbDebug(...) { if (sdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("SDB ", sdbDebugFlag, __VA_ARGS__); }}
|
||||||
#define sdbTrace(...) { if (sdbDebugFlag & DEBUG_TRACE) { taosPrintLog("SDB TRACE ", sdbDebugFlag, __VA_ARGS__); }}
|
#define sdbTrace(...) { if (sdbDebugFlag & DEBUG_TRACE) { taosPrintLog("SDB ", sdbDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define mLError(...) { monitorSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) }
|
#define mLError(...) { monitorSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) }
|
||||||
#define mLWarn(...) { monitorSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) }
|
#define mLWarn(...) { monitorSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) }
|
||||||
|
|
|
@ -44,9 +44,9 @@ int32_t mnodeGetAvailableVgroup(struct SMnodeMsg *pMsg, SVgObj **pVgroup, int32_
|
||||||
|
|
||||||
void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable);
|
void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable);
|
||||||
void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable);
|
void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable);
|
||||||
void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle);
|
|
||||||
void mnodeSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle);
|
void mnodeSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle);
|
||||||
void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
||||||
|
void mnodeSendAlterVgroupMsg(SVgObj *pVgroup);
|
||||||
|
|
||||||
SRpcIpSet mnodeGetIpSetFromVgroup(SVgObj *pVgroup);
|
SRpcIpSet mnodeGetIpSetFromVgroup(SVgObj *pVgroup);
|
||||||
SRpcIpSet mnodeGetIpSetFromIp(char *ep);
|
SRpcIpSet mnodeGetIpSetFromIp(char *ep);
|
||||||
|
|
|
@ -287,14 +287,14 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) {
|
||||||
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCfg->replications < TSDB_MIN_DB_REPLICA_OPTION || pCfg->replications > TSDB_MAX_DB_REPLICA_OPTION) {
|
if (pCfg->fsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->fsyncPeriod > TSDB_MAX_FSYNC_PERIOD) {
|
||||||
mError("invalid db option replications:%d valid range: [%d, %d]", pCfg->replications, TSDB_MIN_DB_REPLICA_OPTION,
|
mError("invalid db option fsyncPeriod:%d, valid range: [%d, %d]", pCfg->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD);
|
||||||
TSDB_MAX_DB_REPLICA_OPTION);
|
|
||||||
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL) {
|
if (pCfg->replications < TSDB_MIN_DB_REPLICA_OPTION || pCfg->replications > TSDB_MAX_DB_REPLICA_OPTION) {
|
||||||
mError("invalid db option walLevel:%d must be greater than 0", pCfg->walLevel);
|
mError("invalid db option replications:%d valid range: [%d, %d]", pCfg->replications, TSDB_MIN_DB_REPLICA_OPTION,
|
||||||
|
TSDB_MAX_DB_REPLICA_OPTION);
|
||||||
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,6 +318,7 @@ static void mnodeSetDefaultDbCfg(SDbCfg *pCfg) {
|
||||||
if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep;
|
if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep;
|
||||||
if (pCfg->minRowsPerFileBlock < 0) pCfg->minRowsPerFileBlock = tsMinRowsInFileBlock;
|
if (pCfg->minRowsPerFileBlock < 0) pCfg->minRowsPerFileBlock = tsMinRowsInFileBlock;
|
||||||
if (pCfg->maxRowsPerFileBlock < 0) pCfg->maxRowsPerFileBlock = tsMaxRowsInFileBlock;
|
if (pCfg->maxRowsPerFileBlock < 0) pCfg->maxRowsPerFileBlock = tsMaxRowsInFileBlock;
|
||||||
|
if (pCfg->fsyncPeriod <0) pCfg->fsyncPeriod = tsFsyncPeriod;
|
||||||
if (pCfg->commitTime < 0) pCfg->commitTime = tsCommitTime;
|
if (pCfg->commitTime < 0) pCfg->commitTime = tsCommitTime;
|
||||||
if (pCfg->precision < 0) pCfg->precision = tsTimePrecision;
|
if (pCfg->precision < 0) pCfg->precision = tsTimePrecision;
|
||||||
if (pCfg->compression < 0) pCfg->compression = tsCompression;
|
if (pCfg->compression < 0) pCfg->compression = tsCompression;
|
||||||
|
@ -367,6 +368,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs
|
||||||
.daysToKeep2 = pCreate->daysToKeep2,
|
.daysToKeep2 = pCreate->daysToKeep2,
|
||||||
.minRowsPerFileBlock = pCreate->minRowsPerFileBlock,
|
.minRowsPerFileBlock = pCreate->minRowsPerFileBlock,
|
||||||
.maxRowsPerFileBlock = pCreate->maxRowsPerFileBlock,
|
.maxRowsPerFileBlock = pCreate->maxRowsPerFileBlock,
|
||||||
|
.fsyncPeriod = pCreate->fsyncPeriod,
|
||||||
.commitTime = pCreate->commitTime,
|
.commitTime = pCreate->commitTime,
|
||||||
.precision = pCreate->precision,
|
.precision = pCreate->precision,
|
||||||
.compression = pCreate->compression,
|
.compression = pCreate->compression,
|
||||||
|
@ -559,6 +561,12 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 4;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||||
|
strcpy(pSchema[cols].name, "fsync");
|
||||||
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
pShow->bytes[cols] = 1;
|
pShow->bytes[cols] = 1;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
|
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
|
||||||
strcpy(pSchema[cols].name, "comp");
|
strcpy(pSchema[cols].name, "comp");
|
||||||
|
@ -682,6 +690,10 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void
|
||||||
*(int8_t *)pWrite = pDb->cfg.walLevel;
|
*(int8_t *)pWrite = pDb->cfg.walLevel;
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int32_t *)pWrite = pDb->cfg.fsyncPeriod;
|
||||||
|
cols++;
|
||||||
|
|
||||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
*(int8_t *)pWrite = pDb->cfg.compression;
|
*(int8_t *)pWrite = pDb->cfg.compression;
|
||||||
cols++;
|
cols++;
|
||||||
|
@ -758,6 +770,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
||||||
pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1);
|
pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1);
|
||||||
pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2);
|
pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2);
|
||||||
pCreate->commitTime = htonl(pCreate->commitTime);
|
pCreate->commitTime = htonl(pCreate->commitTime);
|
||||||
|
pCreate->fsyncPeriod = htonl(pCreate->fsyncPeriod);
|
||||||
pCreate->minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock);
|
pCreate->minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock);
|
||||||
pCreate->maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock);
|
pCreate->maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock);
|
||||||
|
|
||||||
|
@ -785,6 +798,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
|
||||||
int32_t minRows = htonl(pAlter->minRowsPerFileBlock);
|
int32_t minRows = htonl(pAlter->minRowsPerFileBlock);
|
||||||
int32_t maxRows = htonl(pAlter->maxRowsPerFileBlock);
|
int32_t maxRows = htonl(pAlter->maxRowsPerFileBlock);
|
||||||
int32_t commitTime = htonl(pAlter->commitTime);
|
int32_t commitTime = htonl(pAlter->commitTime);
|
||||||
|
int32_t fsyncPeriod = htonl(pAlter->fsyncPeriod);
|
||||||
int8_t compression = pAlter->compression;
|
int8_t compression = pAlter->compression;
|
||||||
int8_t walLevel = pAlter->walLevel;
|
int8_t walLevel = pAlter->walLevel;
|
||||||
int8_t replications = pAlter->replications;
|
int8_t replications = pAlter->replications;
|
||||||
|
@ -861,6 +875,11 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fsyncPeriod >= 0 && fsyncPeriod != pDb->cfg.fsyncPeriod) {
|
||||||
|
mError("db:%s, can't alter fsyncPeriod option", pDb->name);
|
||||||
|
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
if (replications > 0 && replications != pDb->cfg.replications) {
|
if (replications > 0 && replications != pDb->cfg.replications) {
|
||||||
mDebug("db:%s, replications:%d change to %d", pDb->name, pDb->cfg.replications, replications);
|
mDebug("db:%s, replications:%d change to %d", pDb->name, pDb->cfg.replications, replications);
|
||||||
newCfg.replications = replications;
|
newCfg.replications = replications;
|
||||||
|
@ -894,7 +913,7 @@ static int32_t mnodeAlterDbCb(SMnodeMsg *pMsg, int32_t code) {
|
||||||
pIter = mnodeGetNextVgroup(pIter, &pVgroup);
|
pIter = mnodeGetNextVgroup(pIter, &pVgroup);
|
||||||
if (pVgroup == NULL) break;
|
if (pVgroup == NULL) break;
|
||||||
if (pVgroup->pDb == pDb) {
|
if (pVgroup->pDb == pDb) {
|
||||||
mnodeSendCreateVgroupMsg(pVgroup, NULL);
|
mnodeSendAlterVgroupMsg(pVgroup);
|
||||||
}
|
}
|
||||||
mnodeDecVgroupRef(pVgroup);
|
mnodeDecVgroupRef(pVgroup);
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ static void *sdbGetTableFromId(int32_t tableId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbInitWal() {
|
static int32_t sdbInitWal() {
|
||||||
SWalCfg walCfg = {.walLevel = 2, .wals = 2, .keep = 1};
|
SWalCfg walCfg = {.walLevel = 2, .wals = 2, .keep = 1, .fsyncPeriod = 0};
|
||||||
char temp[TSDB_FILENAME_LEN];
|
char temp[TSDB_FILENAME_LEN];
|
||||||
sprintf(temp, "%s/wal", tsMnodeDir);
|
sprintf(temp, "%s/wal", tsMnodeDir);
|
||||||
tsSdbObj.wal = walOpen(temp, &walCfg);
|
tsSdbObj.wal = walOpen(temp, &walCfg);
|
||||||
|
@ -252,13 +252,15 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) {
|
||||||
int32_t processedCount = atomic_add_fetch_32(&pOper->processedCount, 1);
|
int32_t processedCount = atomic_add_fetch_32(&pOper->processedCount, 1);
|
||||||
if (processedCount <= 1) {
|
if (processedCount <= 1) {
|
||||||
if (pMsg != NULL) {
|
if (pMsg != NULL) {
|
||||||
sdbDebug("app:%p:%p, waiting for confirm this operation, count:%d", pMsg->rpcMsg.ahandle, pMsg, processedCount);
|
sdbDebug("app:%p:%p, waiting for confirm this operation, count:%d result:%s", pMsg->rpcMsg.ahandle, pMsg,
|
||||||
|
processedCount, tstrerror(code));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg != NULL) {
|
if (pMsg != NULL) {
|
||||||
sdbDebug("app:%p:%p, is confirmed and will do callback func", pMsg->rpcMsg.ahandle, pMsg);
|
sdbDebug("app:%p:%p, is confirmed and will do callback func, result:%s", pMsg->rpcMsg.ahandle, pMsg,
|
||||||
|
tstrerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pOper->cb != NULL) {
|
if (pOper->cb != NULL) {
|
||||||
|
|
|
@ -50,6 +50,7 @@ static int32_t mnodeAllocVgroupIdPool(SVgObj *pInputVgroup);
|
||||||
static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg);
|
static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg);
|
||||||
|
static void mnodeProcessAlterVnodeRsp(SRpcMsg *rpcMsg);
|
||||||
static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg);
|
static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg);
|
||||||
static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) ;
|
static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) ;
|
||||||
static void mnodeSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
static void mnodeSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
||||||
|
@ -217,6 +218,7 @@ int32_t mnodeInitVgroups() {
|
||||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_VGROUP, mnodeGetVgroupMeta);
|
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_VGROUP, mnodeGetVgroupMeta);
|
||||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VGROUP, mnodeRetrieveVgroups);
|
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VGROUP, mnodeRetrieveVgroups);
|
||||||
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP, mnodeProcessCreateVnodeRsp);
|
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP, mnodeProcessCreateVnodeRsp);
|
||||||
|
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP, mnodeProcessAlterVnodeRsp);
|
||||||
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_DROP_VNODE_RSP, mnodeProcessDropVnodeRsp);
|
mnodeAddPeerRspHandle(TSDB_MSG_TYPE_MD_DROP_VNODE_RSP, mnodeProcessDropVnodeRsp);
|
||||||
mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_CONFIG_VNODE, mnodeProcessVnodeCfgMsg);
|
mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_CONFIG_VNODE, mnodeProcessVnodeCfgMsg);
|
||||||
|
|
||||||
|
@ -247,7 +249,7 @@ void mnodeUpdateVgroup(SVgObj *pVgroup) {
|
||||||
if (sdbUpdateRow(&oper) != TSDB_CODE_SUCCESS) {
|
if (sdbUpdateRow(&oper) != TSDB_CODE_SUCCESS) {
|
||||||
mError("vgId:%d, failed to update vgroup", pVgroup->vgId);
|
mError("vgId:%d, failed to update vgroup", pVgroup->vgId);
|
||||||
}
|
}
|
||||||
mnodeSendCreateVgroupMsg(pVgroup, NULL);
|
mnodeSendAlterVgroupMsg(pVgroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -272,8 +274,17 @@ void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t o
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == openVnodes && pVgroup->status == TAOS_VG_STATUS_READY) {
|
if (i == openVnodes && pVgroup->status == TAOS_VG_STATUS_READY) {
|
||||||
|
SDbObj *pDb = pVgroup->pDb;
|
||||||
|
if (pDb->cfgVersion != 0) {
|
||||||
|
mDebug("vgId:%d, not exist in dnode:%d and cfgVersion is %d, send alter msg", pVgroup->vgId, pDnode->dnodeId,
|
||||||
|
pDb->cfgVersion);
|
||||||
|
mnodeSendAlterVgroupMsg(pVgroup);
|
||||||
|
} else {
|
||||||
|
mDebug("vgId:%d, not exist in dnode:%d and cfgVersion is %d, send create msg", pVgroup->vgId, pDnode->dnodeId,
|
||||||
|
pDb->cfgVersion);
|
||||||
mnodeSendCreateVgroupMsg(pVgroup, NULL);
|
mnodeSendCreateVgroupMsg(pVgroup, NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mnodeDecVgroupRef(pVgroup);
|
mnodeDecVgroupRef(pVgroup);
|
||||||
}
|
}
|
||||||
|
@ -314,7 +325,7 @@ void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVl
|
||||||
mError("dnode:%d, vgId:%d, vnode cfgVersion:%d repica:%d not match with mnode cfgVersion:%d replica:%d",
|
mError("dnode:%d, vgId:%d, vnode cfgVersion:%d repica:%d not match with mnode cfgVersion:%d replica:%d",
|
||||||
pDnode->dnodeId, pVload->vgId, pVload->cfgVersion, pVload->replica, pVgroup->pDb->cfgVersion,
|
pDnode->dnodeId, pVload->vgId, pVload->cfgVersion, pVload->replica, pVgroup->pDb->cfgVersion,
|
||||||
pVgroup->numOfVnodes);
|
pVgroup->numOfVnodes);
|
||||||
mnodeSendCreateVgroupMsg(pVgroup, NULL);
|
mnodeSendAlterVgroupMsg(pVgroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +547,7 @@ void mnodeCleanupVgroups() {
|
||||||
tsVgroupSdb = NULL;
|
tsVgroupSdb = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
SDbObj *pDb = mnodeGetDb(pShow->db);
|
SDbObj *pDb = mnodeGetDb(pShow->db);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
|
@ -630,7 +641,7 @@ static bool mnodeFilterVgroups(SVgObj *pVgroup, STableObj *pTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
SVgObj *pVgroup = NULL;
|
SVgObj *pVgroup = NULL;
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
@ -733,7 +744,7 @@ void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SMDCreateVnodeMsg *mnodeBuildCreateVnodeMsg(SVgObj *pVgroup) {
|
static SMDCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) {
|
||||||
SDbObj *pDb = pVgroup->pDb;
|
SDbObj *pDb = pVgroup->pDb;
|
||||||
if (pDb == NULL) return NULL;
|
if (pDb == NULL) return NULL;
|
||||||
|
|
||||||
|
@ -757,6 +768,7 @@ SMDCreateVnodeMsg *mnodeBuildCreateVnodeMsg(SVgObj *pVgroup) {
|
||||||
pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep2);
|
pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep2);
|
||||||
pCfg->minRowsPerFileBlock = htonl(pDb->cfg.minRowsPerFileBlock);
|
pCfg->minRowsPerFileBlock = htonl(pDb->cfg.minRowsPerFileBlock);
|
||||||
pCfg->maxRowsPerFileBlock = htonl(pDb->cfg.maxRowsPerFileBlock);
|
pCfg->maxRowsPerFileBlock = htonl(pDb->cfg.maxRowsPerFileBlock);
|
||||||
|
pCfg->fsyncPeriod = htonl(pDb->cfg.fsyncPeriod);
|
||||||
pCfg->commitTime = htonl(pDb->cfg.commitTime);
|
pCfg->commitTime = htonl(pDb->cfg.commitTime);
|
||||||
pCfg->precision = pDb->cfg.precision;
|
pCfg->precision = pDb->cfg.precision;
|
||||||
pCfg->compression = pDb->cfg.compression;
|
pCfg->compression = pDb->cfg.compression;
|
||||||
|
@ -799,8 +811,31 @@ SRpcIpSet mnodeGetIpSetFromIp(char *ep) {
|
||||||
return ipSet;
|
return ipSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) {
|
static void mnodeSendAlterVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet) {
|
||||||
SMDCreateVnodeMsg *pCreate = mnodeBuildCreateVnodeMsg(pVgroup);
|
SMDAlterVnodeMsg *pAlter = mnodeBuildVnodeMsg(pVgroup);
|
||||||
|
SRpcMsg rpcMsg = {
|
||||||
|
.ahandle = NULL,
|
||||||
|
.pCont = pAlter,
|
||||||
|
.contLen = pAlter ? sizeof(SMDAlterVnodeMsg) : 0,
|
||||||
|
.code = 0,
|
||||||
|
.msgType = TSDB_MSG_TYPE_MD_ALTER_VNODE
|
||||||
|
};
|
||||||
|
dnodeSendMsgToDnode(ipSet, &rpcMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mnodeSendAlterVgroupMsg(SVgObj *pVgroup) {
|
||||||
|
mDebug("vgId:%d, send alter all vnodes msg, numOfVnodes:%d db:%s", pVgroup->vgId, pVgroup->numOfVnodes,
|
||||||
|
pVgroup->dbName);
|
||||||
|
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
|
||||||
|
SRpcIpSet ipSet = mnodeGetIpSetFromIp(pVgroup->vnodeGid[i].pDnode->dnodeEp);
|
||||||
|
mDebug("vgId:%d, index:%d, send alter vnode msg to dnode %s", pVgroup->vgId, i,
|
||||||
|
pVgroup->vnodeGid[i].pDnode->dnodeEp);
|
||||||
|
mnodeSendAlterVnodeMsg(pVgroup, &ipSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) {
|
||||||
|
SMDCreateVnodeMsg *pCreate = mnodeBuildVnodeMsg(pVgroup);
|
||||||
SRpcMsg rpcMsg = {
|
SRpcMsg rpcMsg = {
|
||||||
.ahandle = ahandle,
|
.ahandle = ahandle,
|
||||||
.pCont = pCreate,
|
.pCont = pCreate,
|
||||||
|
@ -822,6 +857,10 @@ void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mnodeProcessAlterVnodeRsp(SRpcMsg *rpcMsg) {
|
||||||
|
mDebug("alter vnode rsp received");
|
||||||
|
}
|
||||||
|
|
||||||
static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
|
static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
|
||||||
if (rpcMsg->ahandle == NULL) return;
|
if (rpcMsg->ahandle == NULL) return;
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,9 @@ extern int32_t httpDebugFlag;
|
||||||
#define httpFatal(...) { if (httpDebugFlag & DEBUG_FATAL) { taosPrintLog("HTP FATAL ", 255, __VA_ARGS__); }}
|
#define httpFatal(...) { if (httpDebugFlag & DEBUG_FATAL) { taosPrintLog("HTP FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define httpError(...) { if (httpDebugFlag & DEBUG_ERROR) { taosPrintLog("HTP ERROR ", 255, __VA_ARGS__); }}
|
#define httpError(...) { if (httpDebugFlag & DEBUG_ERROR) { taosPrintLog("HTP ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define httpWarn(...) { if (httpDebugFlag & DEBUG_WARN) { taosPrintLog("HTP WARN ", 255, __VA_ARGS__); }}
|
#define httpWarn(...) { if (httpDebugFlag & DEBUG_WARN) { taosPrintLog("HTP WARN ", 255, __VA_ARGS__); }}
|
||||||
#define httpInfo(...) { if (httpDebugFlag & DEBUG_INFO) { taosPrintLog("HTP INFO ", 255, __VA_ARGS__); }}
|
#define httpInfo(...) { if (httpDebugFlag & DEBUG_INFO) { taosPrintLog("HTP ", 255, __VA_ARGS__); }}
|
||||||
#define httpDebug(...) { if (httpDebugFlag & DEBUG_DEBUG) { taosPrintLog("HTP DEBUG ", httpDebugFlag, __VA_ARGS__); }}
|
#define httpDebug(...) { if (httpDebugFlag & DEBUG_DEBUG) { taosPrintLog("HTP ", httpDebugFlag, __VA_ARGS__); }}
|
||||||
#define httpTrace(...) { if (httpDebugFlag & DEBUG_TRACE) { taosPrintLog("HTP TRACE ", httpDebugFlag, __VA_ARGS__); }}
|
#define httpTrace(...) { if (httpDebugFlag & DEBUG_TRACE) { taosPrintLog("HTP ", httpDebugFlag, __VA_ARGS__); }}
|
||||||
#define httpTraceL(...){ if (httpDebugFlag & DEBUG_TRACE) { taosPrintLongString("HTP TRACE ", httpDebugFlag, __VA_ARGS__); }}
|
#define httpTraceL(...){ if (httpDebugFlag & DEBUG_TRACE) { taosPrintLongString("HTP ", httpDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,9 +31,9 @@
|
||||||
#define monitorFatal(...) { if (monitorDebugFlag & DEBUG_FATAL) { taosPrintLog("MON FATAL ", 255, __VA_ARGS__); }}
|
#define monitorFatal(...) { if (monitorDebugFlag & DEBUG_FATAL) { taosPrintLog("MON FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define monitorError(...) { if (monitorDebugFlag & DEBUG_ERROR) { taosPrintLog("MON ERROR ", 255, __VA_ARGS__); }}
|
#define monitorError(...) { if (monitorDebugFlag & DEBUG_ERROR) { taosPrintLog("MON ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define monitorWarn(...) { if (monitorDebugFlag & DEBUG_WARN) { taosPrintLog("MON WARN ", 255, __VA_ARGS__); }}
|
#define monitorWarn(...) { if (monitorDebugFlag & DEBUG_WARN) { taosPrintLog("MON WARN ", 255, __VA_ARGS__); }}
|
||||||
#define monitorInfo(...) { if (monitorDebugFlag & DEBUG_INFO) { taosPrintLog("MON INFO ", 255, __VA_ARGS__); }}
|
#define monitorInfo(...) { if (monitorDebugFlag & DEBUG_INFO) { taosPrintLog("MON ", 255, __VA_ARGS__); }}
|
||||||
#define monitorDebug(...) { if (monitorDebugFlag & DEBUG_DEBUG) { taosPrintLog("MON DEBUG ", monitorDebugFlag, __VA_ARGS__); }}
|
#define monitorDebug(...) { if (monitorDebugFlag & DEBUG_DEBUG) { taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); }}
|
||||||
#define monitorTrace(...) { if (monitorDebugFlag & DEBUG_TRACE) { taosPrintLog("MON TRACE ", monitorDebugFlag, __VA_ARGS__); }}
|
#define monitorTrace(...) { if (monitorDebugFlag & DEBUG_TRACE) { taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define SQL_LENGTH 1024
|
#define SQL_LENGTH 1024
|
||||||
#define LOG_LEN_STR 100
|
#define LOG_LEN_STR 100
|
||||||
|
|
|
@ -23,8 +23,8 @@ extern int32_t mqttDebugFlag;
|
||||||
#define mqttFatal(...) { if (mqttDebugFlag & DEBUG_FATAL) { taosPrintLog("MQT FATAL ", 255, __VA_ARGS__); }}
|
#define mqttFatal(...) { if (mqttDebugFlag & DEBUG_FATAL) { taosPrintLog("MQT FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define mqttError(...) { if (mqttDebugFlag & DEBUG_ERROR) { taosPrintLog("MQT ERROR ", 255, __VA_ARGS__); }}
|
#define mqttError(...) { if (mqttDebugFlag & DEBUG_ERROR) { taosPrintLog("MQT ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define mqttWarn(...) { if (mqttDebugFlag & DEBUG_WARN) { taosPrintLog("MQT WARN ", 255, __VA_ARGS__); }}
|
#define mqttWarn(...) { if (mqttDebugFlag & DEBUG_WARN) { taosPrintLog("MQT WARN ", 255, __VA_ARGS__); }}
|
||||||
#define mqttInfo(...) { if (mqttDebugFlag & DEBUG_INFO) { taosPrintLog("MQT INFO ", 255, __VA_ARGS__); }}
|
#define mqttInfo(...) { if (mqttDebugFlag & DEBUG_INFO) { taosPrintLog("MQT ", 255, __VA_ARGS__); }}
|
||||||
#define mqttDebug(...) { if (mqttDebugFlag & DEBUG_DEBUG) { taosPrintLog("MQT DEBUG ", mqttDebugFlag, __VA_ARGS__); }}
|
#define mqttDebug(...) { if (mqttDebugFlag & DEBUG_DEBUG) { taosPrintLog("MQT ", mqttDebugFlag, __VA_ARGS__); }}
|
||||||
#define mqttTrace(...) { if (mqttDebugFlag & DEBUG_TRACE) { taosPrintLog("MQT TRACE ", mqttDebugFlag, __VA_ARGS__); }}
|
#define mqttTrace(...) { if (mqttDebugFlag & DEBUG_TRACE) { taosPrintLog("MQT ", mqttDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "qtsbuf.h"
|
#include "qtsbuf.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
#include "tref.h"
|
#include "tlockfree.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
|
|
@ -116,6 +116,7 @@ typedef struct SCreateDBInfo {
|
||||||
int32_t daysPerFile;
|
int32_t daysPerFile;
|
||||||
int32_t minRowsPerBlock;
|
int32_t minRowsPerBlock;
|
||||||
int32_t maxRowsPerBlock;
|
int32_t maxRowsPerBlock;
|
||||||
|
int32_t fsyncPeriod;
|
||||||
int64_t commitTime;
|
int64_t commitTime;
|
||||||
int32_t walLevel;
|
int32_t walLevel;
|
||||||
int32_t compressionLevel;
|
int32_t compressionLevel;
|
||||||
|
|
|
@ -28,9 +28,9 @@ extern int32_t tscEmbedded;
|
||||||
#define qFatal(...) { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", 255, __VA_ARGS__); }}
|
#define qFatal(...) { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define qError(...) { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", 255, __VA_ARGS__); }}
|
#define qError(...) { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define qWarn(...) { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", 255, __VA_ARGS__); }}
|
#define qWarn(...) { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", 255, __VA_ARGS__); }}
|
||||||
#define qInfo(...) { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY INFO ", 255, __VA_ARGS__); }}
|
#define qInfo(...) { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", 255, __VA_ARGS__); }}
|
||||||
#define qDebug(...) { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY DEBUG ", qDebugFlag, __VA_ARGS__); }}
|
#define qDebug(...) { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }}
|
||||||
#define qTrace(...) { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY TRACE ", qDebugFlag, __VA_ARGS__); }}
|
#define qTrace(...) { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,6 +221,7 @@ maxrows(Y) ::= MAXROWS INTEGER(X). { Y = X; }
|
||||||
blocks(Y) ::= BLOCKS INTEGER(X). { Y = X; }
|
blocks(Y) ::= BLOCKS INTEGER(X). { Y = X; }
|
||||||
ctime(Y) ::= CTIME INTEGER(X). { Y = X; }
|
ctime(Y) ::= CTIME INTEGER(X). { Y = X; }
|
||||||
wal(Y) ::= WAL INTEGER(X). { Y = X; }
|
wal(Y) ::= WAL INTEGER(X). { Y = X; }
|
||||||
|
fsync(Y) ::= FSYNC INTEGER(X). { Y = X; }
|
||||||
comp(Y) ::= COMP INTEGER(X). { Y = X; }
|
comp(Y) ::= COMP INTEGER(X). { Y = X; }
|
||||||
prec(Y) ::= PRECISION STRING(X). { Y = X; }
|
prec(Y) ::= PRECISION STRING(X). { Y = X; }
|
||||||
|
|
||||||
|
@ -236,6 +237,7 @@ db_optr(Y) ::= db_optr(Z) maxrows(X). { Y = Z; Y.maxRowsPerBlock = strtod
|
||||||
db_optr(Y) ::= db_optr(Z) blocks(X). { Y = Z; Y.numOfBlocks = strtol(X.z, NULL, 10); }
|
db_optr(Y) ::= db_optr(Z) blocks(X). { Y = Z; Y.numOfBlocks = strtol(X.z, NULL, 10); }
|
||||||
db_optr(Y) ::= db_optr(Z) ctime(X). { Y = Z; Y.commitTime = strtol(X.z, NULL, 10); }
|
db_optr(Y) ::= db_optr(Z) ctime(X). { Y = Z; Y.commitTime = strtol(X.z, NULL, 10); }
|
||||||
db_optr(Y) ::= db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); }
|
db_optr(Y) ::= db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); }
|
||||||
|
db_optr(Y) ::= db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); }
|
||||||
db_optr(Y) ::= db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
|
db_optr(Y) ::= db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
|
||||||
db_optr(Y) ::= db_optr(Z) prec(X). { Y = Z; Y.precision = X; }
|
db_optr(Y) ::= db_optr(Z) prec(X). { Y = Z; Y.precision = X; }
|
||||||
db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; }
|
db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; }
|
||||||
|
@ -249,6 +251,7 @@ alter_db_optr(Y) ::= alter_db_optr(Z) keep(X). { Y = Z; Y.keep = X; }
|
||||||
alter_db_optr(Y) ::= alter_db_optr(Z) blocks(X). { Y = Z; Y.numOfBlocks = strtol(X.z, NULL, 10); }
|
alter_db_optr(Y) ::= alter_db_optr(Z) blocks(X). { Y = Z; Y.numOfBlocks = strtol(X.z, NULL, 10); }
|
||||||
alter_db_optr(Y) ::= alter_db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
|
alter_db_optr(Y) ::= alter_db_optr(Z) comp(X). { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
|
||||||
alter_db_optr(Y) ::= alter_db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); }
|
alter_db_optr(Y) ::= alter_db_optr(Z) wal(X). { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); }
|
||||||
|
alter_db_optr(Y) ::= alter_db_optr(Z) fsync(X). { Y = Z; Y.fsyncPeriod = strtod(X.z, NULL, 10); }
|
||||||
|
|
||||||
%type typename {TAOS_FIELD}
|
%type typename {TAOS_FIELD}
|
||||||
typename(A) ::= ids(X). {
|
typename(A) ::= ids(X). {
|
||||||
|
|
|
@ -2202,7 +2202,13 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
|
||||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
|
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
|
||||||
|
|
||||||
SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER;
|
SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER;
|
||||||
while (tsdbNextDataBlock(pQueryHandle)) {
|
while (true) {
|
||||||
|
if (!tsdbNextDataBlock(pQueryHandle)) {
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
summary->totalBlocks += 1;
|
summary->totalBlocks += 1;
|
||||||
|
|
||||||
if (IS_QUERY_KILLED(GET_QINFO_ADDR(pRuntimeEnv))) {
|
if (IS_QUERY_KILLED(GET_QINFO_ADDR(pRuntimeEnv))) {
|
||||||
|
@ -3188,6 +3194,9 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI
|
||||||
|
|
||||||
// add ref for table
|
// add ref for table
|
||||||
pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
||||||
|
if (pRuntimeEnv->pSecQueryHandle == NULL) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
|
|
||||||
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
|
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
|
||||||
switchCtxOrder(pRuntimeEnv);
|
switchCtxOrder(pRuntimeEnv);
|
||||||
|
@ -3260,6 +3269,9 @@ void scanOneTableDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
||||||
|
if (pRuntimeEnv->pSecQueryHandle == NULL) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
pRuntimeEnv->windowResInfo.curIndex = qstatus.windowIndex;
|
pRuntimeEnv->windowResInfo.curIndex = qstatus.windowIndex;
|
||||||
|
|
||||||
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
|
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
|
||||||
|
@ -3916,7 +3928,14 @@ void skipBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
|
||||||
TsdbQueryHandleT pQueryHandle = pRuntimeEnv->pQueryHandle;
|
TsdbQueryHandleT pQueryHandle = pRuntimeEnv->pQueryHandle;
|
||||||
|
|
||||||
SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER;
|
SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER;
|
||||||
while (tsdbNextDataBlock(pQueryHandle)) {
|
while (true) {
|
||||||
|
if (!tsdbNextDataBlock(pQueryHandle)) {
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_QUERY_KILLED(GET_QINFO_ADDR(pRuntimeEnv))) {
|
if (IS_QUERY_KILLED(GET_QINFO_ADDR(pRuntimeEnv))) {
|
||||||
finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query
|
finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query
|
||||||
longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED);
|
longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED);
|
||||||
|
@ -3960,7 +3979,14 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv, TSKEY* start) {
|
||||||
STableQueryInfo *pTableQueryInfo = pQuery->current;
|
STableQueryInfo *pTableQueryInfo = pQuery->current;
|
||||||
|
|
||||||
SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER;
|
SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER;
|
||||||
while (tsdbNextDataBlock(pRuntimeEnv->pQueryHandle)) {
|
while (true) {
|
||||||
|
if (!tsdbNextDataBlock(pRuntimeEnv->pQueryHandle)) {
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
tsdbRetrieveDataBlockInfo(pRuntimeEnv->pQueryHandle, &blockInfo);
|
tsdbRetrieveDataBlockInfo(pRuntimeEnv->pQueryHandle, &blockInfo);
|
||||||
|
|
||||||
if (QUERY_IS_ASC_QUERY(pQuery)) {
|
if (QUERY_IS_ASC_QUERY(pQuery)) {
|
||||||
|
@ -4059,16 +4085,16 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv, TSKEY* start) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) {
|
static int32_t setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) {
|
||||||
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
|
SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv;
|
||||||
SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
|
SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
|
||||||
|
|
||||||
if (onlyQueryTags(pQuery)) {
|
if (onlyQueryTags(pQuery)) {
|
||||||
return;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSTableQuery && (!QUERY_IS_INTERVAL_QUERY(pQuery)) && (!isFixedOutputQuery(pRuntimeEnv))) {
|
if (isSTableQuery && (!QUERY_IS_INTERVAL_QUERY(pQuery)) && (!isFixedOutputQuery(pRuntimeEnv))) {
|
||||||
return;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
STsdbQueryCond cond = {
|
STsdbQueryCond cond = {
|
||||||
|
@ -4090,6 +4116,7 @@ static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) {
|
||||||
cond.twindow = pCheckInfo->win;
|
cond.twindow = pCheckInfo->win;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
if (isFirstLastRowQuery(pQuery)) {
|
if (isFirstLastRowQuery(pQuery)) {
|
||||||
pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
||||||
} else if (isPointInterpoQuery(pQuery)) {
|
} else if (isPointInterpoQuery(pQuery)) {
|
||||||
|
@ -4097,6 +4124,7 @@ static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) {
|
||||||
} else {
|
} else {
|
||||||
pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
||||||
}
|
}
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SFillColInfo* taosCreateFillColInfo(SQuery* pQuery) {
|
static SFillColInfo* taosCreateFillColInfo(SQuery* pQuery) {
|
||||||
|
@ -4133,7 +4161,10 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo
|
||||||
|
|
||||||
setScanLimitationByResultBuffer(pQuery);
|
setScanLimitationByResultBuffer(pQuery);
|
||||||
changeExecuteScanOrder(pQInfo, false);
|
changeExecuteScanOrder(pQInfo, false);
|
||||||
setupQueryHandle(tsdb, pQInfo, isSTableQuery);
|
code = setupQueryHandle(tsdb, pQInfo, isSTableQuery);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pQInfo->tsdb = tsdb;
|
pQInfo->tsdb = tsdb;
|
||||||
pQInfo->vgId = vgId;
|
pQInfo->vgId = vgId;
|
||||||
|
@ -4257,7 +4288,14 @@ static int64_t scanMultiTableDataBlocks(SQInfo *pQInfo) {
|
||||||
|
|
||||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
|
int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order);
|
||||||
|
|
||||||
while (tsdbNextDataBlock(pQueryHandle)) {
|
while (true) {
|
||||||
|
if (!tsdbNextDataBlock(pQueryHandle)) {
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
summary->totalBlocks += 1;
|
summary->totalBlocks += 1;
|
||||||
|
|
||||||
if (IS_QUERY_KILLED(pQInfo)) {
|
if (IS_QUERY_KILLED(pQInfo)) {
|
||||||
|
@ -4338,6 +4376,9 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
|
||||||
pRuntimeEnv->pQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &gp, pQInfo);
|
pRuntimeEnv->pQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &gp, pQInfo);
|
||||||
taosArrayDestroy(tx);
|
taosArrayDestroy(tx);
|
||||||
taosArrayDestroy(g1);
|
taosArrayDestroy(g1);
|
||||||
|
if (pRuntimeEnv->pQueryHandle == NULL) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
|
|
||||||
if (pRuntimeEnv->pTSBuf != NULL) {
|
if (pRuntimeEnv->pTSBuf != NULL) {
|
||||||
if (pRuntimeEnv->cur.vgroupIndex == -1) {
|
if (pRuntimeEnv->cur.vgroupIndex == -1) {
|
||||||
|
@ -4406,6 +4447,12 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
|
||||||
pRuntimeEnv->pQueryHandle = tsdbQueryRowsInExternalWindow(pQInfo->tsdb, &cond, &gp, pQInfo);
|
pRuntimeEnv->pQueryHandle = tsdbQueryRowsInExternalWindow(pQInfo->tsdb, &cond, &gp, pQInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosArrayDestroy(tx);
|
||||||
|
taosArrayDestroy(g1);
|
||||||
|
if (pRuntimeEnv->pQueryHandle == NULL) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
|
|
||||||
initCtxOutputBuf(pRuntimeEnv);
|
initCtxOutputBuf(pRuntimeEnv);
|
||||||
|
|
||||||
SArray* s = tsdbGetQueriedTableList(pRuntimeEnv->pQueryHandle);
|
SArray* s = tsdbGetQueriedTableList(pRuntimeEnv->pQueryHandle);
|
||||||
|
@ -4469,6 +4516,9 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
|
||||||
pRuntimeEnv->pQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &gp, pQInfo);
|
pRuntimeEnv->pQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &gp, pQInfo);
|
||||||
taosArrayDestroy(g1);
|
taosArrayDestroy(g1);
|
||||||
taosArrayDestroy(tx);
|
taosArrayDestroy(tx);
|
||||||
|
if (pRuntimeEnv->pQueryHandle == NULL) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
|
|
||||||
SArray* s = tsdbGetQueriedTableList(pRuntimeEnv->pQueryHandle);
|
SArray* s = tsdbGetQueriedTableList(pRuntimeEnv->pQueryHandle);
|
||||||
assert(taosArrayGetSize(s) >= 1);
|
assert(taosArrayGetSize(s) >= 1);
|
||||||
|
@ -4664,6 +4714,9 @@ static void doSaveContext(SQInfo *pQInfo) {
|
||||||
|
|
||||||
pRuntimeEnv->prevGroupId = INT32_MIN;
|
pRuntimeEnv->prevGroupId = INT32_MIN;
|
||||||
pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo);
|
||||||
|
if (pRuntimeEnv->pSecQueryHandle == NULL) {
|
||||||
|
longjmp(pRuntimeEnv->env, terrno);
|
||||||
|
}
|
||||||
|
|
||||||
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
|
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
|
||||||
switchCtxOrder(pRuntimeEnv);
|
switchCtxOrder(pRuntimeEnv);
|
||||||
|
@ -6499,7 +6552,8 @@ void* qOpenQueryMgmt(int32_t vgId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void queryMgmtKillQueryFn(void* handle) {
|
static void queryMgmtKillQueryFn(void* handle) {
|
||||||
qKillQuery(handle);
|
void** fp = (void**)handle;
|
||||||
|
qKillQuery(*fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qQueryMgmtNotifyClosed(void* pQMgmt) {
|
void qQueryMgmtNotifyClosed(void* pQMgmt) {
|
||||||
|
|
|
@ -896,6 +896,7 @@ void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo) {
|
||||||
pDBInfo->compressionLevel = -1;
|
pDBInfo->compressionLevel = -1;
|
||||||
|
|
||||||
pDBInfo->walLevel = -1;
|
pDBInfo->walLevel = -1;
|
||||||
|
pDBInfo->fsyncPeriod = -1;
|
||||||
pDBInfo->commitTime = -1;
|
pDBInfo->commitTime = -1;
|
||||||
pDBInfo->maxTablesPerVnode = -1;
|
pDBInfo->maxTablesPerVnode = -1;
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"CACHE", TK_CACHE},
|
{"CACHE", TK_CACHE},
|
||||||
{"CTIME", TK_CTIME},
|
{"CTIME", TK_CTIME},
|
||||||
{"WAL", TK_WAL},
|
{"WAL", TK_WAL},
|
||||||
|
{"FSYNC", TK_FSYNC},
|
||||||
{"COMP", TK_COMP},
|
{"COMP", TK_COMP},
|
||||||
{"PRECISION", TK_PRECISION},
|
{"PRECISION", TK_PRECISION},
|
||||||
{"LP", TK_LP},
|
{"LP", TK_LP},
|
||||||
|
|
2253
src/query/src/sql.c
2253
src/query/src/sql.c
File diff suppressed because it is too large
Load Diff
|
@ -28,9 +28,9 @@ extern int32_t tscEmbedded;
|
||||||
#define tFatal(...) { if (rpcDebugFlag & DEBUG_FATAL) { taosPrintLog("RPC FATAL ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
#define tFatal(...) { if (rpcDebugFlag & DEBUG_FATAL) { taosPrintLog("RPC FATAL ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
||||||
#define tError(...) { if (rpcDebugFlag & DEBUG_ERROR) { taosPrintLog("RPC ERROR ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
#define tError(...) { if (rpcDebugFlag & DEBUG_ERROR) { taosPrintLog("RPC ERROR ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
||||||
#define tWarn(...) { if (rpcDebugFlag & DEBUG_WARN) { taosPrintLog("RPC WARN ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
#define tWarn(...) { if (rpcDebugFlag & DEBUG_WARN) { taosPrintLog("RPC WARN ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
||||||
#define tInfo(...) { if (rpcDebugFlag & DEBUG_INFO) { taosPrintLog("RPC INFO ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
#define tInfo(...) { if (rpcDebugFlag & DEBUG_INFO) { taosPrintLog("RPC ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }}
|
||||||
#define tDebug(...) { if (rpcDebugFlag & DEBUG_DEBUG) { taosPrintLog("RPC DEBUG ", rpcDebugFlag, __VA_ARGS__); }}
|
#define tDebug(...) { if (rpcDebugFlag & DEBUG_DEBUG) { taosPrintLog("RPC ", rpcDebugFlag, __VA_ARGS__); }}
|
||||||
#define tTrace(...) { if (rpcDebugFlag & DEBUG_TRACE) { taosPrintLog("RPC TRACE ", rpcDebugFlag, __VA_ARGS__); }}
|
#define tTrace(...) { if (rpcDebugFlag & DEBUG_TRACE) { taosPrintLog("RPC ", rpcDebugFlag, __VA_ARGS__); }}
|
||||||
#define tDump(x, y) { if (rpcDebugFlag & DEBUG_DUMP) { taosDumpData((unsigned char *)x, y); }}
|
#define tDump(x, y) { if (rpcDebugFlag & DEBUG_DUMP) { taosDumpData((unsigned char *)x, y); }}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -21,11 +21,10 @@
|
||||||
#include "tkvstore.h"
|
#include "tkvstore.h"
|
||||||
#include "tlist.h"
|
#include "tlist.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tref.h"
|
#include "tlockfree.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tskiplist.h"
|
#include "tskiplist.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "trwlatch.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -36,9 +35,9 @@ extern int tsdbDebugFlag;
|
||||||
#define tsdbFatal(...) { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", 255, __VA_ARGS__); }}
|
#define tsdbFatal(...) { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define tsdbError(...) { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", 255, __VA_ARGS__); }}
|
#define tsdbError(...) { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define tsdbWarn(...) { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", 255, __VA_ARGS__); }}
|
#define tsdbWarn(...) { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", 255, __VA_ARGS__); }}
|
||||||
#define tsdbInfo(...) { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB INFO ", 255, __VA_ARGS__); }}
|
#define tsdbInfo(...) { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", 255, __VA_ARGS__); }}
|
||||||
#define tsdbDebug(...) { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB DEBUG ", tsdbDebugFlag, __VA_ARGS__); }}
|
#define tsdbDebug(...) { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }}
|
||||||
#define tsdbTrace(...) { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB TRACE ", tsdbDebugFlag, __VA_ARGS__); }}
|
#define tsdbTrace(...) { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define TSDB_MAX_TABLE_SCHEMAS 16
|
#define TSDB_MAX_TABLE_SCHEMAS 16
|
||||||
#define TSDB_FILE_HEAD_SIZE 512
|
#define TSDB_FILE_HEAD_SIZE 512
|
||||||
|
@ -96,6 +95,11 @@ typedef struct {
|
||||||
} STsdbBufPool;
|
} STsdbBufPool;
|
||||||
|
|
||||||
// ------------------ tsdbMemTable.c
|
// ------------------ tsdbMemTable.c
|
||||||
|
typedef struct {
|
||||||
|
STable * pTable;
|
||||||
|
SSkipListIterator *pIter;
|
||||||
|
} SCommitIter;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
TSKEY keyFirst;
|
TSKEY keyFirst;
|
||||||
|
@ -206,10 +210,10 @@ typedef struct {
|
||||||
int64_t offset : 63;
|
int64_t offset : 63;
|
||||||
int32_t algorithm : 8;
|
int32_t algorithm : 8;
|
||||||
int32_t numOfRows : 24;
|
int32_t numOfRows : 24;
|
||||||
int32_t sversion;
|
|
||||||
int32_t len;
|
int32_t len;
|
||||||
|
int32_t keyLen; // key column length, keyOffset = offset+sizeof(SCompData)+sizeof(SCompCol)*numOfCols
|
||||||
int16_t numOfSubBlocks;
|
int16_t numOfSubBlocks;
|
||||||
int16_t numOfCols;
|
int16_t numOfCols; // not including timestamp column
|
||||||
TSKEY keyFirst;
|
TSKEY keyFirst;
|
||||||
TSKEY keyLast;
|
TSKEY keyLast;
|
||||||
} SCompBlock;
|
} SCompBlock;
|
||||||
|
@ -377,6 +381,24 @@ int tsdbUnRefMemTable(STsdbRepo* pRepo, SMemTable* pMemTable);
|
||||||
int tsdbTakeMemSnapshot(STsdbRepo* pRepo, SMemTable** pMem, SMemTable** pIMem);
|
int tsdbTakeMemSnapshot(STsdbRepo* pRepo, SMemTable** pMem, SMemTable** pIMem);
|
||||||
void* tsdbAllocBytes(STsdbRepo* pRepo, int bytes);
|
void* tsdbAllocBytes(STsdbRepo* pRepo, int bytes);
|
||||||
int tsdbAsyncCommit(STsdbRepo* pRepo);
|
int tsdbAsyncCommit(STsdbRepo* pRepo);
|
||||||
|
int tsdbLoadDataFromCache(STable* pTable, SSkipListIterator* pIter, TSKEY maxKey, int maxRowsToRead, SDataCols* pCols,
|
||||||
|
TSKEY* filterKeys, int nFilterKeys);
|
||||||
|
|
||||||
|
static FORCE_INLINE SDataRow tsdbNextIterRow(SSkipListIterator* pIter) {
|
||||||
|
if (pIter == NULL) return NULL;
|
||||||
|
|
||||||
|
SSkipListNode* node = tSkipListIterGet(pIter);
|
||||||
|
if (node == NULL) return NULL;
|
||||||
|
|
||||||
|
return SL_GET_NODE_DATA(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator* pIter) {
|
||||||
|
SDataRow row = tsdbNextIterRow(pIter);
|
||||||
|
if (row == NULL) return -1;
|
||||||
|
|
||||||
|
return dataRowKey(row);
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------ tsdbFile.c
|
// ------------------ tsdbFile.c
|
||||||
#define TSDB_KEY_FILEID(key, daysPerFile, precision) ((key) / tsMsPerDay[(precision)] / (daysPerFile))
|
#define TSDB_KEY_FILEID(key, daysPerFile, precision) ((key) / tsMsPerDay[(precision)] / (daysPerFile))
|
||||||
|
@ -421,6 +443,7 @@ void tsdbRemoveFileGroup(STsdbRepo* pRepo, SFileGroup* pFGroup);
|
||||||
#define helperType(h) (h)->type
|
#define helperType(h) (h)->type
|
||||||
#define helperRepo(h) (h)->pRepo
|
#define helperRepo(h) (h)->pRepo
|
||||||
#define helperState(h) (h)->state
|
#define helperState(h) (h)->state
|
||||||
|
#define TSDB_NLAST_FILE_OPENED(h) ((h)->files.nLastF.fd > 0)
|
||||||
|
|
||||||
int tsdbInitReadHelper(SRWHelper* pHelper, STsdbRepo* pRepo);
|
int tsdbInitReadHelper(SRWHelper* pHelper, STsdbRepo* pRepo);
|
||||||
int tsdbInitWriteHelper(SRWHelper* pHelper, STsdbRepo* pRepo);
|
int tsdbInitWriteHelper(SRWHelper* pHelper, STsdbRepo* pRepo);
|
||||||
|
@ -429,7 +452,7 @@ void tsdbResetHelper(SRWHelper* pHelper);
|
||||||
int tsdbSetAndOpenHelperFile(SRWHelper* pHelper, SFileGroup* pGroup);
|
int tsdbSetAndOpenHelperFile(SRWHelper* pHelper, SFileGroup* pGroup);
|
||||||
int tsdbCloseHelperFile(SRWHelper* pHelper, bool hasError);
|
int tsdbCloseHelperFile(SRWHelper* pHelper, bool hasError);
|
||||||
void tsdbSetHelperTable(SRWHelper* pHelper, STable* pTable, STsdbRepo* pRepo);
|
void tsdbSetHelperTable(SRWHelper* pHelper, STable* pTable, STsdbRepo* pRepo);
|
||||||
int tsdbWriteDataBlock(SRWHelper* pHelper, SDataCols* pDataCols);
|
int tsdbCommitTableData(SRWHelper* pHelper, SCommitIter* pCommitIter, SDataCols* pDataCols, TSKEY maxKey);
|
||||||
int tsdbMoveLastBlockIfNeccessary(SRWHelper* pHelper);
|
int tsdbMoveLastBlockIfNeccessary(SRWHelper* pHelper);
|
||||||
int tsdbWriteCompInfo(SRWHelper* pHelper);
|
int tsdbWriteCompInfo(SRWHelper* pHelper);
|
||||||
int tsdbWriteCompIdx(SRWHelper* pHelper);
|
int tsdbWriteCompIdx(SRWHelper* pHelper);
|
||||||
|
@ -441,6 +464,16 @@ int tsdbLoadBlockDataCols(SRWHelper* pHelper, SCompBlock* pCompBlock, SCompInf
|
||||||
int numOfColIds);
|
int numOfColIds);
|
||||||
int tsdbLoadBlockData(SRWHelper* pHelper, SCompBlock* pCompBlock, SCompInfo* pCompInfo);
|
int tsdbLoadBlockData(SRWHelper* pHelper, SCompBlock* pCompBlock, SCompInfo* pCompInfo);
|
||||||
|
|
||||||
|
static FORCE_INLINE int compTSKEY(const void* key1, const void* key2) {
|
||||||
|
if (*(TSKEY*)key1 > *(TSKEY*)key2) {
|
||||||
|
return 1;
|
||||||
|
} else if (*(TSKEY*)key1 == *(TSKEY*)key2) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------ tsdbMain.c
|
// ------------------ tsdbMain.c
|
||||||
#define REPO_ID(r) (r)->config.tsdbId
|
#define REPO_ID(r) (r)->config.tsdbId
|
||||||
#define IS_REPO_LOCKED(r) (r)->repoLocked
|
#define IS_REPO_LOCKED(r) (r)->repoLocked
|
||||||
|
|
|
@ -18,11 +18,6 @@
|
||||||
|
|
||||||
#define TSDB_DATA_SKIPLIST_LEVEL 5
|
#define TSDB_DATA_SKIPLIST_LEVEL 5
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
STable * pTable;
|
|
||||||
SSkipListIterator *pIter;
|
|
||||||
} SCommitIter;
|
|
||||||
|
|
||||||
static FORCE_INLINE STsdbBufBlock *tsdbGetCurrBufBlock(STsdbRepo *pRepo);
|
static FORCE_INLINE STsdbBufBlock *tsdbGetCurrBufBlock(STsdbRepo *pRepo);
|
||||||
|
|
||||||
static void tsdbFreeBytes(STsdbRepo *pRepo, void *ptr, int bytes);
|
static void tsdbFreeBytes(STsdbRepo *pRepo, void *ptr, int bytes);
|
||||||
|
@ -34,14 +29,11 @@ static char * tsdbGetTsTupleKey(const void *data);
|
||||||
static void * tsdbCommitData(void *arg);
|
static void * tsdbCommitData(void *arg);
|
||||||
static int tsdbCommitMeta(STsdbRepo *pRepo);
|
static int tsdbCommitMeta(STsdbRepo *pRepo);
|
||||||
static void tsdbEndCommit(STsdbRepo *pRepo);
|
static void tsdbEndCommit(STsdbRepo *pRepo);
|
||||||
static TSKEY tsdbNextIterKey(SCommitIter *pIter);
|
|
||||||
static int tsdbHasDataToCommit(SCommitIter *iters, int nIters, TSKEY minKey, TSKEY maxKey);
|
static int tsdbHasDataToCommit(SCommitIter *iters, int nIters, TSKEY minKey, TSKEY maxKey);
|
||||||
static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHelper *pHelper, SDataCols *pDataCols);
|
static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHelper *pHelper, SDataCols *pDataCols);
|
||||||
static void tsdbGetFidKeyRange(int daysPerFile, int8_t precision, int fileId, TSKEY *minKey, TSKEY *maxKey);
|
static void tsdbGetFidKeyRange(int daysPerFile, int8_t precision, int fileId, TSKEY *minKey, TSKEY *maxKey);
|
||||||
static SCommitIter *tsdbCreateTableIters(STsdbRepo *pRepo);
|
static SCommitIter *tsdbCreateCommitIters(STsdbRepo *pRepo);
|
||||||
static void tsdbDestroyTableIters(SCommitIter *iters, int maxTables);
|
static void tsdbDestroyCommitIters(SCommitIter *iters, int maxTables);
|
||||||
static int tsdbReadRowsFromCache(STsdbMeta *pMeta, STable *pTable, SSkipListIterator *pIter, TSKEY maxKey,
|
|
||||||
int maxRowsToRead, SDataCols *pCols);
|
|
||||||
|
|
||||||
// ---------------- INTERNAL FUNCTIONS ----------------
|
// ---------------- INTERNAL FUNCTIONS ----------------
|
||||||
int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
|
int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) {
|
||||||
|
@ -252,6 +244,66 @@ int tsdbAsyncCommit(STsdbRepo *pRepo) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols,
|
||||||
|
TSKEY *filterKeys, int nFilterKeys) {
|
||||||
|
ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0);
|
||||||
|
if (pIter == NULL) return 0;
|
||||||
|
STSchema *pSchema = NULL;
|
||||||
|
int numOfRows = 0;
|
||||||
|
TSKEY keyNext = 0;
|
||||||
|
int filterIter = 0;
|
||||||
|
|
||||||
|
if (nFilterKeys != 0) { // for filter purpose
|
||||||
|
ASSERT(filterKeys != NULL);
|
||||||
|
keyNext = tsdbNextIterKey(pIter);
|
||||||
|
if (keyNext < 0 || keyNext > maxKey) return numOfRows;
|
||||||
|
void *ptr = taosbsearch((void *)(&keyNext), (void *)filterKeys, nFilterKeys, sizeof(TSKEY), compTSKEY, TD_GE);
|
||||||
|
filterIter = (ptr == NULL) ? nFilterKeys : (POINTER_DISTANCE(ptr, filterKeys) / sizeof(TSKEY));
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (numOfRows >= maxRowsToRead) break;
|
||||||
|
|
||||||
|
SDataRow row = tsdbNextIterRow(pIter);
|
||||||
|
if (row == NULL) break;
|
||||||
|
|
||||||
|
keyNext = dataRowKey(row);
|
||||||
|
if (keyNext < 0 || keyNext > maxKey) break;
|
||||||
|
|
||||||
|
bool keyFiltered = false;
|
||||||
|
if (nFilterKeys != 0) {
|
||||||
|
while (true) {
|
||||||
|
if (filterIter >= nFilterKeys) break;
|
||||||
|
if (keyNext == filterKeys[filterIter]) {
|
||||||
|
keyFiltered = true;
|
||||||
|
filterIter++;
|
||||||
|
break;
|
||||||
|
} else if (keyNext < filterKeys[filterIter]) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
filterIter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!keyFiltered) {
|
||||||
|
if (pCols) {
|
||||||
|
if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) {
|
||||||
|
pSchema = tsdbGetTableSchemaImpl(pTable, false, false, dataRowVersion(row));
|
||||||
|
if (pSchema == NULL) {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tdAppendDataRowToDataCol(row, pSchema, pCols);
|
||||||
|
}
|
||||||
|
numOfRows++;
|
||||||
|
}
|
||||||
|
} while (tSkipListIterNext(pIter));
|
||||||
|
|
||||||
|
return numOfRows;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------- LOCAL FUNCTIONS ----------------
|
// ---------------- LOCAL FUNCTIONS ----------------
|
||||||
static FORCE_INLINE STsdbBufBlock *tsdbGetCurrBufBlock(STsdbRepo *pRepo) {
|
static FORCE_INLINE STsdbBufBlock *tsdbGetCurrBufBlock(STsdbRepo *pRepo) {
|
||||||
ASSERT(pRepo != NULL);
|
ASSERT(pRepo != NULL);
|
||||||
|
@ -378,7 +430,7 @@ static void *tsdbCommitData(void *arg) {
|
||||||
|
|
||||||
// Create the iterator to read from cache
|
// Create the iterator to read from cache
|
||||||
if (pMem->numOfRows > 0) {
|
if (pMem->numOfRows > 0) {
|
||||||
iters = tsdbCreateTableIters(pRepo);
|
iters = tsdbCreateCommitIters(pRepo);
|
||||||
if (iters == NULL) {
|
if (iters == NULL) {
|
||||||
tsdbError("vgId:%d failed to create commit iterator since %s", REPO_ID(pRepo), tstrerror(terrno));
|
tsdbError("vgId:%d failed to create commit iterator since %s", REPO_ID(pRepo), tstrerror(terrno));
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
@ -418,7 +470,7 @@ static void *tsdbCommitData(void *arg) {
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
tdFreeDataCols(pDataCols);
|
tdFreeDataCols(pDataCols);
|
||||||
tsdbDestroyTableIters(iters, pCfg->maxTables);
|
tsdbDestroyCommitIters(iters, pCfg->maxTables);
|
||||||
tsdbDestroyHelper(&whelper);
|
tsdbDestroyHelper(&whelper);
|
||||||
tsdbEndCommit(pRepo);
|
tsdbEndCommit(pRepo);
|
||||||
tsdbInfo("vgId:%d commit over", pRepo->config.tsdbId);
|
tsdbInfo("vgId:%d commit over", pRepo->config.tsdbId);
|
||||||
|
@ -479,19 +531,9 @@ static void tsdbEndCommit(STsdbRepo *pRepo) {
|
||||||
if (pRepo->appH.notifyStatus) pRepo->appH.notifyStatus(pRepo->appH.appH, TSDB_STATUS_COMMIT_OVER);
|
if (pRepo->appH.notifyStatus) pRepo->appH.notifyStatus(pRepo->appH.appH, TSDB_STATUS_COMMIT_OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TSKEY tsdbNextIterKey(SCommitIter *pIter) {
|
|
||||||
if (pIter == NULL) return -1;
|
|
||||||
|
|
||||||
SSkipListNode *node = tSkipListIterGet(pIter->pIter);
|
|
||||||
if (node == NULL) return -1;
|
|
||||||
|
|
||||||
SDataRow row = SL_GET_NODE_DATA(node);
|
|
||||||
return dataRowKey(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tsdbHasDataToCommit(SCommitIter *iters, int nIters, TSKEY minKey, TSKEY maxKey) {
|
static int tsdbHasDataToCommit(SCommitIter *iters, int nIters, TSKEY minKey, TSKEY maxKey) {
|
||||||
for (int i = 0; i < nIters; i++) {
|
for (int i = 0; i < nIters; i++) {
|
||||||
TSKEY nextKey = tsdbNextIterKey(iters + i);
|
TSKEY nextKey = tsdbNextIterKey((iters + i)->pIter);
|
||||||
if (nextKey > 0 && (nextKey >= minKey && nextKey <= maxKey)) return 1;
|
if (nextKey > 0 && (nextKey >= minKey && nextKey <= maxKey)) return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -504,7 +546,6 @@ static void tsdbGetFidKeyRange(int daysPerFile, int8_t precision, int fileId, TS
|
||||||
|
|
||||||
static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHelper *pHelper, SDataCols *pDataCols) {
|
static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHelper *pHelper, SDataCols *pDataCols) {
|
||||||
char * dataDir = NULL;
|
char * dataDir = NULL;
|
||||||
STsdbMeta * pMeta = pRepo->tsdbMeta;
|
|
||||||
STsdbCfg * pCfg = &pRepo->config;
|
STsdbCfg * pCfg = &pRepo->config;
|
||||||
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
STsdbFileH *pFileH = pRepo->tsdbFileH;
|
||||||
SFileGroup *pGroup = NULL;
|
SFileGroup *pGroup = NULL;
|
||||||
|
@ -549,33 +590,13 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe
|
||||||
if (pIter->pIter != NULL) {
|
if (pIter->pIter != NULL) {
|
||||||
tdInitDataCols(pDataCols, tsdbGetTableSchemaImpl(pIter->pTable, false, false, -1));
|
tdInitDataCols(pDataCols, tsdbGetTableSchemaImpl(pIter->pTable, false, false, -1));
|
||||||
|
|
||||||
int maxRowsToRead = pCfg->maxRowsPerFileBlock * 4 / 5;
|
if (tsdbCommitTableData(pHelper, pIter, pDataCols, maxKey) < 0) {
|
||||||
int nLoop = 0;
|
|
||||||
while (true) {
|
|
||||||
int rowsRead = tsdbReadRowsFromCache(pMeta, pIter->pTable, pIter->pIter, maxKey, maxRowsToRead, pDataCols);
|
|
||||||
ASSERT(rowsRead >= 0);
|
|
||||||
if (pDataCols->numOfRows == 0) break;
|
|
||||||
nLoop++;
|
|
||||||
|
|
||||||
ASSERT(dataColsKeyFirst(pDataCols) >= minKey && dataColsKeyFirst(pDataCols) <= maxKey);
|
|
||||||
ASSERT(dataColsKeyLast(pDataCols) >= minKey && dataColsKeyLast(pDataCols) <= maxKey);
|
|
||||||
|
|
||||||
int rowsWritten = tsdbWriteDataBlock(pHelper, pDataCols);
|
|
||||||
ASSERT(rowsWritten != 0);
|
|
||||||
if (rowsWritten < 0) {
|
|
||||||
taosRUnLockLatch(&(pIter->pTable->latch));
|
taosRUnLockLatch(&(pIter->pTable->latch));
|
||||||
tsdbError("vgId:%d failed to write data block to table %s tid %d uid %" PRIu64 " since %s", REPO_ID(pRepo),
|
tsdbError("vgId:%d failed to write data of table %s tid %d uid %" PRIu64 " since %s", REPO_ID(pRepo),
|
||||||
TABLE_CHAR_NAME(pIter->pTable), TABLE_TID(pIter->pTable), TABLE_UID(pIter->pTable),
|
TABLE_CHAR_NAME(pIter->pTable), TABLE_TID(pIter->pTable), TABLE_UID(pIter->pTable),
|
||||||
tstrerror(terrno));
|
tstrerror(terrno));
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
ASSERT(rowsWritten <= pDataCols->numOfRows);
|
|
||||||
|
|
||||||
tdPopDataColsPoints(pDataCols, rowsWritten);
|
|
||||||
maxRowsToRead = pCfg->maxRowsPerFileBlock * 4 / 5 - pDataCols->numOfRows;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(pDataCols->numOfRows == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taosRUnLockLatch(&(pIter->pTable->latch));
|
taosRUnLockLatch(&(pIter->pTable->latch));
|
||||||
|
@ -615,7 +636,7 @@ _err:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SCommitIter *tsdbCreateTableIters(STsdbRepo *pRepo) {
|
static SCommitIter *tsdbCreateCommitIters(STsdbRepo *pRepo) {
|
||||||
STsdbCfg * pCfg = &(pRepo->config);
|
STsdbCfg * pCfg = &(pRepo->config);
|
||||||
SMemTable *pMem = pRepo->imem;
|
SMemTable *pMem = pRepo->imem;
|
||||||
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
STsdbMeta *pMeta = pRepo->tsdbMeta;
|
||||||
|
@ -645,21 +666,18 @@ static SCommitIter *tsdbCreateTableIters(STsdbRepo *pRepo) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tSkipListIterNext(iters[i].pIter)) {
|
tSkipListIterNext(iters[i].pIter);
|
||||||
terrno = TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM;
|
|
||||||
goto _err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return iters;
|
return iters;
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
tsdbDestroyTableIters(iters, pCfg->maxTables);
|
tsdbDestroyCommitIters(iters, pCfg->maxTables);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tsdbDestroyTableIters(SCommitIter *iters, int maxTables) {
|
static void tsdbDestroyCommitIters(SCommitIter *iters, int maxTables) {
|
||||||
if (iters == NULL) return;
|
if (iters == NULL) return;
|
||||||
|
|
||||||
for (int i = 1; i < maxTables; i++) {
|
for (int i = 1; i < maxTables; i++) {
|
||||||
|
@ -671,34 +689,3 @@ static void tsdbDestroyTableIters(SCommitIter *iters, int maxTables) {
|
||||||
|
|
||||||
free(iters);
|
free(iters);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbReadRowsFromCache(STsdbMeta *pMeta, STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols) {
|
|
||||||
ASSERT(maxRowsToRead > 0);
|
|
||||||
if (pIter == NULL) return 0;
|
|
||||||
STSchema *pSchema = NULL;
|
|
||||||
|
|
||||||
int numOfRows = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (numOfRows >= maxRowsToRead) break;
|
|
||||||
|
|
||||||
SSkipListNode *node = tSkipListIterGet(pIter);
|
|
||||||
if (node == NULL) break;
|
|
||||||
|
|
||||||
SDataRow row = SL_GET_NODE_DATA(node);
|
|
||||||
if (dataRowKey(row) > maxKey) break;
|
|
||||||
|
|
||||||
if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) {
|
|
||||||
pSchema = tsdbGetTableSchemaImpl(pTable, true, false, dataRowVersion(row));
|
|
||||||
if (pSchema == NULL) {
|
|
||||||
// TODO: deal with the error here
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tdAppendDataRowToDataCol(row, pSchema, pCols);
|
|
||||||
numOfRows++;
|
|
||||||
} while (tSkipListIterNext(pIter));
|
|
||||||
|
|
||||||
return numOfRows;
|
|
||||||
}
|
|
|
@ -727,7 +727,7 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) {
|
||||||
|
|
||||||
T_REF_INC(pTable);
|
T_REF_INC(pTable);
|
||||||
|
|
||||||
tsdbDebug("table %s tid %d uid %" PRIu64 " is created", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable),
|
tsdbTrace("table %s tid %d uid %" PRIu64 " is created", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable),
|
||||||
TABLE_UID(pTable));
|
TABLE_UID(pTable));
|
||||||
|
|
||||||
return pTable;
|
return pTable;
|
||||||
|
@ -740,7 +740,7 @@ _err:
|
||||||
static void tsdbFreeTable(STable *pTable) {
|
static void tsdbFreeTable(STable *pTable) {
|
||||||
if (pTable) {
|
if (pTable) {
|
||||||
if (pTable->name != NULL)
|
if (pTable->name != NULL)
|
||||||
tsdbDebug("table %s tid %d uid %" PRIu64 " is destroyed", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable),
|
tsdbTrace("table %s tid %d uid %" PRIu64 " is freed", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable),
|
||||||
TABLE_UID(pTable));
|
TABLE_UID(pTable));
|
||||||
tfree(TABLE_NAME(pTable));
|
tfree(TABLE_NAME(pTable));
|
||||||
if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) {
|
if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) {
|
||||||
|
|
|
@ -22,18 +22,17 @@
|
||||||
#include "tfile.h"
|
#include "tfile.h"
|
||||||
|
|
||||||
#define TSDB_GET_COMPCOL_LEN(nCols) (sizeof(SCompData) + sizeof(SCompCol) * (nCols) + sizeof(TSCKSUM))
|
#define TSDB_GET_COMPCOL_LEN(nCols) (sizeof(SCompData) + sizeof(SCompCol) * (nCols) + sizeof(TSCKSUM))
|
||||||
|
#define TSDB_KEY_COL_OFFSET 0
|
||||||
|
#define TSDB_GET_COMPBLOCK_IDX(h, b) (POINTER_DISTANCE(b, (h)->pCompInfo->blocks)/sizeof(SCompBlock))
|
||||||
|
|
||||||
static bool tsdbShouldCreateNewLast(SRWHelper *pHelper);
|
static bool tsdbShouldCreateNewLast(SRWHelper *pHelper);
|
||||||
static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, int rowsToWrite,
|
static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, SCompBlock *pCompBlock,
|
||||||
SCompBlock *pCompBlock, bool isLast, bool isSuperBlock);
|
bool isLast, bool isSuperBlock);
|
||||||
static int compareKeyBlock(const void *arg1, const void *arg2);
|
static int compareKeyBlock(const void *arg1, const void *arg2);
|
||||||
static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDataCols);
|
|
||||||
static int compTSKEY(const void *key1, const void *key2);
|
|
||||||
static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t esize);
|
static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t esize);
|
||||||
static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx);
|
static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx);
|
||||||
static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx, int rowsAdded);
|
static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx, int rowsAdded);
|
||||||
static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx);
|
static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx);
|
||||||
static int tsdbGetRowsInRange(SDataCols *pDataCols, TSKEY minKey, TSKEY maxKey);
|
|
||||||
static void tsdbResetHelperFileImpl(SRWHelper *pHelper);
|
static void tsdbResetHelperFileImpl(SRWHelper *pHelper);
|
||||||
static int tsdbInitHelperFile(SRWHelper *pHelper);
|
static int tsdbInitHelperFile(SRWHelper *pHelper);
|
||||||
static void tsdbDestroyHelperFile(SRWHelper *pHelper);
|
static void tsdbDestroyHelperFile(SRWHelper *pHelper);
|
||||||
|
@ -52,9 +51,15 @@ static int tsdbLoadBlockDataColsImpl(SRWHelper *pHelper, SCompBlock *pCompBlock,
|
||||||
static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols);
|
static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols);
|
||||||
static int tsdbEncodeSCompIdx(void **buf, SCompIdx *pIdx);
|
static int tsdbEncodeSCompIdx(void **buf, SCompIdx *pIdx);
|
||||||
static void *tsdbDecodeSCompIdx(void *buf, SCompIdx *pIdx);
|
static void *tsdbDecodeSCompIdx(void *buf, SCompIdx *pIdx);
|
||||||
|
static int tsdbProcessAppendCommit(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols *pDataCols, TSKEY maxKey);
|
||||||
static void tsdbDestroyHelperBlock(SRWHelper *pHelper);
|
static void tsdbDestroyHelperBlock(SRWHelper *pHelper);
|
||||||
static int tsdbLoadColData(SRWHelper *pHelper, SFile *pFile, SCompBlock *pCompBlock, SCompCol *pCompCol,
|
static int tsdbLoadColData(SRWHelper *pHelper, SFile *pFile, SCompBlock *pCompBlock, SCompCol *pCompCol,
|
||||||
SDataCol *pDataCol);
|
SDataCol *pDataCol);
|
||||||
|
static int tsdbWriteBlockToProperFile(SRWHelper *pHelper, SDataCols *pDataCols, SCompBlock *pCompBlock);
|
||||||
|
static int tsdbProcessMergeCommit(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols *pDataCols, TSKEY maxKey,
|
||||||
|
int *blkIdx);
|
||||||
|
static int tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||||
|
TSKEY maxKey, int maxRows);
|
||||||
|
|
||||||
// ---------------------- INTERNAL FUNCTIONS ----------------------
|
// ---------------------- INTERNAL FUNCTIONS ----------------------
|
||||||
int tsdbInitReadHelper(SRWHelper *pHelper, STsdbRepo *pRepo) {
|
int tsdbInitReadHelper(SRWHelper *pHelper, STsdbRepo *pRepo) {
|
||||||
|
@ -225,84 +230,41 @@ void tsdbSetHelperTable(SRWHelper *pHelper, STable *pTable, STsdbRepo *pRepo) {
|
||||||
tdInitDataCols(pHelper->pDataCols[1], pSchema);
|
tdInitDataCols(pHelper->pDataCols[1], pSchema);
|
||||||
|
|
||||||
SCompIdx *pIdx = pHelper->pCompIdx + pTable->tableId.tid;
|
SCompIdx *pIdx = pHelper->pCompIdx + pTable->tableId.tid;
|
||||||
if (pIdx->offset > 0 && pIdx->hasLast) {
|
if (pIdx->offset > 0) {
|
||||||
pHelper->hasOldLastBlock = true;
|
if (pIdx->uid != TABLE_UID(pTable)) {
|
||||||
|
memset((void *)pIdx, 0, sizeof(SCompIdx));
|
||||||
|
} else {
|
||||||
|
if (pIdx->hasLast) pHelper->hasOldLastBlock = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
helperSetState(pHelper, TSDB_HELPER_TABLE_SET);
|
helperSetState(pHelper, TSDB_HELPER_TABLE_SET);
|
||||||
ASSERT(pHelper->state == ((TSDB_HELPER_TABLE_SET << 1) - 1));
|
ASSERT(pHelper->state == ((TSDB_HELPER_TABLE_SET << 1) - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int tsdbCommitTableData(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols *pDataCols, TSKEY maxKey) {
|
||||||
* Write part of of points from pDataCols to file
|
|
||||||
*
|
|
||||||
* @return: number of points written to file successfully
|
|
||||||
* -1 for failure
|
|
||||||
*/
|
|
||||||
int tsdbWriteDataBlock(SRWHelper *pHelper, SDataCols *pDataCols) {
|
|
||||||
ASSERT(helperType(pHelper) == TSDB_WRITE_HELPER);
|
ASSERT(helperType(pHelper) == TSDB_WRITE_HELPER);
|
||||||
ASSERT(pDataCols->numOfRows > 0);
|
|
||||||
|
|
||||||
SCompBlock compBlock;
|
SCompIdx * pIdx = &(pHelper->pCompIdx[TABLE_TID(pCommitIter->pTable)]);
|
||||||
int rowsToWrite = 0;
|
int blkIdx = 0;
|
||||||
TSKEY keyFirst = dataColsKeyFirst(pDataCols);
|
|
||||||
|
|
||||||
STsdbCfg *pCfg = &pHelper->pRepo->config;
|
ASSERT(pIdx->offset == 0 || pIdx->uid == TABLE_UID(pCommitIter->pTable));
|
||||||
|
if (tsdbLoadCompInfo(pHelper, NULL) < 0) return -1;
|
||||||
|
|
||||||
ASSERT(helperHasState(pHelper, TSDB_HELPER_IDX_LOAD));
|
while (true) {
|
||||||
SCompIdx *pIdx = pHelper->pCompIdx + pHelper->tableInfo.tid; // for change purpose
|
ASSERT(blkIdx <= pIdx->numOfBlocks);
|
||||||
|
TSKEY keyFirst = tsdbNextIterKey(pCommitIter->pIter);
|
||||||
|
if (keyFirst < 0 || keyFirst > maxKey) break; // iter over
|
||||||
|
|
||||||
// Load the SCompInfo part if neccessary
|
if (pIdx->len <= 0 || keyFirst > pIdx->maxKey) {
|
||||||
ASSERT(helperHasState(pHelper, TSDB_HELPER_TABLE_SET));
|
if (tsdbProcessAppendCommit(pHelper, pCommitIter, pDataCols, maxKey) < 0) return -1;
|
||||||
if (tsdbLoadCompInfo(pHelper, NULL) < 0) goto _err;
|
blkIdx = pIdx->numOfBlocks;
|
||||||
|
|
||||||
if (pIdx->offset == 0 || (!pIdx->hasLast && keyFirst > pIdx->maxKey)) { // Just append as a super block
|
|
||||||
ASSERT(pHelper->hasOldLastBlock == false);
|
|
||||||
rowsToWrite = pDataCols->numOfRows;
|
|
||||||
SFile *pWFile = NULL;
|
|
||||||
bool isLast = false;
|
|
||||||
|
|
||||||
if (rowsToWrite >= pCfg->minRowsPerFileBlock) {
|
|
||||||
pWFile = &(pHelper->files.dataF);
|
|
||||||
} else {
|
} else {
|
||||||
isLast = true;
|
if (tsdbProcessMergeCommit(pHelper, pCommitIter, pDataCols, maxKey, &blkIdx) < 0) return -1;
|
||||||
pWFile = (pHelper->files.nLastF.fd > 0) ? &(pHelper->files.nLastF) : &(pHelper->files.lastF);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tsdbWriteBlockToFile(pHelper, pWFile, pDataCols, rowsToWrite, &compBlock, isLast, true) < 0) goto _err;
|
|
||||||
|
|
||||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks) < 0) goto _err;
|
|
||||||
} else { // (Has old data) AND ((has last block) OR (key overlap)), need to merge the block
|
|
||||||
SCompBlock *pCompBlock = taosbsearch((void *)(&keyFirst), (void *)(pHelper->pCompInfo->blocks), pIdx->numOfBlocks,
|
|
||||||
sizeof(SCompBlock), compareKeyBlock, TD_GE);
|
|
||||||
|
|
||||||
int blkIdx = (pCompBlock == NULL) ? (pIdx->numOfBlocks - 1) : (pCompBlock - pHelper->pCompInfo->blocks);
|
|
||||||
|
|
||||||
if (pCompBlock == NULL) { // No key overlap, must has last block, just merge with the last block
|
|
||||||
ASSERT(pIdx->hasLast && pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].last);
|
|
||||||
rowsToWrite = tsdbMergeDataWithBlock(pHelper, blkIdx, pDataCols);
|
|
||||||
if (rowsToWrite < 0) goto _err;
|
|
||||||
} else { // Has key overlap
|
|
||||||
|
|
||||||
if (compareKeyBlock((void *)(&keyFirst), (void *)pCompBlock) == 0) {
|
|
||||||
// Key overlap with the block, must merge with the block
|
|
||||||
|
|
||||||
rowsToWrite = tsdbMergeDataWithBlock(pHelper, blkIdx, pDataCols);
|
|
||||||
if (rowsToWrite < 0) goto _err;
|
|
||||||
} else { // Save as a super block in the middle
|
|
||||||
rowsToWrite = tsdbGetRowsInRange(pDataCols, 0, pCompBlock->keyFirst - 1);
|
|
||||||
ASSERT(rowsToWrite > 0);
|
|
||||||
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.dataF), pDataCols, rowsToWrite, &compBlock, false, true) < 0)
|
|
||||||
goto _err;
|
|
||||||
if (tsdbInsertSuperBlock(pHelper, &compBlock, blkIdx) < 0) goto _err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rowsToWrite;
|
return 0;
|
||||||
|
|
||||||
_err:
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsdbMoveLastBlockIfNeccessary(SRWHelper *pHelper) {
|
int tsdbMoveLastBlockIfNeccessary(SRWHelper *pHelper) {
|
||||||
|
@ -310,30 +272,43 @@ int tsdbMoveLastBlockIfNeccessary(SRWHelper *pHelper) {
|
||||||
|
|
||||||
ASSERT(helperType(pHelper) == TSDB_WRITE_HELPER);
|
ASSERT(helperType(pHelper) == TSDB_WRITE_HELPER);
|
||||||
SCompIdx * pIdx = pHelper->pCompIdx + pHelper->tableInfo.tid;
|
SCompIdx * pIdx = pHelper->pCompIdx + pHelper->tableInfo.tid;
|
||||||
SCompBlock compBlock;
|
SCompBlock compBlock = {0};
|
||||||
if ((pHelper->files.nLastF.fd > 0) && (pHelper->hasOldLastBlock)) {
|
if (TSDB_NLAST_FILE_OPENED(pHelper) && (pHelper->hasOldLastBlock)) {
|
||||||
if (tsdbLoadCompInfo(pHelper, NULL) < 0) return -1;
|
if (tsdbLoadCompInfo(pHelper, NULL) < 0) return -1;
|
||||||
|
|
||||||
SCompBlock *pCompBlock = pHelper->pCompInfo->blocks + pIdx->numOfBlocks - 1;
|
SCompBlock *pCompBlock = blockAtIdx(pHelper, pIdx->numOfBlocks - 1);
|
||||||
ASSERT(pCompBlock->last);
|
ASSERT(pCompBlock->last);
|
||||||
|
|
||||||
if (pCompBlock->numOfSubBlocks > 1) {
|
if (pCompBlock->numOfSubBlocks > 1) {
|
||||||
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, pIdx->numOfBlocks - 1), NULL) < 0) return -1;
|
if (tsdbLoadBlockData(pHelper, pCompBlock, NULL) < 0) return -1;
|
||||||
ASSERT(pHelper->pDataCols[0]->numOfRows > 0 && pHelper->pDataCols[0]->numOfRows < pCfg->minRowsPerFileBlock);
|
ASSERT(pHelper->pDataCols[0]->numOfRows == pCompBlock->numOfRows &&
|
||||||
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.nLastF), pHelper->pDataCols[0],
|
pHelper->pDataCols[0]->numOfRows < pCfg->minRowsPerFileBlock);
|
||||||
pHelper->pDataCols[0]->numOfRows, &compBlock, true, true) < 0)
|
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.nLastF), pHelper->pDataCols[0], &compBlock, true, true) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (tsdbUpdateSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1) < 0) return -1;
|
if (tsdbUpdateSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1) < 0) return -1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (lseek(pHelper->files.lastF.fd, pCompBlock->offset, SEEK_SET) < 0) return -1;
|
if (lseek(pHelper->files.lastF.fd, pCompBlock->offset, SEEK_SET) < 0) {
|
||||||
pCompBlock->offset = lseek(pHelper->files.nLastF.fd, 0, SEEK_END);
|
tsdbError("vgId:%d failed to lseek file %s since %s", REPO_ID(pHelper->pRepo), pHelper->files.lastF.fname,
|
||||||
if (pCompBlock->offset < 0) return -1;
|
strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
if (tsendfile(pHelper->files.nLastF.fd, pHelper->files.lastF.fd, NULL, pCompBlock->len) < pCompBlock->len)
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
pCompBlock->offset = lseek(pHelper->files.nLastF.fd, 0, SEEK_END);
|
||||||
|
if (pCompBlock->offset < 0) {
|
||||||
|
tsdbError("vgId:%d failed to lseek file %s since %s", REPO_ID(pHelper->pRepo), pHelper->files.nLastF.fname,
|
||||||
|
strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsendfile(pHelper->files.nLastF.fd, pHelper->files.lastF.fd, NULL, pCompBlock->len) < pCompBlock->len) {
|
||||||
|
tsdbError("vgId:%d failed to sendfile from file %s to file %s since %s", REPO_ID(pHelper->pRepo),
|
||||||
|
pHelper->files.lastF.fname, pHelper->files.nLastF.fname, strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pHelper->hasOldLastBlock = false;
|
pHelper->hasOldLastBlock = false;
|
||||||
}
|
}
|
||||||
|
@ -365,10 +340,12 @@ int tsdbWriteCompInfo(SRWHelper *pHelper) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (pIdx->len > 0) {
|
||||||
pHelper->pCompInfo->delimiter = TSDB_FILE_DELIMITER;
|
pHelper->pCompInfo->delimiter = TSDB_FILE_DELIMITER;
|
||||||
pHelper->pCompInfo->uid = pHelper->tableInfo.uid;
|
pHelper->pCompInfo->uid = pHelper->tableInfo.uid;
|
||||||
pHelper->pCompInfo->checksum = 0;
|
pHelper->pCompInfo->checksum = 0;
|
||||||
ASSERT((pIdx->len - sizeof(SCompInfo) - sizeof(TSCKSUM)) % sizeof(SCompBlock) == 0);
|
ASSERT(pIdx->len > sizeof(SCompInfo) + sizeof(TSCKSUM) &&
|
||||||
|
(pIdx->len - sizeof(SCompInfo) - sizeof(TSCKSUM)) % sizeof(SCompBlock) == 0);
|
||||||
taosCalcChecksumAppend(0, (uint8_t *)pHelper->pCompInfo, pIdx->len);
|
taosCalcChecksumAppend(0, (uint8_t *)pHelper->pCompInfo, pIdx->len);
|
||||||
offset = lseek(pHelper->files.nHeadF.fd, 0, SEEK_END);
|
offset = lseek(pHelper->files.nHeadF.fd, 0, SEEK_END);
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
|
@ -388,6 +365,7 @@ int tsdbWriteCompInfo(SRWHelper *pHelper) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -397,7 +375,12 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) {
|
||||||
|
|
||||||
ASSERT(helperType(pHelper) == TSDB_WRITE_HELPER);
|
ASSERT(helperType(pHelper) == TSDB_WRITE_HELPER);
|
||||||
off_t offset = lseek(pHelper->files.nHeadF.fd, 0, SEEK_END);
|
off_t offset = lseek(pHelper->files.nHeadF.fd, 0, SEEK_END);
|
||||||
if (offset < 0) return -1;
|
if (offset < 0) {
|
||||||
|
tsdbError("vgId:%d failed to lseek file %s to end since %s", REPO_ID(pHelper->pRepo), pHelper->files.nHeadF.fname,
|
||||||
|
strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SFile *pFile = &(pHelper->files.nHeadF);
|
SFile *pFile = &(pHelper->files.nHeadF);
|
||||||
pFile->info.offset = offset;
|
pFile->info.offset = offset;
|
||||||
|
@ -409,6 +392,10 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) {
|
||||||
int drift = POINTER_DISTANCE(buf, pHelper->pBuffer);
|
int drift = POINTER_DISTANCE(buf, pHelper->pBuffer);
|
||||||
if (tsizeof(pHelper->pBuffer) - drift < 128) {
|
if (tsizeof(pHelper->pBuffer) - drift < 128) {
|
||||||
pHelper->pBuffer = trealloc(pHelper->pBuffer, tsizeof(pHelper->pBuffer) * 2);
|
pHelper->pBuffer = trealloc(pHelper->pBuffer, tsizeof(pHelper->pBuffer) * 2);
|
||||||
|
if (pHelper->pBuffer == NULL) {
|
||||||
|
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buf = POINTER_SHIFT(pHelper->pBuffer, drift);
|
buf = POINTER_SHIFT(pHelper->pBuffer, drift);
|
||||||
taosEncodeVariantU32(&buf, i);
|
taosEncodeVariantU32(&buf, i);
|
||||||
|
@ -419,7 +406,12 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) {
|
||||||
int tsize = (char *)buf - (char *)pHelper->pBuffer + sizeof(TSCKSUM);
|
int tsize = (char *)buf - (char *)pHelper->pBuffer + sizeof(TSCKSUM);
|
||||||
taosCalcChecksumAppend(0, (uint8_t *)pHelper->pBuffer, tsize);
|
taosCalcChecksumAppend(0, (uint8_t *)pHelper->pBuffer, tsize);
|
||||||
|
|
||||||
if (twrite(pHelper->files.nHeadF.fd, (void *)pHelper->pBuffer, tsize) < tsize) return -1;
|
if (twrite(pHelper->files.nHeadF.fd, (void *)pHelper->pBuffer, tsize) < tsize) {
|
||||||
|
tsdbError("vgId:%d failed to write %d bytes to file %s since %s", REPO_ID(pHelper->pRepo), tsize,
|
||||||
|
pHelper->files.nHeadF.fname, strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
pFile->info.len = tsize;
|
pFile->info.len = tsize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -496,11 +488,29 @@ int tsdbLoadCompInfo(SRWHelper *pHelper, void *target) {
|
||||||
|
|
||||||
if (!helperHasState(pHelper, TSDB_HELPER_INFO_LOAD)) {
|
if (!helperHasState(pHelper, TSDB_HELPER_INFO_LOAD)) {
|
||||||
if (pIdx->offset > 0) {
|
if (pIdx->offset > 0) {
|
||||||
if (lseek(fd, pIdx->offset, SEEK_SET) < 0) return -1;
|
ASSERT(pIdx->uid == pHelper->tableInfo.uid);
|
||||||
|
if (lseek(fd, pIdx->offset, SEEK_SET) < 0) {
|
||||||
|
tsdbError("vgId:%d failed to lseek file %s since %s", REPO_ID(pHelper->pRepo), pHelper->files.headF.fname,
|
||||||
|
strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
pHelper->pCompInfo = trealloc((void *)pHelper->pCompInfo, pIdx->len);
|
pHelper->pCompInfo = trealloc((void *)pHelper->pCompInfo, pIdx->len);
|
||||||
if (tread(fd, (void *)(pHelper->pCompInfo), pIdx->len) < pIdx->len) return -1;
|
if (tread(fd, (void *)(pHelper->pCompInfo), pIdx->len) < pIdx->len) {
|
||||||
if (!taosCheckChecksumWhole((uint8_t *)pHelper->pCompInfo, pIdx->len)) return -1;
|
tsdbError("vgId:%d failed to read %d bytes from file %s since %s", REPO_ID(pHelper->pRepo), pIdx->len,
|
||||||
|
pHelper->files.headF.fname, strerror(errno));
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!taosCheckChecksumWhole((uint8_t *)pHelper->pCompInfo, pIdx->len)) {
|
||||||
|
tsdbError("vgId:%d file %s SCompInfo part is corrupted, tid %d uid %" PRIu64, REPO_ID(pHelper->pRepo),
|
||||||
|
pHelper->files.headF.fname, pHelper->tableInfo.tid, pHelper->tableInfo.uid);
|
||||||
|
terrno = TSDB_CODE_TDB_FILE_CORRUPTED;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(pIdx->uid == pHelper->pCompInfo->uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
helperSetState(pHelper, TSDB_HELPER_INFO_LOAD);
|
helperSetState(pHelper, TSDB_HELPER_INFO_LOAD);
|
||||||
|
@ -628,13 +638,14 @@ static bool tsdbShouldCreateNewLast(SRWHelper *pHelper) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, int rowsToWrite,
|
static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, SCompBlock *pCompBlock,
|
||||||
SCompBlock *pCompBlock, bool isLast, bool isSuperBlock) {
|
bool isLast, bool isSuperBlock) {
|
||||||
STsdbCfg * pCfg = &(pHelper->pRepo->config);
|
STsdbCfg * pCfg = &(pHelper->pRepo->config);
|
||||||
SCompData *pCompData = (SCompData *)(pHelper->pBuffer);
|
SCompData *pCompData = (SCompData *)(pHelper->pBuffer);
|
||||||
int64_t offset = 0;
|
int64_t offset = 0;
|
||||||
|
int rowsToWrite = pDataCols->numOfRows;
|
||||||
|
|
||||||
ASSERT(rowsToWrite > 0 && rowsToWrite <= pDataCols->numOfRows && rowsToWrite <= pCfg->maxRowsPerFileBlock);
|
ASSERT(rowsToWrite > 0 && rowsToWrite <= pCfg->maxRowsPerFileBlock);
|
||||||
ASSERT(isLast ? rowsToWrite < pCfg->minRowsPerFileBlock : true);
|
ASSERT(isLast ? rowsToWrite < pCfg->minRowsPerFileBlock : true);
|
||||||
|
|
||||||
offset = lseek(pFile->fd, 0, SEEK_END);
|
offset = lseek(pFile->fd, 0, SEEK_END);
|
||||||
|
@ -646,7 +657,7 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa
|
||||||
}
|
}
|
||||||
|
|
||||||
int nColsNotAllNull = 0;
|
int nColsNotAllNull = 0;
|
||||||
for (int ncol = 0; ncol < pDataCols->numOfCols; ncol++) {
|
for (int ncol = 1; ncol < pDataCols->numOfCols; ncol++) { // ncol from 1, we skip the timestamp column
|
||||||
SDataCol *pDataCol = pDataCols->cols + ncol;
|
SDataCol *pDataCol = pDataCols->cols + ncol;
|
||||||
SCompCol *pCompCol = pCompData->cols + nColsNotAllNull;
|
SCompCol *pCompCol = pCompData->cols + nColsNotAllNull;
|
||||||
|
|
||||||
|
@ -658,7 +669,7 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa
|
||||||
|
|
||||||
pCompCol->colId = pDataCol->colId;
|
pCompCol->colId = pDataCol->colId;
|
||||||
pCompCol->type = pDataCol->type;
|
pCompCol->type = pDataCol->type;
|
||||||
if (tDataTypeDesc[pDataCol->type].getStatisFunc && ncol != 0) {
|
if (tDataTypeDesc[pDataCol->type].getStatisFunc) {
|
||||||
(*tDataTypeDesc[pDataCol->type].getStatisFunc)(
|
(*tDataTypeDesc[pDataCol->type].getStatisFunc)(
|
||||||
(TSKEY *)(pDataCols->cols[0].pData), pDataCol->pData, rowsToWrite, &(pCompCol->min), &(pCompCol->max),
|
(TSKEY *)(pDataCols->cols[0].pData), pDataCol->pData, rowsToWrite, &(pCompCol->min), &(pCompCol->max),
|
||||||
&(pCompCol->sum), &(pCompCol->minIndex), &(pCompCol->maxIndex), &(pCompCol->numOfNull));
|
&(pCompCol->sum), &(pCompCol->minIndex), &(pCompCol->maxIndex), &(pCompCol->numOfNull));
|
||||||
|
@ -666,24 +677,24 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa
|
||||||
nColsNotAllNull++;
|
nColsNotAllNull++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(nColsNotAllNull > 0 && nColsNotAllNull <= pDataCols->numOfCols);
|
ASSERT(nColsNotAllNull >= 0 && nColsNotAllNull <= pDataCols->numOfCols);
|
||||||
|
|
||||||
// Compress the data if neccessary
|
// Compress the data if neccessary
|
||||||
int tcol = 0;
|
int tcol = 0;
|
||||||
int32_t toffset = 0;
|
int32_t toffset = 0;
|
||||||
int32_t tsize = TSDB_GET_COMPCOL_LEN(nColsNotAllNull);
|
int32_t tsize = TSDB_GET_COMPCOL_LEN(nColsNotAllNull);
|
||||||
int32_t lsize = tsize;
|
int32_t lsize = tsize;
|
||||||
|
int32_t keyLen = 0;
|
||||||
for (int ncol = 0; ncol < pDataCols->numOfCols; ncol++) {
|
for (int ncol = 0; ncol < pDataCols->numOfCols; ncol++) {
|
||||||
if (tcol >= nColsNotAllNull) break;
|
if (tcol >= nColsNotAllNull) break;
|
||||||
|
|
||||||
SDataCol *pDataCol = pDataCols->cols + ncol;
|
SDataCol *pDataCol = pDataCols->cols + ncol;
|
||||||
SCompCol *pCompCol = pCompData->cols + tcol;
|
SCompCol *pCompCol = pCompData->cols + tcol;
|
||||||
|
|
||||||
if (pDataCol->colId != pCompCol->colId) continue;
|
if (ncol != 0 && (pDataCol->colId != pCompCol->colId)) continue;
|
||||||
void *tptr = (void *)((char *)pCompData + lsize);
|
void *tptr = POINTER_SHIFT(pCompData, lsize);
|
||||||
|
|
||||||
pCompCol->offset = toffset;
|
|
||||||
|
|
||||||
|
int32_t flen = 0; // final length
|
||||||
int32_t tlen = dataColGetNEleLen(pDataCol, rowsToWrite);
|
int32_t tlen = dataColGetNEleLen(pDataCol, rowsToWrite);
|
||||||
|
|
||||||
if (pCfg->compression) {
|
if (pCfg->compression) {
|
||||||
|
@ -695,22 +706,29 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pCompCol->len = (*(tDataTypeDesc[pDataCol->type].compFunc))((char *)pDataCol->pData, tlen, rowsToWrite, tptr,
|
flen = (*(tDataTypeDesc[pDataCol->type].compFunc))((char *)pDataCol->pData, tlen, rowsToWrite, tptr,
|
||||||
tsizeof(pHelper->pBuffer) - lsize, pCfg->compression,
|
tsizeof(pHelper->pBuffer) - lsize, pCfg->compression,
|
||||||
pHelper->compBuffer, tsizeof(pHelper->compBuffer));
|
pHelper->compBuffer, tsizeof(pHelper->compBuffer));
|
||||||
} else {
|
} else {
|
||||||
pCompCol->len = tlen;
|
flen = tlen;
|
||||||
memcpy(tptr, pDataCol->pData, pCompCol->len);
|
memcpy(tptr, pDataCol->pData, flen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add checksum
|
// Add checksum
|
||||||
ASSERT(pCompCol->len > 0);
|
ASSERT(flen > 0);
|
||||||
pCompCol->len += sizeof(TSCKSUM);
|
flen += sizeof(TSCKSUM);
|
||||||
taosCalcChecksumAppend(0, (uint8_t *)tptr, pCompCol->len);
|
taosCalcChecksumAppend(0, (uint8_t *)tptr, flen);
|
||||||
|
|
||||||
toffset += pCompCol->len;
|
if (ncol != 0) {
|
||||||
lsize += pCompCol->len;
|
pCompCol->offset = toffset;
|
||||||
|
pCompCol->len = flen;
|
||||||
tcol++;
|
tcol++;
|
||||||
|
} else {
|
||||||
|
keyLen = flen;
|
||||||
|
}
|
||||||
|
|
||||||
|
toffset += flen;
|
||||||
|
lsize += flen;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCompData->delimiter = TSDB_FILE_DELIMITER;
|
pCompData->delimiter = TSDB_FILE_DELIMITER;
|
||||||
|
@ -732,14 +750,14 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa
|
||||||
pCompBlock->offset = offset;
|
pCompBlock->offset = offset;
|
||||||
pCompBlock->algorithm = pCfg->compression;
|
pCompBlock->algorithm = pCfg->compression;
|
||||||
pCompBlock->numOfRows = rowsToWrite;
|
pCompBlock->numOfRows = rowsToWrite;
|
||||||
pCompBlock->sversion = pHelper->tableInfo.sversion;
|
pCompBlock->len = lsize;
|
||||||
pCompBlock->len = (int32_t)lsize;
|
pCompBlock->keyLen = keyLen;
|
||||||
pCompBlock->numOfSubBlocks = isSuperBlock ? 1 : 0;
|
pCompBlock->numOfSubBlocks = isSuperBlock ? 1 : 0;
|
||||||
pCompBlock->numOfCols = nColsNotAllNull;
|
pCompBlock->numOfCols = nColsNotAllNull;
|
||||||
pCompBlock->keyFirst = dataColsKeyFirst(pDataCols);
|
pCompBlock->keyFirst = dataColsKeyFirst(pDataCols);
|
||||||
pCompBlock->keyLast = dataColsKeyAt(pDataCols, rowsToWrite - 1);
|
pCompBlock->keyLast = dataColsKeyAt(pDataCols, rowsToWrite - 1);
|
||||||
|
|
||||||
tsdbTrace("vgId:%d tid:%d a block of data is written to file %s, offset %" PRId64
|
tsdbDebug("vgId:%d tid:%d a block of data is written to file %s, offset %" PRId64
|
||||||
" numOfRows %d len %d numOfCols %" PRId16 " keyFirst %" PRId64 " keyLast %" PRId64,
|
" numOfRows %d len %d numOfCols %" PRId16 " keyFirst %" PRId64 " keyLast %" PRId64,
|
||||||
REPO_ID(helperRepo(pHelper)), pHelper->tableInfo.tid, pFile->fname, (int64_t)(pCompBlock->offset),
|
REPO_ID(helperRepo(pHelper)), pHelper->tableInfo.tid, pFile->fname, (int64_t)(pCompBlock->offset),
|
||||||
(int)(pCompBlock->numOfRows), pCompBlock->len, pCompBlock->numOfCols, pCompBlock->keyFirst,
|
(int)(pCompBlock->numOfRows), pCompBlock->len, pCompBlock->numOfCols, pCompBlock->keyFirst,
|
||||||
|
@ -764,136 +782,6 @@ static int compareKeyBlock(const void *arg1, const void *arg2) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDataCols) {
|
|
||||||
// TODO: set pHelper->hasOldBlock
|
|
||||||
int rowsWritten = 0;
|
|
||||||
SCompBlock compBlock = {0};
|
|
||||||
STsdbCfg * pCfg = &pHelper->pRepo->config;
|
|
||||||
|
|
||||||
ASSERT(pDataCols->numOfRows > 0);
|
|
||||||
TSKEY keyFirst = dataColsKeyFirst(pDataCols);
|
|
||||||
|
|
||||||
SCompIdx *pIdx = pHelper->pCompIdx + pHelper->tableInfo.tid;
|
|
||||||
ASSERT(blkIdx < pIdx->numOfBlocks);
|
|
||||||
|
|
||||||
// SCompBlock *pCompBlock = pHelper->pCompInfo->blocks + blkIdx;
|
|
||||||
ASSERT(blockAtIdx(pHelper, blkIdx)->numOfSubBlocks >= 1);
|
|
||||||
ASSERT(keyFirst >= blockAtIdx(pHelper, blkIdx)->keyFirst);
|
|
||||||
// ASSERT(compareKeyBlock((void *)&keyFirst, (void *)pCompBlock) == 0);
|
|
||||||
|
|
||||||
if (keyFirst > blockAtIdx(pHelper, blkIdx)->keyLast) { // Merge with the last block by append
|
|
||||||
ASSERT(blockAtIdx(pHelper, blkIdx)->numOfRows < pCfg->minRowsPerFileBlock && blkIdx == pIdx->numOfBlocks - 1);
|
|
||||||
int defaultRowsToWrite = pCfg->maxRowsPerFileBlock * 4 / 5; // TODO: make a interface
|
|
||||||
|
|
||||||
rowsWritten = MIN((defaultRowsToWrite - blockAtIdx(pHelper, blkIdx)->numOfRows), pDataCols->numOfRows);
|
|
||||||
if ((blockAtIdx(pHelper, blkIdx)->numOfSubBlocks < TSDB_MAX_SUBBLOCKS) &&
|
|
||||||
(blockAtIdx(pHelper, blkIdx)->numOfRows + rowsWritten < pCfg->minRowsPerFileBlock) &&
|
|
||||||
(pHelper->files.nLastF.fd) < 0) {
|
|
||||||
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.lastF), pDataCols, rowsWritten, &compBlock, true, false) < 0)
|
|
||||||
goto _err;
|
|
||||||
if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err;
|
|
||||||
} else {
|
|
||||||
// Load
|
|
||||||
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err;
|
|
||||||
ASSERT(pHelper->pDataCols[0]->numOfRows <= blockAtIdx(pHelper, blkIdx)->numOfRows);
|
|
||||||
// Merge
|
|
||||||
if (tdMergeDataCols(pHelper->pDataCols[0], pDataCols, rowsWritten) < 0) goto _err;
|
|
||||||
// Write
|
|
||||||
SFile *pWFile = NULL;
|
|
||||||
bool isLast = false;
|
|
||||||
if (pHelper->pDataCols[0]->numOfRows >= pCfg->minRowsPerFileBlock) {
|
|
||||||
pWFile = &(pHelper->files.dataF);
|
|
||||||
} else {
|
|
||||||
isLast = true;
|
|
||||||
pWFile = (pHelper->files.nLastF.fd > 0) ? &(pHelper->files.nLastF) : &(pHelper->files.lastF);
|
|
||||||
}
|
|
||||||
if (tsdbWriteBlockToFile(pHelper, pWFile, pHelper->pDataCols[0], pHelper->pDataCols[0]->numOfRows, &compBlock,
|
|
||||||
isLast, true) < 0)
|
|
||||||
goto _err;
|
|
||||||
if (tsdbUpdateSuperBlock(pHelper, &compBlock, blkIdx) < 0) goto _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(pHelper->hasOldLastBlock);
|
|
||||||
pHelper->hasOldLastBlock = false;
|
|
||||||
} else {
|
|
||||||
// Key must overlap with the block
|
|
||||||
ASSERT(keyFirst <= blockAtIdx(pHelper, blkIdx)->keyLast);
|
|
||||||
|
|
||||||
TSKEY keyLimit = (blkIdx == pIdx->numOfBlocks - 1) ? INT64_MAX : blockAtIdx(pHelper, blkIdx + 1)->keyFirst - 1;
|
|
||||||
|
|
||||||
// rows1: number of rows must merge in this block
|
|
||||||
int rows1 =
|
|
||||||
tsdbGetRowsInRange(pDataCols, blockAtIdx(pHelper, blkIdx)->keyFirst, blockAtIdx(pHelper, blkIdx)->keyLast);
|
|
||||||
// rows2: max number of rows the block can have more
|
|
||||||
int rows2 = pCfg->maxRowsPerFileBlock - blockAtIdx(pHelper, blkIdx)->numOfRows;
|
|
||||||
// rows3: number of rows between this block and the next block
|
|
||||||
int rows3 = tsdbGetRowsInRange(pDataCols, blockAtIdx(pHelper, blkIdx)->keyFirst, keyLimit);
|
|
||||||
|
|
||||||
ASSERT(rows3 >= rows1);
|
|
||||||
|
|
||||||
if ((rows2 >= rows1) && (blockAtIdx(pHelper, blkIdx)->numOfSubBlocks < TSDB_MAX_SUBBLOCKS) &&
|
|
||||||
((!blockAtIdx(pHelper, blkIdx)->last) ||
|
|
||||||
((rows1 + blockAtIdx(pHelper, blkIdx)->numOfRows < pCfg->minRowsPerFileBlock) &&
|
|
||||||
(pHelper->files.nLastF.fd < 0)))) {
|
|
||||||
rowsWritten = rows1;
|
|
||||||
bool isLast = false;
|
|
||||||
SFile *pFile = NULL;
|
|
||||||
|
|
||||||
if (blockAtIdx(pHelper, blkIdx)->last) {
|
|
||||||
isLast = true;
|
|
||||||
pFile = &(pHelper->files.lastF);
|
|
||||||
} else {
|
|
||||||
pFile = &(pHelper->files.dataF);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tsdbWriteBlockToFile(pHelper, pFile, pDataCols, rows1, &compBlock, isLast, false) < 0) goto _err;
|
|
||||||
if (tsdbAddSubBlock(pHelper, &compBlock, blkIdx, rowsWritten) < 0) goto _err;
|
|
||||||
} else { // Load-Merge-Write
|
|
||||||
// Load
|
|
||||||
if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, blkIdx), NULL) < 0) goto _err;
|
|
||||||
if (blockAtIdx(pHelper, blkIdx)->last) pHelper->hasOldLastBlock = false;
|
|
||||||
|
|
||||||
rowsWritten = rows3;
|
|
||||||
|
|
||||||
int iter1 = 0; // iter over pHelper->pDataCols[0]
|
|
||||||
int iter2 = 0; // iter over pDataCols
|
|
||||||
int round = 0;
|
|
||||||
// tdResetDataCols(pHelper->pDataCols[1]);
|
|
||||||
while (true) {
|
|
||||||
if (iter1 >= pHelper->pDataCols[0]->numOfRows && iter2 >= rows3) break;
|
|
||||||
tdMergeTwoDataCols(pHelper->pDataCols[1], pHelper->pDataCols[0], &iter1, pHelper->pDataCols[0]->numOfRows,
|
|
||||||
pDataCols, &iter2, rowsWritten, pCfg->maxRowsPerFileBlock * 4 / 5);
|
|
||||||
ASSERT(pHelper->pDataCols[1]->numOfRows > 0);
|
|
||||||
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.dataF), pHelper->pDataCols[1],
|
|
||||||
pHelper->pDataCols[1]->numOfRows, &compBlock, false, true) < 0)
|
|
||||||
goto _err;
|
|
||||||
if (round == 0) {
|
|
||||||
tsdbUpdateSuperBlock(pHelper, &compBlock, blkIdx);
|
|
||||||
} else {
|
|
||||||
tsdbInsertSuperBlock(pHelper, &compBlock, blkIdx);
|
|
||||||
}
|
|
||||||
round++;
|
|
||||||
blkIdx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rowsWritten;
|
|
||||||
|
|
||||||
_err:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int compTSKEY(const void *key1, const void *key2) {
|
|
||||||
if (*(TSKEY *)key1 > *(TSKEY *)key2) {
|
|
||||||
return 1;
|
|
||||||
} else if (*(TSKEY *)key1 == *(TSKEY *)key2) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t esize) {
|
static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t esize) {
|
||||||
if (tsizeof((void *)pHelper->pCompInfo) <= esize) {
|
if (tsizeof((void *)pHelper->pCompInfo) <= esize) {
|
||||||
size_t tsize = esize + sizeof(SCompBlock) * 16;
|
size_t tsize = esize + sizeof(SCompBlock) * 16;
|
||||||
|
@ -911,7 +799,7 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
||||||
ASSERT(pCompBlock->numOfSubBlocks == 1);
|
ASSERT(pCompBlock->numOfSubBlocks == 1);
|
||||||
|
|
||||||
// Adjust memory if no more room
|
// Adjust memory if no more room
|
||||||
if (pIdx->len == 0) pIdx->len = sizeof(SCompData) + sizeof(TSCKSUM);
|
if (pIdx->len == 0) pIdx->len = sizeof(SCompInfo) + sizeof(TSCKSUM);
|
||||||
if (tsdbAdjustInfoSizeIfNeeded(pHelper, pIdx->len + sizeof(SCompInfo)) < 0) goto _err;
|
if (tsdbAdjustInfoSizeIfNeeded(pHelper, pIdx->len + sizeof(SCompInfo)) < 0) goto _err;
|
||||||
|
|
||||||
// Change the offset
|
// Change the offset
|
||||||
|
@ -925,22 +813,22 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
||||||
if (tsize > 0) {
|
if (tsize > 0) {
|
||||||
ASSERT(sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1) < tsizeof(pHelper->pCompInfo));
|
ASSERT(sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1) < tsizeof(pHelper->pCompInfo));
|
||||||
ASSERT(sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1) + tsize <= tsizeof(pHelper->pCompInfo));
|
ASSERT(sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1) + tsize <= tsizeof(pHelper->pCompInfo));
|
||||||
memmove((void *)((char *)pHelper->pCompInfo + sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1)),
|
memmove(POINTER_SHIFT(pHelper->pCompInfo, sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1)),
|
||||||
(void *)((char *)pHelper->pCompInfo + sizeof(SCompInfo) + sizeof(SCompBlock) * blkIdx), tsize);
|
POINTER_SHIFT(pHelper->pCompInfo, sizeof(SCompInfo) + sizeof(SCompBlock) * blkIdx), tsize);
|
||||||
}
|
}
|
||||||
pHelper->pCompInfo->blocks[blkIdx] = *pCompBlock;
|
pHelper->pCompInfo->blocks[blkIdx] = *pCompBlock;
|
||||||
|
|
||||||
pIdx->numOfBlocks++;
|
pIdx->numOfBlocks++;
|
||||||
pIdx->len += sizeof(SCompBlock);
|
pIdx->len += sizeof(SCompBlock);
|
||||||
ASSERT(pIdx->len <= tsizeof(pHelper->pCompInfo));
|
ASSERT(pIdx->len <= tsizeof(pHelper->pCompInfo));
|
||||||
pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].keyLast;
|
pIdx->maxKey = blockAtIdx(pHelper, pIdx->numOfBlocks - 1)->keyLast;
|
||||||
pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].last;
|
pIdx->hasLast = blockAtIdx(pHelper, pIdx->numOfBlocks - 1)->last;
|
||||||
|
|
||||||
if (pIdx->numOfBlocks > 1) {
|
if (pIdx->numOfBlocks > 1) {
|
||||||
ASSERT(pHelper->pCompInfo->blocks[0].keyLast < pHelper->pCompInfo->blocks[1].keyFirst);
|
ASSERT(pHelper->pCompInfo->blocks[0].keyLast < pHelper->pCompInfo->blocks[1].keyFirst);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbTrace("vgId:%d tid:%d a super block is inserted at index %d", REPO_ID(pHelper->pRepo), pHelper->tableInfo.tid,
|
tsdbDebug("vgId:%d tid:%d a super block is inserted at index %d", REPO_ID(pHelper->pRepo), pHelper->tableInfo.tid,
|
||||||
blkIdx);
|
blkIdx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1048,8 +936,8 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
||||||
if (pSCompBlock->numOfSubBlocks > 1) {
|
if (pSCompBlock->numOfSubBlocks > 1) {
|
||||||
size_t tsize = pIdx->len - (pSCompBlock->offset + pSCompBlock->len);
|
size_t tsize = pIdx->len - (pSCompBlock->offset + pSCompBlock->len);
|
||||||
if (tsize > 0) {
|
if (tsize > 0) {
|
||||||
memmove((void *)((char *)(pHelper->pCompInfo) + pSCompBlock->offset),
|
memmove(POINTER_SHIFT(pHelper->pCompInfo, pSCompBlock->offset),
|
||||||
(void *)((char *)(pHelper->pCompInfo) + pSCompBlock->offset + pSCompBlock->len), tsize);
|
POINTER_SHIFT(pHelper->pCompInfo, pSCompBlock->offset + pSCompBlock->len), tsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) {
|
for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) {
|
||||||
|
@ -1062,8 +950,8 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
||||||
|
|
||||||
*pSCompBlock = *pCompBlock;
|
*pSCompBlock = *pCompBlock;
|
||||||
|
|
||||||
pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].keyLast;
|
pIdx->maxKey = blockAtIdx(pHelper, pIdx->numOfBlocks - 1)->keyLast;
|
||||||
pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].last;
|
pIdx->hasLast = blockAtIdx(pHelper, pIdx->numOfBlocks - 1)->last;
|
||||||
|
|
||||||
tsdbDebug("vgId:%d tid:%d a super block is updated at index %d", REPO_ID(pHelper->pRepo), pHelper->tableInfo.tid,
|
tsdbDebug("vgId:%d tid:%d a super block is updated at index %d", REPO_ID(pHelper->pRepo), pHelper->tableInfo.tid,
|
||||||
blkIdx);
|
blkIdx);
|
||||||
|
@ -1071,30 +959,6 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the number of rows in range [minKey, maxKey]
|
|
||||||
static int tsdbGetRowsInRange(SDataCols *pDataCols, TSKEY minKey, TSKEY maxKey) {
|
|
||||||
if (pDataCols->numOfRows == 0) return 0;
|
|
||||||
|
|
||||||
ASSERT(minKey <= maxKey);
|
|
||||||
TSKEY keyFirst = dataColsKeyFirst(pDataCols);
|
|
||||||
TSKEY keyLast = dataColsKeyLast(pDataCols);
|
|
||||||
ASSERT(keyFirst <= keyLast);
|
|
||||||
|
|
||||||
if (minKey > keyLast || maxKey < keyFirst) return 0;
|
|
||||||
|
|
||||||
void *ptr1 = taosbsearch((void *)&minKey, (void *)pDataCols->cols[0].pData, pDataCols->numOfRows, sizeof(TSKEY),
|
|
||||||
compTSKEY, TD_GE);
|
|
||||||
ASSERT(ptr1 != NULL);
|
|
||||||
|
|
||||||
void *ptr2 = taosbsearch((void *)&maxKey, (void *)pDataCols->cols[0].pData, pDataCols->numOfRows, sizeof(TSKEY),
|
|
||||||
compTSKEY, TD_LE);
|
|
||||||
ASSERT(ptr2 != NULL);
|
|
||||||
|
|
||||||
if ((TSKEY *)ptr2 - (TSKEY *)ptr1 < 0) return 0;
|
|
||||||
|
|
||||||
return ((TSKEY *)ptr2 - (TSKEY *)ptr1) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tsdbResetHelperFileImpl(SRWHelper *pHelper) {
|
static void tsdbResetHelperFileImpl(SRWHelper *pHelper) {
|
||||||
memset((void *)&pHelper->files, 0, sizeof(pHelper->files));
|
memset((void *)&pHelper->files, 0, sizeof(pHelper->files));
|
||||||
pHelper->files.fid = -1;
|
pHelper->files.fid = -1;
|
||||||
|
@ -1250,7 +1114,8 @@ static int tsdbLoadColData(SRWHelper *pHelper, SFile *pFile, SCompBlock *pCompBl
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lseek(pFile->fd, pCompCol->offset, SEEK_SET) < 0) {
|
int64_t offset = pCompBlock->offset + TSDB_GET_COMPCOL_LEN(pCompBlock->numOfCols) + pCompCol->offset;
|
||||||
|
if (lseek(pFile->fd, offset, SEEK_SET) < 0) {
|
||||||
tsdbError("vgId:%d failed to lseek file %s since %s", REPO_ID(pHelper->pRepo), pFile->fname, strerror(errno));
|
tsdbError("vgId:%d failed to lseek file %s since %s", REPO_ID(pHelper->pRepo), pFile->fname, strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1276,10 +1141,15 @@ static int tsdbLoadColData(SRWHelper *pHelper, SFile *pFile, SCompBlock *pCompBl
|
||||||
|
|
||||||
static int tsdbLoadBlockDataColsImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols, int16_t *colIds, int numOfColIds) {
|
static int tsdbLoadBlockDataColsImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols, int16_t *colIds, int numOfColIds) {
|
||||||
ASSERT(pCompBlock->numOfSubBlocks <= 1);
|
ASSERT(pCompBlock->numOfSubBlocks <= 1);
|
||||||
|
ASSERT(colIds[0] == 0);
|
||||||
|
|
||||||
SFile * pFile = (pCompBlock->last) ? &(pHelper->files.lastF) : &(pHelper->files.dataF);
|
SFile * pFile = (pCompBlock->last) ? &(pHelper->files.lastF) : &(pHelper->files.dataF);
|
||||||
|
SCompCol compCol = {0};
|
||||||
|
|
||||||
if (tsdbLoadCompData(pHelper, pCompBlock, NULL) < 0) goto _err;
|
// If only load timestamp column, no need to load SCompData part
|
||||||
|
if (numOfColIds > 1 && tsdbLoadCompData(pHelper, pCompBlock, NULL) < 0) goto _err;
|
||||||
|
|
||||||
|
pDataCols->numOfRows = pCompBlock->numOfRows;
|
||||||
|
|
||||||
int dcol = 0;
|
int dcol = 0;
|
||||||
int ccol = 0;
|
int ccol = 0;
|
||||||
|
@ -1298,6 +1168,13 @@ static int tsdbLoadBlockDataColsImpl(SRWHelper *pHelper, SCompBlock *pCompBlock,
|
||||||
|
|
||||||
ASSERT(pDataCol->colId == colId);
|
ASSERT(pDataCol->colId == colId);
|
||||||
|
|
||||||
|
if (colId == 0) { // load the key row
|
||||||
|
compCol.colId = colId;
|
||||||
|
compCol.len = pCompBlock->keyLen;
|
||||||
|
compCol.type = pDataCol->type;
|
||||||
|
compCol.offset = TSDB_KEY_COL_OFFSET;
|
||||||
|
pCompCol = &compCol;
|
||||||
|
} else { // load non-key rows
|
||||||
while (ccol < pCompBlock->numOfCols) {
|
while (ccol < pCompBlock->numOfCols) {
|
||||||
pCompCol = &pHelper->pCompData->cols[ccol];
|
pCompCol = &pHelper->pCompData->cols[ccol];
|
||||||
if (pCompCol->colId >= colId) break;
|
if (pCompCol->colId >= colId) break;
|
||||||
|
@ -1311,10 +1188,11 @@ static int tsdbLoadBlockDataColsImpl(SRWHelper *pHelper, SCompBlock *pCompBlock,
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pCompCol->colId == pDataCol->colId);
|
ASSERT(pCompCol->colId == pDataCol->colId);
|
||||||
|
}
|
||||||
|
|
||||||
if (tsdbLoadColData(pHelper, pFile, pCompBlock, pCompCol, pDataCol) < 0) goto _err;
|
if (tsdbLoadColData(pHelper, pFile, pCompBlock, pCompCol, pDataCol) < 0) goto _err;
|
||||||
dcol++;
|
dcol++;
|
||||||
ccol++;
|
if (colId != 0) ccol++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1362,8 +1240,8 @@ static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDa
|
||||||
pDataCols->numOfRows = pCompBlock->numOfRows;
|
pDataCols->numOfRows = pCompBlock->numOfRows;
|
||||||
|
|
||||||
// Recover the data
|
// Recover the data
|
||||||
int ccol = 0;
|
int ccol = 0; // loop iter for SCompCol object
|
||||||
int dcol = 0;
|
int dcol = 0; // loop iter for SDataCols object
|
||||||
while (dcol < pDataCols->numOfCols) {
|
while (dcol < pDataCols->numOfCols) {
|
||||||
SDataCol *pDataCol = &(pDataCols->cols[dcol]);
|
SDataCol *pDataCol = &(pDataCols->cols[dcol]);
|
||||||
if (ccol >= pCompData->numOfCols) {
|
if (ccol >= pCompData->numOfCols) {
|
||||||
|
@ -1373,12 +1251,23 @@ static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDa
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCompCol *pCompCol = &(pCompData->cols[ccol]);
|
int16_t tcolId = 0;
|
||||||
|
int32_t toffset = TSDB_KEY_COL_OFFSET;
|
||||||
|
int32_t tlen = pCompBlock->keyLen;
|
||||||
|
|
||||||
if (pCompCol->colId == pDataCol->colId) {
|
if (dcol != 0) {
|
||||||
|
SCompCol *pCompCol = &(pCompData->cols[ccol]);
|
||||||
|
tcolId = pCompCol->colId;
|
||||||
|
toffset = pCompCol->offset;
|
||||||
|
tlen = pCompCol->len;
|
||||||
|
} else {
|
||||||
|
ASSERT(pDataCol->colId == tcolId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tcolId == pDataCol->colId) {
|
||||||
if (pCompBlock->algorithm == TWO_STAGE_COMP) {
|
if (pCompBlock->algorithm == TWO_STAGE_COMP) {
|
||||||
int zsize = pDataCol->bytes * pCompBlock->numOfRows + COMP_OVERFLOW_BYTES;
|
int zsize = pDataCol->bytes * pCompBlock->numOfRows + COMP_OVERFLOW_BYTES;
|
||||||
if (pCompCol->type == TSDB_DATA_TYPE_BINARY || pCompCol->type == TSDB_DATA_TYPE_NCHAR) {
|
if (pDataCol->type == TSDB_DATA_TYPE_BINARY || pDataCol->type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
zsize += (sizeof(VarDataLenT) * pCompBlock->numOfRows);
|
zsize += (sizeof(VarDataLenT) * pCompBlock->numOfRows);
|
||||||
}
|
}
|
||||||
pHelper->compBuffer = trealloc(pHelper->compBuffer, zsize);
|
pHelper->compBuffer = trealloc(pHelper->compBuffer, zsize);
|
||||||
|
@ -1387,16 +1276,16 @@ static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDa
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tsdbCheckAndDecodeColumnData(pDataCol, (char *)pCompData + tsize + pCompCol->offset, pCompCol->len,
|
if (tsdbCheckAndDecodeColumnData(pDataCol, (char *)pCompData + tsize + toffset, tlen, pCompBlock->algorithm,
|
||||||
pCompBlock->algorithm, pCompBlock->numOfRows, pDataCols->maxPoints,
|
pCompBlock->numOfRows, pDataCols->maxPoints, pHelper->compBuffer,
|
||||||
pHelper->compBuffer, tsizeof(pHelper->compBuffer)) < 0) {
|
tsizeof(pHelper->compBuffer)) < 0) {
|
||||||
tsdbError("vgId:%d file %s is broken at column %d offset %" PRId64, REPO_ID(pHelper->pRepo), pFile->fname,
|
tsdbError("vgId:%d file %s is broken at column %d block offset %" PRId64 " column offset %d",
|
||||||
pCompCol->colId, (int64_t)pCompCol->offset);
|
REPO_ID(pHelper->pRepo), pFile->fname, tcolId, (int64_t)pCompBlock->offset, toffset);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
if (dcol != 0) ccol++;
|
||||||
dcol++;
|
dcol++;
|
||||||
ccol++;
|
} else if (tcolId < pDataCol->colId) {
|
||||||
} else if (pCompCol->colId < pDataCol->colId) {
|
|
||||||
ccol++;
|
ccol++;
|
||||||
} else {
|
} else {
|
||||||
// Set current column as NULL and forward
|
// Set current column as NULL and forward
|
||||||
|
@ -1442,3 +1331,250 @@ static void *tsdbDecodeSCompIdx(void *buf, SCompIdx *pIdx) {
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int tsdbProcessAppendCommit(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols *pDataCols, TSKEY maxKey) {
|
||||||
|
STsdbCfg * pCfg = &(pHelper->pRepo->config);
|
||||||
|
STable * pTable = pCommitIter->pTable;
|
||||||
|
SCompIdx * pIdx = pHelper->pCompIdx + TABLE_TID(pTable);
|
||||||
|
TSKEY keyFirst = tsdbNextIterKey(pCommitIter->pIter);
|
||||||
|
int defaultRowsInBlock = pCfg->maxRowsPerFileBlock * 4 / 5;
|
||||||
|
SCompBlock compBlock = {0};
|
||||||
|
|
||||||
|
ASSERT(pIdx->len <= 0 || keyFirst > pIdx->maxKey);
|
||||||
|
if (pIdx->hasLast) { // append to with last block
|
||||||
|
ASSERT(pIdx->len > 0);
|
||||||
|
SCompBlock *pCompBlock = blockAtIdx(pHelper, pIdx->numOfBlocks - 1);
|
||||||
|
ASSERT(pCompBlock->last && pCompBlock->numOfRows < pCfg->minRowsPerFileBlock);
|
||||||
|
tdResetDataCols(pDataCols);
|
||||||
|
int rowsRead = tsdbLoadDataFromCache(pTable, pCommitIter->pIter, maxKey, defaultRowsInBlock - pCompBlock->numOfRows,
|
||||||
|
pDataCols, NULL, 0);
|
||||||
|
ASSERT(rowsRead > 0 && rowsRead == pDataCols->numOfRows);
|
||||||
|
if (rowsRead + pCompBlock->numOfRows < pCfg->minRowsPerFileBlock &&
|
||||||
|
pCompBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS && !TSDB_NLAST_FILE_OPENED(pHelper)) {
|
||||||
|
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.lastF), pDataCols, &compBlock, true, false) < 0) return -1;
|
||||||
|
if (tsdbAddSubBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1, rowsRead) < 0) return -1;
|
||||||
|
} else {
|
||||||
|
if (tsdbLoadBlockData(pHelper, pCompBlock, NULL) < 0) return -1;
|
||||||
|
ASSERT(pHelper->pDataCols[0]->numOfRows == pCompBlock->numOfRows);
|
||||||
|
|
||||||
|
if (tdMergeDataCols(pHelper->pDataCols[0], pDataCols, pDataCols->numOfRows) < 0) return -1;
|
||||||
|
ASSERT(pHelper->pDataCols[0]->numOfRows == pCompBlock->numOfRows + pDataCols->numOfRows);
|
||||||
|
|
||||||
|
if (tsdbWriteBlockToProperFile(pHelper, pHelper->pDataCols[0], &compBlock) < 0) return -1;
|
||||||
|
if (tsdbUpdateSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pHelper->hasOldLastBlock) pHelper->hasOldLastBlock = false;
|
||||||
|
} else {
|
||||||
|
ASSERT(!pHelper->hasOldLastBlock);
|
||||||
|
tdResetDataCols(pDataCols);
|
||||||
|
int rowsRead = tsdbLoadDataFromCache(pTable, pCommitIter->pIter, maxKey, defaultRowsInBlock, pDataCols, NULL, 0);
|
||||||
|
ASSERT(rowsRead > 0 && rowsRead == pDataCols->numOfRows);
|
||||||
|
|
||||||
|
if (tsdbWriteBlockToProperFile(pHelper, pDataCols, &compBlock) < 0) return -1;
|
||||||
|
if (tsdbInsertSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tsdbProcessMergeCommit(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols *pDataCols, TSKEY maxKey,
|
||||||
|
int *blkIdx) {
|
||||||
|
STsdbCfg * pCfg = &(pHelper->pRepo->config);
|
||||||
|
STable * pTable = pCommitIter->pTable;
|
||||||
|
SCompIdx * pIdx = pHelper->pCompIdx + TABLE_TID(pTable);
|
||||||
|
SCompBlock compBlock = {0};
|
||||||
|
TSKEY keyFirst = tsdbNextIterKey(pCommitIter->pIter);
|
||||||
|
int defaultRowsInBlock = pCfg->maxRowsPerFileBlock * 4 / 5;
|
||||||
|
SDataCols *pDataCols0 = pHelper->pDataCols[0];
|
||||||
|
|
||||||
|
SSkipListIterator slIter = {0};
|
||||||
|
|
||||||
|
ASSERT(keyFirst <= pIdx->maxKey);
|
||||||
|
|
||||||
|
SCompBlock *pCompBlock = taosbsearch((void *)(&keyFirst), (void *)blockAtIdx(pHelper, *blkIdx),
|
||||||
|
pIdx->numOfBlocks - *blkIdx, sizeof(SCompBlock), compareKeyBlock, TD_GE);
|
||||||
|
ASSERT(pCompBlock != NULL);
|
||||||
|
int tblkIdx = TSDB_GET_COMPBLOCK_IDX(pHelper, pCompBlock);
|
||||||
|
|
||||||
|
if (pCompBlock->last) {
|
||||||
|
ASSERT(pCompBlock->numOfRows < pCfg->minRowsPerFileBlock && tblkIdx == pIdx->numOfBlocks - 1);
|
||||||
|
int16_t colId = 0;
|
||||||
|
slIter = *(pCommitIter->pIter);
|
||||||
|
if (tsdbLoadBlockDataCols(pHelper, pCompBlock, NULL, &colId, 1) < 0) return -1;
|
||||||
|
ASSERT(pDataCols0->numOfRows == pCompBlock->numOfRows);
|
||||||
|
|
||||||
|
int rows1 = defaultRowsInBlock - pCompBlock->numOfRows;
|
||||||
|
int rows2 =
|
||||||
|
tsdbLoadDataFromCache(pTable, &slIter, maxKey, rows1, NULL, pDataCols0->cols[0].pData, pDataCols0->numOfRows);
|
||||||
|
if (rows2 == 0) { // all data filtered out
|
||||||
|
*(pCommitIter->pIter) = slIter;
|
||||||
|
} else {
|
||||||
|
if (rows1 + rows2 < pCfg->minRowsPerFileBlock && pCompBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS &&
|
||||||
|
!TSDB_NLAST_FILE_OPENED(pHelper)) {
|
||||||
|
tdResetDataCols(pDataCols);
|
||||||
|
int rowsRead = tsdbLoadDataFromCache(pTable, pCommitIter->pIter, maxKey, rows1, pDataCols,
|
||||||
|
pDataCols0->cols[0].pData, pDataCols0->numOfRows);
|
||||||
|
ASSERT(rowsRead == rows2 && rowsRead == pDataCols->numOfRows);
|
||||||
|
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.lastF), pDataCols, &compBlock, true, false) < 0) return -1;
|
||||||
|
if (tsdbAddSubBlock(pHelper, &compBlock, tblkIdx, rowsRead) < 0) return -1;
|
||||||
|
tblkIdx++;
|
||||||
|
} else {
|
||||||
|
if (tsdbLoadBlockData(pHelper, pCompBlock, NULL) < 0) return -1;
|
||||||
|
int round = 0;
|
||||||
|
int dIter = 0;
|
||||||
|
while (true) {
|
||||||
|
tdResetDataCols(pDataCols);
|
||||||
|
int rowsRead =
|
||||||
|
tsdbLoadAndMergeFromCache(pDataCols0, &dIter, pCommitIter, pDataCols, maxKey, defaultRowsInBlock);
|
||||||
|
if (rowsRead == 0) break;
|
||||||
|
|
||||||
|
if (tsdbWriteBlockToProperFile(pHelper, pDataCols, &compBlock) < 0) return -1;
|
||||||
|
if (round == 0) {
|
||||||
|
if (tsdbUpdateSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||||
|
} else {
|
||||||
|
if (tsdbInsertSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tblkIdx++;
|
||||||
|
round++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pHelper->hasOldLastBlock) pHelper->hasOldLastBlock = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TSKEY keyLimit = (tblkIdx == pIdx->numOfBlocks - 1) ? maxKey : (pCompBlock[1].keyFirst - 1);
|
||||||
|
TSKEY blkKeyFirst = pCompBlock->keyFirst;
|
||||||
|
TSKEY blkKeyLast = pCompBlock->keyLast;
|
||||||
|
|
||||||
|
if (keyFirst < blkKeyFirst) {
|
||||||
|
while (true) {
|
||||||
|
tdResetDataCols(pDataCols);
|
||||||
|
int rowsRead =
|
||||||
|
tsdbLoadDataFromCache(pTable, pCommitIter->pIter, blkKeyFirst - 1, defaultRowsInBlock, pDataCols, NULL, 0);
|
||||||
|
if (rowsRead == 0) break;
|
||||||
|
|
||||||
|
ASSERT(rowsRead == pDataCols->numOfRows);
|
||||||
|
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.dataF), pDataCols, &compBlock, false, true) < 0) return -1;
|
||||||
|
if (tsdbInsertSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||||
|
tblkIdx++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ASSERT(keyFirst <= blkKeyLast);
|
||||||
|
int16_t colId = 0;
|
||||||
|
if (tsdbLoadBlockDataCols(pHelper, pCompBlock, NULL, &colId, 1) < 0) return -1;
|
||||||
|
ASSERT(pDataCols0->numOfRows == pCompBlock->numOfRows);
|
||||||
|
|
||||||
|
slIter = *(pCommitIter->pIter);
|
||||||
|
int rows1 = (pCfg->maxRowsPerFileBlock - pCompBlock->numOfRows);
|
||||||
|
int rows2 = tsdbLoadDataFromCache(pTable, &slIter, blkKeyLast, INT_MAX, NULL, pDataCols0->cols[0].pData,
|
||||||
|
pDataCols0->numOfRows);
|
||||||
|
|
||||||
|
if (rows2 == 0) { // all filtered out
|
||||||
|
*(pCommitIter->pIter) = slIter;
|
||||||
|
} else {
|
||||||
|
int rows3 = tsdbLoadDataFromCache(pTable, &slIter, keyLimit, INT_MAX, NULL, NULL, 0) + rows2;
|
||||||
|
ASSERT(rows3 >= rows2);
|
||||||
|
|
||||||
|
if (pCompBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS && rows1 >= rows2) {
|
||||||
|
int rows = (rows1 >= rows3) ? rows3 : rows2;
|
||||||
|
tdResetDataCols(pDataCols);
|
||||||
|
int rowsRead = tsdbLoadDataFromCache(pTable, pCommitIter->pIter, keyLimit, rows, pDataCols,
|
||||||
|
pDataCols0->cols[0].pData, pDataCols0->numOfRows);
|
||||||
|
ASSERT(rowsRead == rows && rowsRead == pDataCols->numOfRows);
|
||||||
|
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.dataF), pDataCols, &compBlock, false, false) < 0)
|
||||||
|
return -1;
|
||||||
|
if (tsdbAddSubBlock(pHelper, &compBlock, tblkIdx, rowsRead) < 0) return -1;
|
||||||
|
tblkIdx++;
|
||||||
|
} else {
|
||||||
|
if (tsdbLoadBlockData(pHelper, pCompBlock, NULL) < 0) return -1;
|
||||||
|
int round = 0;
|
||||||
|
int dIter = 0;
|
||||||
|
while (true) {
|
||||||
|
int rowsRead =
|
||||||
|
tsdbLoadAndMergeFromCache(pDataCols0, &dIter, pCommitIter, pDataCols, keyLimit, defaultRowsInBlock);
|
||||||
|
if (rowsRead == 0) break;
|
||||||
|
|
||||||
|
if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.dataF), pDataCols, &compBlock, false, true) < 0)
|
||||||
|
return -1;
|
||||||
|
if (round == 0) {
|
||||||
|
if (tsdbUpdateSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||||
|
} else {
|
||||||
|
if (tsdbInsertSuperBlock(pHelper, &compBlock, tblkIdx) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
round++;
|
||||||
|
tblkIdx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*blkIdx = tblkIdx;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||||
|
TSKEY maxKey, int maxRows) {
|
||||||
|
int numOfRows = 0;
|
||||||
|
TSKEY key1 = INT64_MAX;
|
||||||
|
TSKEY key2 = INT64_MAX;
|
||||||
|
STSchema *pSchema = NULL;
|
||||||
|
|
||||||
|
ASSERT(maxRows > 0 && dataColsKeyLast(pDataCols) <= maxKey);
|
||||||
|
tdResetDataCols(pTarget);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
key1 = (*iter >= pDataCols->numOfRows) ? INT64_MAX : dataColsKeyAt(pDataCols, *iter);
|
||||||
|
SDataRow row = tsdbNextIterRow(pCommitIter->pIter);
|
||||||
|
key2 = (row == NULL || dataRowKey(row) > maxKey) ? INT64_MAX : dataRowKey(row);
|
||||||
|
|
||||||
|
if (key1 == INT64_MAX && key2 == INT64_MAX) break;
|
||||||
|
|
||||||
|
if (key1 <= key2) {
|
||||||
|
for (int i = 0; i < pDataCols->numOfCols; i++) {
|
||||||
|
dataColAppendVal(pTarget->cols + i, tdGetColDataOfRow(pDataCols->cols + i, *iter), pTarget->numOfRows,
|
||||||
|
pTarget->maxPoints);
|
||||||
|
}
|
||||||
|
pTarget->numOfRows++;
|
||||||
|
(*iter)++;
|
||||||
|
if (key1 == key2) tSkipListIterNext(pCommitIter->pIter);
|
||||||
|
} else {
|
||||||
|
if (pSchema == NULL || schemaVersion(pSchema) != dataRowVersion(row)) {
|
||||||
|
pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, dataRowVersion(row));
|
||||||
|
ASSERT(pSchema != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
tdAppendDataRowToDataCol(row, pSchema, pTarget);
|
||||||
|
tSkipListIterNext(pCommitIter->pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfRows++;
|
||||||
|
if (numOfRows >= maxRows) break;
|
||||||
|
ASSERT(numOfRows == pTarget->numOfRows && numOfRows <= pTarget->maxPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
return numOfRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tsdbWriteBlockToProperFile(SRWHelper *pHelper, SDataCols *pDataCols, SCompBlock *pCompBlock) {
|
||||||
|
STsdbCfg *pCfg = &(pHelper->pRepo->config);
|
||||||
|
SFile * pFile = NULL;
|
||||||
|
bool isLast = false;
|
||||||
|
|
||||||
|
ASSERT(pDataCols->numOfRows > 0);
|
||||||
|
|
||||||
|
if (pDataCols->numOfRows >= pCfg->minRowsPerFileBlock) {
|
||||||
|
pFile = &(pHelper->files.dataF);
|
||||||
|
} else {
|
||||||
|
isLast = true;
|
||||||
|
pFile = TSDB_NLAST_FILE_OPENED(pHelper) ? &(pHelper->files.nLastF) : &(pHelper->files.lastF);
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(pFile->fd > 0);
|
||||||
|
|
||||||
|
if (tsdbWriteBlockToFile(pHelper, pFile, pDataCols, pCompBlock, isLast, true) < 0) return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -179,7 +179,10 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab
|
||||||
pQueryHandle->outputCapacity = ((STsdbRepo*)tsdb)->config.maxRowsPerFileBlock;
|
pQueryHandle->outputCapacity = ((STsdbRepo*)tsdb)->config.maxRowsPerFileBlock;
|
||||||
pQueryHandle->allocSize = 0;
|
pQueryHandle->allocSize = 0;
|
||||||
|
|
||||||
tsdbInitReadHelper(&pQueryHandle->rhelper, (STsdbRepo*) tsdb);
|
if (tsdbInitReadHelper(&pQueryHandle->rhelper, (STsdbRepo*) tsdb) != 0) {
|
||||||
|
free(pQueryHandle);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
tsdbTakeMemSnapshot(pQueryHandle->pTsdb, &pQueryHandle->mem, &pQueryHandle->imem);
|
tsdbTakeMemSnapshot(pQueryHandle->pTsdb, &pQueryHandle->mem, &pQueryHandle->imem);
|
||||||
|
|
||||||
size_t sizeOfGroup = taosArrayGetSize(groupList->pGroupList);
|
size_t sizeOfGroup = taosArrayGetSize(groupList->pGroupList);
|
||||||
|
@ -238,11 +241,11 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab
|
||||||
|
|
||||||
TsdbQueryHandleT tsdbQueryLastRow(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, void* qinfo) {
|
TsdbQueryHandleT tsdbQueryLastRow(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, void* qinfo) {
|
||||||
STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qinfo);
|
STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qinfo);
|
||||||
|
if (pQueryHandle != NULL) {
|
||||||
pQueryHandle->type = TSDB_QUERY_TYPE_LAST;
|
pQueryHandle->type = TSDB_QUERY_TYPE_LAST;
|
||||||
pQueryHandle->order = TSDB_ORDER_DESC;
|
pQueryHandle->order = TSDB_ORDER_DESC;
|
||||||
|
|
||||||
changeQueryHandleForLastrowQuery(pQueryHandle);
|
changeQueryHandleForLastrowQuery(pQueryHandle);
|
||||||
|
}
|
||||||
return pQueryHandle;
|
return pQueryHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,9 +267,10 @@ SArray* tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle) {
|
||||||
|
|
||||||
TsdbQueryHandleT tsdbQueryRowsInExternalWindow(TSDB_REPO_T *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, void* qinfo) {
|
TsdbQueryHandleT tsdbQueryRowsInExternalWindow(TSDB_REPO_T *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, void* qinfo) {
|
||||||
STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qinfo);
|
STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qinfo);
|
||||||
|
if (pQueryHandle != NULL) {
|
||||||
pQueryHandle->type = TSDB_QUERY_TYPE_EXTERNAL;
|
pQueryHandle->type = TSDB_QUERY_TYPE_EXTERNAL;
|
||||||
changeQueryHandleForInterpQuery(pQueryHandle);
|
changeQueryHandleForInterpQuery(pQueryHandle);
|
||||||
|
}
|
||||||
return pQueryHandle;
|
return pQueryHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1237,10 +1241,12 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void*
|
||||||
STableBlockInfo* pRightBlockInfoEx = &pSupporter->pDataBlockInfo[rightTableIndex][rightTableBlockIndex];
|
STableBlockInfo* pRightBlockInfoEx = &pSupporter->pDataBlockInfo[rightTableIndex][rightTableBlockIndex];
|
||||||
|
|
||||||
// assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset);
|
// assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset);
|
||||||
|
#if 0 // TODO: temporarily comment off requested by Dr. Liao
|
||||||
if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset &&
|
if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset &&
|
||||||
pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) {
|
pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) {
|
||||||
tsdbError("error in header file, two block with same offset:%" PRId64, (int64_t)pLeftBlockInfoEx->compBlock->offset);
|
tsdbError("error in header file, two block with same offset:%" PRId64, (int64_t)pLeftBlockInfoEx->compBlock->offset);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return pLeftBlockInfoEx->compBlock->offset > pRightBlockInfoEx->compBlock->offset ? 1 : -1;
|
return pLeftBlockInfoEx->compBlock->offset > pRightBlockInfoEx->compBlock->offset ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
@ -1522,7 +1528,10 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
|
||||||
pSecQueryHandle->activeIndex = 0;
|
pSecQueryHandle->activeIndex = 0;
|
||||||
pSecQueryHandle->outputCapacity = ((STsdbRepo*)pSecQueryHandle->pTsdb)->config.maxRowsPerFileBlock;
|
pSecQueryHandle->outputCapacity = ((STsdbRepo*)pSecQueryHandle->pTsdb)->config.maxRowsPerFileBlock;
|
||||||
|
|
||||||
tsdbInitReadHelper(&pSecQueryHandle->rhelper, (STsdbRepo*) pSecQueryHandle->pTsdb);
|
if (tsdbInitReadHelper(&pSecQueryHandle->rhelper, (STsdbRepo*) pSecQueryHandle->pTsdb) != 0) {
|
||||||
|
free(pSecQueryHandle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
tsdbTakeMemSnapshot(pSecQueryHandle->pTsdb, &pSecQueryHandle->mem, &pSecQueryHandle->imem);
|
tsdbTakeMemSnapshot(pSecQueryHandle->pTsdb, &pSecQueryHandle->mem, &pSecQueryHandle->imem);
|
||||||
|
|
||||||
// allocate buffer in order to load data blocks from file
|
// allocate buffer in order to load data blocks from file
|
||||||
|
@ -1606,7 +1615,9 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: opt by consider the scan order
|
// TODO: opt by consider the scan order
|
||||||
return doHasDataInBuffer(pQueryHandle);
|
bool ret = doHasDataInBuffer(pQueryHandle);
|
||||||
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeQueryHandleForLastrowQuery(TsdbQueryHandleT pqHandle) {
|
void changeQueryHandleForLastrowQuery(TsdbQueryHandleT pqHandle) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tref.h"
|
#include "tlockfree.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
typedef void (*__cache_free_fn_t)(void*);
|
typedef void (*__cache_free_fn_t)(void*);
|
||||||
|
|
|
@ -12,12 +12,17 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#ifndef __TD_LOCK_FREE_H__
|
||||||
#ifndef TDENGINE_TREF_H
|
#define __TD_LOCK_FREE_H__
|
||||||
#define TDENGINE_TREF_H
|
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// reference counting
|
||||||
typedef void (*_ref_fn_t)(const void* pObj);
|
typedef void (*_ref_fn_t)(const void* pObj);
|
||||||
|
|
||||||
#define T_REF_DECLARE() \
|
#define T_REF_DECLARE() \
|
||||||
|
@ -55,4 +60,47 @@ typedef void (*_ref_fn_t)(const void* pObj);
|
||||||
|
|
||||||
#define T_REF_VAL_GET(x) (x)->_ref.val
|
#define T_REF_VAL_GET(x) (x)->_ref.val
|
||||||
|
|
||||||
#endif // TDENGINE_TREF_H
|
|
||||||
|
|
||||||
|
// single writer multiple reader lock
|
||||||
|
typedef int32_t SRWLatch;
|
||||||
|
|
||||||
|
void taosInitRWLatch(SRWLatch *pLatch);
|
||||||
|
void taosWLockLatch(SRWLatch *pLatch);
|
||||||
|
void taosWUnLockLatch(SRWLatch *pLatch);
|
||||||
|
void taosRLockLatch(SRWLatch *pLatch);
|
||||||
|
void taosRUnLockLatch(SRWLatch *pLatch);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// copy on read
|
||||||
|
#define taosCorBeginRead(x) for (uint32_t i_ = 1; 1; ++i_) { \
|
||||||
|
int32_t old_ = atomic_load_32(x); \
|
||||||
|
if (old_ & 0x00000001) { \
|
||||||
|
if (i_ % 1000 == 0) { \
|
||||||
|
sched_yield(); \
|
||||||
|
} \
|
||||||
|
continue; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define taosCorEndRead(x) \
|
||||||
|
if (atomic_load_32(x) == old_) { \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define taosCorBeginWrite(x) taosCorBeginRead(x) \
|
||||||
|
if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { \
|
||||||
|
continue; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define taosCorEndWrite(x) atomic_add_fetch_32((x), 1); \
|
||||||
|
break; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can use, redistribute, and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License, version 3
|
|
||||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
#ifndef __TD_RWLATCH_H__
|
|
||||||
#define __TD_RWLATCH_H__
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
typedef int32_t SRWLatch;
|
|
||||||
|
|
||||||
void taosInitRWLatch(SRWLatch *pLatch);
|
|
||||||
void taosWLockLatch(SRWLatch *pLatch);
|
|
||||||
void taosWUnLockLatch(SRWLatch *pLatch);
|
|
||||||
void taosRLockLatch(SRWLatch *pLatch);
|
|
||||||
void taosRUnLockLatch(SRWLatch *pLatch);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -15,8 +15,7 @@
|
||||||
// #define _GNU_SOURCE
|
// #define _GNU_SOURCE
|
||||||
// #include <pthread.h>
|
// #include <pthread.h>
|
||||||
|
|
||||||
#include "trwlatch.h"
|
#include "tlockfree.h"
|
||||||
#include "os.h"
|
|
||||||
|
|
||||||
#define TD_RWLATCH_WRITE_FLAG 0x40000000
|
#define TD_RWLATCH_WRITE_FLAG 0x40000000
|
||||||
|
|
|
@ -25,9 +25,9 @@ extern int32_t tscEmbedded;
|
||||||
#define tmrFatal(...) { if (tmrDebugFlag & DEBUG_FATAL) { taosPrintLog("TMR FATAL ", tscEmbedded ? 255 : tmrDebugFlag, __VA_ARGS__); }}
|
#define tmrFatal(...) { if (tmrDebugFlag & DEBUG_FATAL) { taosPrintLog("TMR FATAL ", tscEmbedded ? 255 : tmrDebugFlag, __VA_ARGS__); }}
|
||||||
#define tmrError(...) { if (tmrDebugFlag & DEBUG_ERROR) { taosPrintLog("TMR ERROR ", tscEmbedded ? 255 : tmrDebugFlag, __VA_ARGS__); }}
|
#define tmrError(...) { if (tmrDebugFlag & DEBUG_ERROR) { taosPrintLog("TMR ERROR ", tscEmbedded ? 255 : tmrDebugFlag, __VA_ARGS__); }}
|
||||||
#define tmrWarn(...) { if (tmrDebugFlag & DEBUG_WARN) { taosPrintLog("TMR WARN ", tscEmbedded ? 255 : tmrDebugFlag, __VA_ARGS__); }}
|
#define tmrWarn(...) { if (tmrDebugFlag & DEBUG_WARN) { taosPrintLog("TMR WARN ", tscEmbedded ? 255 : tmrDebugFlag, __VA_ARGS__); }}
|
||||||
#define tmrInfo(...) { if (tmrDebugFlag & DEBUG_INFO) { taosPrintLog("TMR INFO ", tscEmbedded ? 255 : tmrDebugFlag, __VA_ARGS__); }}
|
#define tmrInfo(...) { if (tmrDebugFlag & DEBUG_INFO) { taosPrintLog("TMR ", tscEmbedded ? 255 : tmrDebugFlag, __VA_ARGS__); }}
|
||||||
#define tmrDebug(...) { if (tmrDebugFlag & DEBUG_DEBUG) { taosPrintLog("TMR DEBUG ", tmrDebugFlag, __VA_ARGS__); }}
|
#define tmrDebug(...) { if (tmrDebugFlag & DEBUG_DEBUG) { taosPrintLog("TMR ", tmrDebugFlag, __VA_ARGS__); }}
|
||||||
#define tmrTrace(...) { if (tmrDebugFlag & DEBUG_TRACE) { taosPrintLog("TMR TRACE ", tmrDebugFlag, __VA_ARGS__); }}
|
#define tmrTrace(...) { if (tmrDebugFlag & DEBUG_TRACE) { taosPrintLog("TMR ", tmrDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
#define TIMER_STATE_WAITING 0
|
#define TIMER_STATE_WAITING 0
|
||||||
#define TIMER_STATE_EXPIRED 1
|
#define TIMER_STATE_EXPIRED 1
|
||||||
|
|
|
@ -30,9 +30,9 @@ extern int32_t vDebugFlag;
|
||||||
#define vFatal(...) { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", 255, __VA_ARGS__); }}
|
#define vFatal(...) { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define vError(...) { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", 255, __VA_ARGS__); }}
|
#define vError(...) { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define vWarn(...) { if (vDebugFlag & DEBUG_WARN) { taosPrintLog("VND WARN ", 255, __VA_ARGS__); }}
|
#define vWarn(...) { if (vDebugFlag & DEBUG_WARN) { taosPrintLog("VND WARN ", 255, __VA_ARGS__); }}
|
||||||
#define vInfo(...) { if (vDebugFlag & DEBUG_INFO) { taosPrintLog("VND INFO ", 255, __VA_ARGS__); }}
|
#define vInfo(...) { if (vDebugFlag & DEBUG_INFO) { taosPrintLog("VND ", 255, __VA_ARGS__); }}
|
||||||
#define vDebug(...) { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND DEBUG ", vDebugFlag, __VA_ARGS__); }}
|
#define vDebug(...) { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", vDebugFlag, __VA_ARGS__); }}
|
||||||
#define vTrace(...) { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND TRACE ", vDebugFlag, __VA_ARGS__); }}
|
#define vTrace(...) { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", vDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId; // global vnode group ID
|
int32_t vgId; // global vnode group ID
|
||||||
|
|
|
@ -69,6 +69,7 @@ int32_t vnodeInitResources() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeCleanupResources() {
|
void vnodeCleanupResources() {
|
||||||
|
|
||||||
if (tsDnodeVnodesHash != NULL) {
|
if (tsDnodeVnodesHash != NULL) {
|
||||||
taosHashCleanup(tsDnodeVnodesHash);
|
taosHashCleanup(tsDnodeVnodesHash);
|
||||||
tsDnodeVnodesHash = NULL;
|
tsDnodeVnodesHash = NULL;
|
||||||
|
@ -137,7 +138,7 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) {
|
||||||
return TSDB_CODE_VND_INIT_FAILED;
|
return TSDB_CODE_VND_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
vInfo("vgId:%d, vnode is created, clog:%d", pVnodeCfg->cfg.vgId, pVnodeCfg->cfg.walLevel);
|
vInfo("vgId:%d, vnode is created, walLevel:%d fsyncPeriod:%d", pVnodeCfg->cfg.vgId, pVnodeCfg->cfg.walLevel, pVnodeCfg->cfg.fsyncPeriod);
|
||||||
code = vnodeOpen(pVnodeCfg->cfg.vgId, rootDir);
|
code = vnodeOpen(pVnodeCfg->cfg.vgId, rootDir);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -636,6 +637,7 @@ static int32_t vnodeSaveCfg(SMDCreateVnodeMsg *pVnodeCfg) {
|
||||||
len += snprintf(content + len, maxLen - len, " \"precision\": %d,\n", pVnodeCfg->cfg.precision);
|
len += snprintf(content + len, maxLen - len, " \"precision\": %d,\n", pVnodeCfg->cfg.precision);
|
||||||
len += snprintf(content + len, maxLen - len, " \"compression\": %d,\n", pVnodeCfg->cfg.compression);
|
len += snprintf(content + len, maxLen - len, " \"compression\": %d,\n", pVnodeCfg->cfg.compression);
|
||||||
len += snprintf(content + len, maxLen - len, " \"walLevel\": %d,\n", pVnodeCfg->cfg.walLevel);
|
len += snprintf(content + len, maxLen - len, " \"walLevel\": %d,\n", pVnodeCfg->cfg.walLevel);
|
||||||
|
len += snprintf(content + len, maxLen - len, " \"fsync\": %d,\n", pVnodeCfg->cfg.fsyncPeriod);
|
||||||
len += snprintf(content + len, maxLen - len, " \"replica\": %d,\n", pVnodeCfg->cfg.replications);
|
len += snprintf(content + len, maxLen - len, " \"replica\": %d,\n", pVnodeCfg->cfg.replications);
|
||||||
len += snprintf(content + len, maxLen - len, " \"wals\": %d,\n", pVnodeCfg->cfg.wals);
|
len += snprintf(content + len, maxLen - len, " \"wals\": %d,\n", pVnodeCfg->cfg.wals);
|
||||||
len += snprintf(content + len, maxLen - len, " \"quorum\": %d,\n", pVnodeCfg->cfg.quorum);
|
len += snprintf(content + len, maxLen - len, " \"quorum\": %d,\n", pVnodeCfg->cfg.quorum);
|
||||||
|
@ -800,6 +802,13 @@ static int32_t vnodeReadCfg(SVnodeObj *pVnode) {
|
||||||
}
|
}
|
||||||
pVnode->walCfg.walLevel = (int8_t) walLevel->valueint;
|
pVnode->walCfg.walLevel = (int8_t) walLevel->valueint;
|
||||||
|
|
||||||
|
cJSON *fsyncPeriod = cJSON_GetObjectItem(root, "fsync");
|
||||||
|
if (!walLevel || walLevel->type != cJSON_Number) {
|
||||||
|
vError("vgId:%d, failed to read vnode cfg, fsyncPeriod not found", pVnode->vgId);
|
||||||
|
goto PARSE_OVER;
|
||||||
|
}
|
||||||
|
pVnode->walCfg.fsyncPeriod = fsyncPeriod->valueint;
|
||||||
|
|
||||||
cJSON *wals = cJSON_GetObjectItem(root, "wals");
|
cJSON *wals = cJSON_GetObjectItem(root, "wals");
|
||||||
if (!wals || wals->type != cJSON_Number) {
|
if (!wals || wals->type != cJSON_Number) {
|
||||||
vError("vgId:%d, failed to read vnode cfg, wals not found", pVnode->vgId);
|
vError("vgId:%d, failed to read vnode cfg, wals not found", pVnode->vgId);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tchecksum.h"
|
#include "tchecksum.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
#include "ttimer.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "twal.h"
|
#include "twal.h"
|
||||||
#include "tqueue.h"
|
#include "tqueue.h"
|
||||||
|
@ -35,15 +36,18 @@
|
||||||
#define wFatal(...) { if (wDebugFlag & DEBUG_FATAL) { taosPrintLog("WAL FATAL ", 255, __VA_ARGS__); }}
|
#define wFatal(...) { if (wDebugFlag & DEBUG_FATAL) { taosPrintLog("WAL FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define wError(...) { if (wDebugFlag & DEBUG_ERROR) { taosPrintLog("WAL ERROR ", 255, __VA_ARGS__); }}
|
#define wError(...) { if (wDebugFlag & DEBUG_ERROR) { taosPrintLog("WAL ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define wWarn(...) { if (wDebugFlag & DEBUG_WARN) { taosPrintLog("WAL WARN ", 255, __VA_ARGS__); }}
|
#define wWarn(...) { if (wDebugFlag & DEBUG_WARN) { taosPrintLog("WAL WARN ", 255, __VA_ARGS__); }}
|
||||||
#define wInfo(...) { if (wDebugFlag & DEBUG_INFO) { taosPrintLog("WAL INFO ", 255, __VA_ARGS__); }}
|
#define wInfo(...) { if (wDebugFlag & DEBUG_INFO) { taosPrintLog("WAL ", 255, __VA_ARGS__); }}
|
||||||
#define wDebug(...) { if (wDebugFlag & DEBUG_DEBUG) { taosPrintLog("WAL DEBUG ", wDebugFlag, __VA_ARGS__); }}
|
#define wDebug(...) { if (wDebugFlag & DEBUG_DEBUG) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }}
|
||||||
#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL TRACE ", wDebugFlag, __VA_ARGS__); }}
|
#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t version;
|
uint64_t version;
|
||||||
int fd;
|
int fd;
|
||||||
int keep;
|
int keep;
|
||||||
int level;
|
int level;
|
||||||
|
int32_t fsyncPeriod;
|
||||||
|
void *timer;
|
||||||
|
void *signature;
|
||||||
int max; // maximum number of wal files
|
int max; // maximum number of wal files
|
||||||
uint32_t id; // increase continuously
|
uint32_t id; // increase continuously
|
||||||
int num; // number of wal files
|
int num; // number of wal files
|
||||||
|
@ -52,10 +56,23 @@ typedef struct {
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
} SWal;
|
} SWal;
|
||||||
|
|
||||||
|
static void *walTmrCtrl = NULL;
|
||||||
|
static int tsWalNum = 0;
|
||||||
|
static pthread_once_t walModuleInit = PTHREAD_ONCE_INIT;
|
||||||
static uint32_t walSignature = 0xFAFBFDFE;
|
static uint32_t walSignature = 0xFAFBFDFE;
|
||||||
static int walHandleExistingFiles(const char *path);
|
static int walHandleExistingFiles(const char *path);
|
||||||
static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp);
|
static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp);
|
||||||
static int walRemoveWalFiles(const char *path);
|
static int walRemoveWalFiles(const char *path);
|
||||||
|
static void walProcessFsyncTimer(void *param, void *tmrId);
|
||||||
|
static void walRelease(SWal *pWal);
|
||||||
|
|
||||||
|
static void walModuleInitFunc() {
|
||||||
|
walTmrCtrl = taosTmrInit(1000, 100, 300000, "WAL");
|
||||||
|
if (walTmrCtrl == NULL)
|
||||||
|
walModuleInit = PTHREAD_ONCE_INIT;
|
||||||
|
else
|
||||||
|
wDebug("WAL module is initialized");
|
||||||
|
}
|
||||||
|
|
||||||
void *walOpen(const char *path, const SWalCfg *pCfg) {
|
void *walOpen(const char *path, const SWalCfg *pCfg) {
|
||||||
SWal *pWal = calloc(sizeof(SWal), 1);
|
SWal *pWal = calloc(sizeof(SWal), 1);
|
||||||
|
@ -64,20 +81,38 @@ void *walOpen(const char *path, const SWalCfg *pCfg) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_once(&walModuleInit, walModuleInitFunc);
|
||||||
|
if (walTmrCtrl == NULL) {
|
||||||
|
free(pWal);
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic_add_fetch_32(&tsWalNum, 1);
|
||||||
pWal->fd = -1;
|
pWal->fd = -1;
|
||||||
pWal->max = pCfg->wals;
|
pWal->max = pCfg->wals;
|
||||||
pWal->id = 0;
|
pWal->id = 0;
|
||||||
pWal->num = 0;
|
pWal->num = 0;
|
||||||
pWal->level = pCfg->walLevel;
|
pWal->level = pCfg->walLevel;
|
||||||
pWal->keep = pCfg->keep;
|
pWal->keep = pCfg->keep;
|
||||||
|
pWal->fsyncPeriod = pCfg->fsyncPeriod;
|
||||||
|
pWal->signature = pWal;
|
||||||
tstrncpy(pWal->path, path, sizeof(pWal->path));
|
tstrncpy(pWal->path, path, sizeof(pWal->path));
|
||||||
pthread_mutex_init(&pWal->mutex, NULL);
|
pthread_mutex_init(&pWal->mutex, NULL);
|
||||||
|
|
||||||
|
if (pWal->fsyncPeriod > 0 && pWal->level == TAOS_WAL_FSYNC) {
|
||||||
|
pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl);
|
||||||
|
if (pWal->timer == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
walRelease(pWal);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tmkdir(path, 0755) != 0) {
|
if (tmkdir(path, 0755) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
wError("wal:%s, failed to create directory(%s)", path, strerror(errno));
|
wError("wal:%s, failed to create directory(%s)", path, strerror(errno));
|
||||||
pthread_mutex_destroy(&pWal->mutex);
|
walRelease(pWal);
|
||||||
free(pWal);
|
|
||||||
pWal = NULL;
|
pWal = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,12 +124,11 @@ void *walOpen(const char *path, const SWalCfg *pCfg) {
|
||||||
if (pWal && pWal->fd <0) {
|
if (pWal && pWal->fd <0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
wError("wal:%s, failed to open(%s)", path, strerror(errno));
|
wError("wal:%s, failed to open(%s)", path, strerror(errno));
|
||||||
pthread_mutex_destroy(&pWal->mutex);
|
walRelease(pWal);
|
||||||
free(pWal);
|
|
||||||
pWal = NULL;
|
pWal = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWal) wDebug("wal:%s, it is open, level:%d", path, pWal->level);
|
if (pWal) wDebug("wal:%s, it is open, level:%d fsyncPeriod:%d", path, pWal->level, pWal->fsyncPeriod);
|
||||||
return pWal;
|
return pWal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +136,8 @@ void walClose(void *handle) {
|
||||||
if (handle == NULL) return;
|
if (handle == NULL) return;
|
||||||
|
|
||||||
SWal *pWal = handle;
|
SWal *pWal = handle;
|
||||||
close(pWal->fd);
|
tclose(pWal->fd);
|
||||||
|
if (pWal->timer) taosTmrStopA(&pWal->timer);
|
||||||
|
|
||||||
if (pWal->keep == 0) {
|
if (pWal->keep == 0) {
|
||||||
// remove all files in the directory
|
// remove all files in the directory
|
||||||
|
@ -118,9 +153,7 @@ void walClose(void *handle) {
|
||||||
wDebug("wal:%s, it is closed and kept", pWal->name);
|
wDebug("wal:%s, it is closed and kept", pWal->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_destroy(&pWal->mutex);
|
walRelease(pWal);
|
||||||
|
|
||||||
free(pWal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int walRenew(void *handle) {
|
int walRenew(void *handle) {
|
||||||
|
@ -194,9 +227,9 @@ int walWrite(void *handle, SWalHead *pHead) {
|
||||||
void walFsync(void *handle) {
|
void walFsync(void *handle) {
|
||||||
|
|
||||||
SWal *pWal = handle;
|
SWal *pWal = handle;
|
||||||
if (pWal == NULL) return;
|
if (pWal == NULL || pWal->level != TAOS_WAL_FSYNC || pWal->fd < 0) return;
|
||||||
|
|
||||||
if (pWal->level == TAOS_WAL_FSYNC && pWal->fd >=0) {
|
if (pWal->fsyncPeriod == 0) {
|
||||||
if (fsync(pWal->fd) < 0) {
|
if (fsync(pWal->fd) < 0) {
|
||||||
wError("wal:%s, fsync failed(%s)", pWal->name, strerror(errno));
|
wError("wal:%s, fsync failed(%s)", pWal->name, strerror(errno));
|
||||||
}
|
}
|
||||||
|
@ -303,6 +336,20 @@ int walGetWalFile(void *handle, char *name, uint32_t *index) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void walRelease(SWal *pWal) {
|
||||||
|
|
||||||
|
pthread_mutex_destroy(&pWal->mutex);
|
||||||
|
pWal->signature = NULL;
|
||||||
|
free(pWal);
|
||||||
|
|
||||||
|
if (atomic_sub_fetch_32(&tsWalNum, 1) == 0) {
|
||||||
|
if (walTmrCtrl) taosTmrCleanUp(walTmrCtrl);
|
||||||
|
walTmrCtrl = NULL;
|
||||||
|
walModuleInit = PTHREAD_ONCE_INIT;
|
||||||
|
wDebug("WAL module is cleaned up");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp) {
|
static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp) {
|
||||||
char *name = pWal->name;
|
char *name = pWal->name;
|
||||||
|
|
||||||
|
@ -433,3 +480,15 @@ static int walRemoveWalFiles(const char *path) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void walProcessFsyncTimer(void *param, void *tmrId) {
|
||||||
|
SWal *pWal = param;
|
||||||
|
|
||||||
|
if (pWal->signature != pWal) return;
|
||||||
|
if (pWal->fd < 0) return;
|
||||||
|
|
||||||
|
if (fsync(pWal->fd) < 0) {
|
||||||
|
wError("wal:%s, fsync failed(%s)", pWal->name, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl);
|
||||||
|
}
|
||||||
|
|
|
@ -84,8 +84,17 @@ class WorkerThread:
|
||||||
# Let us have a DB connection of our own
|
# Let us have a DB connection of our own
|
||||||
if (gConfig.per_thread_db_connection): # type: ignore
|
if (gConfig.per_thread_db_connection): # type: ignore
|
||||||
# print("connector_type = {}".format(gConfig.connector_type))
|
# print("connector_type = {}".format(gConfig.connector_type))
|
||||||
self._dbConn = DbConn.createNative() if (
|
if gConfig.connector_type == 'native':
|
||||||
gConfig.connector_type == 'native') else DbConn.createRest()
|
self._dbConn = DbConn.createNative()
|
||||||
|
elif gConfig.connector_type == 'rest':
|
||||||
|
self._dbConn = DbConn.createRest()
|
||||||
|
elif gConfig.connector_type == 'mixed':
|
||||||
|
if Dice.throw(2) == 0: # 1/2 chance
|
||||||
|
self._dbConn = DbConn.createNative()
|
||||||
|
else:
|
||||||
|
self._dbConn = DbConn.createRest()
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Unexpected connector type: {}".format(gConfig.connector_type))
|
||||||
|
|
||||||
self._dbInUse = False # if "use db" was executed already
|
self._dbInUse = False # if "use db" was executed already
|
||||||
|
|
||||||
|
@ -130,22 +139,15 @@ class WorkerThread:
|
||||||
while True:
|
while True:
|
||||||
tc = self._tc # Thread Coordinator, the overall master
|
tc = self._tc # Thread Coordinator, the overall master
|
||||||
tc.crossStepBarrier() # shared barrier first, INCLUDING the last one
|
tc.crossStepBarrier() # shared barrier first, INCLUDING the last one
|
||||||
logger.debug(
|
logger.debug("[TRD] Worker thread [{}] exited barrier...".format(self._tid))
|
||||||
"[TRD] Worker thread [{}] exited barrier...".format(
|
|
||||||
self._tid))
|
|
||||||
self.crossStepGate() # then per-thread gate, after being tapped
|
self.crossStepGate() # then per-thread gate, after being tapped
|
||||||
logger.debug(
|
logger.debug("[TRD] Worker thread [{}] exited step gate...".format(self._tid))
|
||||||
"[TRD] Worker thread [{}] exited step gate...".format(
|
|
||||||
self._tid))
|
|
||||||
if not self._tc.isRunning():
|
if not self._tc.isRunning():
|
||||||
logger.debug(
|
logger.debug("[TRD] Thread Coordinator not running any more, worker thread now stopping...")
|
||||||
"[TRD] Thread Coordinator not running any more, worker thread now stopping...")
|
|
||||||
break
|
break
|
||||||
|
|
||||||
# Fetch a task from the Thread Coordinator
|
# Fetch a task from the Thread Coordinator
|
||||||
logger.debug(
|
logger.debug( "[TRD] Worker thread [{}] about to fetch task".format(self._tid))
|
||||||
"[TRD] Worker thread [{}] about to fetch task".format(
|
|
||||||
self._tid))
|
|
||||||
task = tc.fetchTask()
|
task = tc.fetchTask()
|
||||||
|
|
||||||
# Execute such a task
|
# Execute such a task
|
||||||
|
@ -154,9 +156,7 @@ class WorkerThread:
|
||||||
self._tid, task.__class__.__name__))
|
self._tid, task.__class__.__name__))
|
||||||
task.execute(self)
|
task.execute(self)
|
||||||
tc.saveExecutedTask(task)
|
tc.saveExecutedTask(task)
|
||||||
logger.debug(
|
logger.debug("[TRD] Worker thread [{}] finished executing task".format(self._tid))
|
||||||
"[TRD] Worker thread [{}] finished executing task".format(
|
|
||||||
self._tid))
|
|
||||||
|
|
||||||
self._dbInUse = False # there may be changes between steps
|
self._dbInUse = False # there may be changes between steps
|
||||||
|
|
||||||
|
@ -255,44 +255,53 @@ class ThreadCoordinator:
|
||||||
self._runStatus = MainExec.STATUS_STOPPING
|
self._runStatus = MainExec.STATUS_STOPPING
|
||||||
self._execStats.registerFailure("User Interruption")
|
self._execStats.registerFailure("User Interruption")
|
||||||
|
|
||||||
def run(self):
|
def _runShouldEnd(self, transitionFailed, hasAbortedTask):
|
||||||
self._pool.createAndStartThreads(self)
|
|
||||||
|
|
||||||
# Coordinate all threads step by step
|
|
||||||
self._curStep = -1 # not started yet
|
|
||||||
maxSteps = gConfig.max_steps # type: ignore
|
maxSteps = gConfig.max_steps # type: ignore
|
||||||
self._execStats.startExec() # start the stop watch
|
if self._curStep >= (maxSteps - 1): # maxStep==10, last curStep should be 9
|
||||||
transitionFailed = False
|
return True
|
||||||
hasAbortedTask = False
|
if self._runStatus != MainExec.STATUS_RUNNING:
|
||||||
while(self._curStep < maxSteps - 1 and
|
return True
|
||||||
(not transitionFailed) and
|
if transitionFailed:
|
||||||
(self._runStatus == MainExec.STATUS_RUNNING) and
|
return True
|
||||||
(not hasAbortedTask)): # maxStep==10, last curStep should be 9
|
if hasAbortedTask:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
if not gConfig.debug:
|
def _hasAbortedTask(self): # from execution of previous step
|
||||||
# print this only if we are not in debug mode
|
for task in self._executedTasks:
|
||||||
print(".", end="", flush=True)
|
if task.isAborted():
|
||||||
logger.debug("[TRD] Main thread going to sleep")
|
# print("Task aborted: {}".format(task))
|
||||||
|
# hasAbortedTask = True
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _releaseAllWorkerThreads(self, transitionFailed):
|
||||||
|
self._curStep += 1 # we are about to get into next step. TODO: race condition here!
|
||||||
|
# Now not all threads had time to go to sleep
|
||||||
|
logger.debug(
|
||||||
|
"--\r\n\n--> Step {} starts with main thread waking up".format(self._curStep))
|
||||||
|
|
||||||
|
# A new TE for the new step
|
||||||
|
self._te = None # set to empty first, to signal worker thread to stop
|
||||||
|
if not transitionFailed: # only if not failed
|
||||||
|
self._te = TaskExecutor(self._curStep)
|
||||||
|
|
||||||
|
logger.debug("[TRD] Main thread waking up at step {}, tapping worker threads".format(
|
||||||
|
self._curStep)) # Now not all threads had time to go to sleep
|
||||||
|
# Worker threads will wake up at this point, and each execute it's own task
|
||||||
|
self.tapAllThreads() # release all worker thread from their "gate"
|
||||||
|
|
||||||
|
def _syncAtBarrier(self):
|
||||||
# Now main thread (that's us) is ready to enter a step
|
# Now main thread (that's us) is ready to enter a step
|
||||||
# let other threads go past the pool barrier, but wait at the
|
# let other threads go past the pool barrier, but wait at the
|
||||||
# thread gate
|
# thread gate
|
||||||
|
logger.debug("[TRD] Main thread about to cross the barrier")
|
||||||
self.crossStepBarrier()
|
self.crossStepBarrier()
|
||||||
self._stepBarrier.reset() # Other worker threads should now be at the "gate"
|
self._stepBarrier.reset() # Other worker threads should now be at the "gate"
|
||||||
|
logger.debug("[TRD] Main thread finished crossing the barrier")
|
||||||
|
|
||||||
# At this point, all threads should be pass the overall "barrier" and before the per-thread "gate"
|
def _doTransition(self):
|
||||||
# We use this period to do house keeping work, when all worker
|
transitionFailed = False
|
||||||
# threads are QUIET.
|
|
||||||
hasAbortedTask = False
|
|
||||||
for task in self._executedTasks:
|
|
||||||
if task.isAborted():
|
|
||||||
print("Task aborted: {}".format(task))
|
|
||||||
hasAbortedTask = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if hasAbortedTask: # do transition only if tasks are error free
|
|
||||||
self._execStats.registerFailure("Aborted Task Encountered")
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
sm = self._dbManager.getStateMachine()
|
sm = self._dbManager.getStateMachine()
|
||||||
logger.debug("[STT] starting transitions")
|
logger.debug("[STT] starting transitions")
|
||||||
|
@ -318,38 +327,52 @@ class ThreadCoordinator:
|
||||||
# end, and maybe signal them to stop
|
# end, and maybe signal them to stop
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
# finally:
|
|
||||||
# pass
|
|
||||||
|
|
||||||
self.resetExecutedTasks() # clear the tasks after we are done
|
self.resetExecutedTasks() # clear the tasks after we are done
|
||||||
|
|
||||||
# Get ready for next step
|
# Get ready for next step
|
||||||
logger.debug("<-- Step {} finished".format(self._curStep))
|
logger.debug("<-- Step {} finished, trasition failed = {}".format(self._curStep, transitionFailed))
|
||||||
self._curStep += 1 # we are about to get into next step. TODO: race condition here!
|
return transitionFailed
|
||||||
# Now not all threads had time to go to sleep
|
|
||||||
logger.debug(
|
|
||||||
"\r\n\n--> Step {} starts with main thread waking up".format(self._curStep))
|
|
||||||
|
|
||||||
# A new TE for the new step
|
def run(self):
|
||||||
if not transitionFailed: # only if not failed
|
self._pool.createAndStartThreads(self)
|
||||||
self._te = TaskExecutor(self._curStep)
|
|
||||||
|
|
||||||
logger.debug(
|
# Coordinate all threads step by step
|
||||||
"[TRD] Main thread waking up at step {}, tapping worker threads".format(
|
self._curStep = -1 # not started yet
|
||||||
self._curStep)) # Now not all threads had time to go to sleep
|
|
||||||
# Worker threads will wake up at this point, and each execute it's
|
self._execStats.startExec() # start the stop watch
|
||||||
# own task
|
transitionFailed = False
|
||||||
self.tapAllThreads()
|
hasAbortedTask = False
|
||||||
|
while not self._runShouldEnd(transitionFailed, hasAbortedTask):
|
||||||
|
if not gConfig.debug: # print this only if we are not in debug mode
|
||||||
|
print(".", end="", flush=True)
|
||||||
|
|
||||||
|
self._syncAtBarrier() # For now just cross the barrier
|
||||||
|
|
||||||
|
# At this point, all threads should be pass the overall "barrier" and before the per-thread "gate"
|
||||||
|
# We use this period to do house keeping work, when all worker
|
||||||
|
# threads are QUIET.
|
||||||
|
hasAbortedTask = self._hasAbortedTask() # from previous step
|
||||||
|
if hasAbortedTask:
|
||||||
|
logger.info("Aborted task encountered, exiting test program")
|
||||||
|
self._execStats.registerFailure("Aborted Task Encountered")
|
||||||
|
break # do transition only if tasks are error free
|
||||||
|
|
||||||
|
# Ending previous step
|
||||||
|
transitionFailed = self._doTransition() # To start, we end step -1 first
|
||||||
|
# Then we move on to the next step
|
||||||
|
self._releaseAllWorkerThreads(transitionFailed)
|
||||||
|
|
||||||
|
if hasAbortedTask or transitionFailed : # abnormal ending, workers waiting at "gate"
|
||||||
|
logger.debug("Abnormal ending of main thraed")
|
||||||
|
else: # regular ending, workers waiting at "barrier"
|
||||||
|
logger.debug("Regular ending, main thread waiting for all worker threads to stop...")
|
||||||
|
self._syncAtBarrier()
|
||||||
|
|
||||||
logger.debug("Main thread ready to finish up...")
|
|
||||||
if not transitionFailed: # only in regular situations
|
|
||||||
self.crossStepBarrier() # Cross it one last time, after all threads finish
|
|
||||||
self._stepBarrier.reset()
|
|
||||||
logger.debug("Main thread in exclusive zone...")
|
|
||||||
self._te = None # No more executor, time to end
|
self._te = None # No more executor, time to end
|
||||||
logger.debug("Main thread tapping all threads one last time...")
|
logger.debug("Main thread tapping all threads one last time...")
|
||||||
self.tapAllThreads() # Let the threads run one last time
|
self.tapAllThreads() # Let the threads run one last time
|
||||||
|
|
||||||
|
logger.debug("\r\n\n--> Main thread ready to finish up...")
|
||||||
logger.debug("Main thread joining all threads")
|
logger.debug("Main thread joining all threads")
|
||||||
self._pool.joinAll() # Get all threads to finish
|
self._pool.joinAll() # Get all threads to finish
|
||||||
logger.info("\nAll worker threads finished")
|
logger.info("\nAll worker threads finished")
|
||||||
|
@ -620,9 +643,13 @@ class DbConnRest(DbConn):
|
||||||
self.isOpen = False
|
self.isOpen = False
|
||||||
|
|
||||||
def _doSql(self, sql):
|
def _doSql(self, sql):
|
||||||
|
try:
|
||||||
r = requests.post(self._url,
|
r = requests.post(self._url,
|
||||||
data = sql,
|
data = sql,
|
||||||
auth = HTTPBasicAuth('root', 'taosdata'))
|
auth = HTTPBasicAuth('root', 'taosdata'))
|
||||||
|
except:
|
||||||
|
print("REST API Failure (TODO: more info here)")
|
||||||
|
raise
|
||||||
rj = r.json()
|
rj = r.json()
|
||||||
# Sanity check for the "Json Result"
|
# Sanity check for the "Json Result"
|
||||||
if ('status' not in rj):
|
if ('status' not in rj):
|
||||||
|
@ -717,7 +744,7 @@ class MyTDSql:
|
||||||
class DbConnNative(DbConn):
|
class DbConnNative(DbConn):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._type = self.TYPE_REST
|
self._type = self.TYPE_NATIVE
|
||||||
self._conn = None
|
self._conn = None
|
||||||
self._cursor = None
|
self._cursor = None
|
||||||
|
|
||||||
|
@ -736,10 +763,16 @@ class DbConnNative(DbConn):
|
||||||
break
|
break
|
||||||
return buildPath
|
return buildPath
|
||||||
|
|
||||||
|
connInfoDisplayed = False
|
||||||
def openByType(self): # Open connection
|
def openByType(self): # Open connection
|
||||||
cfgPath = self.getBuildPath() + "/test/cfg"
|
cfgPath = self.getBuildPath() + "/test/cfg"
|
||||||
|
hostAddr = "127.0.0.1"
|
||||||
|
if not self.connInfoDisplayed:
|
||||||
|
logger.info("Initiating TAOS native connection to {}, using config at {}".format(hostAddr, cfgPath))
|
||||||
|
self.connInfoDisplayed = True
|
||||||
|
|
||||||
self._conn = taos.connect(
|
self._conn = taos.connect(
|
||||||
host="127.0.0.1",
|
host=hostAddr,
|
||||||
config=cfgPath) # TODO: make configurable
|
config=cfgPath) # TODO: make configurable
|
||||||
self._cursor = self._conn.cursor()
|
self._cursor = self._conn.cursor()
|
||||||
|
|
||||||
|
@ -2254,8 +2287,9 @@ class ClientManager:
|
||||||
|
|
||||||
def sigIntHandler(self, signalNumber, frame):
|
def sigIntHandler(self, signalNumber, frame):
|
||||||
if self._status != MainExec.STATUS_RUNNING:
|
if self._status != MainExec.STATUS_RUNNING:
|
||||||
print("Ignoring repeated SIGINT...")
|
print("Repeated SIGINT received, forced exit...")
|
||||||
return # do nothing if it's already not running
|
# return # do nothing if it's already not running
|
||||||
|
sys.exit(-1)
|
||||||
self._status = MainExec.STATUS_STOPPING # immediately set our status
|
self._status = MainExec.STATUS_STOPPING # immediately set our status
|
||||||
|
|
||||||
print("Terminating program...")
|
print("Terminating program...")
|
||||||
|
@ -2394,6 +2428,27 @@ def main():
|
||||||
|
|
||||||
'''))
|
'''))
|
||||||
|
|
||||||
|
# parser.add_argument('-a', '--auto-start-service', action='store_true',
|
||||||
|
# help='Automatically start/stop the TDengine service (default: false)')
|
||||||
|
# parser.add_argument('-c', '--connector-type', action='store', default='native', type=str,
|
||||||
|
# help='Connector type to use: native, rest, or mixed (default: 10)')
|
||||||
|
# parser.add_argument('-d', '--debug', action='store_true',
|
||||||
|
# help='Turn on DEBUG mode for more logging (default: false)')
|
||||||
|
# parser.add_argument('-e', '--run-tdengine', action='store_true',
|
||||||
|
# help='Run TDengine service in foreground (default: false)')
|
||||||
|
# parser.add_argument('-l', '--larger-data', action='store_true',
|
||||||
|
# help='Write larger amount of data during write operations (default: false)')
|
||||||
|
# parser.add_argument('-p', '--per-thread-db-connection', action='store_true',
|
||||||
|
# help='Use a single shared db connection (default: false)')
|
||||||
|
# parser.add_argument('-r', '--record-ops', action='store_true',
|
||||||
|
# help='Use a pair of always-fsynced fils to record operations performing + performed, for power-off tests (default: false)')
|
||||||
|
# parser.add_argument('-s', '--max-steps', action='store', default=1000, type=int,
|
||||||
|
# help='Maximum number of steps to run (default: 100)')
|
||||||
|
# parser.add_argument('-t', '--num-threads', action='store', default=5, type=int,
|
||||||
|
# help='Number of threads to run (default: 10)')
|
||||||
|
# parser.add_argument('-x', '--continue-on-exception', action='store_true',
|
||||||
|
# help='Continue execution after encountering unexpected/disallowed errors/exceptions (default: false)')
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-a',
|
'-a',
|
||||||
'--auto-start-service',
|
'--auto-start-service',
|
||||||
|
|
|
@ -0,0 +1,501 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
import subprocess
|
||||||
|
from util.log import *
|
||||||
|
|
||||||
|
|
||||||
|
class TDSimClient:
|
||||||
|
def __init__(self):
|
||||||
|
self.testCluster = False
|
||||||
|
|
||||||
|
self.cfgDict = {
|
||||||
|
"numOfLogLines": "100000000",
|
||||||
|
"numOfThreadsPerCore": "2.0",
|
||||||
|
"locale": "en_US.UTF-8",
|
||||||
|
"charset": "UTF-8",
|
||||||
|
"asyncLog": "0",
|
||||||
|
"anyIp": "0",
|
||||||
|
"sdbDebugFlag": "135",
|
||||||
|
"rpcDebugFlag": "135",
|
||||||
|
"tmrDebugFlag": "131",
|
||||||
|
"cDebugFlag": "135",
|
||||||
|
"udebugFlag": "135",
|
||||||
|
"jnidebugFlag": "135",
|
||||||
|
"qdebugFlag": "135",
|
||||||
|
}
|
||||||
|
|
||||||
|
def init(self, path):
|
||||||
|
self.__init__()
|
||||||
|
self.path = path
|
||||||
|
|
||||||
|
def getLogDir(self):
|
||||||
|
self.logDir = "%s/sim/psim/log" % (self.path)
|
||||||
|
return self.logDir
|
||||||
|
|
||||||
|
def getCfgDir(self):
|
||||||
|
self.cfgDir = "%s/sim/psim/cfg" % (self.path)
|
||||||
|
return self.cfgDir
|
||||||
|
|
||||||
|
def setTestCluster(self, value):
|
||||||
|
self.testCluster = value
|
||||||
|
|
||||||
|
def addExtraCfg(self, option, value):
|
||||||
|
self.cfgDict.update({option: value})
|
||||||
|
|
||||||
|
def cfg(self, option, value):
|
||||||
|
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
def deploy(self):
|
||||||
|
self.logDir = "%s/sim/psim/log" % (self.path)
|
||||||
|
self.cfgDir = "%s/sim/psim/cfg" % (self.path)
|
||||||
|
self.cfgPath = "%s/sim/psim/cfg/taos.cfg" % (self.path)
|
||||||
|
|
||||||
|
cmd = "rm -rf " + self.logDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "mkdir -p " + self.logDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "rm -rf " + self.cfgDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "mkdir -p " + self.cfgDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "touch " + self.cfgPath
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
if self.testCluster:
|
||||||
|
self.cfg("masterIp", "192.168.0.1")
|
||||||
|
self.cfg("secondIp", "192.168.0.2")
|
||||||
|
self.cfg("logDir", self.logDir)
|
||||||
|
|
||||||
|
for key, value in self.cfgDict.items():
|
||||||
|
self.cfg(key, value)
|
||||||
|
|
||||||
|
tdLog.debug("psim is deployed and configured by %s" % (self.cfgPath))
|
||||||
|
|
||||||
|
|
||||||
|
class TDDnode:
|
||||||
|
def __init__(self, index):
|
||||||
|
self.index = index
|
||||||
|
self.running = 0
|
||||||
|
self.deployed = 0
|
||||||
|
self.testCluster = False
|
||||||
|
self.valgrind = 0
|
||||||
|
|
||||||
|
def init(self, path):
|
||||||
|
self.path = path
|
||||||
|
|
||||||
|
def setTestCluster(self, value):
|
||||||
|
self.testCluster = value
|
||||||
|
|
||||||
|
def setValgrind(self, value):
|
||||||
|
self.valgrind = value
|
||||||
|
|
||||||
|
def getDataSize(self):
|
||||||
|
totalSize = 0
|
||||||
|
|
||||||
|
if (self.deployed == 1):
|
||||||
|
for dirpath, dirnames, filenames in os.walk(self.dataDir):
|
||||||
|
for f in filenames:
|
||||||
|
fp = os.path.join(dirpath, f)
|
||||||
|
|
||||||
|
if not os.path.islink(fp):
|
||||||
|
totalSize = totalSize + os.path.getsize(fp)
|
||||||
|
|
||||||
|
return totalSize
|
||||||
|
|
||||||
|
def deploy(self):
|
||||||
|
self.logDir = "%s/sim/dnode%d/log" % (self.path, self.index)
|
||||||
|
self.dataDir = "%s/sim/dnode%d/data" % (self.path, self.index)
|
||||||
|
self.cfgDir = "%s/sim/dnode%d/cfg" % (self.path, self.index)
|
||||||
|
self.cfgPath = "%s/sim/dnode%d/cfg/taos.cfg" % (
|
||||||
|
self.path, self.index)
|
||||||
|
|
||||||
|
cmd = "rm -rf " + self.dataDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "rm -rf " + self.logDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "rm -rf " + self.cfgDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "mkdir -p " + self.dataDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "mkdir -p " + self.logDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "mkdir -p " + self.cfgDir
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
cmd = "touch " + self.cfgPath
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
if self.testCluster:
|
||||||
|
self.startIP()
|
||||||
|
|
||||||
|
if self.testCluster:
|
||||||
|
self.cfg("masterIp", "192.168.0.1")
|
||||||
|
self.cfg("secondIp", "192.168.0.2")
|
||||||
|
self.cfg("publicIp", "192.168.0.%d" % (self.index))
|
||||||
|
self.cfg("internalIp", "192.168.0.%d" % (self.index))
|
||||||
|
self.cfg("privateIp", "192.168.0.%d" % (self.index))
|
||||||
|
self.cfg("dataDir", self.dataDir)
|
||||||
|
self.cfg("logDir", self.logDir)
|
||||||
|
self.cfg("numOfLogLines", "100000000")
|
||||||
|
self.cfg("mnodeEqualVnodeNum", "0")
|
||||||
|
self.cfg("walLevel", "2")
|
||||||
|
self.cfg("fsync", "1000")
|
||||||
|
self.cfg("statusInterval", "1")
|
||||||
|
self.cfg("numOfTotalVnodes", "64")
|
||||||
|
self.cfg("numOfMnodes", "3")
|
||||||
|
self.cfg("numOfThreadsPerCore", "2.0")
|
||||||
|
self.cfg("monitor", "0")
|
||||||
|
self.cfg("maxVnodeConnections", "30000")
|
||||||
|
self.cfg("maxMgmtConnections", "30000")
|
||||||
|
self.cfg("maxMeterConnections", "30000")
|
||||||
|
self.cfg("maxShellConns", "30000")
|
||||||
|
self.cfg("locale", "en_US.UTF-8")
|
||||||
|
self.cfg("charset", "UTF-8")
|
||||||
|
self.cfg("asyncLog", "0")
|
||||||
|
self.cfg("anyIp", "0")
|
||||||
|
self.cfg("dDebugFlag", "135")
|
||||||
|
self.cfg("mDebugFlag", "135")
|
||||||
|
self.cfg("sdbDebugFlag", "135")
|
||||||
|
self.cfg("rpcDebugFlag", "135")
|
||||||
|
self.cfg("tmrDebugFlag", "131")
|
||||||
|
self.cfg("cDebugFlag", "135")
|
||||||
|
self.cfg("httpDebugFlag", "135")
|
||||||
|
self.cfg("monitorDebugFlag", "135")
|
||||||
|
self.cfg("udebugFlag", "135")
|
||||||
|
self.cfg("jnidebugFlag", "135")
|
||||||
|
self.cfg("qdebugFlag", "135")
|
||||||
|
self.deployed = 1
|
||||||
|
tdLog.debug(
|
||||||
|
"dnode:%d is deployed and configured by %s" %
|
||||||
|
(self.index, self.cfgPath))
|
||||||
|
|
||||||
|
def getBuildPath(self):
|
||||||
|
selfPath = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
if ("community" in selfPath):
|
||||||
|
projPath = selfPath[:selfPath.find("community")]
|
||||||
|
else:
|
||||||
|
projPath = selfPath[:selfPath.find("tests")]
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(projPath):
|
||||||
|
if ("taosd" in files):
|
||||||
|
rootRealPath = os.path.dirname(os.path.realpath(root))
|
||||||
|
if ("packaging" not in rootRealPath):
|
||||||
|
buildPath = root[:len(root)-len("/build/bin")]
|
||||||
|
break
|
||||||
|
return buildPath
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
buildPath = self.getBuildPath()
|
||||||
|
|
||||||
|
if (buildPath == ""):
|
||||||
|
tdLog.exit("taosd not found!")
|
||||||
|
else:
|
||||||
|
tdLog.info("taosd found in %s" % buildPath)
|
||||||
|
|
||||||
|
binPath = buildPath + "/build/bin/taosd"
|
||||||
|
|
||||||
|
if self.deployed == 0:
|
||||||
|
tdLog.exit("dnode:%d is not deployed" % (self.index))
|
||||||
|
|
||||||
|
if self.valgrind == 0:
|
||||||
|
cmd = "nohup %s -c %s --random-file-fail-factor 0 > /dev/null 2>&1 & " % (
|
||||||
|
binPath, self.cfgDir)
|
||||||
|
else:
|
||||||
|
valgrindCmdline = "valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"
|
||||||
|
|
||||||
|
cmd = "nohup %s %s -c %s 2>&1 & " % (
|
||||||
|
valgrindCmdline, binPath, self.cfgDir)
|
||||||
|
|
||||||
|
print(cmd)
|
||||||
|
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
self.running = 1
|
||||||
|
tdLog.debug("dnode:%d is running with %s " % (self.index, cmd))
|
||||||
|
|
||||||
|
tdLog.debug("wait 5 seconds for the dnode:%d to start." % (self.index))
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
if self.valgrind == 0:
|
||||||
|
toBeKilled = "taosd"
|
||||||
|
else:
|
||||||
|
toBeKilled = "valgrind.bin"
|
||||||
|
|
||||||
|
if self.running != 0:
|
||||||
|
psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled
|
||||||
|
processID = subprocess.check_output(
|
||||||
|
psCmd, shell=True).decode("utf-8")
|
||||||
|
|
||||||
|
while(processID):
|
||||||
|
killCmd = "kill -INT %s > /dev/null 2>&1" % processID
|
||||||
|
os.system(killCmd)
|
||||||
|
time.sleep(1)
|
||||||
|
processID = subprocess.check_output(
|
||||||
|
psCmd, shell=True).decode("utf-8")
|
||||||
|
for port in range(6030, 6041):
|
||||||
|
fuserCmd = "fuser -k -n tcp %d" % port
|
||||||
|
os.system(fuserCmd)
|
||||||
|
if self.valgrind:
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
self.running = 0
|
||||||
|
tdLog.debug("dnode:%d is stopped by kill -INT" % (self.index))
|
||||||
|
|
||||||
|
def forcestop(self):
|
||||||
|
if self.valgrind == 0:
|
||||||
|
toBeKilled = "taosd"
|
||||||
|
else:
|
||||||
|
toBeKilled = "valgrind.bin"
|
||||||
|
|
||||||
|
if self.running != 0:
|
||||||
|
psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled
|
||||||
|
processID = subprocess.check_output(
|
||||||
|
psCmd, shell=True).decode("utf-8")
|
||||||
|
|
||||||
|
while(processID):
|
||||||
|
killCmd = "kill -KILL %s > /dev/null 2>&1" % processID
|
||||||
|
os.system(killCmd)
|
||||||
|
time.sleep(1)
|
||||||
|
processID = subprocess.check_output(
|
||||||
|
psCmd, shell=True).decode("utf-8")
|
||||||
|
for port in range(6030, 6041):
|
||||||
|
fuserCmd = "fuser -k -n tcp %d" % port
|
||||||
|
os.system(fuserCmd)
|
||||||
|
if self.valgrind:
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
self.running = 0
|
||||||
|
tdLog.debug("dnode:%d is stopped by kill -KILL" % (self.index))
|
||||||
|
|
||||||
|
def startIP(self):
|
||||||
|
cmd = "sudo ifconfig lo:%d 192.168.0.%d up" % (self.index, self.index)
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
def stopIP(self):
|
||||||
|
cmd = "sudo ifconfig lo:%d 192.168.0.%d down" % (
|
||||||
|
self.index, self.index)
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
def cfg(self, option, value):
|
||||||
|
cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath)
|
||||||
|
if os.system(cmd) != 0:
|
||||||
|
tdLog.exit(cmd)
|
||||||
|
|
||||||
|
def getDnodeRootDir(self, index):
|
||||||
|
dnodeRootDir = "%s/sim/psim/dnode%d" % (self.path, index)
|
||||||
|
return dnodeRootDir
|
||||||
|
|
||||||
|
def getDnodesRootDir(self):
|
||||||
|
dnodesRootDir = "%s/sim/psim" % (self.path)
|
||||||
|
return dnodesRootDir
|
||||||
|
|
||||||
|
|
||||||
|
class TDDnodes:
|
||||||
|
def __init__(self):
|
||||||
|
self.dnodes = []
|
||||||
|
self.dnodes.append(TDDnode(1))
|
||||||
|
self.dnodes.append(TDDnode(2))
|
||||||
|
self.dnodes.append(TDDnode(3))
|
||||||
|
self.dnodes.append(TDDnode(4))
|
||||||
|
self.dnodes.append(TDDnode(5))
|
||||||
|
self.dnodes.append(TDDnode(6))
|
||||||
|
self.dnodes.append(TDDnode(7))
|
||||||
|
self.dnodes.append(TDDnode(8))
|
||||||
|
self.dnodes.append(TDDnode(9))
|
||||||
|
self.dnodes.append(TDDnode(10))
|
||||||
|
self.simDeployed = False
|
||||||
|
|
||||||
|
def init(self, path):
|
||||||
|
psCmd = "ps -ef|grep -w taosd| grep -v grep | awk '{print $2}'"
|
||||||
|
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
|
||||||
|
while(processID):
|
||||||
|
killCmd = "kill -KILL %s > /dev/null 2>&1" % processID
|
||||||
|
os.system(killCmd)
|
||||||
|
time.sleep(1)
|
||||||
|
processID = subprocess.check_output(
|
||||||
|
psCmd, shell=True).decode("utf-8")
|
||||||
|
|
||||||
|
psCmd = "ps -ef|grep -w valgrind.bin| grep -v grep | awk '{print $2}'"
|
||||||
|
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
|
||||||
|
while(processID):
|
||||||
|
killCmd = "kill -KILL %s > /dev/null 2>&1" % processID
|
||||||
|
os.system(killCmd)
|
||||||
|
time.sleep(1)
|
||||||
|
processID = subprocess.check_output(
|
||||||
|
psCmd, shell=True).decode("utf-8")
|
||||||
|
|
||||||
|
binPath = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
binPath = binPath + "/../../../debug/"
|
||||||
|
tdLog.debug("binPath %s" % (binPath))
|
||||||
|
binPath = os.path.realpath(binPath)
|
||||||
|
tdLog.debug("binPath real path %s" % (binPath))
|
||||||
|
|
||||||
|
# cmd = "sudo cp %s/build/lib/libtaos.so /usr/local/lib/taos/" % (binPath)
|
||||||
|
# tdLog.debug(cmd)
|
||||||
|
# os.system(cmd)
|
||||||
|
|
||||||
|
# cmd = "sudo cp %s/build/bin/taos /usr/local/bin/taos/" % (binPath)
|
||||||
|
# if os.system(cmd) != 0 :
|
||||||
|
# tdLog.exit(cmd)
|
||||||
|
# tdLog.debug("execute %s" % (cmd))
|
||||||
|
|
||||||
|
# cmd = "sudo cp %s/build/bin/taosd /usr/local/bin/taos/" % (binPath)
|
||||||
|
# if os.system(cmd) != 0 :
|
||||||
|
# tdLog.exit(cmd)
|
||||||
|
# tdLog.debug("execute %s" % (cmd))
|
||||||
|
|
||||||
|
if path == "":
|
||||||
|
# self.path = os.path.expanduser('~')
|
||||||
|
self.path = os.path.abspath(binPath + "../../")
|
||||||
|
else:
|
||||||
|
self.path = os.path.realpath(path)
|
||||||
|
|
||||||
|
for i in range(len(self.dnodes)):
|
||||||
|
self.dnodes[i].init(self.path)
|
||||||
|
|
||||||
|
self.sim = TDSimClient()
|
||||||
|
self.sim.init(self.path)
|
||||||
|
|
||||||
|
def setTestCluster(self, value):
|
||||||
|
self.testCluster = value
|
||||||
|
|
||||||
|
def setValgrind(self, value):
|
||||||
|
self.valgrind = value
|
||||||
|
|
||||||
|
def deploy(self, index):
|
||||||
|
self.sim.setTestCluster(self.testCluster)
|
||||||
|
|
||||||
|
if (self.simDeployed == False):
|
||||||
|
self.sim.deploy()
|
||||||
|
self.simDeployed = True
|
||||||
|
|
||||||
|
self.check(index)
|
||||||
|
self.dnodes[index - 1].setTestCluster(self.testCluster)
|
||||||
|
self.dnodes[index - 1].setValgrind(self.valgrind)
|
||||||
|
self.dnodes[index - 1].deploy()
|
||||||
|
|
||||||
|
def cfg(self, index, option, value):
|
||||||
|
self.check(index)
|
||||||
|
self.dnodes[index - 1].cfg(option, value)
|
||||||
|
|
||||||
|
def start(self, index):
|
||||||
|
self.check(index)
|
||||||
|
self.dnodes[index - 1].start()
|
||||||
|
|
||||||
|
def stop(self, index):
|
||||||
|
self.check(index)
|
||||||
|
self.dnodes[index - 1].stop()
|
||||||
|
|
||||||
|
def getDataSize(self, index):
|
||||||
|
self.check(index)
|
||||||
|
return self.dnodes[index - 1].getDataSize()
|
||||||
|
|
||||||
|
def forcestop(self, index):
|
||||||
|
self.check(index)
|
||||||
|
self.dnodes[index - 1].forcestop()
|
||||||
|
|
||||||
|
def startIP(self, index):
|
||||||
|
self.check(index)
|
||||||
|
|
||||||
|
if self.testCluster:
|
||||||
|
self.dnodes[index - 1].startIP()
|
||||||
|
|
||||||
|
def stopIP(self, index):
|
||||||
|
self.check(index)
|
||||||
|
|
||||||
|
if self.dnodes[index - 1].testCluster:
|
||||||
|
self.dnodes[index - 1].stopIP()
|
||||||
|
|
||||||
|
def check(self, index):
|
||||||
|
if index < 1 or index > 10:
|
||||||
|
tdLog.exit("index:%d should on a scale of [1, 10]" % (index))
|
||||||
|
|
||||||
|
def stopAll(self):
|
||||||
|
tdLog.info("stop all dnodes")
|
||||||
|
for i in range(len(self.dnodes)):
|
||||||
|
self.dnodes[i].stop()
|
||||||
|
|
||||||
|
psCmd = "ps -ef | grep -w taosd | grep 'root' | grep -v grep | awk '{print $2}'"
|
||||||
|
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
|
||||||
|
if processID:
|
||||||
|
cmd = "sudo systemctl stop taosd"
|
||||||
|
os.system(cmd)
|
||||||
|
# if os.system(cmd) != 0 :
|
||||||
|
# tdLog.exit(cmd)
|
||||||
|
psCmd = "ps -ef|grep -w taosd| grep -v grep | awk '{print $2}'"
|
||||||
|
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
|
||||||
|
while(processID):
|
||||||
|
killCmd = "kill -KILL %s > /dev/null 2>&1" % processID
|
||||||
|
os.system(killCmd)
|
||||||
|
time.sleep(1)
|
||||||
|
processID = subprocess.check_output(
|
||||||
|
psCmd, shell=True).decode("utf-8")
|
||||||
|
|
||||||
|
psCmd = "ps -ef|grep -w valgrind.bin| grep -v grep | awk '{print $2}'"
|
||||||
|
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
|
||||||
|
while(processID):
|
||||||
|
killCmd = "kill -KILL %s > /dev/null 2>&1" % processID
|
||||||
|
os.system(killCmd)
|
||||||
|
time.sleep(1)
|
||||||
|
processID = subprocess.check_output(
|
||||||
|
psCmd, shell=True).decode("utf-8")
|
||||||
|
|
||||||
|
# if os.system(cmd) != 0 :
|
||||||
|
# tdLog.exit(cmd)
|
||||||
|
|
||||||
|
def getDnodesRootDir(self):
|
||||||
|
dnodesRootDir = "%s/sim" % (self.path)
|
||||||
|
return dnodesRootDir
|
||||||
|
|
||||||
|
def getSimCfgPath(self):
|
||||||
|
return self.sim.getCfgDir()
|
||||||
|
|
||||||
|
def getSimLogPath(self):
|
||||||
|
return self.sim.getLogDir()
|
||||||
|
|
||||||
|
def addSimExtraCfg(self, option, value):
|
||||||
|
self.sim.addExtraCfg(option, value)
|
||||||
|
|
||||||
|
|
||||||
|
tdDnodes = TDDnodes()
|
|
@ -175,7 +175,8 @@ class TDDnode:
|
||||||
self.cfg("logDir", self.logDir)
|
self.cfg("logDir", self.logDir)
|
||||||
self.cfg("numOfLogLines", "100000000")
|
self.cfg("numOfLogLines", "100000000")
|
||||||
self.cfg("mnodeEqualVnodeNum", "0")
|
self.cfg("mnodeEqualVnodeNum", "0")
|
||||||
self.cfg("walLevel", "1")
|
self.cfg("walLevel", "2")
|
||||||
|
self.cfg("fsync", "1000")
|
||||||
self.cfg("statusInterval", "1")
|
self.cfg("statusInterval", "1")
|
||||||
self.cfg("numOfTotalVnodes", "64")
|
self.cfg("numOfTotalVnodes", "64")
|
||||||
self.cfg("numOfMnodes", "3")
|
self.cfg("numOfMnodes", "3")
|
||||||
|
@ -235,12 +236,12 @@ class TDDnode:
|
||||||
tdLog.exit("dnode:%d is not deployed" % (self.index))
|
tdLog.exit("dnode:%d is not deployed" % (self.index))
|
||||||
|
|
||||||
if self.valgrind == 0:
|
if self.valgrind == 0:
|
||||||
cmd = "nohup %s -c %s > /dev/null 2>&1 & " % (
|
cmd = "nohup %s -c %s --alloc-random-fail --random-file-fail-factor 5 > /dev/null 2>&1 & " % (
|
||||||
binPath, self.cfgDir)
|
binPath, self.cfgDir)
|
||||||
else:
|
else:
|
||||||
valgrindCmdline = "valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"
|
valgrindCmdline = "valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"
|
||||||
|
|
||||||
cmd = "nohup %s %s -c %s --random-file-fail-factor 5 2>&1 & " % (
|
cmd = "nohup %s %s -c %s 2>&1 & " % (
|
||||||
valgrindCmdline, binPath, self.cfgDir)
|
valgrindCmdline, binPath, self.cfgDir)
|
||||||
|
|
||||||
print(cmd)
|
print(cmd)
|
||||||
|
|
|
@ -177,7 +177,8 @@ class TDDnode:
|
||||||
self.cfg("logDir", self.logDir)
|
self.cfg("logDir", self.logDir)
|
||||||
self.cfg("numOfLogLines", "100000000")
|
self.cfg("numOfLogLines", "100000000")
|
||||||
self.cfg("mnodeEqualVnodeNum", "0")
|
self.cfg("mnodeEqualVnodeNum", "0")
|
||||||
self.cfg("walLevel", "1")
|
self.cfg("walLevel", "2")
|
||||||
|
self.cfg("fsync", "1000")
|
||||||
self.cfg("statusInterval", "1")
|
self.cfg("statusInterval", "1")
|
||||||
self.cfg("numOfTotalVnodes", "64")
|
self.cfg("numOfTotalVnodes", "64")
|
||||||
self.cfg("numOfMnodes", "3")
|
self.cfg("numOfMnodes", "3")
|
||||||
|
|
|
@ -110,7 +110,7 @@ echo "second ${HOSTNAME}:7200" >> $TAOS_CFG
|
||||||
echo "serverPort ${NODE}" >> $TAOS_CFG
|
echo "serverPort ${NODE}" >> $TAOS_CFG
|
||||||
echo "dataDir $DATA_DIR" >> $TAOS_CFG
|
echo "dataDir $DATA_DIR" >> $TAOS_CFG
|
||||||
echo "logDir $LOG_DIR" >> $TAOS_CFG
|
echo "logDir $LOG_DIR" >> $TAOS_CFG
|
||||||
echo "debugFlag 131" >> $TAOS_CFG
|
echo "debugFlag 0" >> $TAOS_CFG
|
||||||
echo "mDebugFlag 135" >> $TAOS_CFG
|
echo "mDebugFlag 135" >> $TAOS_CFG
|
||||||
echo "sdbDebugFlag 135" >> $TAOS_CFG
|
echo "sdbDebugFlag 135" >> $TAOS_CFG
|
||||||
echo "dDebugFlag 135" >> $TAOS_CFG
|
echo "dDebugFlag 135" >> $TAOS_CFG
|
||||||
|
@ -119,13 +119,13 @@ echo "tsdbDebugFlag 135" >> $TAOS_CFG
|
||||||
echo "cDebugFlag 135" >> $TAOS_CFG
|
echo "cDebugFlag 135" >> $TAOS_CFG
|
||||||
echo "jnidebugFlag 135" >> $TAOS_CFG
|
echo "jnidebugFlag 135" >> $TAOS_CFG
|
||||||
echo "odbcdebugFlag 135" >> $TAOS_CFG
|
echo "odbcdebugFlag 135" >> $TAOS_CFG
|
||||||
echo "httpDebugFlag 135" >> $TAOS_CFG
|
echo "httpDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "monitorDebugFlag 131" >> $TAOS_CFG
|
echo "monitorDebugFlag 135" >> $TAOS_CFG
|
||||||
echo "mqttDebugFlag 131" >> $TAOS_CFG
|
echo "mqttDebugFlag 135" >> $TAOS_CFG
|
||||||
echo "qdebugFlag 135" >> $TAOS_CFG
|
echo "qdebugFlag 135" >> $TAOS_CFG
|
||||||
echo "rpcDebugFlag 135" >> $TAOS_CFG
|
echo "rpcDebugFlag 135" >> $TAOS_CFG
|
||||||
echo "tmrDebugFlag 131" >> $TAOS_CFG
|
echo "tmrDebugFlag 131" >> $TAOS_CFG
|
||||||
echo "udebugFlag 135" >> $TAOS_CFG
|
echo "udebugFlag 143" >> $TAOS_CFG
|
||||||
echo "sdebugFlag 135" >> $TAOS_CFG
|
echo "sdebugFlag 135" >> $TAOS_CFG
|
||||||
echo "wdebugFlag 135" >> $TAOS_CFG
|
echo "wdebugFlag 135" >> $TAOS_CFG
|
||||||
echo "monitor 0" >> $TAOS_CFG
|
echo "monitor 0" >> $TAOS_CFG
|
||||||
|
@ -133,7 +133,7 @@ echo "monitorInterval 1" >> $TAOS_CFG
|
||||||
echo "http 0" >> $TAOS_CFG
|
echo "http 0" >> $TAOS_CFG
|
||||||
echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG
|
echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG
|
||||||
echo "defaultPass taosdata" >> $TAOS_CFG
|
echo "defaultPass taosdata" >> $TAOS_CFG
|
||||||
echo "numOfLogLines 10000000" >> $TAOS_CFG
|
echo "numOfLogLines 20000000" >> $TAOS_CFG
|
||||||
echo "mnodeEqualVnodeNum 0" >> $TAOS_CFG
|
echo "mnodeEqualVnodeNum 0" >> $TAOS_CFG
|
||||||
echo "clog 2" >> $TAOS_CFG
|
echo "clog 2" >> $TAOS_CFG
|
||||||
echo "statusInterval 1" >> $TAOS_CFG
|
echo "statusInterval 1" >> $TAOS_CFG
|
||||||
|
@ -145,6 +145,6 @@ echo "tableIncStepPerVnode 10000" >> $TAOS_CFG
|
||||||
echo "asyncLog 0" >> $TAOS_CFG
|
echo "asyncLog 0" >> $TAOS_CFG
|
||||||
echo "numOfMnodes 1" >> $TAOS_CFG
|
echo "numOfMnodes 1" >> $TAOS_CFG
|
||||||
echo "locale en_US.UTF-8" >> $TAOS_CFG
|
echo "locale en_US.UTF-8" >> $TAOS_CFG
|
||||||
echo "anyIp 0" >> $TAOS_CFG
|
echo "fsync 0" >> $TAOS_CFG
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# if [ $# != 4 || $# != 5 ]; then
|
||||||
|
# echo "argument list need input : "
|
||||||
|
# echo " -n nodeName"
|
||||||
|
# echo " -s start/stop"
|
||||||
|
# echo " -c clear"
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
|
||||||
|
NODE_NAME=
|
||||||
|
EXEC_OPTON=
|
||||||
|
CLEAR_OPTION="false"
|
||||||
|
while getopts "n:s:u:x:ct" arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
n)
|
||||||
|
NODE_NAME=$OPTARG
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
EXEC_OPTON=$OPTARG
|
||||||
|
;;
|
||||||
|
c)
|
||||||
|
CLEAR_OPTION="clear"
|
||||||
|
;;
|
||||||
|
t)
|
||||||
|
SHELL_OPTION="true"
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
USERS=$OPTARG
|
||||||
|
;;
|
||||||
|
x)
|
||||||
|
SIGNAL=$OPTARG
|
||||||
|
;;
|
||||||
|
?)
|
||||||
|
echo "unkown argument"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
SCRIPT_DIR=`dirname $0`
|
||||||
|
cd $SCRIPT_DIR/../
|
||||||
|
SCRIPT_DIR=`pwd`
|
||||||
|
|
||||||
|
IN_TDINTERNAL="community"
|
||||||
|
if [[ "$SCRIPT_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||||
|
cd ../../..
|
||||||
|
else
|
||||||
|
cd ../../
|
||||||
|
fi
|
||||||
|
|
||||||
|
TAOS_DIR=`pwd`
|
||||||
|
TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1`
|
||||||
|
|
||||||
|
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||||
|
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2,3`
|
||||||
|
else
|
||||||
|
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' --fields=2`
|
||||||
|
fi
|
||||||
|
|
||||||
|
BUILD_DIR=$TAOS_DIR/$BIN_DIR/build
|
||||||
|
|
||||||
|
SIM_DIR=$TAOS_DIR/sim
|
||||||
|
NODE_DIR=$SIM_DIR/$NODE_NAME
|
||||||
|
EXE_DIR=$BUILD_DIR/bin
|
||||||
|
CFG_DIR=$NODE_DIR/cfg
|
||||||
|
LOG_DIR=$NODE_DIR/log
|
||||||
|
DATA_DIR=$NODE_DIR/data
|
||||||
|
MGMT_DIR=$NODE_DIR/data/mgmt
|
||||||
|
TSDB_DIR=$NODE_DIR/data/tsdb
|
||||||
|
|
||||||
|
TAOS_CFG=$NODE_DIR/cfg/taos.cfg
|
||||||
|
|
||||||
|
echo ------------ $EXEC_OPTON $NODE_NAME
|
||||||
|
|
||||||
|
TAOS_FLAG=$SIM_DIR/tsim/flag
|
||||||
|
if [ -f "$TAOS_FLAG" ]; then
|
||||||
|
EXE_DIR=/usr/local/bin/taos
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$CLEAR_OPTION" = "clear" ]; then
|
||||||
|
echo rm -rf $MGMT_DIR $TSDB_DIR
|
||||||
|
rm -rf $TSDB_DIR
|
||||||
|
rm -rf $MGMT_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$EXEC_OPTON" = "start" ]; then
|
||||||
|
echo "ExcuteCmd:" $EXE_DIR/taosd -c $CFG_DIR
|
||||||
|
|
||||||
|
if [ "$SHELL_OPTION" = "true" ]; then
|
||||||
|
nohup valgrind --log-file=${LOG_DIR}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 &
|
||||||
|
else
|
||||||
|
nohup $EXE_DIR/taosd -c $CFG_DIR --random-file-fail-factor 0 > /dev/null 2>&1 &
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
#relative path
|
||||||
|
RCFG_DIR=sim/$NODE_NAME/cfg
|
||||||
|
PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'`
|
||||||
|
while [ -n "$PID" ]
|
||||||
|
do
|
||||||
|
if [ "$SIGNAL" = "SIGINT" ]; then
|
||||||
|
echo try to kill by signal SIGINT
|
||||||
|
kill -SIGINT $PID
|
||||||
|
else
|
||||||
|
echo try to kill by signal SIGKILL
|
||||||
|
kill -9 $PID
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'`
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
|
@ -90,7 +90,7 @@ if [ "$EXEC_OPTON" = "start" ]; then
|
||||||
if [ "$SHELL_OPTION" = "true" ]; then
|
if [ "$SHELL_OPTION" = "true" ]; then
|
||||||
nohup valgrind --log-file=${LOG_DIR}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 &
|
nohup valgrind --log-file=${LOG_DIR}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 &
|
||||||
else
|
else
|
||||||
nohup $EXE_DIR/taosd -c $CFG_DIR --random-file-fail-factor 5 > /dev/null 2>&1 &
|
nohup $EXE_DIR/taosd -c $CFG_DIR --alloc-random-fail --random-file-fail-factor 5 > /dev/null 2>&1 &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
|
@ -52,9 +52,9 @@ system sh/cfg.sh -n dnode1 -c qdebugFlag -v 131
|
||||||
system sh/cfg.sh -n dnode2 -c qdebugFlag -v 131
|
system sh/cfg.sh -n dnode2 -c qdebugFlag -v 131
|
||||||
system sh/cfg.sh -n dnode3 -c qdebugFlag -v 131
|
system sh/cfg.sh -n dnode3 -c qdebugFlag -v 131
|
||||||
|
|
||||||
system sh/cfg.sh -n dnode1 -c cDebugFlag -v 131
|
system sh/cfg.sh -n dnode1 -c cDebugFlag -v 135
|
||||||
system sh/cfg.sh -n dnode2 -c cDebugFlag -v 131
|
system sh/cfg.sh -n dnode2 -c cDebugFlag -v 135
|
||||||
system sh/cfg.sh -n dnode3 -c cDebugFlag -v 131
|
system sh/cfg.sh -n dnode3 -c cDebugFlag -v 135
|
||||||
|
|
||||||
system sh/cfg.sh -n dnode1 -c udebugFlag -v 131
|
system sh/cfg.sh -n dnode1 -c udebugFlag -v 131
|
||||||
system sh/cfg.sh -n dnode2 -c udebugFlag -v 131
|
system sh/cfg.sh -n dnode2 -c udebugFlag -v 131
|
||||||
|
@ -64,6 +64,10 @@ system sh/cfg.sh -n dnode1 -c wdebugFlag -v 131
|
||||||
system sh/cfg.sh -n dnode2 -c wdebugFlag -v 131
|
system sh/cfg.sh -n dnode2 -c wdebugFlag -v 131
|
||||||
system sh/cfg.sh -n dnode3 -c wdebugFlag -v 131
|
system sh/cfg.sh -n dnode3 -c wdebugFlag -v 131
|
||||||
|
|
||||||
|
system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 1000000
|
||||||
|
system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 1000000
|
||||||
|
system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 1000000
|
||||||
|
|
||||||
print ============== deploy
|
print ============== deploy
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s start
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
|
|
@ -15,21 +15,13 @@ system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1
|
||||||
system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1
|
system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1
|
||||||
system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1
|
system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1
|
||||||
|
|
||||||
|
system sh/cfg.sh -n dnode1 -c activeCode -v eglxDLzRpslJWl7OxrPZ2K3sQ5631AP9SVpezsaz2dhJWl7OxrPZ2ElaXs7Gs9nYSVpezsaz2djGIj5StnQ3ZvLHcsE8cwcN
|
||||||
|
|
||||||
system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4
|
system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4
|
||||||
system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4
|
system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4
|
||||||
system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4
|
system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4
|
||||||
system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 4
|
system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 4
|
||||||
|
|
||||||
system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 20
|
|
||||||
system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 20
|
|
||||||
system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 20
|
|
||||||
system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 20
|
|
||||||
|
|
||||||
system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 2
|
|
||||||
system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 2
|
|
||||||
system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 2
|
|
||||||
system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 2
|
|
||||||
|
|
||||||
system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 100000
|
system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 100000
|
||||||
system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 100000
|
system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 100000
|
||||||
system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 100000
|
system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 100000
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "taoserror.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tulog.h"
|
#include "tulog.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
@ -154,7 +155,7 @@ void *threadFunc(void *param) {
|
||||||
TAOS_RES *pSql = taos_query(con, qstr);
|
TAOS_RES *pSql = taos_query(con, qstr);
|
||||||
code = taos_errno(pSql);
|
code = taos_errno(pSql);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
pError("failed to create table %s%d, reason:%s", stableName, t, taos_errstr(con));
|
pError("failed to create table %s%d, reason:%s", stableName, t, tstrerror(code));
|
||||||
}
|
}
|
||||||
taos_free_result(pSql);
|
taos_free_result(pSql);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,9 @@
|
||||||
#define simFatal(...) { if (simDebugFlag & DEBUG_FATAL) { taosPrintLog("SIM FATAL ", 255, __VA_ARGS__); }}
|
#define simFatal(...) { if (simDebugFlag & DEBUG_FATAL) { taosPrintLog("SIM FATAL ", 255, __VA_ARGS__); }}
|
||||||
#define simError(...) { if (simDebugFlag & DEBUG_ERROR) { taosPrintLog("SIM ERROR ", 255, __VA_ARGS__); }}
|
#define simError(...) { if (simDebugFlag & DEBUG_ERROR) { taosPrintLog("SIM ERROR ", 255, __VA_ARGS__); }}
|
||||||
#define simWarn(...) { if (simDebugFlag & DEBUG_WARN) { taosPrintLog("SIM WARN ", 255, __VA_ARGS__); }}
|
#define simWarn(...) { if (simDebugFlag & DEBUG_WARN) { taosPrintLog("SIM WARN ", 255, __VA_ARGS__); }}
|
||||||
#define simInfo(...) { if (simDebugFlag & DEBUG_INFO) { taosPrintLog("SIM INFO ", 255, __VA_ARGS__); }}
|
#define simInfo(...) { if (simDebugFlag & DEBUG_INFO) { taosPrintLog("SIM ", 255, __VA_ARGS__); }}
|
||||||
#define simDebug(...) { if (simDebugFlag & DEBUG_DEBUG) { taosPrintLog("SIM DEBUG ", simDebugFlag, __VA_ARGS__); }}
|
#define simDebug(...) { if (simDebugFlag & DEBUG_DEBUG) { taosPrintLog("SIM ", simDebugFlag, __VA_ARGS__); }}
|
||||||
#define simTrace(...) { if (simDebugFlag & DEBUG_TRACE) { taosPrintLog("SIM TRACE ", simDebugFlag, __VA_ARGS__); }}
|
#define simTrace(...) { if (simDebugFlag & DEBUG_TRACE) { taosPrintLog("SIM ", simDebugFlag, __VA_ARGS__); }}
|
||||||
|
|
||||||
enum { SIM_SCRIPT_TYPE_MAIN, SIM_SCRIPT_TYPE_BACKGROUND };
|
enum { SIM_SCRIPT_TYPE_MAIN, SIM_SCRIPT_TYPE_BACKGROUND };
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue