diff --git a/importSampleData/app/main.go b/importSampleData/app/main.go index 6996047026..61de6e740c 100644 --- a/importSampleData/app/main.go +++ b/importSampleData/app/main.go @@ -7,7 +7,6 @@ import ( "encoding/json" "flag" "fmt" - "github.com/taosdata/TDengine/importSampleData/import" "hash/crc32" "io" "log" @@ -18,88 +17,89 @@ import ( "sync" "time" + dataimport "github.com/taosdata/TDengine/importSampleData/import" + _ "github.com/taosdata/driver-go/taosSql" ) const ( - TIMESTAMP = "timestamp" - DATETIME = "datetime" - MILLISECOND = "millisecond" - DEFAULT_STARTTIME int64 = -1 - DEFAULT_INTERVAL int64 = 1*1000 - DEFAULT_DELAY int64 = -1 - DEFAULT_STATISTIC_TABLE = "statistic" + TIMESTAMP = "timestamp" + DATETIME = "datetime" + MILLISECOND = "millisecond" + DEFAULT_STARTTIME int64 = -1 + DEFAULT_INTERVAL int64 = 1 * 1000 + DEFAULT_DELAY int64 = -1 + DEFAULT_STATISTIC_TABLE = "statistic" - JSON_FORMAT = "json" - CSV_FORMAT = "csv" + JSON_FORMAT = "json" + CSV_FORMAT = "csv" SUPERTABLE_PREFIX = "s_" - SUBTABLE_PREFIX = "t_" + SUBTABLE_PREFIX = "t_" - DRIVER_NAME = "taosSql" + DRIVER_NAME = "taosSql" STARTTIME_LAYOUT = "2006-01-02 15:04:05.000" - INSERT_PREFIX = "insert into " + INSERT_PREFIX = "insert into " ) var ( - - cfg string - cases string - hnum int - vnum int - thread int - batch int - auto int - starttimestr string - interval int64 - host string - port int - user string - password string - dropdb int - db string - dbparam string + cfg string + cases string + hnum int + vnum int + thread int + batch int + auto int + starttimestr string + interval int64 + host string + port int + user string + password string + dropdb int + db string + dbparam string dataSourceName string - startTime int64 + startTime int64 - superTableConfigMap = make(map[string]*superTableConfig) - subTableMap = make(map[string]*dataRows) - scaleTableNames []string + superTableConfigMap = make(map[string]*superTableConfig) + subTableMap = make(map[string]*dataRows) + scaleTableNames []string scaleTableMap = make(map[string]*scaleTableInfo) - successRows []int64 + successRows []int64 lastStaticTime time.Time - lastTotalRows int64 - timeTicker *time.Ticker - delay int64 // default 10 milliseconds - tick int64 - save int - saveTable string + lastTotalRows int64 + timeTicker *time.Ticker + delay int64 // default 10 milliseconds + tick int64 + save int + saveTable string ) type superTableConfig struct { - startTime int64 - endTime int64 - cycleTime int64 + startTime int64 + endTime int64 + cycleTime int64 avgInterval int64 - config dataimport.CaseConfig + config dataimport.CaseConfig } type scaleTableInfo struct { scaleTableName string - subTableName string - insertRows int64 + subTableName string + insertRows int64 } type tableRows struct { - tableName string // tableName - value string // values(...) + tableName string // tableName + value string // values(...) } type dataRows struct { - rows []map[string]interface{} - config dataimport.CaseConfig + rows []map[string]interface{} + config dataimport.CaseConfig } func (rows dataRows) Len() int { @@ -127,10 +127,10 @@ func init() { if db == "" { //db = "go" - db = fmt.Sprintf("test_%s",time.Now().Format("20060102")) + db = fmt.Sprintf("test_%s", time.Now().Format("20060102")) } - if auto == 1 && len(starttimestr) == 0 { + if auto == 1 && len(starttimestr) == 0 { log.Fatalf("startTime must be set when auto is 1, the format is \"yyyy-MM-dd HH:mm:ss.SSS\" ") } @@ -141,7 +141,7 @@ func init() { } startTime = t.UnixNano() / 1e6 // as millisecond - }else{ + } else { startTime = DEFAULT_STARTTIME } @@ -179,7 +179,7 @@ func main() { _, exists := superTableConfigMap[caseConfig.Stname] if !exists { - superTableConfigMap[caseConfig.Stname] = &superTableConfig{config:caseConfig} + superTableConfigMap[caseConfig.Stname] = &superTableConfig{config: caseConfig} } else { log.Fatalf("the stname of case %s already exist.\n", caseConfig.Stname) } @@ -201,9 +201,9 @@ func main() { if DEFAULT_DELAY == delay { // default delay - delay = caseMinumInterval / 2 + delay = caseMinumInterval / 2 if delay < 1 { - delay = 1 + delay = 1 } log.Printf("actual delay is %d ms.", delay) } @@ -232,7 +232,7 @@ func main() { filePerThread := subTableNum / thread leftFileNum := subTableNum % thread - var wg sync.WaitGroup + var wg sync.WaitGroup start = time.Now() @@ -255,31 +255,31 @@ func main() { go staticSpeed() wg.Wait() - usedTime := time.Since(start) + usedTime := time.Since(start) total := getTotalRows(successRows) - log.Printf("finished insert %d rows, used %d ms, speed %d rows/s", total, usedTime/1e6, total * 1e9 / int64(usedTime)) + log.Printf("finished insert %d rows, used %d ms, speed %d rows/s", total, usedTime/1e6, total*1e3/usedTime.Milliseconds()) if vnum == 0 { // continue waiting for insert data - wait := make(chan string) - v := <- wait + wait := make(chan string) + v := <-wait log.Printf("program receive %s, exited.\n", v) - }else{ + } else { timeTicker.Stop() } } -func staticSpeed(){ +func staticSpeed() { connection := getConnection() defer connection.Close() if save == 1 { connection.Exec("use " + db) - _, err := connection.Exec("create table if not exists " + saveTable +"(ts timestamp, speed int)") + _, err := connection.Exec("create table if not exists " + saveTable + "(ts timestamp, speed int)") if err != nil { log.Fatalf("create %s Table error: %s\n", saveTable, err) } @@ -287,13 +287,13 @@ func staticSpeed(){ for { <-timeTicker.C - + currentTime := time.Now() usedTime := currentTime.UnixNano() - lastStaticTime.UnixNano() - + total := getTotalRows(successRows) currentSuccessRows := total - lastTotalRows - + speed := currentSuccessRows * 1e9 / int64(usedTime) log.Printf("insert %d rows, used %d ms, speed %d rows/s", currentSuccessRows, usedTime/1e6, speed) @@ -301,14 +301,14 @@ func staticSpeed(){ insertSql := fmt.Sprintf("insert into %s values(%d, %d)", saveTable, currentTime.UnixNano()/1e6, speed) connection.Exec(insertSql) } - + lastStaticTime = currentTime lastTotalRows = total } } -func getTotalRows(successRows []int64) int64{ +func getTotalRows(successRows []int64) int64 { var total int64 = 0 for j := 0; j < len(successRows); j++ { total += successRows[j] @@ -316,18 +316,18 @@ func getTotalRows(successRows []int64) int64{ return total } -func getSuperTableTimeConfig(fileRows dataRows) (start, cycleTime, avgInterval int64){ +func getSuperTableTimeConfig(fileRows dataRows) (start, cycleTime, avgInterval int64) { if auto == 1 { // use auto generate data time start = startTime avgInterval = interval maxTableRows := normalizationDataWithSameInterval(fileRows, avgInterval) - cycleTime = maxTableRows * avgInterval + avgInterval + cycleTime = maxTableRows*avgInterval + avgInterval } else { // use the sample data primary timestamp - sort.Sort(fileRows)// sort the file data by the primarykey + sort.Sort(fileRows) // sort the file data by the primarykey minTime := getPrimaryKey(fileRows.rows[0][fileRows.config.Timestamp]) maxTime := getPrimaryKey(fileRows.rows[len(fileRows.rows)-1][fileRows.config.Timestamp]) @@ -340,21 +340,21 @@ func getSuperTableTimeConfig(fileRows dataRows) (start, cycleTime, avgInterval i if minTime == maxTime { avgInterval = interval - cycleTime = tableNum * avgInterval + avgInterval - }else{ + cycleTime = tableNum*avgInterval + avgInterval + } else { avgInterval = (maxTime - minTime) / int64(len(fileRows.rows)) * tableNum cycleTime = maxTime - minTime + avgInterval } - + } return } -func createStatisticTable(){ +func createStatisticTable() { connection := getConnection() defer connection.Close() - _, err := connection.Exec("create table if not exist " + db + "."+ saveTable +"(ts timestamp, speed int)") + _, err := connection.Exec("create table if not exist " + db + "." + saveTable + "(ts timestamp, speed int)") if err != nil { log.Fatalf("createStatisticTable error: %s\n", err) } @@ -379,8 +379,8 @@ func createSubTable(subTableMaps map[string]*dataRows) { tableName := getScaleSubTableName(subTableName, i) scaleTableMap[tableName] = &scaleTableInfo{ - subTableName: subTableName, - insertRows: 0, + subTableName: subTableName, + insertRows: 0, } scaleTableNames = append(scaleTableNames, tableName) @@ -389,12 +389,12 @@ func createSubTable(subTableMaps map[string]*dataRows) { buffers.WriteString(" using ") buffers.WriteString(superTableName) buffers.WriteString(" tags(") - for _, tag := range subTableMaps[subTableName].config.Tags{ + for _, tag := range subTableMaps[subTableName].config.Tags { tagValue := fmt.Sprintf("%v", tagValues[strings.ToLower(tag.Name)]) buffers.WriteString("'" + tagValue + "'") buffers.WriteString(",") } - buffers.Truncate(buffers.Len()-1) + buffers.Truncate(buffers.Len() - 1) buffers.WriteString(")") createTableSql := buffers.String() @@ -451,14 +451,14 @@ func createSuperTable(superTableConfigMap map[string]*superTableConfig) { buffer.WriteString(field.Name + " " + field.Type + ",") } - buffer.Truncate(buffer.Len()-1) + buffer.Truncate(buffer.Len() - 1) buffer.WriteString(") tags( ") for _, tag := range superTableConf.config.Tags { buffer.WriteString(tag.Name + " " + tag.Type + ",") } - buffer.Truncate(buffer.Len()-1) + buffer.Truncate(buffer.Len() - 1) buffer.WriteString(")") createSql := buffer.String() @@ -475,16 +475,15 @@ func createSuperTable(superTableConfigMap map[string]*superTableConfig) { func getScaleSubTableName(subTableName string, hnum int) string { if hnum == 0 { - return subTableName + return subTableName } - return fmt.Sprintf( "%s_%d", subTableName, hnum) + return fmt.Sprintf("%s_%d", subTableName, hnum) } func getSuperTableName(stname string) string { return SUPERTABLE_PREFIX + stname } - /** * normalizationData , and return the num of subTables */ @@ -505,12 +504,12 @@ func normalizationData(fileRows dataRows, minTime int64) int64 { value, ok := subTableMap[subTableName] if !ok { subTableMap[subTableName] = &dataRows{ - rows: []map[string]interface{}{row}, - config: fileRows.config, + rows: []map[string]interface{}{row}, + config: fileRows.config, } tableNum++ - }else{ + } else { value.rows = append(value.rows, row) } } @@ -518,9 +517,9 @@ func normalizationData(fileRows dataRows, minTime int64) int64 { } // return the maximum table rows -func normalizationDataWithSameInterval(fileRows dataRows, avgInterval int64) int64{ +func normalizationDataWithSameInterval(fileRows dataRows, avgInterval int64) int64 { // subTableMap - currSubTableMap := make(map[string]*dataRows) + currSubTableMap := make(map[string]*dataRows) for _, row := range fileRows.rows { // get subTableName tableValue := getSubTableNameValue(row[fileRows.config.SubTableName]) @@ -534,10 +533,10 @@ func normalizationDataWithSameInterval(fileRows dataRows, avgInterval int64) int if !ok { row[fileRows.config.Timestamp] = 0 currSubTableMap[subTableName] = &dataRows{ - rows: []map[string]interface{}{row}, - config: fileRows.config, + rows: []map[string]interface{}{row}, + config: fileRows.config, } - }else{ + } else { row[fileRows.config.Timestamp] = int64(len(value.rows)) * avgInterval value.rows = append(value.rows, row) } @@ -545,7 +544,7 @@ func normalizationDataWithSameInterval(fileRows dataRows, avgInterval int64) int } var maxRows, tableRows int = 0, 0 - for tableName := range currSubTableMap{ + for tableName := range currSubTableMap { tableRows = len(currSubTableMap[tableName].rows) subTableMap[tableName] = currSubTableMap[tableName] // add to global subTableMap if tableRows > maxRows { @@ -556,13 +555,11 @@ func normalizationDataWithSameInterval(fileRows dataRows, avgInterval int64) int return int64(maxRows) } - -func getSubTableName(subTableValue string, superTableName string) string { +func getSubTableName(subTableValue string, superTableName string) string { return SUBTABLE_PREFIX + subTableValue + "_" + superTableName } - -func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows []int64) { +func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows []int64) { connection := getConnection() defer connection.Close() defer wg.Done() @@ -591,9 +588,9 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows [] var tableEndTime int64 if vnum == 0 { // need continue generate data - tableEndTime = time.Now().UnixNano()/1e6 - }else { - tableEndTime = tableStartTime + superTableConf.cycleTime * int64(vnum) - superTableConf.avgInterval + tableEndTime = time.Now().UnixNano() / 1e6 + } else { + tableEndTime = tableStartTime + superTableConf.cycleTime*int64(vnum) - superTableConf.avgInterval } insertRows := scaleTableMap[tableName].insertRows @@ -603,10 +600,10 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows [] rowIndex := insertRows % subTableRows currentRow := subTableInfo.rows[rowIndex] - currentTime := getPrimaryKey(currentRow[subTableInfo.config.Timestamp]) + loopNum * superTableConf.cycleTime + tableStartTime + currentTime := getPrimaryKey(currentRow[subTableInfo.config.Timestamp]) + loopNum*superTableConf.cycleTime + tableStartTime if currentTime <= tableEndTime { // append - + if lastTableName != tableName { buffers.WriteString(tableName) buffers.WriteString(" values") @@ -616,22 +613,22 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows [] buffers.WriteString("(") buffers.WriteString(fmt.Sprintf("%v", currentTime)) buffers.WriteString(",") - + // fieldNum := len(subTableInfo.config.Fields) - for _,field := range subTableInfo.config.Fields { + for _, field := range subTableInfo.config.Fields { buffers.WriteString(getFieldValue(currentRow[strings.ToLower(field.Name)])) buffers.WriteString(",") // if( i != fieldNum -1){ - + // } } - buffers.Truncate(buffers.Len()-1) + buffers.Truncate(buffers.Len() - 1) buffers.WriteString(") ") appendRows++ insertRows++ - if appendRows == batch { + if appendRows == batch { // executebatch insertSql := buffers.String() connection.Exec("use " + db) @@ -645,7 +642,7 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows [] lastTableName = "" appendRows = 0 } - }else { + } else { // finished insert current table break } @@ -654,14 +651,14 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows [] scaleTableMap[tableName].insertRows = insertRows } - + // left := len(rows) - if appendRows > 0 { + if appendRows > 0 { // executebatch insertSql := buffers.String() connection.Exec("use " + db) affectedRows := executeBatchInsert(insertSql, connection) - + successRows[threadIndex] += affectedRows currSuccessRows += affectedRows @@ -676,7 +673,7 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows [] break } - if(num == 0){ + if num == 0 { wg.Done() //finished insert history data num++ } @@ -691,7 +688,7 @@ func insertData(threadIndex, start, end int, wg *sync.WaitGroup, successRows [] } -func buildSql(rows []tableRows) string{ +func buildSql(rows []tableRows) string { var lastTableName string @@ -709,7 +706,7 @@ func buildSql(rows []tableRows) string{ if lastTableName == row.tableName { buffers.WriteString(row.value) - }else { + } else { buffers.WriteString(" ") buffers.WriteString(row.tableName) buffers.WriteString(" values") @@ -722,7 +719,7 @@ func buildSql(rows []tableRows) string{ return inserSql } -func buildRow(tableName string, currentTime int64, subTableInfo *dataRows, currentRow map[string]interface{}) tableRows{ +func buildRow(tableName string, currentTime int64, subTableInfo *dataRows, currentRow map[string]interface{}) tableRows { tableRows := tableRows{tableName: tableName} @@ -732,12 +729,12 @@ func buildRow(tableName string, currentTime int64, subTableInfo *dataRows, curre buffers.WriteString(fmt.Sprintf("%v", currentTime)) buffers.WriteString(",") - for _,field := range subTableInfo.config.Fields { + for _, field := range subTableInfo.config.Fields { buffers.WriteString(getFieldValue(currentRow[strings.ToLower(field.Name)])) buffers.WriteString(",") } - buffers.Truncate(buffers.Len()-1) + buffers.Truncate(buffers.Len() - 1) buffers.WriteString(")") insertSql := buffers.String() @@ -764,7 +761,7 @@ func getFieldValue(fieldValue interface{}) string { return fmt.Sprintf("'%v'", fieldValue) } -func getConnection() *sql.DB{ +func getConnection() *sql.DB { db, err := sql.Open(DRIVER_NAME, dataSourceName) if err != nil { panic(err) @@ -772,7 +769,6 @@ func getConnection() *sql.DB{ return db } - func getSubTableNameValue(suffix interface{}) string { return fmt.Sprintf("%v", suffix) } @@ -950,7 +946,7 @@ func parseMillisecond(str interface{}, layout string) int64 { log.Println(err) return -1 } - return t.UnixNano()/1e6 + return t.UnixNano() / 1e6 } // lowerMapKey transfer all the map key to lowercase @@ -1009,7 +1005,7 @@ func checkUserCaseConfig(caseName string, caseConfig *dataimport.CaseConfig) { if i < len(caseConfig.Fields)-1 { // delete middle item, a = a[:i+copy(a[i:], a[i+1:])] caseConfig.Fields = caseConfig.Fields[:i+copy(caseConfig.Fields[i:], caseConfig.Fields[i+1:])] - }else { + } else { // delete the last item caseConfig.Fields = caseConfig.Fields[:len(caseConfig.Fields)-1] } @@ -1057,7 +1053,7 @@ func parseArg() { flag.Parse() } -func printArg() { +func printArg() { fmt.Println("used param: ") fmt.Println("-cfg: ", cfg) fmt.Println("-cases:", cases) diff --git a/importSampleData/bin/taosimport b/importSampleData/bin/taosimport deleted file mode 100755 index 235fde9f06..0000000000 Binary files a/importSampleData/bin/taosimport and /dev/null differ diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index 40b4c43fdd..f652c65f56 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -51,18 +51,15 @@ # number of threads per CPU core # numOfThreadsPerCore 1.0 -# number of vnodes per core in DNode -# numOfVnodesPerCore 8 +# number of vgroups per db +# maxVgroupsPerDb 0 + +# max number of tables per vnode +# maxTablesPerVnode 1000000 # the ratio of threads responsible for querying in the total thread # ratioOfQueryThreads 0.5 -# number of total vnodes in DNode -# numOfTotalVnodes 0 - -# max number of tables per vnode -# maxtablesPerVnode 1000 - # interval of check load balance when the management node is in normal operation # balanceInterval 300 diff --git a/src/client/inc/tscLog.h b/src/client/inc/tscLog.h index 94adcfe17a..9d01edae36 100644 --- a/src/client/inc/tscLog.h +++ b/src/client/inc/tscLog.h @@ -27,11 +27,11 @@ extern int32_t tscEmbedded; #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 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 tscDebug(...) { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC DEBUG ", cDebugFlag, __VA_ARGS__); }} -#define tscTrace(...) { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC TRACE ", cDebugFlag, __VA_ARGS__); }} -#define tscDebugL(...){ if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC DEBUG ", 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 ", tscEmbedded ? 255 : cDebugFlag, __VA_ARGS__); }} +#define tscDebug(...) { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} +#define tscTrace(...) { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", cDebugFlag, __VA_ARGS__); }} +#define tscDebugL(...){ if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", cDebugFlag, __VA_ARGS__); }} #ifdef __cplusplus } diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 4992692109..4af929bf41 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -160,7 +160,9 @@ void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo); int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index); void tscFieldInfoClear(SFieldInfo* pFieldInfo); -int32_t tscNumOfFields(SQueryInfo* pQueryInfo); + +static FORCE_INLINE int32_t tscNumOfFields(SQueryInfo* pQueryInfo) { return pQueryInfo->fieldsInfo.numOfOutput; } + int32_t tscFieldInfoCompare(const SFieldInfo* pFieldInfo1, const SFieldInfo* pFieldInfo2); void addExprParams(SSqlExpr* pExpr, char* argument, int32_t type, int32_t bytes, int16_t tableIndex); diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index a398ad659e..be82eb64a8 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -412,7 +412,44 @@ char *tscGetErrorMsgPayload(SSqlCmd *pCmd); int32_t tscInvalidSQLErrMsg(char *msg, const char *additionalInfo, const char *sql); int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo); -void tscGetResultColumnChr(SSqlRes *pRes, SFieldInfo* pFieldInfo, int32_t column); +//void tscGetResultColumnChr(SSqlRes *pRes, SFieldInfo* pFieldInfo, int32_t column); + +static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t columnIndex) { + SFieldSupInfo* pInfo = (SFieldSupInfo*) TARRAY_GET_ELEM(pFieldInfo->pSupportInfo, columnIndex); + assert(pInfo->pSqlExpr != NULL); + + int32_t type = pInfo->pSqlExpr->resType; + int32_t bytes = pInfo->pSqlExpr->resBytes; + + char* pData = pRes->data + pInfo->pSqlExpr->offset * pRes->numOfRows + bytes * pRes->row; + + if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) { + int32_t realLen = varDataLen(pData); + assert(realLen <= bytes - VARSTR_HEADER_SIZE); + + if (isNull(pData, type)) { + pRes->tsrow[columnIndex] = NULL; + } else { + pRes->tsrow[columnIndex] = ((tstr*)pData)->data; + } + + if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor + *(pData + realLen + VARSTR_HEADER_SIZE) = 0; + } + + pRes->length[columnIndex] = realLen; + } else { + assert(bytes == tDataTypeDesc[type].nSize); + + if (isNull(pData, type)) { + pRes->tsrow[columnIndex] = NULL; + } else { + pRes->tsrow[columnIndex] = pData; + } + + pRes->length[columnIndex] = bytes; + } +} extern void * tscCacheHandle; extern void * tscTmr; diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index eb9b1cb479..549a0e8d0d 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -24,10 +24,10 @@ #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 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 jniDebug(...) { if (jniDebugFlag & DEBUG_DEBUG) { taosPrintLog("JNI DEBUG ", jniDebugFlag, __VA_ARGS__); }} -#define jniTrace(...) { if (jniDebugFlag & DEBUG_TRACE) { taosPrintLog("JNI TRACE ", 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 ", tscEmbedded ? 255 : jniDebugFlag, __VA_ARGS__); }} +#define jniDebug(...) { if (jniDebugFlag & DEBUG_DEBUG) { taosPrintLog("JNI ", jniDebugFlag, __VA_ARGS__); }} +#define jniTrace(...) { if (jniDebugFlag & DEBUG_TRACE) { taosPrintLog("JNI ", jniDebugFlag, __VA_ARGS__); }} int __init = 0; diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 41464aa660..6ab4eeaa8a 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -43,8 +43,9 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const pSql->signature = pSql; pSql->param = param; pSql->pTscObj = pObj; - pSql->maxRetry = TSDB_MAX_REPLICA_NUM; + pSql->maxRetry = TSDB_MAX_REPLICA; pSql->fp = fp; + pSql->fetchFp = fp; pSql->sqlstr = calloc(1, sqlLen + 1); if (pSql->sqlstr == NULL) { @@ -53,7 +54,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const return; } - strtolower(pSql->sqlstr, sqlstr); + strntolower(pSql->sqlstr, sqlstr, sqlLen); tscDebugL("%p SQL: %s", pSql, pSql->sqlstr); pSql->cmd.curSql = pSql->sqlstr; @@ -159,7 +160,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo pRes->code = numOfRows; } - tscQueueAsyncError(pSql->fetchFp, param, pRes->code); + tscQueueAsyncRes(pSql); return; } @@ -167,6 +168,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo if (pCmd->command != TSDB_SQL_RETRIEVE_LOCALMERGE && pCmd->command < TSDB_SQL_LOCAL) { pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; } + tscProcessSql(pSql); } @@ -196,6 +198,10 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi SSqlRes *pRes = &pSql->res; SSqlCmd *pCmd = &pSql->cmd; + // user-defined callback function is stored in fetchFp + pSql->fetchFp = fp; + pSql->fp = tscAsyncFetchRowsProxy; + if (pRes->qhandle == 0) { tscError("qhandle is NULL"); pRes->code = TSDB_CODE_TSC_INVALID_QHANDLE; @@ -203,10 +209,6 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi return; } - // user-defined callback function is stored in fetchFp - pSql->fetchFp = fp; - pSql->fp = tscAsyncFetchRowsProxy; - pSql->param = param; tscResetForNextRetrieve(pRes); @@ -346,31 +348,32 @@ void tscProcessFetchRow(SSchedMsg *pMsg) { void tscProcessAsyncRes(SSchedMsg *pMsg) { SSqlObj *pSql = (SSqlObj *)pMsg->ahandle; - SSqlCmd *pCmd = &pSql->cmd; +// SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; - void *taosres = pSql; +// void *taosres = pSql; // pCmd may be released, so cache pCmd->command - int cmd = pCmd->command; - int code = pRes->code; +// int cmd = pCmd->command; +// int code = pRes->code; // in case of async insert, restore the user specified callback function - bool shouldFree = tscShouldBeFreed(pSql); +// bool shouldFree = tscShouldBeFreed(pSql); - if (cmd == TSDB_SQL_INSERT) { - assert(pSql->fp != NULL); - pSql->fp = pSql->fetchFp; - } +// if (pCmd->command == TSDB_SQL_INSERT) { +// assert(pSql->fp != NULL); + assert(pSql->fp != NULL && pSql->fetchFp != NULL); +// } - if (pSql->fp) { - (*pSql->fp)(pSql->param, taosres, code); - } +// if (pSql->fp) { + pSql->fp = pSql->fetchFp; + (*pSql->fp)(pSql->param, pSql, pRes->code); +// } - if (shouldFree) { - tscDebug("%p sqlObj is automatically freed in async res", pSql); - tscFreeSqlObj(pSql); - } +// if (shouldFree) { +// tscDebug("%p sqlObj is automatically freed in async res", pSql); +// tscFreeSqlObj(pSql); +// } } static void tscProcessAsyncError(SSchedMsg *pMsg) { @@ -420,15 +423,15 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; + pRes->code = code; if (code != TSDB_CODE_SUCCESS) { - pRes->code = code; - tscQueueAsyncRes(pSql); - return; + tscError("%p ge tableMeta failed, code:%s", pSql, tstrerror(code)); + goto _error; + } else { + tscDebug("%p get tableMeta successfully", pSql); } - tscDebug("%p get tableMeta successfully", pSql); - if (pSql->pStream == NULL) { SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); @@ -453,11 +456,9 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { assert(pParObj->signature == pParObj && trs->subqueryIndex == pTableMetaInfo->vgroupIndex && pTableMetaInfo->vgroupIndex >= 0 && pTableMetaInfo->vgroupList != NULL); - if ((code = tscProcessSql(pSql)) == TSDB_CODE_SUCCESS) { - return; - } - - goto _error; + // tscProcessSql can add error into async res + tscProcessSql(pSql); + return; } else { // continue to process normal async query if (pCmd->parseFinished) { tscDebug("%p update table meta in local cache, continue to process sql and send corresponding query", pSql); @@ -477,30 +478,43 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { tscDebug("%p redo parse sql string to build submit block", pSql); pCmd->parseFinished = false; + tscResetSqlCmdObj(pCmd); + code = tsParseSql(pSql, true); if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { return; + } else if (code != TSDB_CODE_SUCCESS) { + goto _error; } - if (code == TSDB_CODE_SUCCESS) { - /* - * Discard previous built submit blocks, and then parse the sql string again and build up all submit blocks, - * and send the required submit block according to index value in supporter to server. - */ - pSql->fp = pSql->fetchFp; // restore the fp - if ((code = tscHandleInsertRetry(pSql)) == TSDB_CODE_SUCCESS) { - return; - } - } + /* + * Discard previous built submit blocks, and then parse the sql string again and build up all submit blocks, + * and send the required submit block according to index value in supporter to server. + */ + pSql->fp = pSql->fetchFp; // restore the fp + tscHandleInsertRetry(pSql); + } 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); - } else {// in case of other query type, continue - if ((code = tscProcessSql(pSql)) == TSDB_CODE_SUCCESS) { + //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); } - goto _error; + return; } else { tscDebug("%p continue parse sql after get table meta", pSql); @@ -538,7 +552,7 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { goto _error; } - if (code == TSDB_CODE_SUCCESS && UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { + if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { code = tscGetSTableVgroupInfo(pSql, pCmd->clauseIndex); if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { return; @@ -550,8 +564,8 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { tscDebug("%p stream:%p meta is updated, start new query, command:%d", pSql, pSql->pStream, pSql->cmd.command); if (!pSql->cmd.parseFinished) { tsParseSql(pSql, false); - sem_post(&pSql->rspSem); } + (*pSql->fp)(pSql->param, pSql, code); return; } diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index 909338aa4a..1ec84f023a 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -330,10 +330,6 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI return TSDB_CODE_SUCCESS; } -bool stableQueryFunctChanged(int32_t funcId) { - return (aAggs[funcId].stableFuncId != funcId); -} - /** * the numOfRes should be kept, since it may be used later * and allow the ResultInfo to be re initialized @@ -361,7 +357,6 @@ static bool function_setup(SQLFunctionCtx *pCtx) { } memset(pCtx->aOutputBuf, 0, (size_t)pCtx->outputBytes); - initResultInfo(pResInfo); return true; } @@ -675,16 +670,16 @@ static void sum_func_second_merge(SQLFunctionCtx *pCtx) { } } -static int32_t precal_req_load_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { +static int32_t statisRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { return BLK_DATA_STATIS_NEEDED; } -static int32_t data_req_load_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { +static int32_t dataBlockRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { return BLK_DATA_ALL_NEEDED; } // todo: if column in current data block are null, opt for this case -static int32_t first_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { +static int32_t firstFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { if (pCtx->order == TSDB_ORDER_DESC) { return BLK_DATA_NO_NEEDED; } @@ -697,7 +692,7 @@ static int32_t first_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, } } -static int32_t last_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { +static int32_t lastFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { if (pCtx->order != pCtx->param[0].i64Key) { return BLK_DATA_NO_NEEDED; } @@ -709,34 +704,40 @@ static int32_t last_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, } } -static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { +static int32_t firstDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { if (pCtx->order == TSDB_ORDER_DESC) { return BLK_DATA_NO_NEEDED; } + + // not initialized yet, it is the first block, load it. + if (pCtx->aOutputBuf == NULL) { + return BLK_DATA_ALL_NEEDED; + } - // result buffer has not been set yet. - return BLK_DATA_ALL_NEEDED; - //todo optimize the filter info -// SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes); -// if (pInfo->hasResult != DATA_SET_FLAG) { -// return BLK_DATA_ALL_NEEDED; -// } else { // data in current block is not earlier than current result -// return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; -// } + SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes); + if (pInfo->hasResult != DATA_SET_FLAG) { + return BLK_DATA_ALL_NEEDED; + } else { // data in current block is not earlier than current result + return (pInfo->ts <= start) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; + } } -static int32_t last_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { +static int32_t lastDistFuncRequired(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) { if (pCtx->order != pCtx->param[0].i64Key) { return BLK_DATA_NO_NEEDED; } - - return BLK_DATA_ALL_NEEDED; -// SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes); -// if (pInfo->hasResult != DATA_SET_FLAG) { -// return BLK_DATA_ALL_NEEDED; -// } else { -// return (pInfo->ts > end) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; -// } + + // not initialized yet, it is the first block, load it. + if (pCtx->aOutputBuf == NULL) { + return BLK_DATA_ALL_NEEDED; + } + + SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes); + if (pInfo->hasResult != DATA_SET_FLAG) { + return BLK_DATA_ALL_NEEDED; + } else { + return (pInfo->ts > end) ? BLK_DATA_NO_NEEDED : BLK_DATA_ALL_NEEDED; + } } ////////////////////////////////////////////////////////////////////////////////////////////// @@ -1549,6 +1550,8 @@ static void first_data_assign_impl(SQLFunctionCtx *pCtx, char *pData, int32_t in * to decide if the value is earlier than current intermediate result */ static void first_dist_function(SQLFunctionCtx *pCtx) { + assert(pCtx->size > 0); + if (pCtx->size == 0) { return; } @@ -1563,7 +1566,12 @@ static void first_dist_function(SQLFunctionCtx *pCtx) { } int32_t notNullElems = 0; - + + // data block is discard, not loaded, do not need to check it + if (!pCtx->preAggVals.dataBlockLoaded) { + return; + } + // find the first not null value for (int32_t i = 0; i < pCtx->size; ++i) { char *data = GET_INPUT_CHAR_INDEX(pCtx, i); @@ -1584,10 +1592,6 @@ static void first_dist_function(SQLFunctionCtx *pCtx) { } static void first_dist_function_f(SQLFunctionCtx *pCtx, int32_t index) { - if (pCtx->size == 0) { - return; - } - char *pData = GET_INPUT_CHAR_INDEX(pCtx, index); if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { return; @@ -1715,10 +1719,6 @@ static void last_data_assign_impl(SQLFunctionCtx *pCtx, char *pData, int32_t ind } static void last_dist_function(SQLFunctionCtx *pCtx) { - if (pCtx->size == 0) { - return; - } - /* * 1. for scan data in asc order, no need to check data * 2. for data blocks that are not loaded, no need to check data @@ -1726,7 +1726,12 @@ static void last_dist_function(SQLFunctionCtx *pCtx) { if (pCtx->order != pCtx->param[0].i64Key) { return; } - + + // data block is discard, not loaded, do not need to check it + if (!pCtx->preAggVals.dataBlockLoaded) { + return; + } + int32_t notNullElems = 0; for (int32_t i = pCtx->size - 1; i >= 0; --i) { @@ -2123,55 +2128,6 @@ static void copyTopBotRes(SQLFunctionCtx *pCtx, int32_t type) { tfree(pData); } -bool top_bot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, char *minval, char *maxval) { - STopBotInfo *pTopBotInfo = (STopBotInfo *)GET_RES_INFO(pCtx)->interResultBuf; - - int32_t numOfExistsRes = pTopBotInfo->num; - - // required number of results are not reached, continue load data block - if (numOfExistsRes < pCtx->param[0].i64Key) { - return true; - } - - tValuePair *pRes = (tValuePair*) pTopBotInfo->res; - - if (functionId == TSDB_FUNC_TOP) { - switch (pCtx->inputType) { - case TSDB_DATA_TYPE_TINYINT: - return GET_INT8_VAL(maxval) > pRes[0].v.i64Key; - case TSDB_DATA_TYPE_SMALLINT: - return GET_INT16_VAL(maxval) > pRes[0].v.i64Key; - case TSDB_DATA_TYPE_INT: - return GET_INT32_VAL(maxval) > pRes[0].v.i64Key; - case TSDB_DATA_TYPE_BIGINT: - return GET_INT64_VAL(maxval) > pRes[0].v.i64Key; - case TSDB_DATA_TYPE_FLOAT: - return GET_FLOAT_VAL(maxval) > pRes[0].v.dKey; - case TSDB_DATA_TYPE_DOUBLE: - return GET_DOUBLE_VAL(maxval) > pRes[0].v.dKey; - default: - return true; - } - } else { - switch (pCtx->inputType) { - case TSDB_DATA_TYPE_TINYINT: - return GET_INT8_VAL(minval) < pRes[0].v.i64Key; - case TSDB_DATA_TYPE_SMALLINT: - return GET_INT16_VAL(minval) < pRes[0].v.i64Key; - case TSDB_DATA_TYPE_INT: - return GET_INT32_VAL(minval) < pRes[0].v.i64Key; - case TSDB_DATA_TYPE_BIGINT: - return GET_INT64_VAL(minval) < pRes[0].v.i64Key; - case TSDB_DATA_TYPE_FLOAT: - return GET_FLOAT_VAL(minval) < pRes[0].v.dKey; - case TSDB_DATA_TYPE_DOUBLE: - return GET_DOUBLE_VAL(minval) < pRes[0].v.dKey; - default: - return true; - } - } -} - /* * Parameters values: * 1. param[0]: maximum allowable results @@ -2182,15 +2138,62 @@ bool top_bot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, char *mi */ static STopBotInfo *getTopBotOutputInfo(SQLFunctionCtx *pCtx) { SResultInfo *pResInfo = GET_RES_INFO(pCtx); - + // only the first_stage_merge is directly written data into final output buffer if (pResInfo->superTableQ && pCtx->currentStage != SECONDARY_STAGE_MERGE) { return (STopBotInfo*) pCtx->aOutputBuf; - } else { // during normal table query and super table at the secondary_stage, result is written to intermediate buffer + } else { // during normal table query and super table at the secondary_stage, result is written to intermediate buffer return pResInfo->interResultBuf; } } +bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const char *minval, const char *maxval) { + STopBotInfo *pTopBotInfo = getTopBotOutputInfo(pCtx); + + // required number of results are not reached, continue load data block + if (pTopBotInfo->num < pCtx->param[0].i64Key) { + return true; + } + + tValuePair **pRes = (tValuePair**) pTopBotInfo->res; + + if (functionId == TSDB_FUNC_TOP) { + switch (pCtx->inputType) { + case TSDB_DATA_TYPE_TINYINT: + return GET_INT8_VAL(maxval) > pRes[0]->v.i64Key; + case TSDB_DATA_TYPE_SMALLINT: + return GET_INT16_VAL(maxval) > pRes[0]->v.i64Key; + case TSDB_DATA_TYPE_INT: + return GET_INT32_VAL(maxval) > pRes[0]->v.i64Key; + case TSDB_DATA_TYPE_BIGINT: + return GET_INT64_VAL(maxval) > pRes[0]->v.i64Key; + case TSDB_DATA_TYPE_FLOAT: + return GET_FLOAT_VAL(maxval) > pRes[0]->v.dKey; + case TSDB_DATA_TYPE_DOUBLE: + return GET_DOUBLE_VAL(maxval) > pRes[0]->v.dKey; + default: + return true; + } + } else { + switch (pCtx->inputType) { + case TSDB_DATA_TYPE_TINYINT: + return GET_INT8_VAL(minval) < pRes[0]->v.i64Key; + case TSDB_DATA_TYPE_SMALLINT: + return GET_INT16_VAL(minval) < pRes[0]->v.i64Key; + case TSDB_DATA_TYPE_INT: + return GET_INT32_VAL(minval) < pRes[0]->v.i64Key; + case TSDB_DATA_TYPE_BIGINT: + return GET_INT64_VAL(minval) < pRes[0]->v.i64Key; + case TSDB_DATA_TYPE_FLOAT: + return GET_FLOAT_VAL(minval) < pRes[0]->v.dKey; + case TSDB_DATA_TYPE_DOUBLE: + return GET_DOUBLE_VAL(minval) < pRes[0]->v.dKey; + default: + return true; + } + } +} + /* * keep the intermediate results during scan data blocks in the format of: * +-----------------------------------+-------------one value pair-----------+------------next value pair-----------+ @@ -2952,10 +2955,14 @@ static void tag_project_function(SQLFunctionCtx *pCtx) { INC_INIT_VAL(pCtx, pCtx->size); assert(pCtx->inputBytes == pCtx->outputBytes); - - for (int32_t i = 0; i < pCtx->size; ++i) { - tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->outputType, true); - + + tVariantDump(&pCtx->tag, pCtx->aOutputBuf, pCtx->outputType, true); + char* data = pCtx->aOutputBuf; + pCtx->aOutputBuf += pCtx->outputBytes; + + // directly copy from the first one + for (int32_t i = 1; i < pCtx->size; ++i) { + memmove(pCtx->aOutputBuf, data, pCtx->outputBytes); pCtx->aOutputBuf += pCtx->outputBytes; } } @@ -3372,7 +3379,7 @@ static void spread_function(SQLFunctionCtx *pCtx) { SResultInfo *pResInfo = GET_RES_INFO(pCtx); SSpreadInfo *pInfo = pResInfo->interResultBuf; - int32_t numOfElems = pCtx->size; + int32_t numOfElems = 0; // todo : opt with pre-calculated result // column missing cause the hasNull to be true @@ -3941,7 +3948,7 @@ static void ts_comp_finalize(SQLFunctionCtx *pCtx) { tsBufFlush(pTSbuf); strcpy(pCtx->aOutputBuf, pTSbuf->path); - tsBufDestory(pTSbuf); + tsBufDestroy(pTSbuf); doFinalizer(pCtx); } @@ -4408,7 +4415,7 @@ static void sumrate_finalizer(SQLFunctionCtx *pCtx) { * e.g., count/sum/avg/min/max/stddev/percentile/apercentile/first/last... * */ -int32_t funcCompatDefList[] = { +int32_t functionCompatList[] = { // count, sum, avg, min, max, stddev, percentile, apercentile, first, last 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // last_row, top, bottom, spread, twa, leastsqr, ts, ts_dummy, tag_dummy, ts_z @@ -4447,7 +4454,7 @@ SQLAggFuncElem aAggs[] = {{ function_finalizer, sum_func_merge, sum_func_second_merge, - precal_req_load_info, + statisRequired, }, { // 2 @@ -4462,7 +4469,7 @@ SQLAggFuncElem aAggs[] = {{ avg_finalizer, avg_func_merge, avg_func_second_merge, - precal_req_load_info, + statisRequired, }, { // 3 @@ -4477,7 +4484,7 @@ SQLAggFuncElem aAggs[] = {{ function_finalizer, min_func_merge, min_func_second_merge, - precal_req_load_info, + statisRequired, }, { // 4 @@ -4492,7 +4499,7 @@ SQLAggFuncElem aAggs[] = {{ function_finalizer, max_func_merge, max_func_second_merge, - precal_req_load_info, + statisRequired, }, { // 5 @@ -4507,7 +4514,7 @@ SQLAggFuncElem aAggs[] = {{ stddev_finalizer, noop1, noop1, - data_req_load_info, + dataBlockRequired, }, { // 6 @@ -4522,7 +4529,7 @@ SQLAggFuncElem aAggs[] = {{ percentile_finalizer, noop1, noop1, - data_req_load_info, + dataBlockRequired, }, { // 7 @@ -4537,7 +4544,7 @@ SQLAggFuncElem aAggs[] = {{ apercentile_finalizer, apercentile_func_merge, apercentile_func_second_merge, - data_req_load_info, + dataBlockRequired, }, { // 8 @@ -4552,7 +4559,7 @@ SQLAggFuncElem aAggs[] = {{ function_finalizer, noop1, noop1, - first_data_req_info, + firstFuncRequired, }, { // 9 @@ -4567,7 +4574,7 @@ SQLAggFuncElem aAggs[] = {{ function_finalizer, noop1, noop1, - last_data_req_info, + lastFuncRequired, }, { // 10 @@ -4583,7 +4590,7 @@ SQLAggFuncElem aAggs[] = {{ last_row_finalizer, noop1, last_dist_func_second_merge, - data_req_load_info, + dataBlockRequired, }, { // 11 @@ -4599,7 +4606,7 @@ SQLAggFuncElem aAggs[] = {{ top_bottom_func_finalizer, top_func_merge, top_func_second_merge, - data_req_load_info, + dataBlockRequired, }, { // 12 @@ -4615,7 +4622,7 @@ SQLAggFuncElem aAggs[] = {{ top_bottom_func_finalizer, bottom_func_merge, bottom_func_second_merge, - data_req_load_info, + dataBlockRequired, }, { // 13 @@ -4645,7 +4652,7 @@ SQLAggFuncElem aAggs[] = {{ twa_function_finalizer, twa_func_merge, twa_function_copy, - data_req_load_info, + dataBlockRequired, }, { // 15 @@ -4660,7 +4667,7 @@ SQLAggFuncElem aAggs[] = {{ leastsquares_finalizer, noop1, noop1, - data_req_load_info, + dataBlockRequired, }, { // 16 @@ -4690,7 +4697,7 @@ SQLAggFuncElem aAggs[] = {{ doFinalizer, copy_function, copy_function, - data_req_load_info, + dataBlockRequired, }, { // 18 @@ -4720,7 +4727,7 @@ SQLAggFuncElem aAggs[] = {{ ts_comp_finalize, copy_function, copy_function, - data_req_load_info, + dataBlockRequired, }, { // 20 @@ -4750,7 +4757,7 @@ SQLAggFuncElem aAggs[] = {{ doFinalizer, copy_function, copy_function, - data_req_load_info, + dataBlockRequired, }, { // 22, multi-output, tag function has only one result @@ -4780,7 +4787,7 @@ SQLAggFuncElem aAggs[] = {{ doFinalizer, copy_function, copy_function, - data_req_load_info, + dataBlockRequired, }, { // 24 @@ -4795,7 +4802,7 @@ SQLAggFuncElem aAggs[] = {{ doFinalizer, noop1, noop1, - data_req_load_info, + dataBlockRequired, }, // distributed version used in two-stage aggregation processes { @@ -4811,7 +4818,7 @@ SQLAggFuncElem aAggs[] = {{ function_finalizer, first_dist_func_merge, first_dist_func_second_merge, - first_dist_data_req_info, + firstDistFuncRequired, }, { // 26 @@ -4826,7 +4833,7 @@ SQLAggFuncElem aAggs[] = {{ function_finalizer, last_dist_func_merge, last_dist_func_second_merge, - last_dist_data_req_info, + lastDistFuncRequired, }, { // 27 @@ -4841,7 +4848,7 @@ SQLAggFuncElem aAggs[] = {{ doFinalizer, noop1, copy_function, - data_req_load_info, + dataBlockRequired, }, { // 28 @@ -4856,7 +4863,7 @@ SQLAggFuncElem aAggs[] = {{ rate_finalizer, rate_func_merge, rate_func_copy, - data_req_load_info, + dataBlockRequired, }, { // 29 @@ -4871,7 +4878,7 @@ SQLAggFuncElem aAggs[] = {{ rate_finalizer, rate_func_merge, rate_func_copy, - data_req_load_info, + dataBlockRequired, }, { // 30 @@ -4886,7 +4893,7 @@ SQLAggFuncElem aAggs[] = {{ sumrate_finalizer, sumrate_func_merge, sumrate_func_second_merge, - data_req_load_info, + dataBlockRequired, }, { // 31 @@ -4901,7 +4908,7 @@ SQLAggFuncElem aAggs[] = {{ sumrate_finalizer, sumrate_func_merge, sumrate_func_second_merge, - data_req_load_info, + dataBlockRequired, }, { // 32 @@ -4916,7 +4923,7 @@ SQLAggFuncElem aAggs[] = {{ sumrate_finalizer, sumrate_func_merge, sumrate_func_second_merge, - data_req_load_info, + dataBlockRequired, }, { // 33 @@ -4931,7 +4938,7 @@ SQLAggFuncElem aAggs[] = {{ sumrate_finalizer, sumrate_func_merge, sumrate_func_second_merge, - data_req_load_info, + dataBlockRequired, }, { // 34 @@ -4946,5 +4953,5 @@ SQLAggFuncElem aAggs[] = {{ noop1, noop1, noop1, - data_req_load_info, + dataBlockRequired, }}; diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 9f0d1a26ab..0cf69dfd46 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -497,7 +497,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { tsem_init(&pSql->rspSem, 0, 0); pSql->signature = pSql; pSql->pTscObj = pObj; - pSql->maxRetry = TSDB_MAX_REPLICA_NUM; + pSql->maxRetry = TSDB_MAX_REPLICA; pStmt->pSql = pSql; return pStmt; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 65e2c976e0..f76a1341d2 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -175,7 +175,6 @@ static int32_t handlePassword(SSqlCmd* pCmd, SSQLToken* pPwd) { return TSDB_CODE_SUCCESS; } -// todo handle memory leak in error handle function int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { if (pInfo == NULL || pSql == NULL || pSql->signature != pSql) { return TSDB_CODE_TSC_APP_ERROR; @@ -2472,7 +2471,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo) { startIdx++; } - int32_t factor = funcCompatDefList[tscSqlExprGet(pQueryInfo, startIdx)->functionId]; + int32_t factor = functionCompatList[tscSqlExprGet(pQueryInfo, startIdx)->functionId]; // diff function cannot be executed with other function // arithmetic function can be executed with other arithmetic functions @@ -2490,7 +2489,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo) { continue; } - if (funcCompatDefList[functionId] != factor) { + if (functionCompatList[functionId] != factor) { return false; } } @@ -4643,21 +4642,24 @@ typedef struct SDNodeDynConfOption { } SDNodeDynConfOption; -int32_t validateEp(char* ep) { +int32_t validateEp(char* ep) { char buf[TSDB_EP_LEN + 1] = {0}; tstrncpy(buf, ep, TSDB_EP_LEN); - char *pos = strchr(buf, ':'); - if (NULL == pos) { - return TSDB_CODE_TSC_INVALID_SQL; + char* pos = strchr(buf, ':'); + if (NULL == pos) { + int32_t val = strtol(ep, NULL, 10); + if (val <= 0 || val > 65536) { + return TSDB_CODE_TSC_INVALID_SQL; + } + } else { + uint16_t port = atoi(pos + 1); + if (0 == port) { + return TSDB_CODE_TSC_INVALID_SQL; + } } - - uint16_t port = atoi(pos+1); - if (0 == port) { - return TSDB_CODE_TSC_INVALID_SQL; - } - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; } int32_t validateDNodeConfig(tDCLSQL* pOptions) { @@ -4665,13 +4667,13 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { return TSDB_CODE_TSC_INVALID_SQL; } - const int DNODE_DYNAMIC_CFG_OPTIONS_SIZE = 17; + const int DNODE_DYNAMIC_CFG_OPTIONS_SIZE = 19; const SDNodeDynConfOption DNODE_DYNAMIC_CFG_OPTIONS[] = { {"resetLog", 8}, {"resetQueryCache", 15}, {"debugFlag", 9}, {"mDebugFlag", 10}, {"dDebugFlag", 10}, {"sdbDebugFlag", 12}, {"vDebugFlag", 10}, {"cDebugFlag", 10}, {"httpDebugFlag", 13}, {"monitorDebugFlag", 16}, {"rpcDebugFlag", 12}, {"uDebugFlag", 10}, {"tmrDebugFlag", 12}, {"qDebugflag", 10}, {"sDebugflag", 10}, {"tsdbDebugFlag", 13}, - {"monitor", 7}}; + {"mqttDebugFlag", 13}, {"wDebugFlag", 10}, {"monitor", 7}}; SSQLToken* pOptionToken = &pOptions->a[1]; @@ -4695,7 +4697,7 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { SSQLToken* pValToken = &pOptions->a[2]; int32_t val = strtol(pValToken->z, NULL, 10); - if (val < 131 || val > 199) { + if (val < 0 || val > 256) { /* options value is out of valid range */ return TSDB_CODE_TSC_INVALID_SQL; } @@ -4963,6 +4965,7 @@ static void setCreateDBOption(SCMCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) { pMsg->commitTime = htonl(pCreateDb->commitTime); pMsg->minRowsPerFileBlock = htonl(pCreateDb->minRowsPerBlock); pMsg->maxRowsPerFileBlock = htonl(pCreateDb->maxRowsPerBlock); + pMsg->fsyncPeriod = htonl(pCreateDb->fsyncPeriod); pMsg->compression = pCreateDb->compressionLevel; pMsg->walLevel = (char)pCreateDb->walLevel; pMsg->replications = pCreateDb->replica; @@ -5490,9 +5493,9 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate) { } if (pCreate->replications != -1 && - (pCreate->replications < TSDB_MIN_REPLICA_NUM || pCreate->replications > TSDB_MAX_REPLICA_NUM)) { + (pCreate->replications < TSDB_MIN_DB_REPLICA_OPTION || pCreate->replications > TSDB_MAX_DB_REPLICA_OPTION)) { snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, - TSDB_MIN_REPLICA_NUM, TSDB_MAX_REPLICA_NUM); + TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); } @@ -5530,6 +5533,13 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate) { 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 && (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, diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 88fcc3828e..d8af6d5c87 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -246,43 +246,52 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; } else { STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - if (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) { - if (pCmd->command == TSDB_SQL_CONNECT) { - rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; - rpcFreeCont(rpcMsg->pCont); - 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 + // if (rpcMsg->code != TSDB_CODE_RPC_NETWORK_UNAVAIL) { + // if (pCmd->command == TSDB_SQL_CONNECT) { + // rpcMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; + // rpcFreeCont(rpcMsg->pCont); + // return; + // } + + // 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 + if (rpcMsg->code == TSDB_CODE_TDB_TABLE_RECONFIGURE) { + pSql->cmd.submitSchema = 1; + } + + pSql->res.code = rpcMsg->code; // keep the previous error code + if (pSql->retry > pSql->maxRetry) { + tscError("%p max retry %d reached, give up", pSql, pSql->maxRetry); } else { - tscWarn("%p it shall renew table meta, code:%s, retry:%d", pSql, tstrerror(rpcMsg->code), ++pSql->retry); + rpcMsg->code = tscRenewTableMeta(pSql, pTableMetaInfo->name); - // 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) { - pSql->cmd.submitSchema = 1; - } - - pSql->res.code = rpcMsg->code; // keep the previous error code - if (pSql->retry > pSql->maxRetry) { - tscError("%p max retry %d reached, give up", pSql, pSql->maxRetry); - } else { - rpcMsg->code = tscRenewTableMeta(pSql, pTableMetaInfo->name); - - // if there is an error occurring, proceed to the following error handling procedure. - // todo add test cases - if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { - rpcFreeCont(rpcMsg->pCont); - return; - } + // if there is an error occurring, proceed to the following error handling procedure. + // todo add test cases + if (rpcMsg->code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { + rpcFreeCont(rpcMsg->pCont); + return; } } } } - + pRes->rspLen = 0; if (pRes->code != TSDB_CODE_TSC_QUERY_CANCELLED) { @@ -339,7 +348,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { } if (rpcMsg->code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { - rpcMsg->code = (pRes->code == TSDB_CODE_SUCCESS) ? pRes->numOfRows: pRes->code; + rpcMsg->code = (pRes->code == TSDB_CODE_SUCCESS)? pRes->numOfRows: pRes->code; bool shouldFree = tscShouldBeFreed(pSql); (*pSql->fp)(pSql->param, pSql, rpcMsg->code); @@ -412,7 +421,7 @@ int tscProcessSql(SSqlObj *pSql) { return pSql->res.code; } } else if (pCmd->command < TSDB_SQL_LOCAL) { - pSql->ipList = tscMgmtIpSet; //? + pSql->ipList = tscMgmtIpSet; } else { // local handler return (*tscProcessMsgRsp[pCmd->command])(pSql); } @@ -476,6 +485,8 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t vgIndex = pTableMetaInfo->vgroupIndex; SVgroupsInfo* pVgroupInfo = pTableMetaInfo->vgroupList; + assert(pVgroupInfo->vgroups[vgIndex].vgId > 0 && vgIndex < pTableMetaInfo->vgroupList->numOfVgroups); + pRetrieveMsg->header.vgId = htonl(pVgroupInfo->vgroups[vgIndex].vgId); } else { STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; @@ -549,6 +560,7 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char assert(index >= 0); if (pTableMetaInfo->vgroupList->numOfVgroups > 0) { + assert(index < pTableMetaInfo->vgroupList->numOfVgroups); pVgroupInfo = &pTableMetaInfo->vgroupList->vgroups[index]; } tscDebug("%p query on stable, vgIndex:%d, numOfVgroups:%d", pSql, index, pTableMetaInfo->vgroupList->numOfVgroups); @@ -1372,7 +1384,6 @@ static int tscLocalResultCommonBuilder(SSqlObj *pSql, int32_t numOfRes) { SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); pRes->code = TSDB_CODE_SUCCESS; - if (pRes->rspType == 0) { pRes->numOfRows = numOfRes; pRes->row = 0; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index f9f93b3f89..0677463d8d 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -113,7 +113,7 @@ SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con pSql->pTscObj = pObj; pSql->signature = pSql; - pSql->maxRetry = TSDB_MAX_REPLICA_NUM; + pSql->maxRetry = TSDB_MAX_REPLICA; tsem_init(&pSql->rspSem, 0, 0); pObj->pDnodeConn = pDnodeConn; @@ -181,6 +181,19 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha 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), void *param, void **taos) { @@ -249,7 +262,31 @@ TAOS_RES* taos_query(TAOS *taos, const char *sqlstr) { tsem_wait(&pSql->rspSem); return pSql; } +TAOS_RES* taos_query_c(TAOS *taos, const char *sqlstr, uint32_t sqlLen) { + STscObj *pObj = (STscObj *)taos; + if (pObj == NULL || pObj->signature != pObj) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return NULL; + } + + if (sqlLen > tsMaxSQLStringLen) { + tscError("sql string exceeds max length:%d", tsMaxSQLStringLen); + terrno = TSDB_CODE_TSC_INVALID_SQL; + return NULL; + } + + SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); + if (pSql == NULL) { + tscError("failed to malloc sqlObj"); + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + return NULL; + } + + doAsyncQuery(pObj, pSql, waitForQueryRsp, taos, sqlstr, sqlLen); + tsem_wait(&pSql->rspSem); + return pSql; +} int taos_result_precision(TAOS_RES *res) { SSqlObj *pSql = (SSqlObj *)res; if (pSql == NULL || pSql->signature != pSql) return 0; @@ -403,7 +440,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { taos_fetch_rows_a(res, waitForRetrieveRsp, pSql->pTscObj); sem_wait(&pSql->rspSem); } - + return doSetResultRowData(pSql, true); } @@ -481,25 +518,14 @@ static bool tscFreeQhandleInVnode(SSqlObj* pSql) { if (pRes->code == TSDB_CODE_SUCCESS && pRes->completed == false && !tscIsTwoStageSTableQuery(pQueryInfo, 0) && (pCmd->command == TSDB_SQL_SELECT || - pCmd->command == TSDB_SQL_SHOW || - pCmd->command == TSDB_SQL_RETRIEVE || - pCmd->command == TSDB_SQL_FETCH) && - (pCmd->command == TSDB_SQL_SELECT && pSql->pStream == NULL && pTableMetaInfo->pTableMeta != NULL)) { + pCmd->command == TSDB_SQL_SHOW || + pCmd->command == TSDB_SQL_RETRIEVE || + pCmd->command == TSDB_SQL_FETCH) && + (pSql->pStream == NULL && pTableMetaInfo->pTableMeta != NULL)) { pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; - tscDebug("%p send msg to dnode to free qhandle ASAP, command:%s", pSql, sqlCmd[pCmd->command]); + tscDebug("%p send msg to dnode to free qhandle ASAP, command:%s, ", pSql, sqlCmd[pCmd->command]); tscProcessSql(pSql); - - // in case of sync model query, waits for response and then goes on -// if (pSql->fp == waitForQueryRsp || pSql->fp == waitForRetrieveRsp) { -// sem_wait(&pSql->rspSem); - -// tscFreeSqlObj(pSql); -// tscDebug("%p sqlObj is freed by app", pSql); -// } else { - tscDebug("%p sqlObj will be freed while rsp received", pSql); -// } - return true; } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 6cc27a4cfe..7c188ec969 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -70,6 +70,7 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) { SSqlObj * pSql = pStream->pSql; pSql->fp = tscProcessStreamQueryCallback; + pSql->fetchFp = tscProcessStreamQueryCallback; pSql->param = pStream; pSql->res.completed = false; @@ -471,6 +472,41 @@ static void setErrorInfo(SSqlObj* pSql, int32_t code, char* info) { } } +static void tscCreateStream(void *param, TAOS_RES *res, int code) { + SSqlStream* pStream = (SSqlStream*)param; + SSqlObj* pSql = pStream->pSql; + SSqlCmd* pCmd = &pSql->cmd; + + if (code != TSDB_CODE_SUCCESS) { + setErrorInfo(pSql, code, pCmd->payload); + tscError("%p open stream failed, sql:%s, reason:%s, code:0x%08x", pSql, pSql->sqlstr, pCmd->payload, code); + pStream->fp(pStream->param, NULL, NULL); + return; + } + + SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); + + pStream->isProject = isProjectStream(pQueryInfo); + pStream->precision = tinfo.precision; + + pStream->ctime = taosGetTimestamp(pStream->precision); + pStream->etime = pQueryInfo->window.ekey; + + tscAddIntoStreamList(pStream); + + tscSetSlidingWindowInfo(pSql, pStream); + pStream->stime = tscGetStreamStartTimestamp(pSql, pStream, pStream->stime); + + int64_t starttime = tscGetLaunchTimestamp(pStream); + pCmd->command = TSDB_SQL_SELECT; + taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer); + + tscDebug("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql, + pStream, pTableMetaInfo->name, pStream->interval, pStream->slidingTime, starttime, pSql->sqlstr); +} + TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *)) { STscObj *pObj = (STscObj *)taos; @@ -482,7 +518,6 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p } pSql->signature = pSql; - pSql->param = pSql; pSql->pTscObj = pObj; SSqlCmd *pCmd = &pSql->cmd; @@ -494,7 +529,14 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p tscFreeSqlObj(pSql); return NULL; } + + pStream->stime = stime; + pStream->fp = fp; + pStream->callback = callback; + pStream->param = param; + pStream->pSql = pSql; pSql->pStream = pStream; + pSql->param = pStream; pSql->sqlstr = calloc(1, strlen(sqlstr) + 1); if (pSql->sqlstr == NULL) { @@ -507,45 +549,18 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p tscDebugL("%p SQL: %s", pSql, pSql->sqlstr); tsem_init(&pSql->rspSem, 0, 0); + pSql->fp = tscCreateStream; + pSql->fetchFp = tscCreateStream; int32_t code = tsParseSql(pSql, true); - if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { - sem_wait(&pSql->rspSem); - } - - if (pRes->code != TSDB_CODE_SUCCESS) { - setErrorInfo(pSql, pRes->code, pCmd->payload); - - tscError("%p open stream failed, sql:%s, reason:%s, code:0x%08x", pSql, sqlstr, pCmd->payload, pRes->code); + if (code == TSDB_CODE_SUCCESS) { + tscCreateStream(pStream, pSql, code); + } else if (code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { + tscError("%p open stream failed, sql:%s, code:%s", pSql, sqlstr, tstrerror(pRes->code)); tscFreeSqlObj(pSql); + free(pStream); return NULL; } - SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); - - pStream->isProject = isProjectStream(pQueryInfo); - pStream->fp = fp; - pStream->callback = callback; - pStream->param = param; - pStream->pSql = pSql; - pStream->precision = tinfo.precision; - - pStream->ctime = taosGetTimestamp(pStream->precision); - pStream->etime = pQueryInfo->window.ekey; - - tscAddIntoStreamList(pStream); - - tscSetSlidingWindowInfo(pSql, pStream); - pStream->stime = tscGetStreamStartTimestamp(pSql, pStream, stime); - - int64_t starttime = tscGetLaunchTimestamp(pStream); - pCmd->command = TSDB_SQL_SELECT; - taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer); - - tscDebug("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql, - pStream, pTableMetaInfo->name, pStream->interval, pStream->slidingTime, starttime, sqlstr); - return pStream; } diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index f7d03bd787..2c5035c2ef 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -107,7 +107,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* pSql->signature = pSql; pSql->param = pSql; pSql->pTscObj = pObj; - pSql->maxRetry = TSDB_MAX_REPLICA_NUM; + pSql->maxRetry = TSDB_MAX_REPLICA; pSql->fp = asyncCallback; int code = tscAllocPayload(pCmd, TSDB_DEFAULT_PAYLOAD_SIZE); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index d3f298c2b2..dd4ed991ed 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -152,8 +152,8 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ tsBufFlush(output1); tsBufFlush(output2); - tsBufDestory(pSupporter1->pTSBuf); - tsBufDestory(pSupporter2->pTSBuf); + tsBufDestroy(pSupporter1->pTSBuf); + tsBufDestroy(pSupporter2->pTSBuf); tscDebug("%p input1:%" PRId64 ", input2:%" PRId64 ", final:%" PRId64 " for secondary query after ts blocks " "intersecting, skey:%" PRId64 ", ekey:%" PRId64, pSql, numOfInput1, numOfInput2, output1->numOfTotal, @@ -550,7 +550,7 @@ static bool checkForDuplicateTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1, return true; } -static void getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray** s1, SArray** s2) { +static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray** s1, SArray** s2) { tscDebug("%p all subqueries retrieve complete, do tags match", pParentSql); SJoinSupporter* p1 = pParentSql->pSubs[0]->param; @@ -568,10 +568,7 @@ static void getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParent *s2 = taosArrayInit(p2->num, p2->tagSize); if (!(checkForDuplicateTagVal(pQueryInfo, p1, pParentSql) && checkForDuplicateTagVal(pQueryInfo, p2, pParentSql))) { - freeJoinSubqueryObj(pParentSql); - pParentSql->res.code = TSDB_CODE_QRY_DUP_JOIN_KEY; - tscQueueAsyncRes(pParentSql); - return; + return TSDB_CODE_QRY_DUP_JOIN_KEY; } int32_t i = 0, j = 0; @@ -594,6 +591,8 @@ static void getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParent i++; } } + + return TSDB_CODE_SUCCESS; } static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRows) { @@ -680,7 +679,14 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow } SArray *s1 = NULL, *s2 = NULL; - getIntersectionOfTableTuple(pQueryInfo, pParentSql, &s1, &s2); + int32_t code = getIntersectionOfTableTuple(pQueryInfo, pParentSql, &s1, &s2); + if (code != TSDB_CODE_SUCCESS) { + freeJoinSubqueryObj(pParentSql); + pParentSql->res.code = code; + tscQueueAsyncRes(pParentSql); + return; + } + if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return. tscDebug("%p tag intersect does not generated qualified tables for join, free all sub SqlObj and quit", pParentSql); freeJoinSubqueryObj(pParentSql); @@ -762,7 +768,7 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); tsBufMerge(pSupporter->pTSBuf, pBuf, pTableMetaInfo->vgroupIndex); - tsBufDestory(pBuf); + tsBufDestroy(pBuf); } // continue to retrieve ts-comp data from vnode @@ -1778,7 +1784,6 @@ static SSqlObj *tscCreateSqlObjForSubquery(SSqlObj *pSql, SRetrieveSupport *trsu pSql->pSubs[trsupport->subqueryIndex] = pNew; } - printf("------------alloc:%p\n", pNew); return pNew; } @@ -1890,9 +1895,11 @@ int32_t tscHandleInsertRetry(SSqlObj* pSql) { assert(pSupporter->index < pSupporter->pState->numOfTotal); STableDataBlocks* pTableDataBlock = taosArrayGetP(pCmd->pDataBlocks, pSupporter->index); - pRes->code = tscCopyDataBlockToPayload(pSql, pTableDataBlock); - if (pRes->code != TSDB_CODE_SUCCESS) { - return pRes->code; + int32_t code = tscCopyDataBlockToPayload(pSql, pTableDataBlock); + + if ((pRes->code = code)!= TSDB_CODE_SUCCESS) { + tscQueueAsyncRes(pSql); + return code; // here the pSql may have been released already. } return tscProcessSql(pSql); @@ -2107,9 +2114,9 @@ static char *getArithemicInputSrc(void *param, const char *name, int32_t colId) void **doSetResultRowData(SSqlObj *pSql, bool finalResult) { SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; - + assert(pRes->row >= 0 && pRes->row <= pRes->numOfRows); - + if(pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE) { if (pRes->completed) { tfree(pRes->tsrow); @@ -2117,29 +2124,31 @@ void **doSetResultRowData(SSqlObj *pSql, bool finalResult) { return pRes->tsrow; } - + if (pRes->row >= pRes->numOfRows) { // all the results has returned to invoker tfree(pRes->tsrow); return pRes->tsrow; } - + SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex); - + size_t size = tscNumOfFields(pQueryInfo); for (int i = 0; i < size; ++i) { - SFieldSupInfo* pSup = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, i); + SFieldSupInfo* pSup = TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.pSupportInfo, i); if (pSup->pSqlExpr != NULL) { tscGetResultColumnChr(pRes, &pQueryInfo->fieldsInfo, i); } - + // primary key column cannot be null in interval query, no need to check if (i == 0 && pQueryInfo->intervalTime > 0) { continue; } - - TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i); - transferNcharData(pSql, i, pField); - + + TAOS_FIELD *pField = TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.pFields, i); + if (pRes->tsrow[i] != NULL && pField->type == TSDB_DATA_TYPE_NCHAR) { + transferNcharData(pSql, i, pField); + } + // calculate the result from several other columns if (pSup->pArithExprInfo != NULL) { if (pRes->pArithSup == NULL) { @@ -2149,10 +2158,10 @@ void **doSetResultRowData(SSqlObj *pSql, bool finalResult) { sas->numOfCols = tscSqlExprNumOfExprs(pQueryInfo); sas->exprList = pQueryInfo->exprList; sas->data = calloc(sas->numOfCols, POINTER_BYTES); - + pRes->pArithSup = sas; } - + if (pRes->buffer[i] == NULL) { TAOS_FIELD* field = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, i); pRes->buffer[i] = malloc(field->bytes); @@ -2162,13 +2171,13 @@ void **doSetResultRowData(SSqlObj *pSql, bool finalResult) { SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, k); pRes->pArithSup->data[k] = (pRes->data + pRes->numOfRows* pExpr->offset) + pRes->row*pExpr->resBytes; } - + tExprTreeCalcTraverse(pRes->pArithSup->pArithExpr->pExpr, 1, pRes->buffer[i], pRes->pArithSup, TSDB_ORDER_ASC, getArithemicInputSrc); pRes->tsrow[i] = pRes->buffer[i]; } } - + pRes->row++; // index increase one-step return pRes->tsrow; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index a58423bbaa..3e0fe0b4be 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -794,7 +794,7 @@ SFieldSupInfo* tscFieldInfoAppend(SFieldInfo* pFieldInfo, TAOS_FIELD* pField) { } SFieldSupInfo* tscFieldInfoGetSupp(SFieldInfo* pFieldInfo, int32_t index) { - return taosArrayGet(pFieldInfo->pSupportInfo, index); + return TARRAY_GET_ELEM(pFieldInfo->pSupportInfo, index); } SFieldSupInfo* tscFieldInfoInsert(SFieldInfo* pFieldInfo, int32_t index, TAOS_FIELD* field) { @@ -858,11 +858,9 @@ void tscFieldInfoCopy(SFieldInfo* dst, const SFieldInfo* src) { } TAOS_FIELD* tscFieldInfoGetField(SFieldInfo* pFieldInfo, int32_t index) { - return taosArrayGet(pFieldInfo->pFields, index); + return TARRAY_GET_ELEM(pFieldInfo->pFields, index); } -int32_t tscNumOfFields(SQueryInfo* pQueryInfo) { return pQueryInfo->fieldsInfo.numOfOutput; } - int16_t tscFieldInfoGetOffset(SQueryInfo* pQueryInfo, int32_t index) { SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, index); assert(pInfo != NULL); @@ -1546,7 +1544,7 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo) { pQueryInfo->groupbyExpr.columnInfo = NULL; } - pQueryInfo->tsBuf = tsBufDestory(pQueryInfo->tsBuf); + pQueryInfo->tsBuf = tsBufDestroy(pQueryInfo->tsBuf); tfree(pQueryInfo->fillVal); } @@ -1650,8 +1648,9 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cm } pNew->fp = fp; + pNew->fetchFp = fp; pNew->param = param; - pNew->maxRetry = TSDB_MAX_REPLICA_NUM; + pNew->maxRetry = TSDB_MAX_REPLICA; pNew->sqlstr = strdup(pSql->sqlstr); if (pNew->sqlstr == NULL) { @@ -1805,8 +1804,10 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void } pNew->fp = fp; + pNew->fetchFp = fp; + pNew->param = param; - pNew->maxRetry = TSDB_MAX_REPLICA_NUM; + pNew->maxRetry = TSDB_MAX_REPLICA; char* name = pTableMetaInfo->name; STableMetaInfo* pFinalInfo = NULL; @@ -2007,7 +2008,7 @@ void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups; - while (++pTableMetaInfo->vgroupIndex < totalVgroups) { + if (++pTableMetaInfo->vgroupIndex < totalVgroups) { tscDebug("%p results from vgroup index:%d completed, try next:%d. total vgroups:%d. current numOfRes:%" PRId64, pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, pRes->numOfClauseTotal); @@ -2043,11 +2044,9 @@ void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) { // set the callback function pSql->fp = fp; - int32_t ret = tscProcessSql(pSql); - if (ret == TSDB_CODE_SUCCESS) { - return; - } else {// todo check for failure - } + tscProcessSql(pSql); + } else { + tscDebug("%p try all %d vnodes, query complete. current numOfRes:%" PRId64, pSql, totalVgroups, pRes->numOfClauseTotal); } } @@ -2085,42 +2084,42 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) { } } -void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t columnIndex) { - SFieldSupInfo* pInfo = taosArrayGet(pFieldInfo->pSupportInfo, columnIndex); - assert(pInfo->pSqlExpr != NULL); - - int32_t type = pInfo->pSqlExpr->resType; - int32_t bytes = pInfo->pSqlExpr->resBytes; - - char* pData = pRes->data + pInfo->pSqlExpr->offset * pRes->numOfRows + bytes * pRes->row; - - if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) { - int32_t realLen = varDataLen(pData); - assert(realLen <= bytes - VARSTR_HEADER_SIZE); - - if (isNull(pData, type)) { - pRes->tsrow[columnIndex] = NULL; - } else { - pRes->tsrow[columnIndex] = ((tstr*)pData)->data; - } - - if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor - *(pData + realLen + VARSTR_HEADER_SIZE) = 0; - } - - pRes->length[columnIndex] = realLen; - } else { - assert(bytes == tDataTypeDesc[type].nSize); - - if (isNull(pData, type)) { - pRes->tsrow[columnIndex] = NULL; - } else { - pRes->tsrow[columnIndex] = pData; - } - - pRes->length[columnIndex] = bytes; - } -} +//void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t columnIndex) { +// SFieldSupInfo* pInfo = TARRAY_GET_ELEM(pFieldInfo->pSupportInfo, columnIndex); +// assert(pInfo->pSqlExpr != NULL); +// +// int32_t type = pInfo->pSqlExpr->resType; +// int32_t bytes = pInfo->pSqlExpr->resBytes; +// +// char* pData = pRes->data + pInfo->pSqlExpr->offset * pRes->numOfRows + bytes * pRes->row; +// +// if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) { +// int32_t realLen = varDataLen(pData); +// assert(realLen <= bytes - VARSTR_HEADER_SIZE); +// +// if (isNull(pData, type)) { +// pRes->tsrow[columnIndex] = NULL; +// } else { +// pRes->tsrow[columnIndex] = ((tstr*)pData)->data; +// } +// +// if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor +// *(pData + realLen + VARSTR_HEADER_SIZE) = 0; +// } +// +// pRes->length[columnIndex] = realLen; +// } else { +// assert(bytes == tDataTypeDesc[type].nSize); +// +// if (isNull(pData, type)) { +// pRes->tsrow[columnIndex] = NULL; +// } else { +// pRes->tsrow[columnIndex] = pData; +// } +// +// pRes->length[columnIndex] = bytes; +// } +//} void* malloc_throw(size_t size) { void* p = malloc(size); diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index da42c064ec..c42fccc372 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -68,7 +68,10 @@ extern int64_t tsMaxRetentWindow; // db parameters in client extern int32_t tsCacheBlockSize; extern int32_t tsBlocksPerVnode; +extern int32_t tsMinTablePerVnode; extern int32_t tsMaxTablePerVnode; +extern int32_t tsTableIncStepPerVnode; +extern int32_t tsMaxVgroupsPerDb; extern int16_t tsDaysPerFile; extern int32_t tsDaysToKeep; extern int32_t tsMinRowsInFileBlock; @@ -77,6 +80,7 @@ extern int16_t tsCommitTime; // seconds extern int32_t tsTimePrecision; extern int16_t tsCompression; extern int16_t tsWAL; +extern int32_t tsFsyncPeriod; extern int32_t tsReplications; // balance diff --git a/src/common/inc/tulog.h b/src/common/inc/tulog.h index 6365b21ef9..2dc2895e63 100644 --- a/src/common/inc/tulog.h +++ b/src/common/inc/tulog.h @@ -25,15 +25,15 @@ extern "C" { extern int32_t uDebugFlag; 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 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 uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL DEBUG ", uDebugFlag, __VA_ARGS__); }} -#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL TRACE ", 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 ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }} +#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }} +#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", uDebugFlag, __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 } diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index 7e551759f9..719d80aa77 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -318,7 +318,7 @@ SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows) { pCols->maxPoints = maxRows; pCols->bufSize = maxRowSize * maxRows; - pCols->buf = malloc(pCols->bufSize); + pCols->buf = calloc(1, pCols->bufSize); if (pCols->buf == NULL) { free(pCols); return NULL; @@ -384,9 +384,11 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) { } void tdResetDataCols(SDataCols *pCols) { - pCols->numOfRows = 0; - for (int i = 0; i < pCols->maxCols; i++) { - dataColReset(pCols->cols + i); + if (pCols != NULL) { + pCols->numOfRows = 0; + for (int i = 0; i < pCols->maxCols; i++) { + dataColReset(pCols->cols + i); + } } } diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index fae771e855..f1f4db7265 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -38,7 +38,7 @@ uint16_t tsDnodeShellPort = 6030; // udp[6035-6039] tcp[6035] uint16_t tsDnodeDnodePort = 6035; // udp/tcp uint16_t tsSyncPort = 6040; int32_t tsStatusInterval = 1; // second -int16_t tsNumOfVnodesPerCore = 8; +int16_t tsNumOfVnodesPerCore = 32; int16_t tsNumOfTotalVnodes = TSDB_INVALID_VNODE_NUM; int32_t tsNumOfMnodes = 3; int32_t tsEnableVnodeBak = 1; @@ -110,13 +110,12 @@ int16_t tsCommitTime = TSDB_DEFAULT_COMMIT_TIME; // seconds int32_t tsTimePrecision = TSDB_DEFAULT_PRECISION; int16_t tsCompression = TSDB_DEFAULT_COMP_LEVEL; int16_t tsWAL = TSDB_DEFAULT_WAL_LEVEL; -int32_t tsReplications = TSDB_DEFAULT_REPLICA_NUM; - -#ifdef _TD_ARM_32_ - int32_t tsMaxTablePerVnode = 100; -#else - int32_t tsMaxTablePerVnode = TSDB_DEFAULT_TABLES; -#endif +int32_t tsFsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; +int32_t tsReplications = TSDB_DEFAULT_DB_REPLICA_OPTION; +int32_t tsMaxVgroupsPerDb = 0; +int32_t tsMinTablePerVnode = 100; +int32_t tsMaxTablePerVnode = TSDB_DEFAULT_TABLES; +int32_t tsTableIncStepPerVnode = TSDB_TABLES_STEP; // balance int32_t tsEnableBalance = 1; @@ -195,7 +194,7 @@ int32_t monitorDebugFlag = 131; int32_t qDebugFlag = 131; int32_t rpcDebugFlag = 131; int32_t uDebugFlag = 131; -int32_t debugFlag = 131; +int32_t debugFlag = 0; int32_t sDebugFlag = 135; int32_t wDebugFlag = 135; int32_t tsdbDebugFlag = 131; @@ -203,7 +202,7 @@ int32_t tsdbDebugFlag = 131; static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT; void taosSetAllDebugFlag() { - for (int32_t i = 0; i < tsGlobalConfigNum; ++i) { + if (debugFlag != 0) { mDebugFlag = debugFlag; sdbDebugFlag = debugFlag; dDebugFlag = debugFlag; @@ -220,8 +219,8 @@ void taosSetAllDebugFlag() { wDebugFlag = debugFlag; tsdbDebugFlag = 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) { @@ -394,16 +393,6 @@ static void doInitGlobalConfig() { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); - cfg.option = "numOfVnodesPerCore"; - cfg.ptr = &tsNumOfVnodesPerCore; - cfg.valType = TAOS_CFG_VTYPE_INT16; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 1; - cfg.maxValue = 64; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosInitConfigOption(cfg); - cfg.option = "numOfTotalVnodes"; cfg.ptr = &tsNumOfTotalVnodes; cfg.valType = TAOS_CFG_VTYPE_INT16; @@ -560,7 +549,7 @@ static void doInitGlobalConfig() { cfg.ptr = &tsMinIntervalTime; cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 10; + cfg.minValue = 1; cfg.maxValue = 1000000; cfg.ptrLength = 0; cfg.unitType = TAOS_CFG_UTYPE_MS; @@ -606,8 +595,18 @@ static void doInitGlobalConfig() { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + cfg.option = "maxVgroupsPerDb"; + cfg.ptr = &tsMaxVgroupsPerDb; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 8192; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + // database configs - cfg.option = "maxtablesPerVnode"; + cfg.option = "maxTablesPerVnode"; cfg.ptr = &tsMaxTablePerVnode; cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; @@ -617,6 +616,26 @@ static void doInitGlobalConfig() { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + cfg.option = "minTablesPerVnode"; + cfg.ptr = &tsMinTablePerVnode; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = TSDB_MIN_TABLES; + cfg.maxValue = TSDB_MAX_TABLES; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "tableIncStepPerVnode"; + cfg.ptr = &tsTableIncStepPerVnode; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = TSDB_MIN_TABLES; + cfg.maxValue = TSDB_MAX_TABLES; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + cfg.option = "cache"; cfg.ptr = &tsCacheBlockSize; cfg.valType = TAOS_CFG_VTYPE_INT32; @@ -697,12 +716,22 @@ static void doInitGlobalConfig() { cfg.unitType = TAOS_CFG_UTYPE_NONE; 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.ptr = &tsReplications; cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = TSDB_MIN_REPLICA_NUM; - cfg.maxValue = TSDB_MAX_REPLICA_NUM; + cfg.minValue = TSDB_MIN_DB_REPLICA_OPTION; + cfg.maxValue = TSDB_MAX_DB_REPLICA_OPTION; cfg.ptrLength = 0; cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); diff --git a/src/common/src/tname.c b/src/common/src/tname.c index 8b85ecfbc7..15ec68fc66 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -82,7 +82,7 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in } int64_t start = ((startTime - intervalTime) / slidingTime + 1) * slidingTime; - if (!(timeUnit == 'a' || timeUnit == 'm' || timeUnit == 's' || timeUnit == 'h')) { + if (!(timeUnit == 'u' || timeUnit == 'a' || timeUnit == 'm' || timeUnit == 's' || timeUnit == 'h')) { /* * here we revised the start time of day according to the local time zone, * but in case of DST, the start time of one day need to be dynamically decided. diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index eff25e8c93..44b1d9fc38 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -367,31 +367,31 @@ bool isValidDataType(int32_t type) { return type >= TSDB_DATA_TYPE_NULL && type <= TSDB_DATA_TYPE_NCHAR; } -bool isNull(const char *val, int32_t type) { - switch (type) { - case TSDB_DATA_TYPE_BOOL: - return *(uint8_t *)val == TSDB_DATA_BOOL_NULL; - case TSDB_DATA_TYPE_TINYINT: - return *(uint8_t *)val == TSDB_DATA_TINYINT_NULL; - case TSDB_DATA_TYPE_SMALLINT: - return *(uint16_t *)val == TSDB_DATA_SMALLINT_NULL; - case TSDB_DATA_TYPE_INT: - return *(uint32_t *)val == TSDB_DATA_INT_NULL; - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_TIMESTAMP: - return *(uint64_t *)val == TSDB_DATA_BIGINT_NULL; - case TSDB_DATA_TYPE_FLOAT: - return *(uint32_t *)val == TSDB_DATA_FLOAT_NULL; - case TSDB_DATA_TYPE_DOUBLE: - return *(uint64_t *)val == TSDB_DATA_DOUBLE_NULL; - case TSDB_DATA_TYPE_NCHAR: - return *(uint32_t*) varDataVal(val) == TSDB_DATA_NCHAR_NULL; - case TSDB_DATA_TYPE_BINARY: - return *(uint8_t *) varDataVal(val) == TSDB_DATA_BINARY_NULL; - default: - return false; - }; -} +//bool isNull(const char *val, int32_t type) { +// switch (type) { +// case TSDB_DATA_TYPE_BOOL: +// return *(uint8_t *)val == TSDB_DATA_BOOL_NULL; +// case TSDB_DATA_TYPE_TINYINT: +// return *(uint8_t *)val == TSDB_DATA_TINYINT_NULL; +// case TSDB_DATA_TYPE_SMALLINT: +// return *(uint16_t *)val == TSDB_DATA_SMALLINT_NULL; +// case TSDB_DATA_TYPE_INT: +// return *(uint32_t *)val == TSDB_DATA_INT_NULL; +// case TSDB_DATA_TYPE_BIGINT: +// case TSDB_DATA_TYPE_TIMESTAMP: +// return *(uint64_t *)val == TSDB_DATA_BIGINT_NULL; +// case TSDB_DATA_TYPE_FLOAT: +// return *(uint32_t *)val == TSDB_DATA_FLOAT_NULL; +// case TSDB_DATA_TYPE_DOUBLE: +// return *(uint64_t *)val == TSDB_DATA_DOUBLE_NULL; +// case TSDB_DATA_TYPE_NCHAR: +// return *(uint32_t*) varDataVal(val) == TSDB_DATA_NCHAR_NULL; +// case TSDB_DATA_TYPE_BINARY: +// return *(uint8_t *) varDataVal(val) == TSDB_DATA_BINARY_NULL; +// default: +// return false; +// }; +//} void setVardataNull(char* val, int32_t type) { if (type == TSDB_DATA_TYPE_BINARY) { diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java index 48290d3e62..273bc6920c 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java @@ -52,7 +52,7 @@ public class TDNode { public void start() { String selfPath = System.getProperty("user.dir"); String binPath = ""; - String projDir = selfPath + "/../../../../"; + String projDir = selfPath + "/../../../"; try { ArrayList taosdPath = new ArrayList<>(); @@ -68,7 +68,7 @@ public class TDNode { return; } else { for(String p : taosdPath) { - if(!p.contains("packing")) { + if(!p.contains("packaging")) { binPath = p; } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java new file mode 100644 index 0000000000..cb78a5ca0e --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java @@ -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); + } + +} \ No newline at end of file diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index 04d3a6fd6d..51cd471a6b 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -23,6 +23,7 @@ #include "taos.h" #include "taosdef.h" #include "taosmsg.h" +#include "ttimer.h" #include "tcq.h" #include "tdataformat.h" #include "tglobal.h" @@ -45,10 +46,12 @@ typedef struct { struct SCqObj *pHead; void *dbConn; int master; + void *tmrCtrl; pthread_mutex_t mutex; } SCqContext; typedef struct SCqObj { + tmr_h tmrId; uint64_t uid; int32_t tid; // table ID int rowSize; // bytes of a row @@ -66,13 +69,14 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row); static void cqCreateStream(SCqContext *pContext, SCqObj *pObj); void *cqOpen(void *ahandle, const SCqCfg *pCfg) { - SCqContext *pContext = calloc(sizeof(SCqContext), 1); if (pContext == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } + pContext->tmrCtrl = taosTmrInit(0, 0, 0, "CQ"); + tstrncpy(pContext->user, pCfg->user, sizeof(pContext->user)); tstrncpy(pContext->pass, pCfg->pass, sizeof(pContext->pass)); const char* db = pCfg->db; @@ -99,6 +103,9 @@ void cqClose(void *handle) { SCqContext *pContext = handle; if (handle == NULL) return; + taosTmrCleanUp(pContext->tmrCtrl); + pContext->tmrCtrl = NULL; + // stop all CQs cqStop(pContext); @@ -154,8 +161,10 @@ void cqStop(void *handle) { taos_close_stream(pObj->pStream); pObj->pStream = NULL; cTrace("vgId:%d, id:%d CQ:%s is closed", pContext->vgId, pObj->tid, pObj->sqlStr); + } else { + taosTmrStop(pObj->tmrId); + pObj->tmrId = 0; } - pObj = pObj->next; } @@ -211,8 +220,13 @@ void cqDrop(void *handle) { } // free the resources associated - if (pObj->pStream) taos_close_stream(pObj->pStream); - pObj->pStream = NULL; + if (pObj->pStream) { + taos_close_stream(pObj->pStream); + pObj->pStream = NULL; + } else { + taosTmrStop(pObj->tmrId); + pObj->tmrId = 0; + } cTrace("vgId:%d, id:%d CQ:%s is dropped", pContext->vgId, pObj->tid, pObj->sqlStr); tdFreeSchema(pObj->pSchema); @@ -222,18 +236,30 @@ void cqDrop(void *handle) { pthread_mutex_unlock(&pContext->mutex); } -static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { +static void cqProcessCreateTimer(void *param, void *tmrId) { + SCqObj* pObj = (SCqObj*)param; + SCqContext* pContext = pObj->pContext; + if (pContext->dbConn == NULL) { pContext->dbConn = taos_connect("localhost", pContext->user, pContext->pass, pContext->db, 0); if (pContext->dbConn == NULL) { cError("vgId:%d, failed to connect to TDengine(%s)", pContext->vgId, tstrerror(terrno)); - return; } } + + cqCreateStream(pContext, pObj); +} - int64_t lastKey = 0; +static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) { pObj->pContext = pContext; - pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, lastKey, pObj, NULL); + + if (pContext->dbConn == NULL) { + pObj->tmrId = taosTmrStart(cqProcessCreateTimer, 1000, pObj, pContext->tmrCtrl); + return; + } + pObj->tmrId = 0; + + pObj->pStream = taos_open_stream(pContext->dbConn, pObj->sqlStr, cqProcessStreamRes, 0, pObj, NULL); if (pObj->pStream) { pContext->num++; cTrace("vgId:%d, id:%d CQ:%s is openned", pContext->vgId, pObj->tid, pObj->sqlStr); diff --git a/src/dnode/inc/dnodeInt.h b/src/dnode/inc/dnodeInt.h index 76f2f41673..f4cbee1d13 100644 --- a/src/dnode/inc/dnodeInt.h +++ b/src/dnode/inc/dnodeInt.h @@ -26,10 +26,10 @@ extern int32_t dDebugFlag; #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 dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }} -#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND INFO ", 255, __VA_ARGS__); }} -#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND DEBUG ", dDebugFlag, __VA_ARGS__); }} -#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND TRACE ", dDebugFlag, __VA_ARGS__); }} +#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }} +#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", 255, __VA_ARGS__); }} +#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }} +#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }} #ifdef __cplusplus } diff --git a/src/dnode/inc/dnodeModule.h b/src/dnode/inc/dnodeModule.h index 6a6da0a2a5..8618de3244 100644 --- a/src/dnode/inc/dnodeModule.h +++ b/src/dnode/inc/dnodeModule.h @@ -22,7 +22,6 @@ extern "C" { int32_t dnodeInitModules(); void dnodeStartModules(); -void dnodeStartStream(); void dnodeCleanupModules(); void dnodeProcessModuleStatus(uint32_t moduleStatus); diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 987a189959..6476bb7831 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -123,7 +123,6 @@ int32_t dnodeInitSystem() { dnodeStartModules(); dnodeSetRunStatus(TSDB_DNODE_RUN_STATUS_RUNING); - dnodeStartStream(); dInfo("TDengine is initialized successfully"); diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index b1c93d7195..8e1696c802 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -72,6 +72,7 @@ static void *dnodeProcessMgmtQueue(void *param); static int32_t dnodeOpenVnodes(); static void dnodeCloseVnodes(); static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *pMsg); +static int32_t dnodeProcessAlterVnodeMsg(SRpcMsg *pMsg); static int32_t dnodeProcessDropVnodeMsg(SRpcMsg *pMsg); static int32_t dnodeProcessAlterStreamMsg(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() { 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_ALTER_STREAM] = dnodeProcessAlterStreamMsg; dnodeProcessMgmtMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE] = dnodeProcessConfigDnodeMsg; @@ -352,23 +354,6 @@ static int32_t dnodeOpenVnodes() { return TSDB_CODE_SUCCESS; } -void dnodeStartStream() { - int32_t vnodeList[TSDB_MAX_VNODES] = {0}; - int32_t numOfVnodes = 0; - int32_t status = vnodeGetVnodeList(vnodeList, &numOfVnodes); - - if (status != TSDB_CODE_SUCCESS) { - dInfo("get dnode list failed"); - return; - } - - for (int32_t i = 0; i < numOfVnodes; ++i) { - vnodeStartStream(vnodeList[i]); - } - - dInfo("streams started"); -} - static void dnodeCloseVnodes() { int32_t vnodeList[TSDB_MAX_VNODES]= {0}; int32_t numOfVnodes = 0; @@ -388,7 +373,7 @@ static void dnodeCloseVnodes() { dInfo("total vnodes:%d are all closed", numOfVnodes); } -static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) { +static void* dnodeParseVnodeMsg(SRpcMsg *rpcMsg) { SMDCreateVnodeMsg *pCreate = rpcMsg->pCont; pCreate->cfg.vgId = htonl(pCreate->cfg.vgId); pCreate->cfg.cfgVersion = htonl(pCreate->cfg.cfgVersion); @@ -401,20 +386,42 @@ static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) { pCreate->cfg.daysToKeep = htonl(pCreate->cfg.daysToKeep); pCreate->cfg.minRowsPerFileBlock = htonl(pCreate->cfg.minRowsPerFileBlock); pCreate->cfg.maxRowsPerFileBlock = htonl(pCreate->cfg.maxRowsPerFileBlock); + pCreate->cfg.fsyncPeriod = htonl(pCreate->cfg.fsyncPeriod); pCreate->cfg.commitTime = htonl(pCreate->cfg.commitTime); for (int32_t j = 0; j < pCreate->cfg.replications; ++j) { pCreate->nodes[j].nodeId = htonl(pCreate->nodes[j].nodeId); } - void *pVnode = vnodeAcquireVnode(pCreate->cfg.vgId); + return pCreate; +} + +static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) { + SMDCreateVnodeMsg *pCreate = dnodeParseVnodeMsg(rpcMsg); + + void *pVnode = vnodeAcquire(pCreate->cfg.vgId); if (pVnode != NULL) { - dDebug("vgId:%d, already exist, processed as alter msg", pCreate->cfg.vgId); - int32_t code = vnodeAlter(pVnode, pCreate); + dDebug("vgId:%d, already exist, return success", pCreate->cfg.vgId); + 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 = vnodeAcquire(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); return code; } else { - return vnodeCreate(pCreate); + dError("vgId:%d, vnode not exist, can't alter it", pAlter->cfg.vgId); + return TSDB_CODE_VND_INVALID_VGROUP_ID; } } @@ -698,10 +705,13 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) { pStatus->alternativeRole = (uint8_t) tsAlternativeRole; // fill cluster cfg parameters - pStatus->clusterCfg.numOfMnodes = tsNumOfMnodes; - pStatus->clusterCfg.mnodeEqualVnodeNum = tsMnodeEqualVnodeNum; - pStatus->clusterCfg.offlineThreshold = tsOfflineThreshold; - pStatus->clusterCfg.statusInterval = tsStatusInterval; + pStatus->clusterCfg.numOfMnodes = htonl(tsNumOfMnodes); + pStatus->clusterCfg.enableBalance = htonl(tsEnableBalance); + pStatus->clusterCfg.mnodeEqualVnodeNum = htonl(tsMnodeEqualVnodeNum); + pStatus->clusterCfg.offlineThreshold = htonl(tsOfflineThreshold); + pStatus->clusterCfg.statusInterval = htonl(tsStatusInterval); + pStatus->clusterCfg.maxtablesPerVnode = htonl(tsMaxTablePerVnode); + pStatus->clusterCfg.maxVgroupsPerDb = htonl(tsMaxVgroupsPerDb); strcpy(pStatus->clusterCfg.arbitrator, tsArbitrator); strcpy(pStatus->clusterCfg.timezone, tsTimezone); strcpy(pStatus->clusterCfg.locale, tsLocale); diff --git a/src/dnode/src/dnodePeer.c b/src/dnode/src/dnodePeer.c index 6ab5188934..2a3436583f 100644 --- a/src/dnode/src/dnodePeer.c +++ b/src/dnode/src/dnodePeer.c @@ -44,6 +44,7 @@ int32_t dnodeInitServer() { dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = dnodeDispatchToVnodeWriteQueue; 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_ALTER_STREAM] = dnodeDispatchToMgmtQueue; dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE] = dnodeDispatchToMgmtQueue; @@ -60,7 +61,7 @@ int32_t dnodeInitServer() { rpcInit.label = "DND-S"; rpcInit.numOfThreads = 1; rpcInit.cfp = dnodeProcessReqMsgFromDnode; - rpcInit.sessions = 100; + rpcInit.sessions = TSDB_MAX_VNODES; rpcInit.connType = TAOS_CONN_SERVER; rpcInit.idleTime = tsShellActivityTimer * 1000; @@ -122,7 +123,7 @@ int32_t dnodeInitClient() { rpcInit.label = "DND-C"; rpcInit.numOfThreads = 1; rpcInit.cfp = dnodeProcessRspFromDnode; - rpcInit.sessions = 100; + rpcInit.sessions = TSDB_MAX_VNODES; rpcInit.connType = TAOS_CONN_CLIENT; rpcInit.idleTime = tsShellActivityTimer * 1000; rpcInit.user = "t"; diff --git a/src/dnode/src/dnodeSystem.c b/src/dnode/src/dnodeSystem.c index 971bd0a110..901e0061e9 100644 --- a/src/dnode/src/dnodeSystem.c +++ b/src/dnode/src/dnodeSystem.c @@ -70,7 +70,13 @@ int32_t main(int32_t argc, char *argv[]) { } #endif #ifdef TAOS_RANDOM_FILE_FAIL - else if (strcmp(argv[i], "--random-file-fail-factor") == 0) { + else if (strcmp(argv[i], "--random-file-fail-output") == 0) { + if ((i < argc - 1) && (argv[i + 1][0] != '-')) { + taosSetRandomFileFailOutput(argv[++i]); + } else { + taosSetRandomFileFailOutput(NULL); + } + } else if (strcmp(argv[i], "--random-file-fail-factor") == 0) { if ( (i+1) < argc ) { int factor = atoi(argv[i+1]); printf("The factor of random failure is %d\n", factor); @@ -129,7 +135,7 @@ int32_t main(int32_t argc, char *argv[]) { static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) { if (signum == SIGUSR1) { - taosCfgDynamicOptions("debugFlag 151"); + taosCfgDynamicOptions("debugFlag 143"); return; } if (signum == SIGUSR2) { diff --git a/src/dnode/src/dnodeVRead.c b/src/dnode/src/dnodeVRead.c index 66135a93e9..bbea1a5e0b 100644 --- a/src/dnode/src/dnodeVRead.c +++ b/src/dnode/src/dnodeVRead.c @@ -91,23 +91,21 @@ void dnodeDispatchToVnodeReadQueue(SRpcMsg *pMsg) { int32_t queuedMsgNum = 0; int32_t leftLen = pMsg->contLen; char *pCont = (char *) pMsg->pCont; - void *pVnode; while (leftLen > 0) { SMsgHead *pHead = (SMsgHead *) pCont; pHead->vgId = htonl(pHead->vgId); pHead->contLen = htonl(pHead->contLen); - pVnode = vnodeAcquireVnode(pHead->vgId); + taos_queue queue = vnodeAcquireRqueue(pHead->vgId); - if (pVnode == NULL) { + if (queue == NULL) { leftLen -= pHead->contLen; pCont -= pHead->contLen; continue; } // put message into queue - taos_queue queue = vnodeGetRqueue(pVnode); SReadMsg *pRead = (SReadMsg *)taosAllocateQitem(sizeof(SReadMsg)); pRead->rpcMsg = *pMsg; pRead->pCont = pCont; @@ -175,18 +173,6 @@ void dnodeFreeVnodeRqueue(void *rqueue) { // dynamically adjust the number of threads } -void dnodePutItemIntoReadQueue(void *pVnode, void *qhandle) { - SReadMsg *pRead = (SReadMsg *)taosAllocateQitem(sizeof(SReadMsg)); - pRead->rpcMsg.msgType = TSDB_MSG_TYPE_QUERY; - pRead->pCont = qhandle; - pRead->contLen = 0; - - assert(pVnode != NULL); - taos_queue queue = vnodeAcquireRqueue(pVnode); - - taosWriteQitem(queue, TAOS_QTYPE_QUERY, pRead); -} - void dnodeSendRpcReadRsp(void *pVnode, SReadMsg *pRead, int32_t code) { SRpcMsg rpcRsp = { .handle = pRead->rpcMsg.handle, diff --git a/src/dnode/src/dnodeVWrite.c b/src/dnode/src/dnodeVWrite.c index 546e8cecb9..dc09a03e14 100644 --- a/src/dnode/src/dnodeVWrite.c +++ b/src/dnode/src/dnodeVWrite.c @@ -104,7 +104,7 @@ void dnodeDispatchToVnodeWriteQueue(SRpcMsg *pMsg) { pHead->vgId = htonl(pHead->vgId); pHead->contLen = htonl(pHead->contLen); - taos_queue queue = vnodeGetWqueue(pHead->vgId); + taos_queue queue = vnodeAcquireWqueue(pHead->vgId); if (queue) { // put message into queue SWriteMsg *pWrite = (SWriteMsg *)taosAllocateQitem(sizeof(SWriteMsg)); @@ -232,9 +232,10 @@ static void *dnodeProcessWriteQueue(void *param) { pHead->msgType = pWrite->rpcMsg.msgType; pHead->version = 0; pHead->len = pWrite->contLen; - dDebug("%p, msg:%s will be processed in vwrite queue", pWrite->rpcMsg.ahandle, taosMsg[pWrite->rpcMsg.msgType]); + dDebug("%p, rpc msg:%s will be processed in vwrite queue", pWrite->rpcMsg.ahandle, taosMsg[pWrite->rpcMsg.msgType]); } else { pHead = (SWalHead *)item; + dTrace("%p, wal msg:%s will be processed in vwrite queue, version:%" PRIu64, pHead, taosMsg[pHead->msgType], pHead->version); } int32_t code = vnodeProcessWrite(pVnode, type, pHead, pRspRet); diff --git a/src/inc/dnode.h b/src/inc/dnode.h index 096aae58f2..b561c407a3 100644 --- a/src/inc/dnode.h +++ b/src/inc/dnode.h @@ -53,7 +53,6 @@ void *dnodeAllocateVnodeWqueue(void *pVnode); void dnodeFreeVnodeWqueue(void *queue); void *dnodeAllocateVnodeRqueue(void *pVnode); void dnodeFreeVnodeRqueue(void *rqueue); -void dnodePutItemIntoReadQueue(void *pVnode, void *qhandle); void dnodeSendRpcVnodeWriteRsp(void *pVnode, void *param, int32_t code); int32_t dnodeAllocateMnodePqueue(); diff --git a/src/inc/query.h b/src/inc/query.h index c648270b21..d201b649f9 100644 --- a/src/inc/query.h +++ b/src/inc/query.h @@ -20,7 +20,6 @@ extern "C" { #endif typedef void* qinfo_t; -typedef void (*_qinfo_free_fn_t)(void*); /** * create the qinfo object according to QueryTableMsg @@ -29,13 +28,8 @@ typedef void (*_qinfo_free_fn_t)(void*); * @param qinfo * @return */ -int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryTableMsg, void* param, _qinfo_free_fn_t fn, qinfo_t* qinfo); +int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryTableMsg, void* param, qinfo_t* qinfo); -/** - * Destroy QInfo object - * @param qinfo qhandle - */ -void qDestroyQueryInfo(qinfo_t qinfo); /** * the main query execution function, including query on both table and multitables, @@ -84,8 +78,14 @@ bool qHasMoreResultsToRetrieve(qinfo_t qinfo); */ int32_t qKillQuery(qinfo_t qinfo); +/** + * destroy query info structure + * @param qHandle + */ +void qDestroyQueryInfo(qinfo_t qHandle); + void* qOpenQueryMgmt(int32_t vgId); -void qSetQueryMgmtClosed(void* pExecutor); +void qQueryMgmtNotifyClosed(void* pExecutor); void qCleanupQueryMgmt(void* pExecutor); void** qRegisterQInfo(void* pMgmt, uint64_t qInfo); void** qAcquireQInfo(void* pMgmt, uint64_t key); diff --git a/src/inc/taos.h b/src/inc/taos.h index 1d609bc7db..d6f1883572 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -67,6 +67,8 @@ DLL_EXPORT void taos_init(); DLL_EXPORT void taos_cleanup(); 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_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); typedef struct TAOS_BIND { @@ -88,6 +90,7 @@ TAOS_RES * taos_stmt_use_result(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_c(TAOS *taos, const char *sql, uint32_t sqlLen); 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 void taos_free_result(TAOS_RES *res); diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index e4ee058cef..7696c91bdf 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -160,7 +160,32 @@ extern tDataTypeDescriptor tDataTypeDesc[11]; #define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*) bool isValidDataType(int32_t type); -bool isNull(const char *val, int32_t type); +//bool isNull(const char *val, int32_t type); +static inline __attribute__((always_inline)) bool isNull(const char *val, int32_t type) { + switch (type) { + case TSDB_DATA_TYPE_BOOL: + return *(uint8_t *)val == TSDB_DATA_BOOL_NULL; + case TSDB_DATA_TYPE_TINYINT: + return *(uint8_t *)val == TSDB_DATA_TINYINT_NULL; + case TSDB_DATA_TYPE_SMALLINT: + return *(uint16_t *)val == TSDB_DATA_SMALLINT_NULL; + case TSDB_DATA_TYPE_INT: + return *(uint32_t *)val == TSDB_DATA_INT_NULL; + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_TIMESTAMP: + return *(uint64_t *)val == TSDB_DATA_BIGINT_NULL; + case TSDB_DATA_TYPE_FLOAT: + return *(uint32_t *)val == TSDB_DATA_FLOAT_NULL; + case TSDB_DATA_TYPE_DOUBLE: + return *(uint64_t *)val == TSDB_DATA_DOUBLE_NULL; + case TSDB_DATA_TYPE_NCHAR: + return *(uint32_t*) varDataVal(val) == TSDB_DATA_NCHAR_NULL; + case TSDB_DATA_TYPE_BINARY: + return *(uint8_t *) varDataVal(val) == TSDB_DATA_BINARY_NULL; + default: + return false; + }; +} void setVardataNull(char* val, int32_t type); void setNull(char *val, int32_t type, int32_t bytes); @@ -249,8 +274,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value #define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth #define TSDB_CQ_SQL_SIZE 1024 -#define TSDB_MAX_VNODES 256 -#define TSDB_MIN_VNODES 50 +#define TSDB_MAX_VNODES 2048 +#define TSDB_MIN_VNODES 256 #define TSDB_INVALID_VNODE_NUM 0 #define TSDB_DNODE_ROLE_ANY 0 @@ -271,8 +296,9 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_DEFAULT_TOTAL_BLOCKS 4 #define TSDB_MIN_TABLES 4 -#define TSDB_MAX_TABLES 200000 -#define TSDB_DEFAULT_TABLES 1000 +#define TSDB_MAX_TABLES 10000000 +#define TSDB_DEFAULT_TABLES 1000000 +#define TSDB_TABLES_STEP 1000 #define TSDB_MIN_DAYS_PER_FILE 1 #define TSDB_MAX_DAYS_PER_FILE 3650 @@ -306,9 +332,13 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); #define TSDB_MAX_WAL_LEVEL 2 #define TSDB_DEFAULT_WAL_LEVEL 1 -#define TSDB_MIN_REPLICA_NUM 1 -#define TSDB_MAX_REPLICA_NUM 3 -#define TSDB_DEFAULT_REPLICA_NUM 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_MAX_DB_REPLICA_OPTION 3 +#define TSDB_DEFAULT_DB_REPLICA_OPTION 1 #define TSDB_MAX_JOIN_TABLE_NUM 5 #define TSDB_MAX_UNION_CLAUSE 5 diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index d2bef9ea57..3503e39d31 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -200,6 +200,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_CREATE_TB_MSG, 0, 0x060E, "tsdb inval TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM, 0, 0x060F, "tsdb no table data in memory skiplist") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_FILE_ALREADY_EXISTS, 0, 0x0610, "tsdb file already exists") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_RECONFIGURE, 0, 0x0611, "tsdb need to reconfigure table") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO, 0, 0x0612, "tsdb create table information") // query TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_QHANDLE, 0, 0x0700, "query invalid handle") @@ -208,6 +209,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NO_DISKSPACE, 0, 0x0702, "query no d TAOS_DEFINE_ERROR(TSDB_CODE_QRY_OUT_OF_MEMORY, 0, 0x0703, "query out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_APP_ERROR, 0, 0x0704, "query app error") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_DUP_JOIN_KEY, 0, 0x0705, "query duplicated join key") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_EXCEED_TAGS_LIMIT, 0, 0x0706, "query tag conditon too many") // grant TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0800, "grant expired") diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index ac89d1dabb..b7afaf1e06 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -58,7 +58,7 @@ 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_ALTER_STREAM, "alter-stream" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_CONFIG_DNODE, "config-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY4, "dummy4" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_ALTER_VNODE, "alter-vnode" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY5, "dummy5" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY6, "dummy6" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY7, "dummy7" ) @@ -515,6 +515,7 @@ typedef struct { int32_t minRowsPerFileBlock; int32_t maxRowsPerFileBlock; int32_t commitTime; + int32_t fsyncPeriod; uint8_t precision; // time resolution int8_t compression; int8_t walLevel; @@ -562,9 +563,12 @@ typedef struct { typedef struct { int32_t numOfMnodes; // tsNumOfMnodes + int32_t enableBalance; // tsEnableBalance int32_t mnodeEqualVnodeNum; // tsMnodeEqualVnodeNum int32_t offlineThreshold; // tsOfflineThreshold int32_t statusInterval; // tsStatusInterval + int32_t maxtablesPerVnode; + int32_t maxVgroupsPerDb; char arbitrator[TSDB_EP_LEN]; // tsArbitrator char timezone[64]; // tsTimezone char locale[TSDB_LOCALE_LEN]; // tsLocale @@ -606,6 +610,7 @@ typedef struct { int32_t minRowsPerFileBlock; int32_t maxRowsPerFileBlock; int32_t commitTime; + int32_t fsyncPeriod; int8_t precision; int8_t compression; int8_t walLevel; @@ -624,7 +629,7 @@ typedef struct { char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; SMDVnodeCfg cfg; SMDVnodeDesc nodes[TSDB_MAX_REPLICA]; -} SMDCreateVnodeMsg; +} SMDCreateVnodeMsg, SMDAlterVnodeMsg; typedef struct { char tableId[TSDB_TABLE_ID_LEN]; @@ -644,7 +649,7 @@ typedef struct SCMSTableVgroupMsg { typedef struct { int32_t vgId; int8_t numOfIps; - SIpAddr ipAddr[TSDB_MAX_REPLICA_NUM]; + SIpAddr ipAddr[TSDB_MAX_REPLICA]; } SCMVgroupInfo; typedef struct { diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index b8cc1768e8..a1e87a7437 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -117,7 +117,6 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg); int tsdbDropTable(TSDB_REPO_T *pRepo, STableId tableId); int tsdbUpdateTableTagValue(TSDB_REPO_T *repo, SUpdateTableTagValMsg *pMsg); TSKEY tsdbGetTableLastKey(TSDB_REPO_T *repo, uint64_t uid); -void tsdbStartStream(TSDB_REPO_T *repo); uint32_t tsdbGetFileInfo(TSDB_REPO_T *repo, char *name, uint32_t *index, uint32_t eindex, int32_t *size); diff --git a/src/inc/tsync.h b/src/inc/tsync.h index 972db294f6..65b91d87e4 100644 --- a/src/inc/tsync.h +++ b/src/inc/tsync.h @@ -79,7 +79,7 @@ typedef void (*FConfirmForward)(void *ahandle, void *mhandle, int32_t code); typedef void (*FNotifyRole)(void *ahandle, int8_t role); // when data file is synced successfully, notity app -typedef void (*FNotifyFileSynced)(void *ahandle, uint64_t fversion); +typedef int (*FNotifyFileSynced)(void *ahandle, uint64_t fversion); typedef struct { int32_t vgId; // vgroup ID diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index b313d6ebb1..0b63e9e71d 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -110,117 +110,117 @@ #define TK_BLOCKS 92 #define TK_CTIME 93 #define TK_WAL 94 -#define TK_COMP 95 -#define TK_PRECISION 96 -#define TK_LP 97 -#define TK_RP 98 -#define TK_TAGS 99 -#define TK_USING 100 -#define TK_AS 101 -#define TK_COMMA 102 -#define TK_NULL 103 -#define TK_SELECT 104 -#define TK_UNION 105 -#define TK_ALL 106 -#define TK_FROM 107 -#define TK_VARIABLE 108 -#define TK_INTERVAL 109 -#define TK_FILL 110 -#define TK_SLIDING 111 -#define TK_ORDER 112 -#define TK_BY 113 -#define TK_ASC 114 -#define TK_DESC 115 -#define TK_GROUP 116 -#define TK_HAVING 117 -#define TK_LIMIT 118 -#define TK_OFFSET 119 -#define TK_SLIMIT 120 -#define TK_SOFFSET 121 -#define TK_WHERE 122 -#define TK_NOW 123 -#define TK_RESET 124 -#define TK_QUERY 125 -#define TK_ADD 126 -#define TK_COLUMN 127 -#define TK_TAG 128 -#define TK_CHANGE 129 -#define TK_SET 130 -#define TK_KILL 131 -#define TK_CONNECTION 132 -#define TK_STREAM 133 -#define TK_COLON 134 -#define TK_ABORT 135 -#define TK_AFTER 136 -#define TK_ATTACH 137 -#define TK_BEFORE 138 -#define TK_BEGIN 139 -#define TK_CASCADE 140 -#define TK_CLUSTER 141 -#define TK_CONFLICT 142 -#define TK_COPY 143 -#define TK_DEFERRED 144 -#define TK_DELIMITERS 145 -#define TK_DETACH 146 -#define TK_EACH 147 -#define TK_END 148 -#define TK_EXPLAIN 149 -#define TK_FAIL 150 -#define TK_FOR 151 -#define TK_IGNORE 152 -#define TK_IMMEDIATE 153 -#define TK_INITIALLY 154 -#define TK_INSTEAD 155 -#define TK_MATCH 156 -#define TK_KEY 157 -#define TK_OF 158 -#define TK_RAISE 159 -#define TK_REPLACE 160 -#define TK_RESTRICT 161 -#define TK_ROW 162 -#define TK_STATEMENT 163 -#define TK_TRIGGER 164 -#define TK_VIEW 165 -#define TK_COUNT 166 -#define TK_SUM 167 -#define TK_AVG 168 -#define TK_MIN 169 -#define TK_MAX 170 -#define TK_FIRST 171 -#define TK_LAST 172 -#define TK_TOP 173 -#define TK_BOTTOM 174 -#define TK_STDDEV 175 -#define TK_PERCENTILE 176 -#define TK_APERCENTILE 177 -#define TK_LEASTSQUARES 178 -#define TK_HISTOGRAM 179 -#define TK_DIFF 180 -#define TK_SPREAD 181 -#define TK_TWA 182 -#define TK_INTERP 183 -#define TK_LAST_ROW 184 -#define TK_RATE 185 -#define TK_IRATE 186 -#define TK_SUM_RATE 187 -#define TK_SUM_IRATE 188 -#define TK_AVG_RATE 189 -#define TK_AVG_IRATE 190 -#define TK_TBID 191 -#define TK_SEMI 192 -#define TK_NONE 193 -#define TK_PREV 194 -#define TK_LINEAR 195 -#define TK_IMPORT 196 -#define TK_METRIC 197 -#define TK_TBNAME 198 -#define TK_JOIN 199 -#define TK_METRICS 200 -#define TK_STABLE 201 -#define TK_INSERT 202 -#define TK_INTO 203 -#define TK_VALUES 204 - +#define TK_FSYNC 95 +#define TK_COMP 96 +#define TK_PRECISION 97 +#define TK_LP 98 +#define TK_RP 99 +#define TK_TAGS 100 +#define TK_USING 101 +#define TK_AS 102 +#define TK_COMMA 103 +#define TK_NULL 104 +#define TK_SELECT 105 +#define TK_UNION 106 +#define TK_ALL 107 +#define TK_FROM 108 +#define TK_VARIABLE 109 +#define TK_INTERVAL 110 +#define TK_FILL 111 +#define TK_SLIDING 112 +#define TK_ORDER 113 +#define TK_BY 114 +#define TK_ASC 115 +#define TK_DESC 116 +#define TK_GROUP 117 +#define TK_HAVING 118 +#define TK_LIMIT 119 +#define TK_OFFSET 120 +#define TK_SLIMIT 121 +#define TK_SOFFSET 122 +#define TK_WHERE 123 +#define TK_NOW 124 +#define TK_RESET 125 +#define TK_QUERY 126 +#define TK_ADD 127 +#define TK_COLUMN 128 +#define TK_TAG 129 +#define TK_CHANGE 130 +#define TK_SET 131 +#define TK_KILL 132 +#define TK_CONNECTION 133 +#define TK_STREAM 134 +#define TK_COLON 135 +#define TK_ABORT 136 +#define TK_AFTER 137 +#define TK_ATTACH 138 +#define TK_BEFORE 139 +#define TK_BEGIN 140 +#define TK_CASCADE 141 +#define TK_CLUSTER 142 +#define TK_CONFLICT 143 +#define TK_COPY 144 +#define TK_DEFERRED 145 +#define TK_DELIMITERS 146 +#define TK_DETACH 147 +#define TK_EACH 148 +#define TK_END 149 +#define TK_EXPLAIN 150 +#define TK_FAIL 151 +#define TK_FOR 152 +#define TK_IGNORE 153 +#define TK_IMMEDIATE 154 +#define TK_INITIALLY 155 +#define TK_INSTEAD 156 +#define TK_MATCH 157 +#define TK_KEY 158 +#define TK_OF 159 +#define TK_RAISE 160 +#define TK_REPLACE 161 +#define TK_RESTRICT 162 +#define TK_ROW 163 +#define TK_STATEMENT 164 +#define TK_TRIGGER 165 +#define TK_VIEW 166 +#define TK_COUNT 167 +#define TK_SUM 168 +#define TK_AVG 169 +#define TK_MIN 170 +#define TK_MAX 171 +#define TK_FIRST 172 +#define TK_LAST 173 +#define TK_TOP 174 +#define TK_BOTTOM 175 +#define TK_STDDEV 176 +#define TK_PERCENTILE 177 +#define TK_APERCENTILE 178 +#define TK_LEASTSQUARES 179 +#define TK_HISTOGRAM 180 +#define TK_DIFF 181 +#define TK_SPREAD 182 +#define TK_TWA 183 +#define TK_INTERP 184 +#define TK_LAST_ROW 185 +#define TK_RATE 186 +#define TK_IRATE 187 +#define TK_SUM_RATE 188 +#define TK_SUM_IRATE 189 +#define TK_AVG_RATE 190 +#define TK_AVG_IRATE 191 +#define TK_TBID 192 +#define TK_SEMI 193 +#define TK_NONE 194 +#define TK_PREV 195 +#define TK_LINEAR 196 +#define TK_IMPORT 197 +#define TK_METRIC 198 +#define TK_TBNAME 199 +#define TK_JOIN 200 +#define TK_METRICS 201 +#define TK_STABLE 202 +#define TK_INSERT 203 +#define TK_INTO 204 +#define TK_VALUES 205 #define TK_SPACE 300 #define TK_COMMENT 301 diff --git a/src/inc/twal.h b/src/inc/twal.h index 8c2c3c69a1..4fdb7aa275 100644 --- a/src/inc/twal.h +++ b/src/inc/twal.h @@ -35,6 +35,7 @@ typedef struct { typedef struct { int8_t walLevel; // wal level + int32_t fsyncPeriod; // millisecond int8_t wals; // number of WAL files; int8_t keep; // keep the wal file when closed } SWalCfg; diff --git a/src/inc/vnode.h b/src/inc/vnode.h index 1e6cfa9700..15ddb6afee 100644 --- a/src/inc/vnode.h +++ b/src/inc/vnode.h @@ -22,10 +22,10 @@ extern "C" { typedef enum _VN_STATUS { TAOS_VN_STATUS_INIT, - TAOS_VN_STATUS_UPDATING, TAOS_VN_STATUS_READY, TAOS_VN_STATUS_CLOSING, - TAOS_VN_STATUS_DELETING, + TAOS_VN_STATUS_UPDATING, + TAOS_VN_STATUS_RESET, } EVnStatus; typedef struct { @@ -44,17 +44,13 @@ typedef struct { int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg); int32_t vnodeDrop(int32_t vgId); int32_t vnodeOpen(int32_t vgId, char *rootDir); -int32_t vnodeStartStream(int32_t vgId); int32_t vnodeAlter(void *pVnode, SMDCreateVnodeMsg *pVnodeCfg); int32_t vnodeClose(int32_t vgId); -void vnodeRelease(void *pVnode); -void* vnodeAcquireVnode(int32_t vgId); // add refcount -void* vnodeGetVnode(int32_t vgId); // keep refcount unchanged - -void* vnodeAcquireRqueue(void *); -void* vnodeGetRqueue(void *); -void* vnodeGetWqueue(int32_t vgId); +void* vnodeAcquire(int32_t vgId); // add refcount +void* vnodeAcquireRqueue(int32_t vgId); // add refCount, get read queue +void* vnodeAcquireWqueue(int32_t vgId); // add recCount, get write queue +void vnodeRelease(void *pVnode); // dec refCount void* vnodeGetWal(void *pVnode); int32_t vnodeProcessWrite(void *pVnode, int qtype, void *pHead, void *item); diff --git a/src/kit/shell/src/shellImport.c b/src/kit/shell/src/shellImport.c index a440db7301..afd2d85dae 100644 --- a/src/kit/shell/src/shellImport.c +++ b/src/kit/shell/src/shellImport.c @@ -136,7 +136,7 @@ static void shellGetDirectoryFileList(char *inputDir) static void shellSourceFile(TAOS *con, char *fptr) { wordexp_t full_path; int read_len = 0; - char * cmd = malloc(MAX_COMMAND_SIZE); + char * cmd = malloc(tsMaxSQLStringLen); size_t cmd_len = 0; char * line = NULL; size_t line_len = 0; @@ -185,7 +185,7 @@ static void shellSourceFile(TAOS *con, char *fptr) { int lineNo = 0; while ((read_len = getline(&line, &line_len, f)) != -1) { ++lineNo; - if (read_len >= MAX_COMMAND_SIZE) continue; + if (read_len >= tsMaxSQLStringLen) continue; line[--read_len] = '\0'; if (read_len == 0 || isCommentLine(line)) { // line starts with # diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 70f18b32bd..a1b1998298 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -179,8 +179,8 @@ static struct argp_option options[] = { {"start-time", 'S', "START_TIME", 0, "Start 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}, - {"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}, + {"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}, {"allow-sys", 'a', 0, 0, "Allow to dump sys database", 3}, {0}}; @@ -304,10 +304,10 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { case 'N': arguments->data_batch = atoi(arg); break; - case 'T': + case 't': arguments->table_batch = atoi(arg); break; - case 't': + case 'T': arguments->thread_num = atoi(arg); break; case OPT_ABORT: @@ -406,7 +406,7 @@ int main(int argc, char *argv[]) { printf("password: %s\n", tsArguments.password); printf("port: %u\n", tsArguments.port); printf("cversion: %s\n", tsArguments.cversion); - printf("mysqlFlag: %d", tsArguments.mysqlFlag); + printf("mysqlFlag: %d\n", tsArguments.mysqlFlag); printf("outpath: %s\n", tsArguments.outpath); printf("inpath: %s\n", tsArguments.inpath); printf("encode: %s\n", tsArguments.encode); @@ -821,7 +821,7 @@ _exit_failure: 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_RES *tmpResult = NULL; int count = 0; @@ -832,6 +832,13 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon) { 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); tmpResult = taos_query(taosCon, tempCommand); @@ -862,6 +869,92 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon) { taos_free_result(tmpResult); 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); 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); */ - count = taosGetTableDes(table, tableDes, taosCon); + count = taosGetTableDes(table, tableDes, taosCon, false); if (count < 0) { free(tableDes); return -1; } + // create child-table using super-table taosDumpCreateMTableClause(tableDes, metric, count, fp); } else { // dump table definition - count = taosGetTableDes(table, tableDes, taosCon); + count = taosGetTableDes(table, tableDes, taosCon, false); if (count < 0) { free(tableDes); return -1; } + // create normal-table or super-table taosDumpCreateTableClause(tableDes, count, fp); } @@ -1033,7 +1128,7 @@ int32_t taosDumpStable(char *table, FILE *fp, TAOS* taosCon) { exit(-1); } - count = taosGetTableDes(table, tableDes, taosCon); + count = taosGetTableDes(table, tableDes, taosCon, true); if (count < 0) { free(tableDes); @@ -1083,7 +1178,6 @@ int32_t taosDumpCreateSuperTableClause(TAOS* taosCon, char* dbName, FILE *fp) taos_free_result(tmpResult); exit(-1); } - taos_free_result(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 (strcasecmp(tableDes->cols[counter].type, "binary") == 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 { pstr += sprintf(pstr, ", %s", tableDes->cols[counter].note); } } else { if (strcasecmp(tableDes->cols[counter].type, "binary") == 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 { pstr += sprintf(pstr, "%s", tableDes->cols[counter].note); } @@ -1363,7 +1459,7 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS* return -1; } - numFields = taos_field_count(taosCon); + numFields = taos_field_count(tmpResult); assert(numFields > 0); TAOS_FIELD *fields = taos_fetch_fields(tmpResult); 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); + cmd[read_len + cmd_len]= '\0'; if (queryDB(taos, cmd)) { fprintf(stderr, "error sql: linenu:%d, file:%s\n", lineNo, fileName); } diff --git a/src/kit/taosmigrate/taosmigrateVnodeCfg.c b/src/kit/taosmigrate/taosmigrateVnodeCfg.c index b925fb10aa..e830ef78f5 100644 --- a/src/kit/taosmigrate/taosmigrateVnodeCfg.c +++ b/src/kit/taosmigrate/taosmigrateVnodeCfg.c @@ -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, " \"compression\": %d,\n", pVnode->tsdbCfg.compression); 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, " \"wals\": %d,\n", pVnode->walCfg.wals); 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; + 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"); if (!wals || wals->type != cJSON_Number) { printf("vgId:%d, failed to read vnode cfg, wals not found\n", pVnode->vgId); diff --git a/src/mnode/inc/mnodeDb.h b/src/mnode/inc/mnodeDb.h index c8557af166..ca6c2a86a2 100644 --- a/src/mnode/inc/mnodeDb.h +++ b/src/mnode/inc/mnodeDb.h @@ -44,10 +44,7 @@ void mnodeRemoveSuperTableFromDb(SDbObj *pDb); void mnodeAddTableIntoDb(SDbObj *pDb); void mnodeRemoveTableFromDb(SDbObj *pDb); void mnodeAddVgroupIntoDb(SVgObj *pVgroup); -void mnodeAddVgroupIntoDbTail(SVgObj *pVgroup); void mnodeRemoveVgroupFromDb(SVgObj *pVgroup); -void mnodeMoveVgroupToTail(SVgObj *pVgroup); -void mnodeMoveVgroupToHead(SVgObj *pVgroup); #ifdef __cplusplus } diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index b40080759f..b7489a9fc5 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -145,10 +145,8 @@ typedef struct SVgObj { int64_t totalStorage; int64_t compStorage; int64_t pointsWritten; - struct SVgObj *prev, *next; struct SDbObj *pDb; void * idPool; - SChildTableObj **tableList; } SVgObj; typedef struct { @@ -162,6 +160,7 @@ typedef struct { int32_t minRowsPerFileBlock; int32_t maxRowsPerFileBlock; int32_t commitTime; + int32_t fsyncPeriod; int8_t precision; int8_t compression; int8_t walLevel; @@ -183,9 +182,11 @@ typedef struct SDbObj { int32_t numOfVgroups; int32_t numOfTables; int32_t numOfSuperTables; - SVgObj *pHead; - SVgObj *pTail; + int32_t vgListSize; + int32_t vgListIndex; + SVgObj **vgList; struct SAcctObj *pAcct; + pthread_mutex_t mutex; } SDbObj; typedef struct SUserObj { @@ -246,7 +247,8 @@ typedef struct { int16_t offset[TSDB_MAX_COLUMNS]; int16_t bytes[TSDB_MAX_COLUMNS]; int32_t numOfReads; - int8_t reserved0[2]; + int8_t maxReplica; + int8_t reserved0[0]; uint16_t payloadLen; char payload[]; } SShowObj; diff --git a/src/mnode/inc/mnodeDnode.h b/src/mnode/inc/mnodeDnode.h index 9e21f8f56a..f371786524 100644 --- a/src/mnode/inc/mnodeDnode.h +++ b/src/mnode/inc/mnodeDnode.h @@ -40,6 +40,7 @@ char* mnodeGetDnodeStatusStr(int32_t dnodeStatus); void mgmtMonitorDnodeModule(); int32_t mnodeGetDnodesNum(); +int32_t mnodeGetOnlinDnodesCpuCoreNum(); int32_t mnodeGetOnlinDnodesNum(); void * mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode); void mnodeIncDnodeRef(SDnodeObj *pDnode); diff --git a/src/mnode/inc/mnodeInt.h b/src/mnode/inc/mnodeInt.h index a450a8027f..44626fd167 100644 --- a/src/mnode/inc/mnodeInt.h +++ b/src/mnode/inc/mnodeInt.h @@ -29,17 +29,17 @@ extern int32_t sdbDebugFlag; // mnode log function #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 mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }} -#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND INFO ", 255, __VA_ARGS__); }} -#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND DEBUG ", mDebugFlag, __VA_ARGS__); }} -#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND TRACE ", mDebugFlag, __VA_ARGS__); }} +#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }} +#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }} +#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", 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 sdbError(...) { if (sdbDebugFlag & DEBUG_ERROR) { taosPrintLog("SDB ERROR ", 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 sdbDebug(...) { if (sdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("SDB DEBUG ", sdbDebugFlag, __VA_ARGS__); }} -#define sdbTrace(...) { if (sdbDebugFlag & DEBUG_TRACE) { taosPrintLog("SDB TRACE ", sdbDebugFlag, __VA_ARGS__); }} +#define sdbWarn(...) { if (sdbDebugFlag & DEBUG_WARN) { taosPrintLog("SDB WARN ", 255, __VA_ARGS__); }} +#define sdbInfo(...) { if (sdbDebugFlag & DEBUG_INFO) { taosPrintLog("SDB ", 255, __VA_ARGS__); }} +#define sdbDebug(...) { if (sdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("SDB ", sdbDebugFlag, __VA_ARGS__); }} +#define sdbTrace(...) { if (sdbDebugFlag & DEBUG_TRACE) { taosPrintLog("SDB ", sdbDebugFlag, __VA_ARGS__); }} #define mLError(...) { monitorSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) } #define mLWarn(...) { monitorSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) } diff --git a/src/mnode/inc/mnodeSdb.h b/src/mnode/inc/mnodeSdb.h index eec6d45e23..0c47f684f8 100644 --- a/src/mnode/inc/mnodeSdb.h +++ b/src/mnode/inc/mnodeSdb.h @@ -94,6 +94,7 @@ void sdbDecRef(void *thandle, void *pRow); int64_t sdbGetNumOfRows(void *handle); int32_t sdbGetId(void *handle); uint64_t sdbGetVersion(); +bool sdbCheckRowDeleted(void *thandle, void *pRow); #ifdef __cplusplus } diff --git a/src/mnode/inc/mnodeVgroup.h b/src/mnode/inc/mnodeVgroup.h index 29a0fe1799..3f1da89605 100644 --- a/src/mnode/inc/mnodeVgroup.h +++ b/src/mnode/inc/mnodeVgroup.h @@ -30,23 +30,23 @@ void mnodeDecVgroupRef(SVgObj *pVgroup); void mnodeDropAllDbVgroups(SDbObj *pDropDb); void mnodeSendDropAllDbVgroupsMsg(SDbObj *pDropDb); void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode); -void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb); +//void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb); void * mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup); void mnodeUpdateVgroup(SVgObj *pVgroup); void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload); void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t openVnodes); -int32_t mnodeCreateVgroup(struct SMnodeMsg *pMsg, SDbObj *pDb); +int32_t mnodeCreateVgroup(struct SMnodeMsg *pMsg); void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle); void mnodeAlterVgroup(SVgObj *pVgroup, void *ahandle); -SVgObj *mnodeGetAvailableVgroup(SDbObj *pDb); +int32_t mnodeGetAvailableVgroup(struct SMnodeMsg *pMsg, SVgObj **pVgroup, int32_t *sid); void mnodeAddTableIntoVgroup(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 mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle); +void mnodeSendAlterVgroupMsg(SVgObj *pVgroup); SRpcIpSet mnodeGetIpSetFromVgroup(SVgObj *pVgroup); SRpcIpSet mnodeGetIpSetFromIp(char *ep); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 8c74c9413d..fb97d6f380 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -38,6 +38,7 @@ #include "mnodeUser.h" #include "mnodeVgroup.h" +#define VG_LIST_SIZE 8 static void * tsDbSdb = NULL; static int32_t tsDbUpdateSize; @@ -50,8 +51,14 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessAlterDbMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg); +static void mnodeDestroyDb(SDbObj *pDb) { + pthread_mutex_destroy(&pDb->mutex); + tfree(pDb->vgList); + tfree(pDb); +} + static int32_t mnodeDbActionDestroy(SSdbOper *pOper) { - tfree(pOper->pObj); + mnodeDestroyDb(pOper->pObj); return TSDB_CODE_SUCCESS; } @@ -59,8 +66,9 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) { SDbObj *pDb = pOper->pObj; SAcctObj *pAcct = mnodeGetAcct(pDb->acct); - pDb->pHead = NULL; - pDb->pTail = NULL; + pthread_mutex_init(&pDb->mutex, NULL); + pDb->vgListSize = VG_LIST_SIZE; + pDb->vgList = calloc(pDb->vgListSize, sizeof(SVgObj *)); pDb->numOfVgroups = 0; pDb->numOfTables = 0; pDb->numOfSuperTables = 0; @@ -94,14 +102,15 @@ static int32_t mnodeDbActionDelete(SSdbOper *pOper) { } static int32_t mnodeDbActionUpdate(SSdbOper *pOper) { - SDbObj *pDb = pOper->pObj; - SDbObj *pSaved = mnodeGetDb(pDb->name); - if (pDb != pSaved) { - memcpy(pSaved, pDb, pOper->rowSize); - free(pDb); + SDbObj *pNew = pOper->pObj; + SDbObj *pDb = mnodeGetDb(pNew->name); + if (pDb != NULL && pNew != pDb) { + memcpy(pDb, pNew, pOper->rowSize); + free(pNew->vgList); + free(pNew); } - mnodeUpdateAllDbVgroups(pSaved); - mnodeDecDbRef(pSaved); + //mnodeUpdateAllDbVgroups(pDb); + mnodeDecDbRef(pDb); return TSDB_CODE_SUCCESS; } @@ -278,14 +287,14 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) { return TSDB_CODE_MND_INVALID_DB_OPTION; } - if (pCfg->replications < TSDB_MIN_REPLICA_NUM || pCfg->replications > TSDB_MAX_REPLICA_NUM) { - mError("invalid db option replications:%d valid range: [%d, %d]", pCfg->replications, TSDB_MIN_REPLICA_NUM, - TSDB_MAX_REPLICA_NUM); + if (pCfg->fsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->fsyncPeriod > TSDB_MAX_FSYNC_PERIOD) { + mError("invalid db option fsyncPeriod:%d, valid range: [%d, %d]", pCfg->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); return TSDB_CODE_MND_INVALID_DB_OPTION; } - if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL) { - mError("invalid db option walLevel:%d must be greater than 0", pCfg->walLevel); + if (pCfg->replications < TSDB_MIN_DB_REPLICA_OPTION || pCfg->replications > TSDB_MAX_DB_REPLICA_OPTION) { + 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; } @@ -309,6 +318,7 @@ static void mnodeSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = pCfg->daysToKeep; if (pCfg->minRowsPerFileBlock < 0) pCfg->minRowsPerFileBlock = tsMinRowsInFileBlock; if (pCfg->maxRowsPerFileBlock < 0) pCfg->maxRowsPerFileBlock = tsMaxRowsInFileBlock; + if (pCfg->fsyncPeriod <0) pCfg->fsyncPeriod = tsFsyncPeriod; if (pCfg->commitTime < 0) pCfg->commitTime = tsCommitTime; if (pCfg->precision < 0) pCfg->precision = tsTimePrecision; if (pCfg->compression < 0) pCfg->compression = tsCompression; @@ -358,6 +368,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs .daysToKeep2 = pCreate->daysToKeep2, .minRowsPerFileBlock = pCreate->minRowsPerFileBlock, .maxRowsPerFileBlock = pCreate->maxRowsPerFileBlock, + .fsyncPeriod = pCreate->fsyncPeriod, .commitTime = pCreate->commitTime, .precision = pCreate->precision, .compression = pCreate->compression, @@ -384,7 +395,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { - tfree(pDb); + mnodeDestroyDb(pDb); mLInfo("db:%s, failed to create, reason:%s", pDb->name, tstrerror(code)); return code; } else { @@ -421,45 +432,33 @@ void mnodePrintVgroups(SDbObj *pDb, char *oper) { void mnodeAddVgroupIntoDb(SVgObj *pVgroup) { SDbObj *pDb = pVgroup->pDb; - pVgroup->next = pDb->pHead; - pVgroup->prev = NULL; + pthread_mutex_lock(&pDb->mutex); + int32_t vgPos = pDb->numOfVgroups++; + if (vgPos >= pDb->vgListSize) { + pDb->vgList = realloc(pDb->vgList, pDb->vgListSize * 2 * sizeof(SVgObj *)); + memset(pDb->vgList + pDb->vgListSize, 0, pDb->vgListSize * sizeof(SVgObj *)); + pDb->vgListSize *= 2; + } - if (pDb->pHead) pDb->pHead->prev = pVgroup; - if (pDb->pTail == NULL) pDb->pTail = pVgroup; - - pDb->pHead = pVgroup; - pDb->numOfVgroups++; -} - -void mnodeAddVgroupIntoDbTail(SVgObj *pVgroup) { - SDbObj *pDb = pVgroup->pDb; - pVgroup->next = NULL; - pVgroup->prev = pDb->pTail; - - if (pDb->pTail) pDb->pTail->next = pVgroup; - if (pDb->pHead == NULL) pDb->pHead = pVgroup; - - pDb->pTail = pVgroup; - pDb->numOfVgroups++; + pDb->vgList[vgPos] = pVgroup; + pthread_mutex_unlock(&pDb->mutex); } void mnodeRemoveVgroupFromDb(SVgObj *pVgroup) { SDbObj *pDb = pVgroup->pDb; - if (pVgroup->prev) pVgroup->prev->next = pVgroup->next; - if (pVgroup->next) pVgroup->next->prev = pVgroup->prev; - if (pVgroup->prev == NULL) pDb->pHead = pVgroup->next; - if (pVgroup->next == NULL) pDb->pTail = pVgroup->prev; - pDb->numOfVgroups--; -} -void mnodeMoveVgroupToTail(SVgObj *pVgroup) { - mnodeRemoveVgroupFromDb(pVgroup); - mnodeAddVgroupIntoDbTail(pVgroup); -} + pthread_mutex_lock(&pDb->mutex); + for (int32_t v1 = 0; v1 < pDb->numOfVgroups; ++v1) { + if (pDb->vgList[v1] == pVgroup) { + for (int32_t v2 = v1; v2 < pDb->numOfVgroups - 1; ++v2) { + pDb->vgList[v2] = pDb->vgList[v2 + 1]; + } + pDb->numOfVgroups--; + break; + } + } -void mnodeMoveVgroupToHead(SVgObj *pVgroup) { - mnodeRemoveVgroupFromDb(pVgroup); - mnodeAddVgroupIntoDb(pVgroup); + pthread_mutex_unlock(&pDb->mutex); } void mnodeCleanupDbs() { @@ -531,11 +530,6 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn #ifndef __CLOUD_VERSION__ if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) { #endif - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "maxtables"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; pShow->bytes[cols] = 4; pSchema[cols].type = TSDB_DATA_TYPE_INT; @@ -561,18 +555,18 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "ctime(Sec.)"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - pShow->bytes[cols] = 1; pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; strcpy(pSchema[cols].name, "wallevel"); pSchema[cols].bytes = htons(pShow->bytes[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; pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; strcpy(pSchema[cols].name, "comp"); @@ -676,10 +670,6 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void #ifndef __CLOUD_VERSION__ if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) { #endif - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pDb->cfg.maxTables; // table num can be created should minus 1 - cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int32_t *)pWrite = pDb->cfg.cacheBlockSize; cols++; @@ -697,11 +687,11 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pDb->cfg.commitTime; + *(int8_t *)pWrite = pDb->cfg.walLevel; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int8_t *)pWrite = pDb->cfg.walLevel; + *(int32_t *)pWrite = pDb->cfg.fsyncPeriod; cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; @@ -780,6 +770,7 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) { pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1); pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2); pCreate->commitTime = htonl(pCreate->commitTime); + pCreate->fsyncPeriod = htonl(pCreate->fsyncPeriod); pCreate->minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock); pCreate->maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock); @@ -807,6 +798,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { int32_t minRows = htonl(pAlter->minRowsPerFileBlock); int32_t maxRows = htonl(pAlter->maxRowsPerFileBlock); int32_t commitTime = htonl(pAlter->commitTime); + int32_t fsyncPeriod = htonl(pAlter->fsyncPeriod); int8_t compression = pAlter->compression; int8_t walLevel = pAlter->walLevel; int8_t replications = pAlter->replications; @@ -883,6 +875,11 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { 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) { mDebug("db:%s, replications:%d change to %d", pDb->name, pDb->cfg.replications, replications); newCfg.replications = replications; @@ -916,7 +913,7 @@ static int32_t mnodeAlterDbCb(SMnodeMsg *pMsg, int32_t code) { pIter = mnodeGetNextVgroup(pIter, &pVgroup); if (pVgroup == NULL) break; if (pVgroup->pDb == pDb) { - mnodeSendCreateVgroupMsg(pVgroup, NULL); + mnodeSendAlterVgroupMsg(pVgroup); } mnodeDecVgroupRef(pVgroup); } diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 29272fbd4f..06d79bd7e1 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -69,6 +69,7 @@ static int32_t mnodeDnodeActionInsert(SSdbOper *pOper) { SDnodeObj *pDnode = pOper->pObj; if (pDnode->status != TAOS_DN_STATUS_DROPPING) { pDnode->status = TAOS_DN_STATUS_OFFLINE; + pDnode->lastAccess = tsAccessSquence; } return TSDB_CODE_SUCCESS; @@ -187,7 +188,27 @@ int32_t mnodeGetDnodesNum() { return sdbGetNumOfRows(tsDnodeSdb); } -int32_t mnodeGetOnlinDnodesNum(char *ep) { +int32_t mnodeGetOnlinDnodesCpuCoreNum() { + SDnodeObj *pDnode = NULL; + void * pIter = NULL; + int32_t cpuCores = 0; + + while (1) { + pIter = mnodeGetNextDnode(pIter, &pDnode); + if (pDnode == NULL) break; + if (pDnode->status != TAOS_DN_STATUS_OFFLINE) { + cpuCores += pDnode->numOfCores; + } + mnodeDecDnodeRef(pDnode); + } + + sdbFreeIter(pIter); + + if (cpuCores < 2) cpuCores = 2; + return cpuCores; +} + +int32_t mnodeGetOnlinDnodesNum() { SDnodeObj *pDnode = NULL; void * pIter = NULL; int32_t onlineDnodes = 0; @@ -248,18 +269,37 @@ void mnodeUpdateDnode(SDnodeObj *pDnode) { } static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) { + if (strcmp(pMsg->pUser->user, TSDB_DEFAULT_USER) != 0) { + mError("failed to cfg dnode, no rights"); + return TSDB_CODE_MND_NO_RIGHTS; + } + SCMCfgDnodeMsg *pCmCfgDnode = pMsg->rpcMsg.pCont; if (pCmCfgDnode->ep[0] == 0) { - strcpy(pCmCfgDnode->ep, tsLocalEp); - } else { - // TODO temporary disabled for compiling: strcpy(pCmCfgDnode->ep, pCmCfgDnode->ep); - } + tstrncpy(pCmCfgDnode->ep, tsLocalEp, TSDB_EP_LEN); + } - if (strcmp(pMsg->pUser->user, TSDB_DEFAULT_USER) != 0) { - return TSDB_CODE_MND_NO_RIGHTS; + int32_t dnodeId = 0; + char* pos = strchr(pCmCfgDnode->ep, ':'); + if (NULL == pos) { + dnodeId = strtol(pCmCfgDnode->ep, NULL, 10); + if (dnodeId <= 0 || dnodeId > 65536) { + mError("failed to cfg dnode, invalid dnodeId:%s", pCmCfgDnode->ep); + return TSDB_CODE_MND_DNODE_NOT_EXIST; + } } SRpcIpSet ipSet = mnodeGetIpSetFromIp(pCmCfgDnode->ep); + if (dnodeId != 0) { + SDnodeObj *pDnode = mnodeGetDnode(dnodeId); + if (pDnode == NULL) { + mError("failed to cfg dnode, invalid dnodeId:%d", dnodeId); + return TSDB_CODE_MND_DNODE_NOT_EXIST; + } + ipSet = mnodeGetIpSetFromIp(pDnode->dnodeEp); + mnodeDecDnodeRef(pDnode); + } + SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg)); strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep); strcpy(pMdCfgDnode->config, pCmCfgDnode->config); @@ -271,9 +311,9 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) { .pCont = pMdCfgDnode, .contLen = sizeof(SMDCfgDnodeMsg) }; - dnodeSendMsgToDnode(&ipSet, &rpcMdCfgDnodeMsg); mInfo("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user); + dnodeSendMsgToDnode(&ipSet, &rpcMdCfgDnodeMsg); return TSDB_CODE_SUCCESS; } @@ -283,15 +323,18 @@ static void mnodeProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) { } static bool mnodeCheckClusterCfgPara(const SClusterCfg *clusterCfg) { - if (clusterCfg->numOfMnodes != tsNumOfMnodes) return false; - if (clusterCfg->mnodeEqualVnodeNum != tsMnodeEqualVnodeNum) return false; - if (clusterCfg->offlineThreshold != tsOfflineThreshold) return false; - if (clusterCfg->statusInterval != tsStatusInterval) return false; + if (clusterCfg->numOfMnodes != htonl(tsNumOfMnodes)) return false; + if (clusterCfg->enableBalance != htonl(tsEnableBalance)) return false; + if (clusterCfg->mnodeEqualVnodeNum != htonl(tsMnodeEqualVnodeNum)) return false; + if (clusterCfg->offlineThreshold != htonl(tsOfflineThreshold)) return false; + if (clusterCfg->statusInterval != htonl(tsStatusInterval)) return false; + if (clusterCfg->maxtablesPerVnode != htonl(tsMaxTablePerVnode)) return false; + if (clusterCfg->maxVgroupsPerDb != htonl(tsMaxVgroupsPerDb)) return false; if (0 != strncasecmp(clusterCfg->arbitrator, tsArbitrator, strlen(tsArbitrator))) return false; if (0 != strncasecmp(clusterCfg->timezone, tsTimezone, strlen(tsTimezone))) return false; - if (0 != strncasecmp(clusterCfg->locale, tsLocale, strlen(tsLocale))) return false; - if (0 != strncasecmp(clusterCfg->charset, tsCharset, strlen(tsCharset))) return false; + if (0 != strncasecmp(clusterCfg->locale, tsLocale, strlen(tsLocale))) return false; + if (0 != strncasecmp(clusterCfg->charset, tsCharset, strlen(tsCharset))) return false; return true; } @@ -376,7 +419,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) { if (false == ret) { mnodeDecDnodeRef(pDnode); rpcFreeCont(pRsp); - mError("dnode %s cluster cfg parameters inconsistent", pStatus->dnodeEp); + mError("dnode:%d, %s cluster cfg parameters inconsistent", pDnode->dnodeId, pStatus->dnodeEp); return TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT; } @@ -468,18 +511,22 @@ static int32_t mnodeDropDnodeByEp(char *ep, SMnodeMsg *pMsg) { return TSDB_CODE_MND_DNODE_NOT_EXIST; } - mnodeDecDnodeRef(pDnode); if (strcmp(pDnode->dnodeEp, mnodeGetMnodeMasterEp()) == 0) { mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep); + mnodeDecDnodeRef(pDnode); return TSDB_CODE_MND_NO_REMOVE_MASTER; } mInfo("dnode:%d, start to drop it", pDnode->dnodeId); + #ifndef _SYNC - return mnodeDropDnode(pDnode, pMsg); + int32_t code = mnodeDropDnode(pDnode, pMsg); #else - return balanceDropDnode(pDnode); + int32_t code = balanceDropDnode(pDnode); #endif + + mnodeDecDnodeRef(pDnode); + return code; } static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) { diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index af4a09a45a..9121f31131 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -115,7 +115,7 @@ SConnObj *mnodeAccquireConn(int32_t connId, char *user, uint32_t ip, uint16_t po uint64_t expireTime = CONN_KEEP_TIME * 1000 + (uint64_t)taosGetTimestampMs(); SConnObj *pConn = taosCacheUpdateExpireTimeByName(tsMnodeConnCache, &connId, sizeof(int32_t), expireTime); if (pConn == NULL) { - mError("connId:%d, is already destroyed, user:%s ip:%s:%u", connId, user, taosIpStr(ip), port); + mDebug("connId:%d, is already destroyed, user:%s ip:%s:%u", connId, user, taosIpStr(ip), port); return NULL; } diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index cdcb7357f1..e08f8ca0db 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -170,7 +170,7 @@ static void *sdbGetTableFromId(int32_t tableId) { } 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]; sprintf(temp, "%s/wal", tsMnodeDir); tsSdbObj.wal = walOpen(temp, &walCfg); @@ -252,20 +252,26 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { int32_t processedCount = atomic_add_fetch_32(&pOper->processedCount, 1); if (processedCount <= 1) { 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; } 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) { pOper->retCode = (*pOper->cb)(pMsg, pOper->retCode); } - dnodeSendRpcMnodeWriteRsp(pMsg, pOper->retCode); + + // if ahandle, means this func is called by sdb write + if (ahandle == NULL) { + sdbDecRef(pOper->table, pOper->pObj); + } taosFreeQitem(pOper); } @@ -389,7 +395,7 @@ void sdbCleanUp() { } void sdbIncRef(void *handle, void *pObj) { - if (pObj == NULL) return; + if (pObj == NULL || handle == NULL) return; SSdbTable *pTable = handle; int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); @@ -398,7 +404,7 @@ void sdbIncRef(void *handle, void *pObj) { } void sdbDecRef(void *handle, void *pObj) { - if (pObj == NULL) return; + if (pObj == NULL || handle == NULL) return; SSdbTable *pTable = handle; int32_t * pRefCount = (int32_t *)(pObj + pTable->refCountPos); @@ -581,16 +587,26 @@ static int sdbWrite(void *param, void *data, int type) { return sdbInsertHash(pTable, &oper); } else if (action == SDB_ACTION_DELETE) { SSdbRow *rowMeta = sdbGetRowMeta(pTable, pHead->cont); - assert(rowMeta != NULL && rowMeta->row != NULL); + if (rowMeta == NULL || rowMeta->row == NULL) { + sdbError("table:%s, failed to get object:%s from wal while dispose delete action", pTable->tableName, + pHead->cont); + return TSDB_CODE_SUCCESS; + } SSdbOper oper = {.table = pTable, .pObj = rowMeta->row}; return sdbDeleteHash(pTable, &oper); } else if (action == SDB_ACTION_UPDATE) { SSdbRow *rowMeta = sdbGetRowMeta(pTable, pHead->cont); - assert(rowMeta != NULL && rowMeta->row != NULL); + if (rowMeta == NULL || rowMeta->row == NULL) { + sdbError("table:%s, failed to get object:%s from wal while dispose update action", pTable->tableName, + pHead->cont); + return TSDB_CODE_SUCCESS; + } SSdbOper oper = {.rowSize = pHead->len, .rowData = pHead->cont, .table = pTable}; code = (*pTable->decodeFp)(&oper); return sdbUpdateHash(pTable, &oper); - } else { return TSDB_CODE_MND_INVALID_MSG_TYPE; } + } else { + return TSDB_CODE_MND_INVALID_MSG_TYPE; + } } int32_t sdbInsertRow(SSdbOper *pOper) { @@ -647,6 +663,14 @@ int32_t sdbInsertRow(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } +bool sdbCheckRowDeleted(void *pTableInput, void *pRow) { + SSdbTable *pTable = pTableInput; + if (pTable == NULL) return false; + + int8_t *updateEnd = pRow + pTable->refCountPos - 1; + return (*updateEnd == 1); +} + int32_t sdbDeleteRow(SSdbOper *pOper) { SSdbTable *pTable = (SSdbTable *)pOper->table; if (pTable == NULL) return TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE; @@ -663,14 +687,18 @@ int32_t sdbDeleteRow(SSdbOper *pOper) { return TSDB_CODE_MND_SDB_INVAID_META_ROW; } + sdbIncRef(pTable, pOper->pObj); + int32_t code = sdbDeleteHash(pTable, pOper); if (code != TSDB_CODE_SUCCESS) { sdbError("table:%s, failed to delete from hash", pTable->tableName); + sdbDecRef(pTable, pOper->pObj); return code; } // just delete data from memory if (pOper->type != SDB_OPER_GLOBAL) { + sdbDecRef(pTable, pOper->pObj); return TSDB_CODE_SUCCESS; } @@ -692,7 +720,6 @@ int32_t sdbDeleteRow(SSdbOper *pOper) { pNewOper->pMsg, pTable->tableName, pOper->pObj, sdbGetKeyStrFromObj(pTable, pOper->pObj)); } - sdbIncRef(pNewOper->table, pNewOper->pObj); taosWriteQitem(tsSdbWriteQueue, TAOS_QTYPE_RPC, pNewOper); return TSDB_CODE_SUCCESS; } @@ -968,10 +995,11 @@ static void *sdbWorkerFp(void *param) { int32_t code = sdbWrite(pOper, pHead, type); if (code > 0) code = 0; - if (pOper) + if (pOper) { pOper->retCode = code; - else + } else { pHead->len = code; // hackway + } } walFsync(tsSdbObj.wal); @@ -983,7 +1011,6 @@ static void *sdbWorkerFp(void *param) { if (type == TAOS_QTYPE_RPC) { pOper = (SSdbOper *)item; - sdbDecRef(pOper->table, pOper->pObj); sdbConfirmForward(NULL, pOper, pOper->retCode); } else if (type == TAOS_QTYPE_FWD) { pHead = (SWalHead *)item; diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 523d7001c2..80c4fc95ab 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -72,7 +72,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg); static int32_t mnodeProcessDropTableMsg(SMnodeMsg *mnodeMsg); static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg); static void mnodeProcessDropSuperTableRsp(SRpcMsg *rpcMsg); -static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg); +static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn); static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg); static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *mnodeMsg); @@ -319,15 +319,6 @@ static int32_t mnodeChildTableActionRestored() { continue; } - if (pVgroup->tableList == NULL) { - mError("ctable:%s, vgId:%d tableList is null", pTable->info.tableId, pTable->vgId); - pTable->vgId = 0; - SSdbOper desc = {.type = SDB_OPER_LOCAL, .pObj = pTable, .table = tsChildTableSdb}; - sdbDeleteRow(&desc); - mnodeDecTableRef(pTable); - continue; - } - if (pTable->info.type == TSDB_CHILD_TABLE) { SSuperTableObj *pSuperTable = mnodeGetSuperTableByUid(pTable->suid); if (pSuperTable == NULL) { @@ -385,7 +376,7 @@ static void mnodeCleanupChildTables() { } static void mnodeAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCtable) { - pStable->numOfTables++; + atomic_add_fetch_32(&pStable->numOfTables, 1); if (pStable->vgHash == NULL) { pStable->vgHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false); @@ -394,18 +385,22 @@ static void mnodeAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCt if (pStable->vgHash != NULL) { if (taosHashGet(pStable->vgHash, &pCtable->vgId, sizeof(pCtable->vgId)) == NULL) { taosHashPut(pStable->vgHash, &pCtable->vgId, sizeof(pCtable->vgId), &pCtable->vgId, sizeof(pCtable->vgId)); + mDebug("table:%s, vgId:%d is put into stable vgList, sizeOfVgList:%d", pStable->info.tableId, pCtable->vgId, + (int32_t)taosHashGetSize(pStable->vgHash)); } } } static void mnodeRemoveTableFromStable(SSuperTableObj *pStable, SChildTableObj *pCtable) { - pStable->numOfTables--; + atomic_sub_fetch_32(&pStable->numOfTables, 1); if (pStable->vgHash == NULL) return; SVgObj *pVgroup = mnodeGetVgroup(pCtable->vgId); if (pVgroup == NULL) { taosHashRemove(pStable->vgHash, (char *)&pCtable->vgId, sizeof(pCtable->vgId)); + mDebug("table:%s, vgId:%d is remove from stable vgList, sizeOfVgList:%d", pStable->info.tableId, pCtable->vgId, + (int32_t)taosHashGetSize(pStable->vgHash)); } mnodeDecVgroupRef(pVgroup); } @@ -757,11 +752,15 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) { } if (pMsg->pTable->type == TSDB_SUPER_TABLE) { - mInfo("app:%p:%p, table:%s, start to drop stable", pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId); + SSuperTableObj *pSTable = (SSuperTableObj *)pMsg->pTable; + mInfo("app:%p:%p, table:%s, start to drop stable, uid:%" PRIu64 ", numOfChildTables:%d, sizeOfVgList:%d", + pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId, pSTable->uid, pSTable->numOfTables, (int32_t)taosHashGetSize(pSTable->vgHash)); return mnodeProcessDropSuperTableMsg(pMsg); } else { - mInfo("app:%p:%p, table:%s, start to drop ctable", pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId); - return mnodeProcessDropChildTableMsg(pMsg); + SChildTableObj *pCTable = (SChildTableObj *)pMsg->pTable; + mInfo("app:%p:%p, table:%s, start to drop ctable, vgId:%d sid:%d uid:%" PRIu64, pMsg->rpcMsg.ahandle, pMsg, + pDrop->tableId, pCTable->vgId, pCTable->sid, pCTable->uid); + return mnodeProcessDropChildTableMsg(pMsg, true); } } @@ -808,7 +807,7 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) { assert(pTable); if (code == TSDB_CODE_SUCCESS) { - mLInfo("stable:%s, is created in sdb", pTable->info.tableId); + mLInfo("stable:%s, is created in sdb, uid:%" PRIu64, pTable->info.tableId, pTable->uid); } else { mError("app:%p:%p, stable:%s, failed to create in sdb, reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, tstrerror(code)); @@ -896,7 +895,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) { if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; SSuperTableObj *pStable = (SSuperTableObj *)pMsg->pTable; - if (pStable->numOfTables != 0) { + if (pStable->vgHash != NULL /*pStable->numOfTables != 0*/) { SHashMutableIterator *pIter = taosHashCreateIter(pStable->vgHash); while (taosHashIterNext(pIter)) { int32_t *pVgId = taosHashIterGet(pIter); @@ -1600,8 +1599,8 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) { assert(pTable); if (code == TSDB_CODE_SUCCESS) { - mDebug("app:%p:%p, table:%s, create table in sid:%d, uid:%" PRIu64, pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, - pTable->sid, pTable->uid); + mDebug("app:%p:%p, table:%s, created in mnode, vgId:%d sid:%d, uid:%" PRIu64 ", result:%s", pMsg->rpcMsg.ahandle, + pMsg, pTable->info.tableId, pTable->vgId, pTable->sid, pTable->uid, tstrerror(code)); } else { mError("app:%p:%p, table:%s, failed to create table sid:%d, uid:%" PRIu64 ", reason:%s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId, pTable->sid, pTable->uid, tstrerror(code)); @@ -1730,27 +1729,25 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) { return code; } - SVgObj *pVgroup = mnodeGetAvailableVgroup(pMsg->pDb); - if (pVgroup == NULL) { - mDebug("app:%p:%p, table:%s, start to create a new vgroup", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId); - return mnodeCreateVgroup(pMsg, pMsg->pDb); - } - if (pMsg->retry == 0) { if (pMsg->pTable == NULL) { - int32_t sid = taosAllocateId(pVgroup->idPool); - if (sid <= 0) { - mDebug("app:%p:%p, table:%s, no enough sid in vgId:%d", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId, - pVgroup->vgId); - return mnodeCreateVgroup(pMsg, pMsg->pDb); + SVgObj *pVgroup = NULL; + int32_t sid = 0; + code = mnodeGetAvailableVgroup(pMsg, &pVgroup, &sid); + if (code != TSDB_CODE_SUCCESS) { + mDebug("app:%p:%p, table:%s, failed to get available vgroup, reason:%s", pMsg->rpcMsg.ahandle, pMsg, + pCreate->tableId, tstrerror(code)); + return code; } - if (pMsg->pVgroup == NULL) { - pMsg->pVgroup = pVgroup; - mnodeIncVgroupRef(pVgroup); + if (pMsg->pVgroup != NULL) { + mnodeDecVgroupRef(pMsg->pVgroup); } - mDebug("app:%p:%p, table:%s, create table in vgroup, vgId:%d sid:%d", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId, + pMsg->pVgroup = pVgroup; + mnodeIncVgroupRef(pVgroup); + + mDebug("app:%p:%p, table:%s, allocated in vgroup, vgId:%d sid:%d", pMsg->rpcMsg.ahandle, pMsg, pCreate->tableId, pVgroup->vgId, sid); return mnodeDoCreateChildTable(pMsg, sid); @@ -1769,7 +1766,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) { } } -static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { +static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) { SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); if (pMsg->pVgroup == NULL) { @@ -1793,7 +1790,9 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { SRpcIpSet ipSet = mnodeGetIpSetFromVgroup(pMsg->pVgroup); - mInfo("app:%p:%p, table:%s, send drop ctable msg", pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId); + mInfo("app:%p:%p, table:%s, send drop ctable msg, vgId:%d sid:%d uid:%" PRIu64, pMsg->rpcMsg.ahandle, pMsg, + pDrop->tableId, pTable->vgId, pTable->sid, pTable->uid); + SRpcMsg rpcMsg = { .ahandle = pMsg, .pCont = pDrop, @@ -1802,6 +1801,8 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { .msgType = TSDB_MSG_TYPE_MD_DROP_TABLE }; + if (!needReturn) rpcMsg.ahandle = NULL; + dnodeSendMsgToDnode(&ipSet, &rpcMsg); return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -2125,7 +2126,7 @@ static void mnodeDropAllChildTablesInStable(SSuperTableObj *pStable) { int32_t numOfTables = 0; SChildTableObj *pTable = NULL; - mInfo("stable:%s, all child tables(%d) will dropped from sdb", pStable->info.tableId, numOfTables); + mInfo("stable:%s, all child tables:%d will dropped from sdb", pStable->info.tableId, pStable->numOfTables); while (1) { pIter = mnodeGetNextChildTable(pIter, &pTable); @@ -2149,6 +2150,7 @@ static void mnodeDropAllChildTablesInStable(SSuperTableObj *pStable) { mInfo("stable:%s, all child tables:%d is dropped from sdb", pStable->info.tableId, numOfTables); } +#if 0 static SChildTableObj* mnodeGetTableByPos(int32_t vnode, int32_t sid) { SVgObj *pVgroup = mnodeGetVgroup(vnode); if (pVgroup == NULL) return NULL; @@ -2159,8 +2161,11 @@ static SChildTableObj* mnodeGetTableByPos(int32_t vnode, int32_t sid) { mnodeDecVgroupRef(pVgroup); return pTable; } +#endif static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) { + return TSDB_CODE_COM_OPS_NOT_SUPPORT; +#if 0 SDMConfigTableMsg *pCfg = pMsg->rpcMsg.pCont; pCfg->dnodeId = htonl(pCfg->dnodeId); pCfg->vgId = htonl(pCfg->vgId); @@ -2184,6 +2189,7 @@ static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) { pMsg->rpcRsp.rsp = pCreate; pMsg->rpcRsp.len = htonl(pCreate->contLen); return TSDB_CODE_SUCCESS; +#endif } // handle drop child response @@ -2195,12 +2201,15 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) { SChildTableObj *pTable = (SChildTableObj *)mnodeMsg->pTable; assert(pTable); - mInfo("app:%p:%p, table:%s, drop table rsp received, thandle:%p result:%s", mnodeMsg->rpcMsg.ahandle, mnodeMsg, - pTable->info.tableId, mnodeMsg->rpcMsg.handle, tstrerror(rpcMsg->code)); + + mInfo("app:%p:%p, table:%s, drop table rsp received, vgId:%d sid:%d uid:%" PRIu64 ", thandle:%p result:%s", + mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId, pTable->vgId, pTable->sid, pTable->uid, + mnodeMsg->rpcMsg.handle, tstrerror(rpcMsg->code)); if (rpcMsg->code != TSDB_CODE_SUCCESS) { - mError("app:%p:%p, table:%s, failed to drop in dnode, reason:%s", mnodeMsg->rpcMsg.ahandle, mnodeMsg, - pTable->info.tableId, tstrerror(rpcMsg->code)); + mError("app:%p:%p, table:%s, failed to drop in dnode, vgId:%d sid:%d uid:%" PRIu64 ", reason:%s", + mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId, pTable->vgId, pTable->sid, pTable->uid, + tstrerror(rpcMsg->code)); dnodeSendRpcMnodeWriteRsp(mnodeMsg, rpcMsg->code); return; } @@ -2247,6 +2256,14 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { SChildTableObj *pTable = (SChildTableObj *)mnodeMsg->pTable; assert(pTable); + // If the table is deleted by another thread during creation, stop creating and send drop msg to vnode + if (sdbCheckRowDeleted(tsChildTableSdb, pTable)) { + mDebug("app:%p:%p, table:%s, create table rsp received, but a deleting opertion incoming, vgId:%d sid:%d uid:%" PRIu64, + mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId, pTable->vgId, pTable->sid, pTable->uid); + mnodeProcessDropChildTableMsg(mnodeMsg, false); + rpcMsg->code = TSDB_CODE_SUCCESS; + } + if (rpcMsg->code == TSDB_CODE_SUCCESS || rpcMsg->code == TSDB_CODE_TDB_TABLE_ALREADY_EXIST) { SCMCreateTableMsg *pCreate = mnodeMsg->rpcMsg.pCont; if (pCreate->getMeta) { diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 966d4b0dd8..8c8aa5fb31 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -40,30 +40,41 @@ typedef enum { TAOS_VG_STATUS_READY, - TAOS_VG_STATUS_DROPPING + TAOS_VG_STATUS_DROPPING, + TAOS_VG_STATUS_CREATING, + TAOS_VG_STATUS_UPDATING, } EVgroupStatus; +char* vgroupStatus[] = { + "ready", + "dropping", + "creating", + "updating" +}; + static void *tsVgroupSdb = NULL; static int32_t tsVgUpdateSize = 0; +static int32_t mnodeAllocVgroupIdPool(SVgObj *pInputVgroup); static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn); static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg); +static void mnodeProcessAlterVnodeRsp(SRpcMsg *rpcMsg); static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg); static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) ; static void mnodeSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle); -static int32_t mnodeVgroupActionDestroy(SSdbOper *pOper) { - SVgObj *pVgroup = pOper->pObj; +static void mnodeDestroyVgroup(SVgObj *pVgroup) { if (pVgroup->idPool) { taosIdPoolCleanUp(pVgroup->idPool); pVgroup->idPool = NULL; } - if (pVgroup->tableList) { - tfree(pVgroup->tableList); - } - tfree(pOper->pObj); + tfree(pVgroup); +} + +static int32_t mnodeVgroupActionDestroy(SSdbOper *pOper) { + mnodeDestroyVgroup(pOper->pObj); return TSDB_CODE_SUCCESS; } @@ -82,21 +93,10 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) { } pVgroup->pDb = pDb; - pVgroup->prev = NULL; - pVgroup->next = NULL; + pVgroup->status = TAOS_VG_STATUS_CREATING; pVgroup->accessState = TSDB_VN_ALL_ACCCESS; - - int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables; - pVgroup->tableList = calloc(pDb->cfg.maxTables, sizeof(SChildTableObj *)); - if (pVgroup->tableList == NULL) { - mError("vgId:%d, failed to malloc(size:%d) for the tableList of vgroups", pVgroup->vgId, size); - return -1; - } - - pVgroup->idPool = taosInitIdPool(pDb->cfg.maxTables); - if (pVgroup->idPool == NULL) { - mError("vgId:%d, failed to taosInitIdPool for vgroups", pVgroup->vgId); - tfree(pVgroup->tableList); + if (mnodeAllocVgroupIdPool(pVgroup) < 0) { + mError("vgId:%d, failed to init idpool for vgroups", pVgroup->vgId); return -1; } @@ -134,20 +134,6 @@ static int32_t mnodeVgroupActionDelete(SSdbOper *pOper) { return TSDB_CODE_SUCCESS; } -static void mnodeVgroupUpdateIdPool(SVgObj *pVgroup) { - int32_t oldTables = taosIdPoolMaxSize(pVgroup->idPool); - SDbObj *pDb = pVgroup->pDb; - if (pDb != NULL) { - if (pDb->cfg.maxTables != oldTables) { - mInfo("vgId:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxTables); - taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxTables); - int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables; - pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size); - memset(pVgroup->tableList + oldTables, 0, (pDb->cfg.maxTables - oldTables) * sizeof(SChildTableObj *)); - } - } -} - static int32_t mnodeVgroupActionUpdate(SSdbOper *pOper) { SVgObj *pNew = pOper->pObj; SVgObj *pVgroup = mnodeGetVgroup(pNew->vgId); @@ -174,7 +160,6 @@ static int32_t mnodeVgroupActionUpdate(SSdbOper *pOper) { free(pNew); } - mnodeVgroupUpdateIdPool(pVgroup); // reset vgid status on vgroup changed mDebug("vgId:%d, reset sync status to unsynced", pVgroup->vgId); @@ -243,6 +228,7 @@ int32_t mnodeInitVgroups() { mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_VGROUP, mnodeGetVgroupMeta); mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_VGROUP, mnodeRetrieveVgroups); 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); mnodeAddPeerMsgHandle(TSDB_MSG_TYPE_DM_CONFIG_VNODE, mnodeProcessVnodeCfgMsg); @@ -273,7 +259,7 @@ void mnodeUpdateVgroup(SVgObj *pVgroup) { if (sdbUpdateRow(&oper) != TSDB_CODE_SUCCESS) { mError("vgId:%d, failed to update vgroup", pVgroup->vgId); } - mnodeSendCreateVgroupMsg(pVgroup, NULL); + mnodeSendAlterVgroupMsg(pVgroup); } /* @@ -297,10 +283,17 @@ void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t o pNextV++; } - if (i == openVnodes && pVgroup->status == TAOS_VG_STATUS_READY) { - mnodeSendCreateVgroupMsg(pVgroup, NULL); + if (i == openVnodes) { + if (pVgroup->status == TAOS_VG_STATUS_CREATING || pVgroup->status == TAOS_VG_STATUS_DROPPING) { + mDebug("vgId:%d, not exist in dnode:%d and status is %s, do nothing", pVgroup->vgId, pDnode->dnodeId, + vgroupStatus[pVgroup->status]); + } else { + mDebug("vgId:%d, not exist in dnode:%d and status is %s, send create msg", pVgroup->vgId, pDnode->dnodeId, + vgroupStatus[pVgroup->status]); + mnodeSendCreateVgroupMsg(pVgroup, NULL); + } } - + mnodeDecVgroupRef(pVgroup); } @@ -340,12 +333,136 @@ 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", pDnode->dnodeId, pVload->vgId, pVload->cfgVersion, pVload->replica, pVgroup->pDb->cfgVersion, pVgroup->numOfVnodes); - mnodeSendCreateVgroupMsg(pVgroup, NULL); + mnodeSendAlterVgroupMsg(pVgroup); } } -SVgObj *mnodeGetAvailableVgroup(SDbObj *pDb) { - return pDb->pHead; +static int32_t mnodeAllocVgroupIdPool(SVgObj *pInputVgroup) { + SDbObj *pDb = pInputVgroup->pDb; + if (pDb == NULL) return TSDB_CODE_MND_APP_ERROR; + + int32_t minIdPoolSize = TSDB_MAX_TABLES; + int32_t maxIdPoolSize = tsMinTablePerVnode; + for (int32_t v = 0; v < pDb->numOfVgroups; ++v) { + SVgObj *pVgroup = pDb->vgList[v]; + if (pVgroup == NULL) continue; + + int32_t idPoolSize = taosIdPoolMaxSize(pVgroup->idPool); + minIdPoolSize = MIN(minIdPoolSize, idPoolSize); + maxIdPoolSize = MAX(maxIdPoolSize, idPoolSize); + } + + // new vgroup + if (pInputVgroup->idPool == NULL) { + pInputVgroup->idPool = taosInitIdPool(maxIdPoolSize); + if (pInputVgroup->idPool == NULL) { + mError("vgId:%d, failed to init idPool for vgroup, size:%d", pInputVgroup->vgId, maxIdPoolSize); + return TSDB_CODE_MND_OUT_OF_MEMORY; + } else { + mDebug("vgId:%d, init idPool for vgroup, size:%d", pInputVgroup->vgId, maxIdPoolSize); + return TSDB_CODE_SUCCESS; + } + } + + // realloc all vgroups in db + int32_t newIdPoolSize; + if (minIdPoolSize * 4 < tsTableIncStepPerVnode) { + newIdPoolSize = minIdPoolSize * 4; + } else { + newIdPoolSize = ((minIdPoolSize / tsTableIncStepPerVnode) + 1) * tsTableIncStepPerVnode; + } + + if (newIdPoolSize > tsMaxTablePerVnode) { + if (minIdPoolSize >= tsMaxTablePerVnode) { + mError("db:%s, minIdPoolSize:%d newIdPoolSize:%d larger than maxTablesPerVnode:%d", pDb->name, minIdPoolSize, newIdPoolSize, + tsMaxTablePerVnode); + return TSDB_CODE_MND_NO_ENOUGH_DNODES; + } else { + newIdPoolSize = tsMaxTablePerVnode; + } + } + + for (int32_t v = 0; v < pDb->numOfVgroups; ++v) { + SVgObj *pVgroup = pDb->vgList[v]; + if (pVgroup == NULL) continue; + + int32_t oldIdPoolSize = taosIdPoolMaxSize(pVgroup->idPool); + if (newIdPoolSize == oldIdPoolSize) continue; + + if (taosUpdateIdPool(pVgroup->idPool, newIdPoolSize) < 0) { + mError("vgId:%d, failed to update idPoolSize from %d to %d", pVgroup->vgId, oldIdPoolSize, newIdPoolSize); + return TSDB_CODE_MND_NO_ENOUGH_DNODES; + } else { + mDebug("vgId:%d, idPoolSize update from %d to %d", pVgroup->vgId, oldIdPoolSize, newIdPoolSize); + } + } + + return TSDB_CODE_SUCCESS; +} + +int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSid) { + SDbObj *pDb = pMsg->pDb; + pthread_mutex_lock(&pDb->mutex); + + for (int32_t v = 0; v < pDb->numOfVgroups; ++v) { + int vgIndex = (v + pDb->vgListIndex) % pDb->numOfVgroups; + SVgObj *pVgroup = pDb->vgList[vgIndex]; + if (pVgroup == NULL) { + mError("db:%s, index:%d vgroup is null", pDb->name, vgIndex); + pthread_mutex_unlock(&pDb->mutex); + return TSDB_CODE_MND_APP_ERROR; + } + + int32_t sid = taosAllocateId(pVgroup->idPool); + if (sid <= 0) { + mDebug("app:%p:%p, db:%s, no enough sid in vgId:%d", pMsg->rpcMsg.ahandle, pMsg, pDb->name, pVgroup->vgId); + continue; + } + + *pSid = sid; + *ppVgroup = pVgroup; + pDb->vgListIndex = vgIndex; + + pthread_mutex_unlock(&pDb->mutex); + return TSDB_CODE_SUCCESS; + } + + int maxVgroupsPerDb = tsMaxVgroupsPerDb; + if (maxVgroupsPerDb <= 0) { + maxVgroupsPerDb = mnodeGetOnlinDnodesCpuCoreNum(); + maxVgroupsPerDb = MAX(maxVgroupsPerDb, 2); + } + + if (pDb->numOfVgroups < maxVgroupsPerDb) { + mDebug("app:%p:%p, db:%s, try to create a new vgroup, numOfVgroups:%d maxVgroupsPerDb:%d", pMsg->rpcMsg.ahandle, pMsg, + pDb->name, pDb->numOfVgroups, maxVgroupsPerDb); + pthread_mutex_unlock(&pDb->mutex); + int32_t code = mnodeCreateVgroup(pMsg); + if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return code; + } + + SVgObj *pVgroup = pDb->vgList[0]; + if (pVgroup == NULL) return TSDB_CODE_MND_NO_ENOUGH_DNODES; + + int32_t code = mnodeAllocVgroupIdPool(pVgroup); + if (code != TSDB_CODE_SUCCESS) { + pthread_mutex_unlock(&pDb->mutex); + return code; + } + + int32_t sid = taosAllocateId(pVgroup->idPool); + if (sid <= 0) { + mError("app:%p:%p, db:%s, no enough sid in vgId:%d", pMsg->rpcMsg.ahandle, pMsg, pDb->name, pVgroup->vgId); + pthread_mutex_unlock(&pDb->mutex); + return TSDB_CODE_MND_NO_ENOUGH_DNODES; + } + + *pSid = sid; + *ppVgroup = pVgroup; + pDb->vgListIndex = 0; + pthread_mutex_unlock(&pDb->mutex); + + return TSDB_CODE_SUCCESS; } void *mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup) { @@ -363,6 +480,10 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; sdbDeleteRow(&desc); return code; + } else { + pVgroup->status = TAOS_VG_STATUS_READY; + SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; + sdbUpdateRow(&desc); } mInfo("app:%p:%p, vgId:%d, is created in mnode, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, @@ -373,13 +494,16 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { } pMsg->expected = pVgroup->numOfVnodes; + pMsg->successed = 0; + pMsg->received = 0; mnodeSendCreateVgroupMsg(pVgroup, pMsg); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { +int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) { if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; + SDbObj *pDb = pMsg->pDb; SVgObj *pVgroup = (SVgObj *)calloc(1, sizeof(SVgObj)); tstrncpy(pVgroup->dbName, pDb->name, TSDB_ACCT_LEN + TSDB_DB_NAME_LEN); @@ -407,7 +531,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { int32_t code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { pMsg->pVgroup = NULL; - tfree(pVgroup); + mnodeDestroyVgroup(pVgroup); } else { code = TSDB_CODE_MND_ACTION_IN_PROGRESS; } @@ -435,7 +559,7 @@ void mnodeCleanupVgroups() { 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); if (pDb == NULL) { return TSDB_CODE_MND_DB_NOT_SELECTED; @@ -461,29 +585,27 @@ int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; - int32_t maxReplica = 0; - SVgObj *pVgroup = NULL; - STableObj *pTable = NULL; - if (pShow->payloadLen > 0 ) { - pTable = mnodeGetTable(pShow->payload); - if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) { - mnodeDecTableRef(pTable); - return TSDB_CODE_MND_INVALID_TABLE_NAME; - } - mnodeDecTableRef(pTable); - pVgroup = mnodeGetVgroup(((SChildTableObj*)pTable)->vgId); - if (NULL == pVgroup) return TSDB_CODE_MND_INVALID_TABLE_NAME; - mnodeDecVgroupRef(pVgroup); - maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; - } else { - SVgObj *pVgroup = pDb->pHead; - while (pVgroup != NULL) { - maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; - pVgroup = pVgroup->next; + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "poolSize"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "onlineVnodes"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->maxReplica = 1; + for (int32_t v = 0; v < pDb->numOfVgroups; ++v) { + SVgObj *pVgroup = pDb->vgList[v]; + if (pVgroup != NULL) { + pShow->maxReplica = pVgroup->numOfVnodes > pShow->maxReplica ? pVgroup->numOfVnodes : pShow->maxReplica; } } - for (int32_t i = 0; i < maxReplica; ++i) { + for (int32_t i = 0; i < pShow->maxReplica; ++i) { pShow->bytes[cols] = 2; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; strcpy(pSchema[cols].name, "dnode"); @@ -507,48 +629,54 @@ int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { pShow->numOfColumns = cols; pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - - if (NULL == pTable) { - pShow->numOfRows = pDb->numOfVgroups; - pShow->pIter = pDb->pHead; - } else { - pShow->numOfRows = 1; - pShow->pIter = pVgroup; + for (int32_t i = 1; i < cols; ++i) { + pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; } - mnodeDecDbRef(pDb); + pShow->numOfRows = pDb->numOfVgroups; + pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; + mnodeDecDbRef(pDb); return 0; } -int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn) { +static bool mnodeFilterVgroups(SVgObj *pVgroup, STableObj *pTable) { + if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) { + return true; + } + + SChildTableObj *pCTable = (SChildTableObj *)pTable; + if (pVgroup->vgId == pCTable->vgId) { + return true; + } else { + return false; + } +} + +static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn) { int32_t numOfRows = 0; SVgObj *pVgroup = NULL; - int32_t maxReplica = 0; int32_t cols = 0; char * pWrite; SDbObj *pDb = mnodeGetDb(pShow->db); if (pDb == NULL) return 0; - + if (pDb->status != TSDB_DB_STATUS_READY) { mError("db:%s, status:%d, in dropping", pDb->name, pDb->status); return 0; } - pVgroup = pDb->pHead; - while (pVgroup != NULL) { - maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; - pVgroup = pVgroup->next; + STableObj *pTable = NULL; + if (pShow->payloadLen > 0 ) { + pTable = mnodeGetTable(pShow->payload); } while (numOfRows < rows) { - pVgroup = (SVgObj *) pShow->pIter; + pShow->pIter = mnodeGetNextVgroup(pShow->pIter, &pVgroup); if (pVgroup == NULL) break; - pShow->pIter = (void *) pVgroup->next; + if (pVgroup->pDb != pDb) continue; + if (!mnodeFilterVgroups(pVgroup, pTable)) continue; cols = 0; @@ -560,7 +688,22 @@ int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pC *(int32_t *) pWrite = pVgroup->numOfTables; cols++; - for (int32_t i = 0; i < maxReplica; ++i) { + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = taosIdPoolMaxSize(pVgroup->idPool); + cols++; + + int32_t onlineVnodes = 0; + for (int32_t i = 0; i < pShow->maxReplica; ++i) { + if (pVgroup->vnodeGid[i].role == TAOS_SYNC_ROLE_SLAVE || pVgroup->vnodeGid[i].role == TAOS_SYNC_ROLE_MASTER) { + onlineVnodes++; + } + } + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = onlineVnodes; + cols++; + + for (int32_t i = 0; i < pShow->maxReplica; ++i) { pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int16_t *) pWrite = pVgroup->vnodeGid[i].dnodeId; cols++; @@ -588,41 +731,39 @@ int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pC } } + mnodeDecVgroupRef(pVgroup); numOfRows++; } pShow->numOfReads += numOfRows; + mnodeDecTableRef(pTable); mnodeDecDbRef(pDb); return numOfRows; } void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) { - if (pTable->sid >= 1 && pVgroup->tableList[pTable->sid - 1] == NULL) { - pVgroup->tableList[pTable->sid - 1] = pTable; - taosIdPoolMarkStatus(pVgroup->idPool, pTable->sid); - pVgroup->numOfTables++; - } - - if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables) { - mnodeMoveVgroupToTail(pVgroup); + int32_t idPoolSize = taosIdPoolMaxSize(pVgroup->idPool); + if (pTable->sid > idPoolSize) { + mnodeAllocVgroupIdPool(pVgroup); } - mnodeIncVgroupRef(pVgroup); + if (pTable->sid >= 1) { + taosIdPoolMarkStatus(pVgroup->idPool, pTable->sid); + pVgroup->numOfTables++; + mnodeIncVgroupRef(pVgroup); + } } void mnodeRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable) { - if (pTable->sid >= 1 && pVgroup->tableList[pTable->sid - 1] != NULL) { - pVgroup->tableList[pTable->sid - 1] = NULL; + if (pTable->sid >= 1) { taosFreeId(pVgroup->idPool, pTable->sid); pVgroup->numOfTables--; + mnodeDecVgroupRef(pVgroup); } - - mnodeMoveVgroupToHead(pVgroup); - mnodeDecVgroupRef(pVgroup); } -SMDCreateVnodeMsg *mnodeBuildCreateVnodeMsg(SVgObj *pVgroup) { +static SMDCreateVnodeMsg *mnodeBuildVnodeMsg(SVgObj *pVgroup) { SDbObj *pDb = pVgroup->pDb; if (pDb == NULL) return NULL; @@ -630,19 +771,23 @@ SMDCreateVnodeMsg *mnodeBuildCreateVnodeMsg(SVgObj *pVgroup) { if (pVnode == NULL) return NULL; strcpy(pVnode->db, pVgroup->dbName); + int32_t maxTables = taosIdPoolMaxSize(pVgroup->idPool); + //TODO: dynamic alloc tables in tsdb + maxTables = MAX(10000, tsMaxTablePerVnode); SMDVnodeCfg *pCfg = &pVnode->cfg; pCfg->vgId = htonl(pVgroup->vgId); pCfg->cfgVersion = htonl(pDb->cfgVersion); pCfg->cacheBlockSize = htonl(pDb->cfg.cacheBlockSize); pCfg->totalBlocks = htonl(pDb->cfg.totalBlocks); - pCfg->maxTables = htonl(pDb->cfg.maxTables + 1); + pCfg->maxTables = htonl(maxTables + 1); pCfg->daysPerFile = htonl(pDb->cfg.daysPerFile); pCfg->daysToKeep = htonl(pDb->cfg.daysToKeep); pCfg->daysToKeep1 = htonl(pDb->cfg.daysToKeep1); pCfg->daysToKeep2 = htonl(pDb->cfg.daysToKeep2); pCfg->minRowsPerFileBlock = htonl(pDb->cfg.minRowsPerFileBlock); pCfg->maxRowsPerFileBlock = htonl(pDb->cfg.maxRowsPerFileBlock); + pCfg->fsyncPeriod = htonl(pDb->cfg.fsyncPeriod); pCfg->commitTime = htonl(pDb->cfg.commitTime); pCfg->precision = pDb->cfg.precision; pCfg->compression = pDb->cfg.compression; @@ -685,8 +830,31 @@ SRpcIpSet mnodeGetIpSetFromIp(char *ep) { return ipSet; } -void mnodeSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) { - SMDCreateVnodeMsg *pCreate = mnodeBuildCreateVnodeMsg(pVgroup); +static void mnodeSendAlterVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet) { + 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 = { .ahandle = ahandle, .pCont = pCreate, @@ -708,6 +876,10 @@ void mnodeSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle) { } } +static void mnodeProcessAlterVnodeRsp(SRpcMsg *rpcMsg) { + mDebug("alter vnode rsp received"); +} + static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { if (rpcMsg->ahandle == NULL) return; @@ -724,6 +896,8 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { pVgroup->vgId, tstrerror(rpcMsg->code), mnodeMsg->received, mnodeMsg->successed, mnodeMsg->expected, mnodeMsg->rpcMsg.handle, rpcMsg->ahandle); + assert(mnodeMsg->received <= mnodeMsg->expected); + if (mnodeMsg->received != mnodeMsg->expected) return; if (mnodeMsg->received == mnodeMsg->successed) { @@ -857,9 +1031,10 @@ void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode) { sdbFreeIter(pIter); - mInfo("dnode:%d, all vgroups is dropped from sdb", pDropDnode->dnodeId); + mInfo("dnode:%d, all vgroups:%d is dropped from sdb", pDropDnode->dnodeId, numOfVgroups); } +#if 0 void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb) { void * pIter = NULL; SVgObj *pVgroup = NULL; @@ -881,6 +1056,7 @@ void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb) { mInfo("db:%s, all vgroups is updated in sdb", pAlterDb->name); } +#endif void mnodeDropAllDbVgroups(SDbObj *pDropDb) { void * pIter = NULL; diff --git a/src/plugins/http/inc/httpCode.h b/src/plugins/http/inc/httpCode.h index 0235040139..08111260e9 100644 --- a/src/plugins/http/inc/httpCode.h +++ b/src/plugins/http/inc/httpCode.h @@ -105,7 +105,7 @@ #define HTTP_OP_VALUE_TYPE 79 //tgf -#define HTTP_TG_STABLE_NOT_EXIST 80 +#define HTTP_TG_STABLE_NOT_EXIST 80 extern char *httpMsg[]; diff --git a/src/plugins/http/inc/httpInt.h b/src/plugins/http/inc/httpInt.h index 8ca1c2ff11..ffd621be7a 100644 --- a/src/plugins/http/inc/httpInt.h +++ b/src/plugins/http/inc/httpInt.h @@ -61,6 +61,9 @@ #define HTTP_CHECK_BODY_CONTINUE 0 #define HTTP_CHECK_BODY_SUCCESS 1 +#define HTTP_READ_DATA_SUCCESS 0 +#define HTTP_READ_DATA_FAILED 1 + #define HTTP_WRITE_RETRY_TIMES 500 #define HTTP_WRITE_WAIT_TIME_MS 5 #define HTTP_EXPIRED_TIME 60000 diff --git a/src/plugins/http/inc/httpLog.h b/src/plugins/http/inc/httpLog.h index f4c20a40d5..9c145a43e8 100644 --- a/src/plugins/http/inc/httpLog.h +++ b/src/plugins/http/inc/httpLog.h @@ -22,10 +22,10 @@ extern int32_t httpDebugFlag; #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 httpWarn(...) { if (httpDebugFlag & DEBUG_WARN) { taosPrintLog("HTP WARN ", 255, __VA_ARGS__); }} -#define httpInfo(...) { if (httpDebugFlag & DEBUG_INFO) { taosPrintLog("HTP INFO ", 255, __VA_ARGS__); }} -#define httpDebug(...) { if (httpDebugFlag & DEBUG_DEBUG) { taosPrintLog("HTP DEBUG ", httpDebugFlag, __VA_ARGS__); }} -#define httpTrace(...) { if (httpDebugFlag & DEBUG_TRACE) { taosPrintLog("HTP TRACE ", httpDebugFlag, __VA_ARGS__); }} -#define httpTraceL(...){ if (httpDebugFlag & DEBUG_TRACE) { taosPrintLongString("HTP TRACE ", httpDebugFlag, __VA_ARGS__); }} +#define httpWarn(...) { if (httpDebugFlag & DEBUG_WARN) { taosPrintLog("HTP WARN ", 255, __VA_ARGS__); }} +#define httpInfo(...) { if (httpDebugFlag & DEBUG_INFO) { taosPrintLog("HTP ", 255, __VA_ARGS__); }} +#define httpDebug(...) { if (httpDebugFlag & DEBUG_DEBUG) { taosPrintLog("HTP ", httpDebugFlag, __VA_ARGS__); }} +#define httpTrace(...) { if (httpDebugFlag & DEBUG_TRACE) { taosPrintLog("HTP ", httpDebugFlag, __VA_ARGS__); }} +#define httpTraceL(...){ if (httpDebugFlag & DEBUG_TRACE) { taosPrintLongString("HTP ", httpDebugFlag, __VA_ARGS__); }} #endif diff --git a/src/plugins/http/inc/httpServer.h b/src/plugins/http/inc/httpServer.h index 04dadfe04c..508baa6112 100644 --- a/src/plugins/http/inc/httpServer.h +++ b/src/plugins/http/inc/httpServer.h @@ -23,6 +23,6 @@ void httpCleanUpConnect(); void *httpInitServer(char *ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle); void httpCleanUpServer(HttpServer *pServer); -bool httpReadDataImp(HttpContext *pContext); +int httpReadDataImp(HttpContext *pContext); #endif diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index 98fba9cb3b..cefcca7821 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -137,7 +137,7 @@ void httpReleaseContext(HttpContext *pContext) { assert(refCount >= 0); HttpContext **ppContext = pContext->ppContext; - httpDebug("context:%p, is releasd, data:%p refCount:%d", pContext, ppContext, refCount); + httpDebug("context:%p, is released, data:%p refCount:%d", pContext, ppContext, refCount); if (tsHttpServer.contextCache != NULL) { taosCacheRelease(tsHttpServer.contextCache, (void **)(&ppContext), false); diff --git a/src/plugins/http/src/httpHandle.c b/src/plugins/http/src/httpHandle.c index 2c94f61950..407d19b307 100644 --- a/src/plugins/http/src/httpHandle.c +++ b/src/plugins/http/src/httpHandle.c @@ -60,6 +60,7 @@ bool httpParseURL(HttpContext* pContext) { char* pSeek; char* pEnd = strchr(pParser->pLast, ' '); if (pEnd == NULL) { + httpSendErrorResp(pContext, HTTP_UNSUPPORT_URL); return false; } @@ -275,14 +276,14 @@ bool httpParseChunkedBody(HttpContext* pContext, HttpParser* pParser, bool test) return true; } -bool httpReadChunkedBody(HttpContext* pContext, HttpParser* pParser) { +int httpReadChunkedBody(HttpContext* pContext, HttpParser* pParser) { bool parsedOk = httpParseChunkedBody(pContext, pParser, true); if (parsedOk) { httpParseChunkedBody(pContext, pParser, false); return HTTP_CHECK_BODY_SUCCESS; } else { httpTrace("context:%p, fd:%d, ip:%s, chunked body not finished, continue read", pContext, pContext->fd, pContext->ipstr); - if (!httpReadDataImp(pContext)) { + if (httpReadDataImp(pContext) != HTTP_READ_DATA_SUCCESS) { httpError("context:%p, fd:%d, ip:%s, read chunked request error", pContext, pContext->fd, pContext->ipstr); return HTTP_CHECK_BODY_ERROR; } else { @@ -296,7 +297,6 @@ int httpReadUnChunkedBody(HttpContext* pContext, HttpParser* pParser) { if (dataReadLen > pParser->data.len) { httpError("context:%p, fd:%d, ip:%s, un-chunked body length invalid, read size:%d dataReadLen:%d > pContext->data.len:%d", pContext, pContext->fd, pContext->ipstr, pContext->parser.bufsize, dataReadLen, pParser->data.len); - httpSendErrorResp(pContext, HTTP_PARSE_BODY_ERROR); return HTTP_CHECK_BODY_ERROR; } else if (dataReadLen < pParser->data.len) { httpTrace("context:%p, fd:%d, ip:%s, un-chunked body not finished, read size:%d dataReadLen:%d < pContext->data.len:%d, continue read", @@ -358,20 +358,13 @@ bool httpParseRequest(HttpContext* pContext) { } int httpCheckReadCompleted(HttpContext* pContext) { - HttpParser *pParser = &pContext->parser; - if (pContext->httpChunked == HTTP_UNCUNKED) { - int ret = httpReadUnChunkedBody(pContext, pParser); - if (ret != HTTP_CHECK_BODY_SUCCESS) { - return ret; - } - } else { - int ret = httpReadChunkedBody(pContext, pParser); - if (ret != HTTP_CHECK_BODY_SUCCESS) { - return ret; - } - } + HttpParser* pParser = &pContext->parser; - return HTTP_CHECK_BODY_SUCCESS; + if (pContext->httpChunked == HTTP_UNCUNKED) { + return httpReadUnChunkedBody(pContext, pParser); + } else { + return httpReadChunkedBody(pContext, pParser); + } } bool httpDecodeRequest(HttpContext* pContext) { diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index dbe299cef7..177d447f10 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -69,7 +69,7 @@ void httpCleanUpConnect() { httpDebug("http server:%s is cleaned up", pServer->label); } -bool httpReadDataImp(HttpContext *pContext) { +int httpReadDataImp(HttpContext *pContext) { HttpParser *pParser = &pContext->parser; while (pParser->bufsize <= (HTTP_BUFFER_SIZE - HTTP_STEP_SIZE)) { @@ -85,8 +85,7 @@ bool httpReadDataImp(HttpContext *pContext) { } else { httpError("context:%p, fd:%d, ip:%s, read from socket error:%d, close connect", pContext, pContext->fd, pContext->ipstr, errno); - httpReleaseContext(pContext); - return false; + return HTTP_READ_DATA_FAILED; } } else { pParser->bufsize += nread; @@ -95,15 +94,13 @@ bool httpReadDataImp(HttpContext *pContext) { if (pParser->bufsize >= (HTTP_BUFFER_SIZE - HTTP_STEP_SIZE)) { httpError("context:%p, fd:%d, ip:%s, thread:%s, request big than:%d", pContext, pContext->fd, pContext->ipstr, pContext->pThread->label, HTTP_BUFFER_SIZE); - httpSendErrorResp(pContext, HTTP_REQUSET_TOO_BIG); - httpNotifyContextClose(pContext); - return false; + return HTTP_REQUSET_TOO_BIG; } } pParser->buffer[pParser->bufsize] = 0; - return true; + return HTTP_READ_DATA_SUCCESS; } static bool httpDecompressData(HttpContext *pContext) { @@ -141,8 +138,14 @@ static bool httpReadData(HttpContext *pContext) { httpInitContext(pContext); } - if (!httpReadDataImp(pContext)) { - httpNotifyContextClose(pContext); + int32_t code = httpReadDataImp(pContext); + if (code != HTTP_READ_DATA_SUCCESS) { + if (code == HTTP_READ_DATA_FAILED) { + httpReleaseContext(pContext); + } else { + httpSendErrorResp(pContext, code); + httpNotifyContextClose(pContext); + } return false; } diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index 7a515d124e..a01cb07a98 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -47,6 +47,10 @@ void httpProcessMultiSqlRetrieveCallBack(void *param, TAOS_RES *result, int numO } } + // if (tscResultsetFetchCompleted(result)) { + // isContinue = false; + // } + if (isContinue) { // retrieve next batch of rows httpDebug("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, continue retrieve, numOfRows:%d, sql:%s", @@ -75,7 +79,8 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { HttpContext *pContext = (HttpContext *)param; if (pContext == NULL) return; - HttpSqlCmds * multiCmds = pContext->multiCmds; + code = taos_errno(result); + HttpSqlCmds *multiCmds = pContext->multiCmds; HttpEncodeMethod *encode = pContext->encodeMethod; HttpSqlCmd *singleCmd = multiCmds->cmds + multiCmds->pos; @@ -109,8 +114,8 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) { return; } - int num_fields = taos_field_count(result); - if (num_fields == 0) { + bool isUpdate = tscIsUpdateQuery(result); + if (isUpdate) { // not select or show commands int affectRows = taos_affected_rows(result); httpDebug("context:%p, fd:%d, ip:%s, user:%s, process pos:%d, affect rows:%d, sql:%s", @@ -221,9 +226,9 @@ void httpProcessSingleSqlRetrieveCallBack(void *param, TAOS_RES *result, int num if (numOfRows < 0) { httpError("context:%p, fd:%d, ip:%s, user:%s, retrieve failed, code:%s", pContext, pContext->fd, pContext->ipstr, pContext->user, tstrerror(numOfRows)); - } - - taos_free_result(result); + } + + taos_free_result(result); if (encode->stopJsonFp) { (encode->stopJsonFp)(pContext, &pContext->singleCmd); @@ -238,6 +243,7 @@ void httpProcessSingleSqlCallBack(void *param, TAOS_RES *result, int unUsedCode) if (pContext == NULL) return; int32_t code = taos_errno(result); + HttpEncodeMethod *encode = pContext->encodeMethod; if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index 36468b3fdb..22cb111b83 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -30,10 +30,10 @@ #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 monitorWarn(...) { if (monitorDebugFlag & DEBUG_WARN) { taosPrintLog("MON WARN ", 255, __VA_ARGS__); }} -#define monitorInfo(...) { if (monitorDebugFlag & DEBUG_INFO) { taosPrintLog("MON INFO ", 255, __VA_ARGS__); }} -#define monitorDebug(...) { if (monitorDebugFlag & DEBUG_DEBUG) { taosPrintLog("MON DEBUG ", monitorDebugFlag, __VA_ARGS__); }} -#define monitorTrace(...) { if (monitorDebugFlag & DEBUG_TRACE) { taosPrintLog("MON TRACE ", monitorDebugFlag, __VA_ARGS__); }} +#define monitorWarn(...) { if (monitorDebugFlag & DEBUG_WARN) { taosPrintLog("MON WARN ", 255, __VA_ARGS__); }} +#define monitorInfo(...) { if (monitorDebugFlag & DEBUG_INFO) { taosPrintLog("MON ", 255, __VA_ARGS__); }} +#define monitorDebug(...) { if (monitorDebugFlag & DEBUG_DEBUG) { taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); }} +#define monitorTrace(...) { if (monitorDebugFlag & DEBUG_TRACE) { taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); }} #define SQL_LENGTH 1024 #define LOG_LEN_STR 100 diff --git a/src/plugins/mqtt/inc/mqttLog.h b/src/plugins/mqtt/inc/mqttLog.h index 5d5f98a13b..e186b81112 100644 --- a/src/plugins/mqtt/inc/mqttLog.h +++ b/src/plugins/mqtt/inc/mqttLog.h @@ -22,9 +22,9 @@ extern int32_t mqttDebugFlag; #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 mqttWarn(...) { if (mqttDebugFlag & DEBUG_WARN) { taosPrintLog("MQT WARN ", 255, __VA_ARGS__); }} -#define mqttInfo(...) { if (mqttDebugFlag & DEBUG_INFO) { taosPrintLog("MQT INFO ", 255, __VA_ARGS__); }} -#define mqttDebug(...) { if (mqttDebugFlag & DEBUG_DEBUG) { taosPrintLog("MQT DEBUG ", mqttDebugFlag, __VA_ARGS__); }} -#define mqttTrace(...) { if (mqttDebugFlag & DEBUG_TRACE) { taosPrintLog("MQT TRACE ", mqttDebugFlag, __VA_ARGS__); }} +#define mqttWarn(...) { if (mqttDebugFlag & DEBUG_WARN) { taosPrintLog("MQT WARN ", 255, __VA_ARGS__); }} +#define mqttInfo(...) { if (mqttDebugFlag & DEBUG_INFO) { taosPrintLog("MQT ", 255, __VA_ARGS__); }} +#define mqttDebug(...) { if (mqttDebugFlag & DEBUG_DEBUG) { taosPrintLog("MQT ", mqttDebugFlag, __VA_ARGS__); }} +#define mqttTrace(...) { if (mqttDebugFlag & DEBUG_TRACE) { taosPrintLog("MQT ", mqttDebugFlag, __VA_ARGS__); }} #endif diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index 6cd6edd6db..f77036ef9d 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -24,7 +24,7 @@ #include "qtsbuf.h" #include "taosdef.h" #include "tarray.h" -#include "tref.h" +#include "tlockfree.h" #include "tsdb.h" #include "tsqlfunction.h" #include "query.h" @@ -121,6 +121,7 @@ typedef struct SQueryCostInfo { uint32_t loadBlockStatis; uint32_t discardBlocks; uint64_t elapsedTime; + uint64_t ioTime; uint64_t computTime; } SQueryCostInfo; @@ -192,7 +193,6 @@ typedef struct SQInfo { int32_t offset; // offset in group result set of subgroup, todo refactor SArray* arrTableIdInfo; - T_REF_DECLARE() /* * the query is executed position on which meter of the whole list. * when the index reaches the last one of the list, it means the query is completed. @@ -201,8 +201,6 @@ typedef struct SQInfo { */ int32_t tableIndex; int32_t numOfGroupResultPages; - _qinfo_free_fn_t freeFn; //todo remove it - void* pBuf; // allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables; } SQInfo; diff --git a/src/query/inc/qUtil.h b/src/query/inc/qUtil.h index 9b818b367f..8fe3c0f495 100644 --- a/src/query/inc/qUtil.h +++ b/src/query/inc/qUtil.h @@ -37,7 +37,7 @@ SWindowResult *getWindowResult(SWindowResInfo *pWindowResInfo, int32_t slot); #define curTimeWindow(_winres) ((_winres)->curIndex) bool isWindowResClosed(SWindowResInfo *pWindowResInfo, int32_t slot); -void createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTableQuery, SPosInfo *posInfo, size_t interBufSize); +int32_t createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTableQuery, SPosInfo *posInfo, size_t interBufSize); char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWindowResult *pResult); diff --git a/src/query/inc/qsqlparser.h b/src/query/inc/qsqlparser.h index 704f3e7418..9e8706cf92 100644 --- a/src/query/inc/qsqlparser.h +++ b/src/query/inc/qsqlparser.h @@ -116,6 +116,7 @@ typedef struct SCreateDBInfo { int32_t daysPerFile; int32_t minRowsPerBlock; int32_t maxRowsPerBlock; + int32_t fsyncPeriod; int64_t commitTime; int32_t walLevel; int32_t compressionLevel; diff --git a/src/query/inc/qtsbuf.h b/src/query/inc/qtsbuf.h index e437e1c4e5..59b224e096 100644 --- a/src/query/inc/qtsbuf.h +++ b/src/query/inc/qtsbuf.h @@ -107,7 +107,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order); STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete); STSBuf* tsBufCreateFromCompBlocks(const char* pData, int32_t numOfBlocks, int32_t len, int32_t tsOrder); -void* tsBufDestory(STSBuf* pTSBuf); +void* tsBufDestroy(STSBuf* pTSBuf); void tsBufAppend(STSBuf* pTSBuf, int32_t vnodeId, int64_t tag, const char* pData, int32_t len); int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf, int32_t vnodeIdx); diff --git a/src/query/inc/queryLog.h b/src/query/inc/queryLog.h index fd1322e995..a1c447a6eb 100644 --- a/src/query/inc/queryLog.h +++ b/src/query/inc/queryLog.h @@ -27,10 +27,10 @@ extern int32_t tscEmbedded; #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 qWarn(...) { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", 255, __VA_ARGS__); }} -#define qInfo(...) { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY INFO ", 255, __VA_ARGS__); }} -#define qDebug(...) { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY DEBUG ", qDebugFlag, __VA_ARGS__); }} -#define qTrace(...) { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY TRACE ", qDebugFlag, __VA_ARGS__); }} +#define qWarn(...) { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", 255, __VA_ARGS__); }} +#define qInfo(...) { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", 255, __VA_ARGS__); }} +#define qDebug(...) { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} +#define qTrace(...) { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} #ifdef __cplusplus } diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index b4ea1254b7..d709b4f838 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -221,6 +221,7 @@ maxrows(Y) ::= MAXROWS INTEGER(X). { Y = X; } blocks(Y) ::= BLOCKS INTEGER(X). { Y = X; } ctime(Y) ::= CTIME 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; } 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) 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) 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) prec(X). { Y = Z; Y.precision = 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) 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) fsync(X). { Y = Z; Y.fsyncPeriod = strtod(X.z, NULL, 10); } %type typename {TAOS_FIELD} typename(A) ::= ids(X). { diff --git a/src/query/inc/tsqlfunction.h b/src/query/inc/tsqlfunction.h index 63b7abb379..e57cb26456 100644 --- a/src/query/inc/tsqlfunction.h +++ b/src/query/inc/tsqlfunction.h @@ -125,7 +125,8 @@ typedef struct SArithmeticSupport { } SArithmeticSupport; typedef struct SQLPreAggVal { - bool isSet; + bool isSet; // statistics info set or not + bool dataBlockLoaded; // data block is loaded or not SDataStatis statis; } SQLPreAggVal; @@ -187,7 +188,7 @@ typedef struct SQLFunctionCtx { } SQLFunctionCtx; typedef struct SQLAggFuncElem { - char aName[TSDB_FUNCTIONS_NAME_MAX_LENGTH]; + char aName[TSDB_FUNCTIONS_NAME_MAX_LENGTH]; uint8_t nAggIdx; // index of function in aAggs int8_t stableFuncId; // transfer function for super table query @@ -224,25 +225,14 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI #define IS_SINGLEOUTPUT(x) (((x)&TSDB_FUNCSTATE_SO) != 0) #define IS_OUTER_FORWARD(x) (((x)&TSDB_FUNCSTATE_OF) != 0) -/* - * the status of one block, used in metric query. all blocks are mixed together, - * we need the status to decide if one block is a first/end/inter block of one meter - */ -enum { - BLK_FILE_BLOCK = 0x1, - BLK_BLOCK_LOADED = 0x2, - BLK_CACHE_BLOCK = 0x4, // in case of cache block, block must be loaded -}; - /* determine the real data need to calculated the result */ enum { - BLK_DATA_NO_NEEDED = 0x0, + BLK_DATA_NO_NEEDED = 0x0, BLK_DATA_STATIS_NEEDED = 0x1, - BLK_DATA_ALL_NEEDED = 0x3, + BLK_DATA_ALL_NEEDED = 0x3, + BLK_DATA_DISCARD = 0x4, // discard current data block since it is not qualified for filter }; -#define SET_DATA_BLOCK_NOT_LOADED(x) ((x) &= (~BLK_BLOCK_LOADED)); - typedef struct STwaInfo { TSKEY lastKey; int8_t hasResult; // flag to denote has value @@ -264,12 +254,9 @@ typedef struct STwaInfo { /* global sql function array */ extern struct SQLAggFuncElem aAggs[]; -/* compatible check array list */ -extern int32_t funcCompatDefList[]; +extern int32_t functionCompatList[]; // compatible check array list -bool top_bot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, char *minval, char *maxval); - -bool stableQueryFunctChanged(int32_t funcId); +bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const char *minval, const char *maxval); void resetResultInfo(SResultInfo *pResInfo); void setResultInfoBuf(SResultInfo *pResInfo, int32_t size, bool superTable, char* buf); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 53a32a2356..77e7321d3d 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -44,7 +44,7 @@ #define SET_MASTER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER_SCAN) #define SET_REVERSE_SCAN_FLAG(runtime) ((runtime)->scanFlag = REVERSE_SCAN) -#define GET_QINFO_ADDR(x) ((void *)((char *)(x)-offsetof(SQInfo, runtimeEnv))) +#define GET_QINFO_ADDR(x) ((SQInfo *)((char *)(x)-offsetof(SQInfo, runtimeEnv))) #define GET_COL_DATA_POS(query, index, step) ((query)->pos + (index) * (step)) #define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC)) @@ -120,6 +120,7 @@ static UNUSED_FUNC void* u_calloc(size_t num, size_t __size) { #define GET_TABLEGROUP(q, _index) ((SArray*) taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index))) static void setQueryStatus(SQuery *pQuery, int8_t status); +static void finalizeQueryResult(SQueryRuntimeEnv *pRuntimeEnv); #define QUERY_IS_INTERVAL_QUERY(_q) ((_q)->intervalTime > 0) @@ -351,27 +352,6 @@ static bool hasTagValOutput(SQuery* pQuery) { return false; } -static SDataStatis *getStatisInfo(SQuery *pQuery, SDataStatis *pStatis, int32_t numOfCols, int32_t index) { - // for a tag column, no corresponding field info - SColIndex *pColIndex = &pQuery->pSelectExpr[index].base.colInfo; - if (TSDB_COL_IS_TAG(pColIndex->flag)) { - return NULL; - } - - /* - * Choose the right column field info by field id, since the file block may be out of date, - * which means the newest table schema is not equalled to the schema of this block. - * TODO: speedup by using bsearch - */ - for (int32_t i = 0; i < numOfCols; ++i) { - if (pColIndex->colId == pStatis[i].colId) { - return &pStatis[i]; - } - } - - return NULL; -} - /** * @param pQuery * @param col @@ -380,19 +360,14 @@ static SDataStatis *getStatisInfo(SQuery *pQuery, SDataStatis *pStatis, int32_t * @param pColStatis * @return */ -static bool hasNullValue(SQuery *pQuery, int32_t col, int32_t numOfCols, SDataStatis *pStatis, SDataStatis **pColStatis) { - SColIndex *pColIndex = &pQuery->pSelectExpr[col].base.colInfo; - if (TSDB_COL_IS_TAG(pColIndex->flag)) { - return false; - } - - // query on primary timestamp column, not null value at all - if (pColIndex->colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { +static bool hasNullValue(SColIndex* pColIndex, SDataStatis *pStatis, SDataStatis **pColStatis) { + if (TSDB_COL_IS_TAG(pColIndex->flag) || pColIndex->colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { return false; } if (pStatis != NULL) { - *pColStatis = getStatisInfo(pQuery, pStatis, numOfCols, col); + *pColStatis = &pStatis[pColIndex->colIndex]; + assert((*pColStatis)->colId == pColIndex->colId); } else { *pColStatis = NULL; } @@ -842,8 +817,8 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas if (pDataBlock == NULL) { return NULL; } - char *dataBlock = NULL; + char *dataBlock = NULL; SQuery *pQuery = pRuntimeEnv->pQuery; SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx; @@ -864,6 +839,7 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas sas->data = calloc(pQuery->numOfCols, POINTER_BYTES); if (sas->data == NULL) { + finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -887,10 +863,14 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas } else { // other type of query function SColIndex *pCol = &pQuery->pSelectExpr[col].base.colInfo; - if (TSDB_COL_IS_TAG(pCol->flag) || pDataBlock == NULL) { + if (TSDB_COL_IS_TAG(pCol->flag)) { dataBlock = NULL; } else { - dataBlock = getDataBlockImpl(pDataBlock, pCol->colId); + SColIndex* pColIndex = &pQuery->pSelectExpr[col].base.colInfo; + SColumnInfoData *p = taosArrayGet(pDataBlock, pColIndex->colIndex); + assert(p->info.colId == pColIndex->colId); + + dataBlock = p->pData; } } @@ -922,6 +902,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * SArithmeticSupport *sasArray = calloc((size_t)pQuery->numOfOutput, sizeof(SArithmeticSupport)); if (sasArray == NULL) { + finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -1168,6 +1149,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS SArithmeticSupport *sasArray = calloc((size_t)pQuery->numOfOutput, sizeof(SArithmeticSupport)); if (sasArray == NULL) { + finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -1365,7 +1347,7 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, void* inputData, TSKEY int32_t colId = pQuery->pSelectExpr[colIndex].base.colInfo.colId; SDataStatis *tpField = NULL; - pCtx->hasNull = hasNullValue(pQuery, colIndex, pBlockInfo->numOfCols, pStatis, &tpField); + pCtx->hasNull = hasNullValue(&pQuery->pSelectExpr[colIndex].base.colInfo, pStatis, &tpField); pCtx->aInputElemBuf = inputData; if (tpField != NULL) { @@ -1376,6 +1358,8 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, void* inputData, TSKEY pCtx->preAggVals.isSet = false; } + pCtx->preAggVals.dataBlockLoaded = (inputData != NULL); + // limit/offset query will affect this value pCtx->startOffset = QUERY_IS_ASC_QUERY(pQuery) ? pQuery->pos:0; pCtx->size = QUERY_IS_ASC_QUERY(pQuery) ? pBlockInfo->rows - pQuery->pos : pQuery->pos + 1; @@ -1619,22 +1603,21 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { tsdbCleanupQueryHandle(pRuntimeEnv->pQueryHandle); tsdbCleanupQueryHandle(pRuntimeEnv->pSecQueryHandle); - pRuntimeEnv->pTSBuf = tsBufDestory(pRuntimeEnv->pTSBuf); + pRuntimeEnv->pTSBuf = tsBufDestroy(pRuntimeEnv->pTSBuf); } -static bool isQueryKilled(SQInfo *pQInfo) { - return (pQInfo->code == TSDB_CODE_TSC_QUERY_CANCELLED); -} +#define IS_QUERY_KILLED(_q) ((_q)->code == TSDB_CODE_TSC_QUERY_CANCELLED) static void setQueryKilled(SQInfo *pQInfo) { pQInfo->code = TSDB_CODE_TSC_QUERY_CANCELLED; } -static bool isFixedOutputQuery(SQuery *pQuery) { - if (pQuery->intervalTime != 0) { +static bool isFixedOutputQuery(SQueryRuntimeEnv* pRuntimeEnv) { + SQuery* pQuery = pRuntimeEnv->pQuery; + if (QUERY_IS_INTERVAL_QUERY(pQuery)) { return false; } // Note:top/bottom query is fixed output query - if (isTopBottomQuery(pQuery) || isGroupbyNormalCol(pQuery->pGroupbyExpr)) { + if (pRuntimeEnv->topBotQuery || pRuntimeEnv->groupbyNormalCol) { return true; } @@ -1947,73 +1930,46 @@ char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWi pQuery->pSelectExpr[columnIndex].bytes * realRowId; } -/** - * decrease the refcount for each table involved in this query - * @param pQInfo - */ -UNUSED_FUNC void vnodeDecMeterRefcnt(SQInfo *pQInfo) { - if (pQInfo != NULL) { - // assert(taosHashGetSize(pQInfo->tableqinfoGroupInfo) >= 1); - } +#define IS_PREFILTER_TYPE(_t) ((_t) != TSDB_DATA_TYPE_BINARY && (_t) != TSDB_DATA_TYPE_NCHAR) -#if 0 - if (pQInfo == NULL || pQInfo->tableqinfoGroupInfo.numOfTables == 1) { - atomic_fetch_sub_32(&pQInfo->pObj->numOfQueries, 1); - qDebug("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pQInfo->pObj->vnode, - pQInfo->pObj->sid, pQInfo->pObj->meterId, pQInfo->pObj->numOfQueries); - } else { - int32_t num = 0; - for (int32_t i = 0; i < pQInfo->tableqinfoGroupInfo.numOfTables; ++i) { - SMeterObj *pMeter = getMeterObj(pQInfo->tableqinfoGroupInfo, pQInfo->pSidSet->pTableIdList[i]->sid); - atomic_fetch_sub_32(&(pMeter->numOfQueries), 1); - - if (pMeter->numOfQueries > 0) { - qDebug("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pMeter->vnode, pMeter->sid, - pMeter->meterId, pMeter->numOfQueries); - num++; - } - } - - /* - * in order to reduce log output, for all meters of which numOfQueries count are 0, - * we do not output corresponding information - */ - num = pQInfo->tableqinfoGroupInfo.numOfTables - num; - qDebug("QInfo:%p metric query is over, dec query ref for %d meters, numOfQueries on %d meters are 0", pQInfo, - pQInfo->tableqinfoGroupInfo.numOfTables, num); - } -#endif -} - -static bool needToLoadDataBlock(SQuery *pQuery, SDataStatis *pDataStatis, SQLFunctionCtx *pCtx, - int32_t numOfTotalPoints) { - if (pDataStatis == NULL) { +static bool needToLoadDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SDataStatis *pDataStatis, SQLFunctionCtx *pCtx, + int32_t numOfRows) { + SQuery* pQuery = pRuntimeEnv->pQuery; + if (pDataStatis == NULL || (pQuery->numOfFilterCols == 0 && (!pRuntimeEnv->topBotQuery))) { return true; } -#if 0 for (int32_t k = 0; k < pQuery->numOfFilterCols; ++k) { SSingleColumnFilterInfo *pFilterInfo = &pQuery->pFilterInfo[k]; - int32_t colIndex = pFilterInfo->info.colIndex; - // this column not valid in current data block - if (colIndex < 0 || pDataStatis[colIndex].colId != pFilterInfo->info.data.colId) { - continue; + int32_t index = -1; + for(int32_t i = 0; i < pQuery->numOfCols; ++i) { + if (pDataStatis[i].colId == pFilterInfo->info.colId) { + index = i; + break; + } + } + + // no statistics data + if (index == -1) { + return true; } // not support pre-filter operation on binary/nchar data type - if (!vnodeSupportPrefilter(pFilterInfo->info.data.type)) { - continue; + if (!IS_PREFILTER_TYPE(pFilterInfo->info.type)) { + return true; } // all points in current column are NULL, no need to check its boundary value - if (pDataStatis[colIndex].numOfNull == numOfTotalPoints) { + if (pDataStatis[index].numOfNull == numOfRows) { continue; } - if (pFilterInfo->info.info.type == TSDB_DATA_TYPE_FLOAT) { - float minval = *(double *)(&pDataStatis[colIndex].min); - float maxval = *(double *)(&pDataStatis[colIndex].max); + SDataStatis* pDataBlockst = &pDataStatis[index]; + + if (pFilterInfo->info.type == TSDB_DATA_TYPE_FLOAT) { + float minval = *(double *)(&pDataBlockst->min); + float maxval = *(double *)(&pDataBlockst->max); for (int32_t i = 0; i < pFilterInfo->numOfFilters; ++i) { if (pFilterInfo->pFilters[i].fp(&pFilterInfo->pFilters[i], (char *)&minval, (char *)&maxval)) { @@ -2022,54 +1978,50 @@ static bool needToLoadDataBlock(SQuery *pQuery, SDataStatis *pDataStatis, SQLFun } } else { for (int32_t i = 0; i < pFilterInfo->numOfFilters; ++i) { - if (pFilterInfo->pFilters[i].fp(&pFilterInfo->pFilters[i], (char *)&pDataStatis[colIndex].min, - (char *)&pDataStatis[colIndex].max)) { + if (pFilterInfo->pFilters[i].fp(&pFilterInfo->pFilters[i], (char *)&pDataBlockst->min, (char *)&pDataBlockst->max)) { return true; } } } } - // todo disable this opt code block temporarily - // for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { - // int32_t functId = pQuery->pSelectExpr[i].base.functionId; - // if (functId == TSDB_FUNC_TOP || functId == TSDB_FUNC_BOTTOM) { - // return top_bot_datablock_filter(&pCtx[i], functId, (char *)&pField[i].min, (char *)&pField[i].max); - // } - // } - -#endif - return true; -} - -SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, void* pQueryHandle, SDataBlockInfo* pBlockInfo, SDataStatis **pStatis) { - SQuery *pQuery = pRuntimeEnv->pQuery; - - uint32_t r = 0; - SArray * pDataBlock = NULL; - - if (pQuery->numOfFilterCols > 0) { - r = BLK_DATA_ALL_NEEDED; - } else { - // check if this data block is required to load + if (pRuntimeEnv->topBotQuery) { for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { - SSqlFuncMsg* pSqlFunc = &pQuery->pSelectExpr[i].base; - - int32_t functionId = pSqlFunc->functionId; - int32_t colId = pSqlFunc->colInfo.colId; - r |= aAggs[functionId].dataReqFunc(&pRuntimeEnv->pCtx[i], pQuery->window.skey, pQuery->window.ekey, colId); - } - - if (pRuntimeEnv->pTSBuf > 0 || QUERY_IS_INTERVAL_QUERY(pQuery)) { - r |= BLK_DATA_ALL_NEEDED; + int32_t functionId = pQuery->pSelectExpr[i].base.functionId; + if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) { + return topbot_datablock_filter(&pCtx[i], functionId, (char *)&pDataStatis[i].min, (char *)&pDataStatis[i].max); + } } } - if (r == BLK_DATA_NO_NEEDED) { - qDebug("QInfo:%p data block discard, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_QINFO_ADDR(pRuntimeEnv), + return false; +} + +int32_t loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, void* pQueryHandle, SDataBlockInfo* pBlockInfo, SDataStatis **pStatis, SArray** pDataBlock) { + SQuery *pQuery = pRuntimeEnv->pQuery; + + uint32_t status = 0; + if (pQuery->numOfFilterCols > 0) { + status = BLK_DATA_ALL_NEEDED; + } else { // check if this data block is required to load + for (int32_t i = 0; i < pQuery->numOfOutput; ++i) { + SSqlFuncMsg* pSqlFunc = &pQuery->pSelectExpr[i].base; + + int32_t functionId = pSqlFunc->functionId; + int32_t colId = pSqlFunc->colInfo.colId; + status |= aAggs[functionId].dataReqFunc(&pRuntimeEnv->pCtx[i], pBlockInfo->window.skey, pBlockInfo->window.ekey, colId); + } + + if (pRuntimeEnv->pTSBuf > 0 || QUERY_IS_INTERVAL_QUERY(pQuery)) { + status |= BLK_DATA_ALL_NEEDED; + } + } + + if (status == BLK_DATA_NO_NEEDED) { + qDebug("QInfo:%p data block discard, brange:%"PRId64 "-%"PRId64", rows:%d", GET_QINFO_ADDR(pRuntimeEnv), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); pRuntimeEnv->summary.discardBlocks += 1; - } else if (r == BLK_DATA_STATIS_NEEDED) { + } else if (status == BLK_DATA_STATIS_NEEDED) { if (tsdbRetrieveDataBlockStatisInfo(pQueryHandle, pStatis) != TSDB_CODE_SUCCESS) { // return DISK_DATA_LOAD_FAILED; } @@ -2077,32 +2029,34 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, void* pQueryHandle, pRuntimeEnv->summary.loadBlockStatis += 1; if (*pStatis == NULL) { // data block statistics does not exist, load data block - pDataBlock = tsdbRetrieveDataBlock(pQueryHandle, NULL); + *pDataBlock = tsdbRetrieveDataBlock(pQueryHandle, NULL); pRuntimeEnv->summary.totalCheckedRows += pBlockInfo->rows; } } else { - assert(r == BLK_DATA_ALL_NEEDED); + assert(status == BLK_DATA_ALL_NEEDED); // load the data block statistics to perform further filter - pRuntimeEnv->summary.loadBlockStatis +=1; + pRuntimeEnv->summary.loadBlockStatis += 1; if (tsdbRetrieveDataBlockStatisInfo(pQueryHandle, pStatis) != TSDB_CODE_SUCCESS) { } - if (!needToLoadDataBlock(pQuery,*pStatis, pRuntimeEnv->pCtx, pBlockInfo->rows)) { + if (!needToLoadDataBlock(pRuntimeEnv, *pStatis, pRuntimeEnv->pCtx, pBlockInfo->rows)) { #if defined(_DEBUG_VIEW) qDebug("QInfo:%p block discarded by per-filter", GET_QINFO_ADDR(pRuntimeEnv)); #endif // current block has been discard due to filter applied pRuntimeEnv->summary.discardBlocks += 1; - // return DISK_DATA_DISCARDED; + qDebug("QInfo:%p data block discard, brange:%"PRId64 "-%"PRId64", rows:%d", GET_QINFO_ADDR(pRuntimeEnv), + pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); + return BLK_DATA_DISCARD; } pRuntimeEnv->summary.totalCheckedRows += pBlockInfo->rows; pRuntimeEnv->summary.loadBlocks += 1; - pDataBlock = tsdbRetrieveDataBlock(pQueryHandle, NULL); + *pDataBlock = tsdbRetrieveDataBlock(pQueryHandle, NULL); } - return pDataBlock; + return TSDB_CODE_SUCCESS; } int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) { @@ -2199,7 +2153,7 @@ static void ensureOutputBufferSimple(SQueryRuntimeEnv* pRuntimeEnv, int32_t capa static void ensureOutputBuffer(SQueryRuntimeEnv* pRuntimeEnv, SDataBlockInfo* pBlockInfo) { // in case of prj/diff query, ensure the output buffer is sufficient to accommodate the results of current block SQuery* pQuery = pRuntimeEnv->pQuery; - if (!QUERY_IS_INTERVAL_QUERY(pQuery) && !pRuntimeEnv->groupbyNormalCol && !isFixedOutputQuery(pQuery)) { + if (!QUERY_IS_INTERVAL_QUERY(pQuery) && !pRuntimeEnv->groupbyNormalCol && !isFixedOutputQuery(pRuntimeEnv)) { SResultRec *pRec = &pQuery->rec; if (pQuery->rec.capacity - pQuery->rec.rows < pBlockInfo->rows) { @@ -2245,12 +2199,20 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { pQuery->order.order); TsdbQueryHandleT pQueryHandle = IS_MASTER_SCAN(pRuntimeEnv)? pRuntimeEnv->pQueryHandle : pRuntimeEnv->pSecQueryHandle; + int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); 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; - if (isQueryKilled(GET_QINFO_ADDR(pRuntimeEnv))) { - return 0; + + if (IS_QUERY_KILLED(GET_QINFO_ADDR(pRuntimeEnv))) { + longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); } tsdbRetrieveDataBlockInfo(pQueryHandle, &blockInfo); @@ -2277,7 +2239,11 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { ensureOutputBuffer(pRuntimeEnv, &blockInfo); SDataStatis *pStatis = NULL; - SArray *pDataBlock = loadDataBlockOnDemand(pRuntimeEnv, pQueryHandle, &blockInfo, &pStatis); + SArray *pDataBlock = NULL; + if (loadDataBlockOnDemand(pRuntimeEnv, pQueryHandle, &blockInfo, &pStatis, &pDataBlock) == BLK_DATA_DISCARD) { + pQuery->current->lastKey = QUERY_IS_ASC_QUERY(pQuery)? blockInfo.window.ekey + step:blockInfo.window.skey + step; + continue; + } // query start position can not move into tableApplyFunctionsOnBlock due to limit/offset condition pQuery->pos = QUERY_IS_ASC_QUERY(pQuery)? 0 : blockInfo.rows - 1; @@ -2300,8 +2266,6 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { if (QUERY_IS_INTERVAL_QUERY(pQuery) && IS_MASTER_SCAN(pRuntimeEnv)) { if (Q_STATUS_EQUAL(pQuery->status, QUERY_COMPLETED)) { -// int32_t step = QUERY_IS_ASC_QUERY(pQuery) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP; - closeAllTimeWindow(&pRuntimeEnv->windowResInfo); // removeRedundantWindow(&pRuntimeEnv->windowResInfo, pTableQueryInfo->lastKey - step, step); pRuntimeEnv->windowResInfo.curIndex = pRuntimeEnv->windowResInfo.size - 1; // point to the last time window @@ -2996,16 +2960,23 @@ void switchCtxOrder(SQueryRuntimeEnv *pRuntimeEnv) { } } -void createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTableQuery, SPosInfo *posInfo, size_t interBufSize) { +int32_t createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTableQuery, SPosInfo *posInfo, size_t interBufSize) { int32_t numOfCols = pQuery->numOfOutput; pResultRow->resultInfo = calloc((size_t)numOfCols, sizeof(SResultInfo)); + if (pResultRow->resultInfo == NULL) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } pResultRow->pos = *posInfo; char* buf = calloc(1, interBufSize); + if (buf == NULL) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } // set the intermediate result output buffer setWindowResultInfo(pResultRow->resultInfo, pQuery, isSTableQuery, buf); + return TSDB_CODE_SUCCESS; } void resetCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) { @@ -3223,6 +3194,9 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI // add ref for table pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo); + if (pRuntimeEnv->pSecQueryHandle == NULL) { + longjmp(pRuntimeEnv->env, terrno); + } setQueryStatus(pQuery, QUERY_NOT_COMPLETED); switchCtxOrder(pRuntimeEnv); @@ -3295,6 +3269,9 @@ void scanOneTableDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) { } pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo); + if (pRuntimeEnv->pSecQueryHandle == NULL) { + longjmp(pRuntimeEnv->env, terrno); + } pRuntimeEnv->windowResInfo.curIndex = qstatus.windowIndex; setQueryStatus(pQuery, QUERY_NOT_COMPLETED); @@ -3304,8 +3281,9 @@ void scanOneTableDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) { cond.twindow.skey, cond.twindow.ekey); // check if query is killed or not - if (isQueryKilled(pQInfo)) { - return; + if (IS_QUERY_KILLED(pQInfo)) { + finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query + longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); } } @@ -3385,7 +3363,10 @@ static STableQueryInfo *createTableQueryInfo(SQueryRuntimeEnv *pRuntimeEnv, void if (QUERY_IS_INTERVAL_QUERY(pQuery) || pRuntimeEnv->groupbyNormalCol) { int32_t initialSize = 16; int32_t initialThreshold = 100; - initWindowResInfo(&pTableQueryInfo->windowResInfo, pRuntimeEnv, initialSize, initialThreshold, TSDB_DATA_TYPE_INT); + int32_t code = initWindowResInfo(&pTableQueryInfo->windowResInfo, pRuntimeEnv, initialSize, initialThreshold, TSDB_DATA_TYPE_INT); + if (code != TSDB_CODE_SUCCESS) { + return NULL; + } } else { // in other aggregate query, do not initialize the windowResInfo } @@ -3400,12 +3381,10 @@ void destroyTableQueryInfo(STableQueryInfo *pTableQueryInfo, int32_t numOfCols) cleanupTimeWindowInfo(&pTableQueryInfo->windowResInfo, numOfCols); } -#define SET_CURRENT_QUERY_TABLE_INFO(_runtime, _tableInfo) \ - do { \ - SQuery *_query = (_runtime)->pQuery; \ - _query->current = _tableInfo; \ - assert((((_tableInfo)->lastKey >= (_tableInfo)->win.skey) && QUERY_IS_ASC_QUERY(_query)) || \ - (((_tableInfo)->lastKey <= (_tableInfo)->win.skey) && !QUERY_IS_ASC_QUERY(_query))); \ +#define CHECK_QUERY_TIME_RANGE(_q, _tableInfo) \ + do { \ + assert((((_tableInfo)->lastKey >= (_tableInfo)->win.skey) && QUERY_IS_ASC_QUERY(_q)) || \ + (((_tableInfo)->lastKey <= (_tableInfo)->win.skey) && !QUERY_IS_ASC_QUERY(_q))); \ } while (0) /** @@ -3695,28 +3674,29 @@ void copyFromWindowResToSData(SQInfo *pQInfo, SWindowResInfo *pResultInfo) { assert(pQuery->rec.rows <= pQuery->rec.capacity); } -static void updateWindowResNumOfRes(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *pTableQueryInfo) { +static void updateWindowResNumOfRes(SQueryRuntimeEnv *pRuntimeEnv) { SQuery *pQuery = pRuntimeEnv->pQuery; // update the number of result for each, only update the number of rows for the corresponding window result. - if (!QUERY_IS_INTERVAL_QUERY(pQuery)) { + if (QUERY_IS_INTERVAL_QUERY(pQuery)) { + return; + } - for (int32_t i = 0; i < pRuntimeEnv->windowResInfo.size; ++i) { - SWindowResult *pResult = &pRuntimeEnv->windowResInfo.pResult[i]; + for (int32_t i = 0; i < pRuntimeEnv->windowResInfo.size; ++i) { + SWindowResult *pResult = &pRuntimeEnv->windowResInfo.pResult[i]; - for (int32_t j = 0; j < pQuery->numOfOutput; ++j) { - int32_t functionId = pRuntimeEnv->pCtx[j].functionId; - if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ) { - continue; - } - - pResult->numOfRows = MAX(pResult->numOfRows, pResult->resultInfo[j].numOfRes); + for (int32_t j = 0; j < pQuery->numOfOutput; ++j) { + int32_t functionId = pRuntimeEnv->pCtx[j].functionId; + if (functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TAGPRJ) { + continue; } + + pResult->numOfRows = MAX(pResult->numOfRows, pResult->resultInfo[j].numOfRes); } } } -void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pDataBlockInfo, SDataStatis *pStatis, +static void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pDataBlockInfo, SDataStatis *pStatis, SArray *pDataBlock, __block_search_fn_t searchFn) { SQuery * pQuery = pRuntimeEnv->pQuery; STableQueryInfo* pTableQueryInfo = pQuery->current; @@ -3729,8 +3709,6 @@ void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo * } else { blockwiseApplyFunctions(pRuntimeEnv, pStatis, pDataBlockInfo, pWindowResInfo, searchFn, pDataBlock); } - - updateWindowResNumOfRes(pRuntimeEnv, pTableQueryInfo); } bool queryHasRemainResults(SQueryRuntimeEnv* pRuntimeEnv) { @@ -3877,9 +3855,10 @@ static void queryCostStatis(SQInfo *pQInfo) { // pQInfo, pSummary->readDiskBlocks, pSummary->totalBlockSize, pSummary->loadBlocksUs / 1000.0, // pSummary->skippedFileBlocks, pSummary->totalGenData); - qDebug("QInfo:%p :cost summary: elpased time:%"PRId64" us, total blocks:%d, use block statis:%d, use block data:%d, " - "total rows:%"PRId64 ", check rows:%"PRId64, pQInfo, pSummary->elapsedTime, pSummary->totalBlocks, - pSummary->loadBlockStatis, pSummary->loadBlocks, pSummary->totalRows, pSummary->totalCheckedRows); + qDebug("QInfo:%p :cost summary: elapsed time:%"PRId64" us, io time:%"PRId64" us, total blocks:%d, load block statis:%d," + " load data block:%d, total rows:%"PRId64 ", check rows:%"PRId64, + pQInfo, pSummary->elapsedTime, pSummary->ioTime, pSummary->totalBlocks, pSummary->loadBlockStatis, + pSummary->loadBlocks, pSummary->totalRows, pSummary->totalCheckedRows); // qDebug("QInfo:%p cost: temp file:%d Bytes", pQInfo, pSummary->tmpBufferInDisk); // @@ -3949,9 +3928,17 @@ void skipBlocks(SQueryRuntimeEnv *pRuntimeEnv) { TsdbQueryHandleT pQueryHandle = pRuntimeEnv->pQueryHandle; SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER; - while (tsdbNextDataBlock(pQueryHandle)) { - if (isQueryKilled(GET_QINFO_ADDR(pRuntimeEnv))) { - return; + while (true) { + if (!tsdbNextDataBlock(pQueryHandle)) { + if (terrno != TSDB_CODE_SUCCESS) { + longjmp(pRuntimeEnv->env, terrno); + } + break; + } + + if (IS_QUERY_KILLED(GET_QINFO_ADDR(pRuntimeEnv))) { + finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query + longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); } tsdbRetrieveDataBlockInfo(pQueryHandle, &blockInfo); @@ -3992,7 +3979,14 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv, TSKEY* start) { STableQueryInfo *pTableQueryInfo = pQuery->current; 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); if (QUERY_IS_ASC_QUERY(pQuery)) { @@ -4091,16 +4085,16 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv, TSKEY* start) { 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; SQuery *pQuery = pQInfo->runtimeEnv.pQuery; if (onlyQueryTags(pQuery)) { - return; + return TSDB_CODE_SUCCESS; } - if (isSTableQuery && (!QUERY_IS_INTERVAL_QUERY(pQuery)) && (!isFixedOutputQuery(pQuery))) { - return; + if (isSTableQuery && (!QUERY_IS_INTERVAL_QUERY(pQuery)) && (!isFixedOutputQuery(pRuntimeEnv))) { + return TSDB_CODE_SUCCESS; } STsdbQueryCond cond = { @@ -4115,13 +4109,14 @@ static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) { && (cond.order == TSDB_ORDER_ASC) && (!QUERY_IS_INTERVAL_QUERY(pQuery)) && (!isGroupbyNormalCol(pQuery->pGroupbyExpr)) - && (!isFixedOutputQuery(pQuery)) + && (!isFixedOutputQuery(pRuntimeEnv)) ) { SArray* pa = GET_TABLEGROUP(pQInfo, 0); STableQueryInfo* pCheckInfo = taosArrayGetP(pa, 0); cond.twindow = pCheckInfo->win; } + terrno = TSDB_CODE_SUCCESS; if (isFirstLastRowQuery(pQuery)) { pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo); } else if (isPointInterpoQuery(pQuery)) { @@ -4129,6 +4124,7 @@ static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) { } else { pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo); } + return terrno; } static SFillColInfo* taosCreateFillColInfo(SQuery* pQuery) { @@ -4158,11 +4154,17 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQuery *pQuery = pQInfo->runtimeEnv.pQuery; + pQuery->precision = tsdbGetCfg(tsdb)->precision; + pRuntimeEnv->topBotQuery = isTopBottomQuery(pQuery); + pRuntimeEnv->hasTagResults = hasTagValOutput(pQuery); setScanLimitationByResultBuffer(pQuery); changeExecuteScanOrder(pQInfo, false); - setupQueryHandle(tsdb, pQInfo, isSTableQuery); + code = setupQueryHandle(tsdb, pQInfo, isSTableQuery); + if (code != TSDB_CODE_SUCCESS) { + return code; + } pQInfo->tsdb = tsdb; pQInfo->vgId = vgId; @@ -4203,7 +4205,10 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo type = TSDB_DATA_TYPE_INT; // group id } - initWindowResInfo(&pRuntimeEnv->windowResInfo, pRuntimeEnv, 32, 4096, type); + code = initWindowResInfo(&pRuntimeEnv->windowResInfo, pRuntimeEnv, 32, 4096, type); + if (code != TSDB_CODE_SUCCESS) { + return code; + } } } else if (pRuntimeEnv->groupbyNormalCol || QUERY_IS_INTERVAL_QUERY(pQuery)) { @@ -4220,7 +4225,10 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo type = TSDB_DATA_TYPE_TIMESTAMP; } - initWindowResInfo(&pRuntimeEnv->windowResInfo, pRuntimeEnv, rows, 4096, type); + code = initWindowResInfo(&pRuntimeEnv->windowResInfo, pRuntimeEnv, rows, 4096, type); + if (code != TSDB_CODE_SUCCESS) { + return code; + } } if (pQuery->fillType != TSDB_FILL_NONE && !isPointInterpoQuery(pQuery)) { @@ -4236,10 +4244,6 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo pQuery->fillType, pColInfo); } - // todo refactor - pRuntimeEnv->topBotQuery = isTopBottomQuery(pQuery); - pRuntimeEnv->hasTagResults = hasTagValOutput(pQuery); - setQueryStatus(pQuery, QUERY_NOT_COMPLETED); return TSDB_CODE_SUCCESS; } @@ -4255,6 +4259,23 @@ static void enableExecutionForNextTable(SQueryRuntimeEnv *pRuntimeEnv) { } } +static FORCE_INLINE void setEnvForEachBlock(SQInfo* pQInfo, STableQueryInfo* pTableQueryInfo, SDataBlockInfo* pBlockInfo) { + SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv; + SQuery* pQuery = pQInfo->runtimeEnv.pQuery; + int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); + + if (!QUERY_IS_INTERVAL_QUERY(pQuery)) { + setExecutionContext(pQInfo, pTableQueryInfo->groupIndex, pBlockInfo->window.ekey + step); + } else { // interval query + TSKEY nextKey = pBlockInfo->window.skey; + setIntervalQueryRange(pQInfo, nextKey); + + if (pRuntimeEnv->hasTagResults || pRuntimeEnv->pTSBuf != NULL) { + setAdditionalInfo(pQInfo, pTableQueryInfo->pTable, pTableQueryInfo); + } + } +} + static int64_t scanMultiTableDataBlocks(SQInfo *pQInfo) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQuery* pQuery = pRuntimeEnv->pQuery; @@ -4265,36 +4286,41 @@ static int64_t scanMultiTableDataBlocks(SQInfo *pQInfo) { TsdbQueryHandleT pQueryHandle = IS_MASTER_SCAN(pRuntimeEnv)? pRuntimeEnv->pQueryHandle : pRuntimeEnv->pSecQueryHandle; SDataBlockInfo blockInfo = SDATA_BLOCK_INITIALIZER; - while (tsdbNextDataBlock(pQueryHandle)) { - summary->totalBlocks += 1; - if (isQueryKilled(pQInfo)) { + int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); + + while (true) { + if (!tsdbNextDataBlock(pQueryHandle)) { + if (terrno != TSDB_CODE_SUCCESS) { + longjmp(pRuntimeEnv->env, terrno); + } break; } + summary->totalBlocks += 1; + + if (IS_QUERY_KILLED(pQInfo)) { + longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); + } + tsdbRetrieveDataBlockInfo(pQueryHandle, &blockInfo); STableQueryInfo **pTableQueryInfo = (STableQueryInfo**) taosHashGet(pQInfo->tableqinfoGroupInfo.map, &blockInfo.tid, sizeof(blockInfo.tid)); if(pTableQueryInfo == NULL) { break; } - assert(*pTableQueryInfo != NULL); - SET_CURRENT_QUERY_TABLE_INFO(pRuntimeEnv, *pTableQueryInfo); - - SDataStatis *pStatis = NULL; - SArray *pDataBlock = loadDataBlockOnDemand(pRuntimeEnv, pQueryHandle, &blockInfo, &pStatis); + pQuery->current = *pTableQueryInfo; + CHECK_QUERY_TIME_RANGE(pQuery, *pTableQueryInfo); if (!pRuntimeEnv->groupbyNormalCol) { - if (!QUERY_IS_INTERVAL_QUERY(pQuery)) { - int32_t step = QUERY_IS_ASC_QUERY(pQuery)? 1:-1; - setExecutionContext(pQInfo, (*pTableQueryInfo)->groupIndex, blockInfo.window.ekey + step); - } else { // interval query - TSKEY nextKey = blockInfo.window.skey; - setIntervalQueryRange(pQInfo, nextKey); + setEnvForEachBlock(pQInfo, *pTableQueryInfo, &blockInfo); + } - if (pRuntimeEnv->hasTagResults || pRuntimeEnv->pTSBuf != NULL) { - setAdditionalInfo(pQInfo, (*pTableQueryInfo)->pTable, *pTableQueryInfo); - } - } + SDataStatis *pStatis = NULL; + SArray *pDataBlock = NULL; + + if (loadDataBlockOnDemand(pRuntimeEnv, pQueryHandle, &blockInfo, &pStatis, &pDataBlock) == BLK_DATA_DISCARD) { + pQuery->current->lastKey = QUERY_IS_ASC_QUERY(pQuery)? blockInfo.window.ekey + step:blockInfo.window.skey + step; + continue; } summary->totalRows += blockInfo.rows; @@ -4304,6 +4330,8 @@ static int64_t scanMultiTableDataBlocks(SQInfo *pQInfo) { pQInfo, blockInfo.uid, blockInfo.tid, blockInfo.window.skey, blockInfo.window.ekey, blockInfo.rows, pQuery->current->lastKey); } + updateWindowResNumOfRes(pRuntimeEnv); + int64_t et = taosGetTimestampMs(); return et - st; } @@ -4316,7 +4344,9 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { SArray *group = GET_TABLEGROUP(pQInfo, 0); STableQueryInfo* pCheckInfo = taosArrayGetP(group, index); - setTagVal(pRuntimeEnv, pCheckInfo->pTable, pQInfo->tsdb); + if (pRuntimeEnv->hasTagResults || pRuntimeEnv->pTSBuf != NULL) { + setTagVal(pRuntimeEnv, pCheckInfo->pTable, pQInfo->tsdb); + } STableId* id = TSDB_TABLEID(pCheckInfo->pTable); qDebug("QInfo:%p query on (%d): uid:%" PRIu64 ", tid:%d, qrange:%" PRId64 "-%" PRId64, pQInfo, index, @@ -4346,6 +4376,9 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { pRuntimeEnv->pQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &gp, pQInfo); taosArrayDestroy(tx); taosArrayDestroy(g1); + if (pRuntimeEnv->pQueryHandle == NULL) { + longjmp(pRuntimeEnv->env, terrno); + } if (pRuntimeEnv->pTSBuf != NULL) { if (pRuntimeEnv->cur.vgroupIndex == -1) { @@ -4413,6 +4446,12 @@ static void sequentialTableProcess(SQInfo *pQInfo) { } else { pRuntimeEnv->pQueryHandle = tsdbQueryRowsInExternalWindow(pQInfo->tsdb, &cond, &gp, pQInfo); } + + taosArrayDestroy(tx); + taosArrayDestroy(g1); + if (pRuntimeEnv->pQueryHandle == NULL) { + longjmp(pRuntimeEnv->env, terrno); + } initCtxOutputBuf(pRuntimeEnv); @@ -4477,6 +4516,9 @@ static void sequentialTableProcess(SQInfo *pQInfo) { pRuntimeEnv->pQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &gp, pQInfo); taosArrayDestroy(g1); taosArrayDestroy(tx); + if (pRuntimeEnv->pQueryHandle == NULL) { + longjmp(pRuntimeEnv->env, terrno); + } SArray* s = tsdbGetQueriedTableList(pRuntimeEnv->pQueryHandle); assert(taosArrayGetSize(s) >= 1); @@ -4549,8 +4591,8 @@ static void sequentialTableProcess(SQInfo *pQInfo) { 1 == taosArrayGetSize(pQInfo->tableqinfoGroupInfo.pGroupList)); while (pQInfo->tableIndex < pQInfo->tableqinfoGroupInfo.numOfTables) { - if (isQueryKilled(pQInfo)) { - return; + if (IS_QUERY_KILLED(pQInfo)) { + longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); } pQuery->current = taosArrayGetP(group, pQInfo->tableIndex); @@ -4672,6 +4714,9 @@ static void doSaveContext(SQInfo *pQInfo) { pRuntimeEnv->prevGroupId = INT32_MIN; pRuntimeEnv->pSecQueryHandle = tsdbQueryTables(pQInfo->tsdb, &cond, &pQInfo->tableGroupInfo, pQInfo); + if (pRuntimeEnv->pSecQueryHandle == NULL) { + longjmp(pRuntimeEnv->env, terrno); + } setQueryStatus(pQuery, QUERY_NOT_COMPLETED); switchCtxOrder(pRuntimeEnv); @@ -4744,9 +4789,10 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { qDebug("QInfo:%p master scan completed, elapsed time: %" PRId64 "ms, reverse scan start", pQInfo, el); // query error occurred or query is killed, abort current execution - if (pQInfo->code != TSDB_CODE_SUCCESS || isQueryKilled(pQInfo)) { + if (pQInfo->code != TSDB_CODE_SUCCESS || IS_QUERY_KILLED(pQInfo)) { qDebug("QInfo:%p query killed or error occurred, code:%s, abort", pQInfo, tstrerror(pQInfo->code)); - return; + finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query + longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); } // close all time window results @@ -4766,9 +4812,10 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { setQueryStatus(pQuery, QUERY_COMPLETED); - if (pQInfo->code != TSDB_CODE_SUCCESS || isQueryKilled(pQInfo)) { + if (pQInfo->code != TSDB_CODE_SUCCESS || IS_QUERY_KILLED(pQInfo)) { qDebug("QInfo:%p query killed or error occurred, code:%s, abort", pQInfo, tstrerror(pQInfo->code)); - return; + finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query + longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); } if (QUERY_IS_INTERVAL_QUERY(pQuery) || isSumAvgRateQuery(pQuery)) { @@ -4806,8 +4853,9 @@ static void tableFixedOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) scanOneTableDataBlocks(pRuntimeEnv, pTableInfo->lastKey); finalizeQueryResult(pRuntimeEnv); - if (isQueryKilled(pQInfo)) { - return; + if (IS_QUERY_KILLED(pQInfo)) { + finalizeQueryResult(pRuntimeEnv); // clean up allocated resource during query + longjmp(pRuntimeEnv->env, TSDB_CODE_TSC_QUERY_CANCELLED); } // since the numOfRows must be identical for all sql functions that are allowed to be executed simutaneously. @@ -4839,10 +4887,6 @@ static void tableMultiOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) scanOneTableDataBlocks(pRuntimeEnv, pQuery->current->lastKey); finalizeQueryResult(pRuntimeEnv); - if (isQueryKilled(pQInfo)) { - return; - } - pQuery->rec.rows = getNumOfResult(pRuntimeEnv); if (pQuery->limit.offset > 0 && pQuery->numOfFilterCols > 0 && pQuery->rec.rows > 0) { skipResults(pRuntimeEnv); @@ -4887,10 +4931,6 @@ static void tableIntervalProcessImpl(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) while (1) { scanOneTableDataBlocks(pRuntimeEnv, start); - if (isQueryKilled(GET_QINFO_ADDR(pRuntimeEnv))) { - return; - } - assert(!Q_STATUS_EQUAL(pQuery->status, QUERY_NOT_COMPLETED)); finalizeQueryResult(pRuntimeEnv); @@ -5024,7 +5064,7 @@ static void tableQueryImpl(SQInfo *pQInfo) { // group by normal column, sliding window query, interval query are handled by interval query processor if (QUERY_IS_INTERVAL_QUERY(pQuery) || pRuntimeEnv->groupbyNormalCol) { // interval (down sampling operation) tableIntervalProcess(pQInfo, item); - } else if (isFixedOutputQuery(pQuery)) { + } else if (isFixedOutputQuery(pRuntimeEnv)) { tableFixedOutputProcess(pQInfo, item); } else { // diff/add/multiply/subtract/division assert(pQuery->checkBuffer == 1); @@ -5044,7 +5084,7 @@ static void stableQueryImpl(SQInfo *pQInfo) { int64_t st = taosGetTimestampUs(); if (QUERY_IS_INTERVAL_QUERY(pQuery) || - (isFixedOutputQuery(pQuery) && (!isPointInterpoQuery(pQuery)) && !pRuntimeEnv->groupbyNormalCol && + (isFixedOutputQuery(pRuntimeEnv) && (!isPointInterpoQuery(pQuery)) && !pRuntimeEnv->groupbyNormalCol && !isFirstLastRowQuery(pQuery))) { multiTableQueryProcess(pQInfo); } else { @@ -5052,6 +5092,7 @@ static void stableQueryImpl(SQInfo *pQInfo) { isFirstLastRowQuery(pQuery) || pRuntimeEnv->groupbyNormalCol); sequentialTableProcess(pQInfo); + } // record the total elapsed time @@ -5383,10 +5424,11 @@ static int32_t buildAirthmeticExprFromMsg(SExprInfo *pArithExprInfo, SQueryTable qDebug("qmsg:%p create arithmetic expr from binary string: %s", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz); tExprNode* pExprNode = NULL; - TRY(32) { + TRY(TSDB_MAX_TAGS) { pExprNode = exprTreeFromBinary(pArithExprInfo->base.arg[0].argValue.pz, pArithExprInfo->base.arg[0].argBytes); } CATCH( code ) { CLEANUP_EXECUTE(); + qError("qmsg:%p failed to create arithmetic expression string from:%s, reason: %s", pQueryMsg, pArithExprInfo->base.arg[0].argValue.pz, tstrerror(code)); return code; } END_TRY @@ -5644,17 +5686,23 @@ static void freeQInfo(SQInfo *pQInfo); static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, SSqlGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols) { - SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo)); - if (pQInfo == NULL) { - return NULL; - } - - SQuery *pQuery = calloc(1, sizeof(SQuery)); - pQInfo->runtimeEnv.pQuery = pQuery; - int16_t numOfCols = pQueryMsg->numOfCols; int16_t numOfOutput = pQueryMsg->numOfOutput; + SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo)); + if (pQInfo == NULL) { + goto _cleanup_qinfo; + } + // to make sure third party won't overwrite this structure + pQInfo->signature = pQInfo; + pQInfo->tableGroupInfo = *pTableGroupInfo; + + SQuery *pQuery = calloc(1, sizeof(SQuery)); + if (pQuery == NULL) { + goto _cleanup_query; + } + pQInfo->runtimeEnv.pQuery = pQuery; + pQuery->numOfCols = numOfCols; pQuery->numOfOutput = numOfOutput; pQuery->limit.limit = pQueryMsg->limit; @@ -5668,6 +5716,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, pQuery->slidingTimeUnit = pQueryMsg->slidingTimeUnit; pQuery->fillType = pQueryMsg->fillType; pQuery->numOfTags = pQueryMsg->numOfTags; + pQuery->tagColList = pTagCols; // todo do not allocate ?? pQuery->colList = calloc(numOfCols, sizeof(SSingleColumnFilterInfo)); @@ -5680,8 +5729,6 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, pQuery->colList[i].filters = tscFilterInfoClone(pQueryMsg->colList[i].filters, pQuery->colList[i].numOfFilters); } - pQuery->tagColList = pTagCols; - // calculate the result row size for (int16_t col = 0; col < numOfOutput; ++col) { assert(pExprs[col].bytes > 0); @@ -5726,10 +5773,6 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, memcpy(pQuery->fillVal, (char *)pQueryMsg->fillVal, pQuery->numOfOutput * sizeof(int64_t)); } - // to make sure third party won't overwrite this structure - pQInfo->signature = pQInfo; - - pQInfo->tableGroupInfo = *pTableGroupInfo; size_t numOfGroups = 0; if (pTableGroupInfo->pGroupList != NULL) { numOfGroups = taosArrayGetSize(pTableGroupInfo->pGroupList); @@ -5753,6 +5796,10 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, size_t s = taosArrayGetSize(pa); SArray* p1 = taosArrayInit(s, POINTER_BYTES); + if (p1 == NULL) { + goto _cleanup; + } + taosArrayPush(pQInfo->tableqinfoGroupInfo.pGroupList, &p1); for(int32_t j = 0; j < s; ++j) { void* pTable = taosArrayGetP(pa, j); @@ -5767,13 +5814,14 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, void* buf = pQInfo->pBuf + index * sizeof(STableQueryInfo); STableQueryInfo* item = createTableQueryInfo(&pQInfo->runtimeEnv, pTable, window, buf); + if (item == NULL) { + goto _cleanup; + } item->groupIndex = i; taosArrayPush(p1, &item); taosHashPut(pQInfo->tableqinfoGroupInfo.map, &id->tid, sizeof(id->tid), &item, POINTER_BYTES); index += 1; } - - taosArrayPush(pQInfo->tableqinfoGroupInfo.pGroupList, &p1); } pQInfo->arrTableIdInfo = taosArrayInit(tableIndex, sizeof(STableIdInfo)); @@ -5792,6 +5840,21 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, qDebug("qmsg:%p QInfo:%p created", pQueryMsg, pQInfo); return pQInfo; +_cleanup_qinfo: + tsdbDestoryTableGroup(pTableGroupInfo); + +_cleanup_query: + taosArrayDestroy(pGroupbyExpr->columnInfo); + tfree(pGroupbyExpr); + tfree(pTagCols); + for (int32_t i = 0; i < numOfOutput; ++i) { + SExprInfo* pExprInfo = &pExprs[i]; + if (pExprInfo->pExpr != NULL) { + tExprTreeDestroy(&pExprInfo->pExpr, NULL); + } + } + tfree(pExprs); + _cleanup: freeQInfo(pQInfo); return NULL; @@ -5811,7 +5874,7 @@ static bool isValidQInfo(void *param) { return (sig == (uint64_t)pQInfo); } -static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQInfo *pQInfo, bool isSTable, void* param, _qinfo_free_fn_t fn) { +static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQInfo *pQInfo, bool isSTable, void* param) { int32_t code = TSDB_CODE_SUCCESS; SQuery *pQuery = pQInfo->runtimeEnv.pQuery; @@ -5836,7 +5899,6 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQ } pQInfo->param = param; - pQInfo->freeFn = fn; if (pQInfo->tableqinfoGroupInfo.numOfTables == 0) { qDebug("QInfo:%p no table qualified for tag filter, abort query", pQInfo); @@ -5911,19 +5973,21 @@ static void freeQInfo(SQInfo *pQInfo) { } // todo refactor, extract method to destroytableDataInfo - int32_t numOfGroups = GET_NUM_OF_TABLEGROUP(pQInfo); - for (int32_t i = 0; i < numOfGroups; ++i) { - SArray *p = GET_TABLEGROUP(pQInfo, i); + if (pQInfo->tableqinfoGroupInfo.pGroupList != NULL) { + int32_t numOfGroups = GET_NUM_OF_TABLEGROUP(pQInfo); + for (int32_t i = 0; i < numOfGroups; ++i) { + SArray *p = GET_TABLEGROUP(pQInfo, i); - size_t num = taosArrayGetSize(p); - for(int32_t j = 0; j < num; ++j) { - STableQueryInfo* item = taosArrayGetP(p, j); - if (item != NULL) { - destroyTableQueryInfo(item, pQuery->numOfOutput); + size_t num = taosArrayGetSize(p); + for(int32_t j = 0; j < num; ++j) { + STableQueryInfo* item = taosArrayGetP(p, j); + if (item != NULL) { + destroyTableQueryInfo(item, pQuery->numOfOutput); + } } - } - taosArrayDestroy(p); + taosArrayDestroy(p); + } } tfree(pQInfo->pBuf); @@ -6038,8 +6102,7 @@ typedef struct SQueryMgmt { pthread_mutex_t lock; } SQueryMgmt; -int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, void* param, _qinfo_free_fn_t fn, - qinfo_t* pQInfo) { +int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, void* param, qinfo_t* pQInfo) { assert(pQueryMsg != NULL && tsdb != NULL); int32_t code = TSDB_CODE_SUCCESS; @@ -6105,6 +6168,9 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, vo code = tsdbQuerySTableByTagCond(tsdb, id->uid, tagCond, pQueryMsg->tagCondLen, pQueryMsg->tagNameRelType, tbnameCond, &tableGroupInfo, pGroupColIndex, numOfGroupByCols); if (code != TSDB_CODE_SUCCESS) { + if (code == TSDB_CODE_QRY_EXCEED_TAGS_LIMIT) { + qError("qmsg:%p failed to QueryStable, reason: %s", pQueryMsg, tstrerror(code)); + } goto _over; } } else { @@ -6129,7 +6195,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, vo goto _over; } - code = initQInfo(pQueryMsg, tsdb, vgId, *pQInfo, isSTableQuery, param, fn); + code = initQInfo(pQueryMsg, tsdb, vgId, *pQInfo, isSTableQuery, param); _over: free(tagCond); @@ -6152,44 +6218,21 @@ _over: //pQInfo already freed in initQInfo, but *pQInfo may not pointer to null; if (code != TSDB_CODE_SUCCESS) { *pQInfo = NULL; - } else { - SQInfo* pq = (SQInfo*) (*pQInfo); - - T_REF_INC(pq); - T_REF_INC(pq); } // if failed to add ref for all meters in this query, abort current query return code; } -static void doDestoryQueryInfo(SQInfo* pQInfo) { - assert(pQInfo != NULL); - qDebug("QInfo:%p query completed", pQInfo); - queryCostStatis(pQInfo); // print the query cost summary - freeQInfo(pQInfo); -} - void qDestroyQueryInfo(qinfo_t qHandle) { SQInfo* pQInfo = (SQInfo*) qHandle; if (!isValidQInfo(pQInfo)) { return; } - int32_t ref = T_REF_DEC(pQInfo); - qDebug("QInfo:%p dec refCount, value:%d", pQInfo, ref); - - if (ref == 0) { - _qinfo_free_fn_t freeFp = pQInfo->freeFn; - void* param = pQInfo->param; - - doDestoryQueryInfo(pQInfo); - if (freeFp != NULL) { - assert(param != NULL); - freeFp(param); - } - - } + qDebug("QInfo:%p query completed", pQInfo); + queryCostStatis(pQInfo); // print the query cost summary + freeQInfo(pQInfo); } void qTableQuery(qinfo_t qinfo) { @@ -6200,31 +6243,24 @@ void qTableQuery(qinfo_t qinfo) { return; } - if (isQueryKilled(pQInfo)) { + if (IS_QUERY_KILLED(pQInfo)) { qDebug("QInfo:%p it is already killed, abort", pQInfo); - sem_post(&pQInfo->dataReady); - qDestroyQueryInfo(pQInfo); return; } if (pQInfo->tableqinfoGroupInfo.numOfTables == 0) { qDebug("QInfo:%p no table exists for query, abort", pQInfo); - sem_post(&pQInfo->dataReady); - qDestroyQueryInfo(pQInfo); return; } - int32_t ret = setjmp(pQInfo->runtimeEnv.env); - // error occurs, record the error code and return to client + int32_t ret = setjmp(pQInfo->runtimeEnv.env); if (ret != TSDB_CODE_SUCCESS) { pQInfo->code = ret; - qDebug("QInfo:%p query abort due to error occurs, code:%s", pQInfo, tstrerror(pQInfo->code)); + qDebug("QInfo:%p query abort due to error/cancel occurs, code:%s", pQInfo, tstrerror(pQInfo->code)); sem_post(&pQInfo->dataReady); - qDestroyQueryInfo(pQInfo); - return; } @@ -6241,7 +6277,7 @@ void qTableQuery(qinfo_t qinfo) { } SQuery* pQuery = pRuntimeEnv->pQuery; - if (isQueryKilled(pQInfo)) { + if (IS_QUERY_KILLED(pQInfo)) { qDebug("QInfo:%p query is killed", pQInfo); } else if (pQuery->rec.rows == 0) { qDebug("QInfo:%p over, %zu tables queried, %"PRId64" rows are returned", pQInfo, pQInfo->tableqinfoGroupInfo.numOfTables, pQuery->rec.total); @@ -6251,7 +6287,6 @@ void qTableQuery(qinfo_t qinfo) { } sem_post(&pQInfo->dataReady); - qDestroyQueryInfo(pQInfo); } int32_t qRetrieveQueryResultInfo(qinfo_t qinfo) { @@ -6262,7 +6297,7 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo) { } SQuery *pQuery = pQInfo->runtimeEnv.pQuery; - if (isQueryKilled(pQInfo)) { + if (IS_QUERY_KILLED(pQInfo)) { qDebug("QInfo:%p query is killed, code:%d", pQInfo, pQInfo->code); return pQInfo->code; } @@ -6295,7 +6330,7 @@ bool qHasMoreResultsToRetrieve(qinfo_t qinfo) { } if (ret) { - T_REF_INC(pQInfo); +// T_REF_INC(pQInfo); qDebug("QInfo:%p has more results waits for client retrieve", pQInfo); } @@ -6337,7 +6372,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co code = pQInfo->code; } - if (isQueryKilled(pQInfo) || Q_STATUS_EQUAL(pQuery->status, QUERY_OVER)) { + if (IS_QUERY_KILLED(pQInfo) || Q_STATUS_EQUAL(pQuery->status, QUERY_OVER)) { (*pRsp)->completed = 1; // notify no more result to client } @@ -6351,8 +6386,8 @@ int32_t qKillQuery(qinfo_t qinfo) { return TSDB_CODE_QRY_INVALID_QHANDLE; } + sem_post(&pQInfo->dataReady); setQueryKilled(pQInfo); - qDestroyQueryInfo(pQInfo); return TSDB_CODE_SUCCESS; } @@ -6497,6 +6532,7 @@ void freeqinfoFn(void *qhandle) { } qKillQuery(*handle); + qDestroyQueryInfo(*handle); } void* qOpenQueryMgmt(int32_t vgId) { @@ -6515,7 +6551,12 @@ void* qOpenQueryMgmt(int32_t vgId) { return pQueryHandle; } -void qSetQueryMgmtClosed(void* pQMgmt) { +static void queryMgmtKillQueryFn(void* handle) { + void** fp = (void**)handle; + qKillQuery(*fp); +} + +void qQueryMgmtNotifyClosed(void* pQMgmt) { if (pQMgmt == NULL) { return; } @@ -6527,7 +6568,7 @@ void qSetQueryMgmtClosed(void* pQMgmt) { pQueryMgmt->closed = true; pthread_mutex_unlock(&pQueryMgmt->lock); - taosCacheRefresh(pQueryMgmt->qinfoPool, freeqinfoFn); + taosCacheRefresh(pQueryMgmt->qinfoPool, queryMgmtKillQueryFn); } void qCleanupQueryMgmt(void* pQMgmt) { @@ -6559,13 +6600,14 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qInfo) { SQueryMgmt *pQueryMgmt = pMgmt; if (pQueryMgmt->qinfoPool == NULL) { + qError("QInfo:%p failed to add qhandle into qMgmt, since qMgmt is closed", (void *)qInfo); return NULL; } pthread_mutex_lock(&pQueryMgmt->lock); if (pQueryMgmt->closed) { pthread_mutex_unlock(&pQueryMgmt->lock); - + qError("QInfo:%p failed to add qhandle into cache, since qMgmt is colsing", (void *)qInfo); return NULL; } else { uint64_t handleVal = (uint64_t) qInfo; diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index dce2c24ea0..acdc46fcc1 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -50,9 +50,15 @@ int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRun // use the pointer arraylist pWindowResInfo->pResult = calloc(threshold, sizeof(SWindowResult)); + if (pWindowResInfo->pResult == NULL) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } for (int32_t i = 0; i < pWindowResInfo->capacity; ++i) { SPosInfo posInfo = {-1, -1}; - createQueryResultInfo(pRuntimeEnv->pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, &posInfo, pRuntimeEnv->interBufSize); + int32_t code = createQueryResultInfo(pRuntimeEnv->pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, &posInfo, pRuntimeEnv->interBufSize); + if (code != TSDB_CODE_SUCCESS) { + return code; + } } return TSDB_CODE_SUCCESS; @@ -76,9 +82,11 @@ void cleanupTimeWindowInfo(SWindowResInfo *pWindowResInfo, int32_t numOfCols) { return; } - for (int32_t i = 0; i < pWindowResInfo->capacity; ++i) { - SWindowResult *pResult = &pWindowResInfo->pResult[i]; - destroyTimeWindowRes(pResult, numOfCols); + if (pWindowResInfo->pResult != NULL) { + for (int32_t i = 0; i < pWindowResInfo->capacity; ++i) { + SWindowResult *pResult = &pWindowResInfo->pResult[i]; + destroyTimeWindowRes(pResult, numOfCols); + } } taosHashCleanup(pWindowResInfo->hashList); diff --git a/src/query/src/qast.c b/src/query/src/qast.c index ffd339f111..c5f4a9ce6c 100644 --- a/src/query/src/qast.c +++ b/src/query/src/qast.c @@ -962,10 +962,13 @@ static UNUSED_FUNC char* exception_strdup(const char* str) { static tExprNode* exprTreeFromBinaryImpl(SBufferReader* br) { int32_t anchor = CLEANUP_GET_ANCHOR(); + if (CLEANUP_EXCEED_LIMIT()) { + THROW(TSDB_CODE_QRY_EXCEED_TAGS_LIMIT); + return NULL; + } tExprNode* pExpr = exception_calloc(1, sizeof(tExprNode)); CLEANUP_PUSH_VOID_PTR_PTR(true, tExprNodeDestroy, pExpr, NULL); - pExpr->nodeType = tbufReadUint8(br); if (pExpr->nodeType == TSQL_NODE_VALUE) { @@ -995,7 +998,6 @@ static tExprNode* exprTreeFromBinaryImpl(SBufferReader* br) { pExpr->_node.hasPK = tbufReadUint8(br); pExpr->_node.pLeft = exprTreeFromBinaryImpl(br); pExpr->_node.pRight = exprTreeFromBinaryImpl(br); - assert(pExpr->_node.pLeft != NULL && pExpr->_node.pRight != NULL); } diff --git a/src/query/src/qparserImpl.c b/src/query/src/qparserImpl.c index d4ac540d2f..ecc11f8f4d 100644 --- a/src/query/src/qparserImpl.c +++ b/src/query/src/qparserImpl.c @@ -896,6 +896,7 @@ void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo) { pDBInfo->compressionLevel = -1; pDBInfo->walLevel = -1; + pDBInfo->fsyncPeriod = -1; pDBInfo->commitTime = -1; pDBInfo->maxTablesPerVnode = -1; diff --git a/src/query/src/qtokenizer.c b/src/query/src/qtokenizer.c index 80d59a384e..0ea0ff7bf3 100644 --- a/src/query/src/qtokenizer.c +++ b/src/query/src/qtokenizer.c @@ -124,6 +124,7 @@ static SKeyword keywordTable[] = { {"CACHE", TK_CACHE}, {"CTIME", TK_CTIME}, {"WAL", TK_WAL}, + {"FSYNC", TK_FSYNC}, {"COMP", TK_COMP}, {"PRECISION", TK_PRECISION}, {"LP", TK_LP}, @@ -509,10 +510,11 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { for (i = 1; isdigit(z[i]); i++) { } - /* here is the 1a/2s/3m/9y */ - if ((z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' || z[i] == 'y' || - z[i] == 'w' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || - z[i] == 'Y' || z[i] == 'W') && + /* here is the 1u/1a/2s/3m/9y */ + if ((z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' || + z[i] == 'y' || z[i] == 'w' || + z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || + z[i] == 'Y' || z[i] == 'W') && (isIdChar[(uint8_t)z[i + 1]] == 0)) { *tokenType = TK_VARIABLE; i += 1; diff --git a/src/query/src/qtsbuf.c b/src/query/src/qtsbuf.c index fedaa315d3..b84fbded38 100644 --- a/src/query/src/qtsbuf.c +++ b/src/query/src/qtsbuf.c @@ -79,7 +79,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { pTSBuf->numOfAlloc = header.numOfVnode; STSVnodeBlockInfoEx* tmp = realloc(pTSBuf->pData, sizeof(STSVnodeBlockInfoEx) * pTSBuf->numOfAlloc); if (tmp == NULL) { - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); return NULL; } @@ -92,7 +92,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { pTSBuf->tsOrder = header.tsOrder; if (pTSBuf->tsOrder != TSDB_ORDER_ASC && pTSBuf->tsOrder != TSDB_ORDER_DESC) { // tscError("invalid order info in buf:%d", pTSBuf->tsOrder); - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); return NULL; } @@ -100,7 +100,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { STSVnodeBlockInfo* buf = (STSVnodeBlockInfo*)calloc(1, infoSize); if (buf == NULL) { - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); return NULL; } @@ -120,7 +120,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { struct stat fileStat; if (fstat(fileno(pTSBuf->f), &fileStat) != 0) { - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); return NULL; } @@ -137,7 +137,7 @@ STSBuf* tsBufCreateFromFile(const char* path, bool autoDelete) { return pTSBuf; } -void* tsBufDestory(STSBuf* pTSBuf) { +void* tsBufDestroy(STSBuf* pTSBuf) { if (pTSBuf == NULL) { return NULL; } @@ -920,13 +920,13 @@ static STSBuf* allocResForTSBuf(STSBuf* pTSBuf) { pTSBuf->numOfAlloc = INITIAL_VNODEINFO_SIZE; pTSBuf->pData = calloc(pTSBuf->numOfAlloc, sizeof(STSVnodeBlockInfoEx)); if (pTSBuf->pData == NULL) { - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); return NULL; } pTSBuf->tsData.rawBuf = malloc(MEM_BUF_SIZE); if (pTSBuf->tsData.rawBuf == NULL) { - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); return NULL; } @@ -936,13 +936,13 @@ static STSBuf* allocResForTSBuf(STSBuf* pTSBuf) { pTSBuf->assistBuf = malloc(MEM_BUF_SIZE); if (pTSBuf->assistBuf == NULL) { - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); return NULL; } pTSBuf->block.payload = malloc(MEM_BUF_SIZE); if (pTSBuf->block.payload == NULL) { - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); return NULL; } diff --git a/src/query/src/sql.c b/src/query/src/sql.c index eafb052593..ac9952bb97 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -25,11 +25,11 @@ #include /************ Begin %include sections from the grammar ************************/ -#include -#include #include #include #include +#include +#include #include "qsqlparser.h" #include "tcmdtype.h" #include "tstoken.h" @@ -97,26 +97,26 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 270 +#define YYNOCODE 272 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SSQLToken typedef union { int yyinit; ParseTOKENTYPE yy0; - int yy150; - SQuerySQL* yy190; - SCreateAcctSQL yy219; - tSQLExprList* yy260; - SSubclauseInfo* yy263; - int64_t yy279; - SLimitVal yy284; - tVariantList* yy322; - TAOS_FIELD yy325; - tFieldList* yy369; - SCreateDBInfo yy374; - SCreateTableSQL* yy408; - tSQLExpr* yy500; - tVariant yy518; + SSubclauseInfo* yy25; + tSQLExpr* yy66; + SCreateAcctSQL yy73; + int yy82; + SQuerySQL* yy150; + SCreateDBInfo yy158; + TAOS_FIELD yy181; + SLimitVal yy188; + tSQLExprList* yy224; + int64_t yy271; + tVariant yy312; + SCreateTableSQL* yy374; + tFieldList* yy449; + tVariantList* yy494; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -126,17 +126,17 @@ typedef union { #define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 -#define YYNSTATE 241 -#define YYNRULE 220 -#define YYNTOKEN 205 -#define YY_MAX_SHIFT 240 -#define YY_MIN_SHIFTREDUCE 397 -#define YY_MAX_SHIFTREDUCE 616 -#define YY_ERROR_ACTION 617 -#define YY_ACCEPT_ACTION 618 -#define YY_NO_ACTION 619 -#define YY_MIN_REDUCE 620 -#define YY_MAX_REDUCE 839 +#define YYNSTATE 242 +#define YYNRULE 223 +#define YYNTOKEN 206 +#define YY_MAX_SHIFT 241 +#define YY_MIN_SHIFTREDUCE 401 +#define YY_MAX_SHIFTREDUCE 623 +#define YY_ERROR_ACTION 624 +#define YY_ACCEPT_ACTION 625 +#define YY_NO_ACTION 626 +#define YY_MIN_REDUCE 627 +#define YY_MAX_REDUCE 849 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -202,216 +202,217 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (541) +#define YY_ACTTAB_COUNT (547) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 718, 438, 717, 11, 716, 134, 618, 240, 719, 439, - /* 10 */ 721, 720, 758, 41, 43, 21, 35, 36, 153, 238, - /* 20 */ 135, 29, 135, 438, 197, 39, 37, 40, 38, 158, - /* 30 */ 827, 439, 826, 34, 33, 139, 135, 32, 31, 30, - /* 40 */ 41, 43, 747, 35, 36, 157, 827, 166, 29, 733, - /* 50 */ 103, 197, 39, 37, 40, 38, 182, 21, 103, 99, - /* 60 */ 34, 33, 755, 155, 32, 31, 30, 398, 399, 400, - /* 70 */ 401, 402, 403, 404, 405, 406, 407, 408, 409, 239, - /* 80 */ 438, 736, 41, 43, 103, 35, 36, 103, 439, 168, - /* 90 */ 29, 732, 21, 197, 39, 37, 40, 38, 32, 31, - /* 100 */ 30, 56, 34, 33, 747, 781, 32, 31, 30, 43, - /* 110 */ 185, 35, 36, 782, 823, 192, 29, 21, 154, 197, - /* 120 */ 39, 37, 40, 38, 167, 572, 733, 8, 34, 33, - /* 130 */ 61, 113, 32, 31, 30, 659, 35, 36, 126, 59, - /* 140 */ 194, 29, 58, 17, 197, 39, 37, 40, 38, 215, - /* 150 */ 26, 733, 169, 34, 33, 214, 213, 32, 31, 30, - /* 160 */ 16, 233, 208, 232, 207, 206, 205, 231, 204, 230, - /* 170 */ 229, 203, 714, 219, 703, 704, 705, 706, 707, 708, - /* 180 */ 709, 710, 711, 712, 713, 162, 585, 50, 60, 576, - /* 190 */ 175, 579, 165, 582, 234, 162, 585, 179, 178, 576, - /* 200 */ 27, 579, 734, 582, 51, 162, 585, 12, 98, 576, - /* 210 */ 736, 579, 736, 582, 228, 26, 21, 159, 160, 34, - /* 220 */ 33, 196, 836, 32, 31, 30, 148, 159, 160, 76, - /* 230 */ 822, 533, 88, 87, 142, 228, 668, 159, 160, 126, - /* 240 */ 147, 553, 554, 39, 37, 40, 38, 821, 220, 544, - /* 250 */ 733, 34, 33, 46, 501, 32, 31, 30, 517, 525, - /* 260 */ 17, 514, 151, 515, 152, 516, 184, 26, 16, 233, - /* 270 */ 140, 232, 237, 236, 95, 231, 660, 230, 229, 126, - /* 280 */ 530, 42, 217, 216, 578, 18, 581, 181, 161, 170, - /* 290 */ 171, 42, 584, 577, 150, 580, 74, 78, 83, 86, - /* 300 */ 77, 42, 584, 574, 545, 602, 80, 583, 14, 13, - /* 310 */ 141, 586, 584, 143, 507, 13, 47, 583, 46, 73, - /* 320 */ 72, 116, 117, 68, 64, 67, 3, 583, 130, 128, - /* 330 */ 91, 90, 89, 506, 201, 48, 144, 22, 22, 575, - /* 340 */ 521, 519, 522, 520, 10, 9, 85, 84, 145, 146, - /* 350 */ 137, 133, 138, 735, 136, 792, 791, 163, 788, 518, - /* 360 */ 787, 164, 757, 727, 218, 100, 749, 774, 773, 114, - /* 370 */ 26, 115, 112, 670, 202, 131, 24, 211, 667, 212, - /* 380 */ 835, 70, 834, 832, 118, 688, 25, 183, 23, 132, - /* 390 */ 657, 79, 93, 540, 655, 186, 81, 82, 653, 652, - /* 400 */ 172, 190, 127, 746, 650, 649, 648, 647, 646, 638, - /* 410 */ 129, 644, 642, 52, 640, 44, 49, 195, 761, 762, - /* 420 */ 775, 191, 193, 189, 187, 28, 210, 75, 221, 222, - /* 430 */ 223, 224, 225, 199, 226, 227, 235, 53, 616, 174, - /* 440 */ 615, 149, 62, 173, 65, 176, 177, 614, 180, 651, - /* 450 */ 607, 184, 92, 527, 645, 541, 120, 689, 121, 122, - /* 460 */ 119, 123, 125, 124, 94, 104, 1, 731, 105, 111, - /* 470 */ 108, 106, 107, 109, 110, 2, 55, 57, 101, 156, - /* 480 */ 188, 5, 546, 102, 19, 6, 587, 20, 4, 15, - /* 490 */ 63, 7, 198, 478, 200, 475, 473, 472, 471, 469, - /* 500 */ 442, 209, 66, 45, 69, 71, 22, 503, 502, 500, - /* 510 */ 54, 463, 461, 453, 459, 455, 457, 451, 449, 477, - /* 520 */ 476, 474, 470, 468, 46, 440, 96, 413, 411, 620, - /* 530 */ 619, 619, 619, 619, 619, 619, 619, 619, 619, 619, - /* 540 */ 97, + /* 0 */ 727, 442, 726, 11, 725, 625, 241, 508, 728, 443, + /* 10 */ 730, 731, 729, 41, 43, 524, 35, 36, 521, 134, + /* 20 */ 522, 29, 523, 442, 197, 39, 37, 40, 38, 153, + /* 30 */ 239, 443, 219, 34, 33, 217, 216, 32, 31, 30, + /* 40 */ 41, 43, 757, 35, 36, 139, 170, 171, 29, 135, + /* 50 */ 21, 197, 39, 37, 40, 38, 182, 833, 158, 837, + /* 60 */ 34, 33, 744, 768, 32, 31, 30, 402, 403, 404, + /* 70 */ 405, 406, 407, 408, 409, 410, 411, 412, 413, 240, + /* 80 */ 41, 43, 846, 35, 36, 742, 60, 135, 29, 135, + /* 90 */ 21, 197, 39, 37, 40, 38, 157, 837, 27, 836, + /* 100 */ 34, 33, 56, 228, 32, 31, 30, 103, 43, 8, + /* 110 */ 35, 36, 61, 113, 765, 29, 757, 525, 197, 39, + /* 120 */ 37, 40, 38, 166, 537, 743, 579, 34, 33, 18, + /* 130 */ 154, 32, 31, 30, 16, 234, 208, 233, 207, 206, + /* 140 */ 205, 232, 204, 231, 230, 229, 203, 723, 168, 711, + /* 150 */ 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, + /* 160 */ 722, 35, 36, 792, 103, 192, 29, 175, 155, 197, + /* 170 */ 39, 37, 40, 38, 179, 178, 21, 581, 34, 33, + /* 180 */ 442, 12, 32, 31, 30, 162, 592, 746, 443, 583, + /* 190 */ 17, 586, 76, 589, 103, 162, 592, 26, 228, 583, + /* 200 */ 148, 586, 99, 589, 103, 21, 88, 87, 142, 167, + /* 210 */ 165, 743, 169, 582, 147, 214, 213, 159, 160, 50, + /* 220 */ 791, 196, 74, 78, 83, 86, 77, 159, 160, 746, + /* 230 */ 235, 540, 80, 162, 592, 17, 51, 583, 215, 586, + /* 240 */ 743, 589, 26, 39, 37, 40, 38, 832, 194, 746, + /* 250 */ 58, 34, 33, 47, 185, 32, 31, 30, 666, 831, + /* 260 */ 59, 126, 181, 560, 561, 159, 160, 16, 234, 150, + /* 270 */ 233, 21, 48, 585, 232, 588, 231, 230, 229, 34, + /* 280 */ 33, 745, 42, 32, 31, 30, 116, 117, 68, 64, + /* 290 */ 67, 151, 42, 591, 32, 31, 30, 130, 128, 91, + /* 300 */ 90, 89, 675, 591, 220, 126, 743, 98, 590, 238, + /* 310 */ 237, 95, 667, 152, 26, 126, 532, 584, 590, 587, + /* 320 */ 551, 161, 552, 184, 46, 609, 14, 593, 514, 13, + /* 330 */ 42, 13, 46, 513, 201, 73, 72, 22, 22, 10, + /* 340 */ 9, 591, 528, 526, 529, 527, 85, 84, 802, 140, + /* 350 */ 141, 143, 801, 144, 163, 145, 590, 146, 798, 137, + /* 360 */ 3, 133, 138, 136, 797, 164, 759, 737, 218, 767, + /* 370 */ 100, 784, 783, 114, 112, 115, 677, 202, 131, 24, + /* 380 */ 211, 674, 212, 845, 70, 844, 26, 842, 118, 93, + /* 390 */ 695, 25, 547, 23, 186, 132, 664, 79, 662, 81, + /* 400 */ 82, 660, 659, 172, 190, 127, 657, 656, 655, 654, + /* 410 */ 653, 645, 129, 651, 649, 647, 52, 49, 756, 771, + /* 420 */ 104, 772, 44, 785, 195, 193, 191, 189, 187, 28, + /* 430 */ 210, 75, 221, 222, 223, 224, 225, 226, 199, 227, + /* 440 */ 236, 53, 623, 174, 173, 622, 62, 177, 149, 621, + /* 450 */ 183, 65, 176, 614, 658, 180, 92, 94, 652, 121, + /* 460 */ 125, 534, 120, 696, 741, 119, 110, 107, 105, 106, + /* 470 */ 122, 108, 123, 2, 111, 109, 124, 1, 184, 57, + /* 480 */ 55, 548, 156, 101, 188, 5, 553, 102, 6, 63, + /* 490 */ 594, 19, 4, 20, 15, 198, 7, 200, 483, 479, + /* 500 */ 477, 476, 475, 473, 446, 209, 66, 45, 69, 71, + /* 510 */ 22, 510, 509, 507, 54, 467, 465, 457, 463, 459, + /* 520 */ 461, 455, 453, 482, 481, 480, 478, 474, 472, 46, + /* 530 */ 444, 417, 415, 627, 626, 626, 626, 626, 626, 626, + /* 540 */ 626, 626, 626, 626, 626, 96, 97, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 225, 1, 227, 258, 229, 258, 206, 207, 233, 9, - /* 10 */ 235, 236, 209, 13, 14, 209, 16, 17, 208, 209, - /* 20 */ 258, 21, 258, 1, 24, 25, 26, 27, 28, 267, - /* 30 */ 268, 9, 268, 33, 34, 258, 258, 37, 38, 39, - /* 40 */ 13, 14, 242, 16, 17, 267, 268, 241, 21, 243, - /* 50 */ 209, 24, 25, 26, 27, 28, 256, 209, 209, 209, - /* 60 */ 33, 34, 259, 226, 37, 38, 39, 45, 46, 47, + /* 0 */ 226, 1, 228, 260, 230, 207, 208, 5, 234, 9, + /* 10 */ 236, 237, 238, 13, 14, 2, 16, 17, 5, 260, + /* 20 */ 7, 21, 9, 1, 24, 25, 26, 27, 28, 209, + /* 30 */ 210, 9, 210, 33, 34, 33, 34, 37, 38, 39, + /* 40 */ 13, 14, 244, 16, 17, 260, 33, 34, 21, 260, + /* 50 */ 210, 24, 25, 26, 27, 28, 258, 260, 269, 270, + /* 60 */ 33, 34, 240, 210, 37, 38, 39, 45, 46, 47, /* 70 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 80 */ 1, 244, 13, 14, 209, 16, 17, 209, 9, 63, - /* 90 */ 21, 243, 209, 24, 25, 26, 27, 28, 37, 38, - /* 100 */ 39, 101, 33, 34, 242, 264, 37, 38, 39, 14, - /* 110 */ 260, 16, 17, 264, 258, 266, 21, 209, 256, 24, - /* 120 */ 25, 26, 27, 28, 241, 98, 243, 97, 33, 34, - /* 130 */ 100, 101, 37, 38, 39, 213, 16, 17, 216, 264, - /* 140 */ 262, 21, 264, 97, 24, 25, 26, 27, 28, 241, - /* 150 */ 104, 243, 126, 33, 34, 129, 130, 37, 38, 39, - /* 160 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, - /* 170 */ 95, 96, 225, 209, 227, 228, 229, 230, 231, 232, - /* 180 */ 233, 234, 235, 236, 237, 1, 2, 102, 245, 5, - /* 190 */ 125, 7, 226, 9, 226, 1, 2, 132, 133, 5, - /* 200 */ 257, 7, 238, 9, 119, 1, 2, 44, 97, 5, - /* 210 */ 244, 7, 244, 9, 78, 104, 209, 33, 34, 33, - /* 220 */ 34, 37, 244, 37, 38, 39, 63, 33, 34, 72, - /* 230 */ 258, 37, 69, 70, 71, 78, 213, 33, 34, 216, - /* 240 */ 77, 114, 115, 25, 26, 27, 28, 258, 241, 98, - /* 250 */ 243, 33, 34, 102, 5, 37, 38, 39, 2, 98, - /* 260 */ 97, 5, 258, 7, 258, 9, 105, 104, 85, 86, - /* 270 */ 258, 88, 60, 61, 62, 92, 213, 94, 95, 216, - /* 280 */ 102, 97, 33, 34, 5, 107, 7, 124, 59, 33, - /* 290 */ 34, 97, 108, 5, 131, 7, 64, 65, 66, 67, - /* 300 */ 68, 97, 108, 1, 98, 98, 74, 123, 102, 102, - /* 310 */ 258, 98, 108, 258, 98, 102, 102, 123, 102, 127, - /* 320 */ 128, 64, 65, 66, 67, 68, 97, 123, 64, 65, - /* 330 */ 66, 67, 68, 98, 98, 121, 258, 102, 102, 37, - /* 340 */ 5, 5, 7, 7, 127, 128, 72, 73, 258, 258, - /* 350 */ 258, 258, 258, 244, 258, 239, 239, 239, 239, 103, - /* 360 */ 239, 239, 209, 240, 239, 209, 242, 265, 265, 209, - /* 370 */ 104, 209, 246, 209, 209, 209, 209, 209, 209, 209, - /* 380 */ 209, 209, 209, 209, 209, 209, 209, 242, 209, 209, - /* 390 */ 209, 209, 59, 108, 209, 261, 209, 209, 209, 209, - /* 400 */ 209, 261, 209, 255, 209, 209, 209, 209, 209, 209, - /* 410 */ 209, 209, 209, 118, 209, 117, 120, 112, 210, 210, - /* 420 */ 210, 111, 116, 110, 109, 122, 75, 84, 83, 49, - /* 430 */ 80, 82, 53, 210, 81, 79, 75, 210, 5, 5, - /* 440 */ 5, 210, 214, 134, 214, 134, 5, 5, 125, 210, - /* 450 */ 87, 105, 211, 98, 210, 98, 222, 224, 218, 221, - /* 460 */ 223, 219, 217, 220, 211, 254, 215, 242, 253, 247, - /* 470 */ 250, 252, 251, 249, 248, 212, 106, 102, 97, 1, - /* 480 */ 97, 113, 98, 97, 102, 113, 98, 102, 97, 97, - /* 490 */ 72, 97, 99, 9, 99, 5, 5, 5, 5, 5, - /* 500 */ 76, 15, 72, 16, 128, 128, 102, 5, 5, 98, - /* 510 */ 97, 5, 5, 5, 5, 5, 5, 5, 5, 5, - /* 520 */ 5, 5, 5, 5, 102, 76, 21, 59, 58, 0, - /* 530 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 540 */ 21, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 550 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 560 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 570 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 580 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 590 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 600 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 610 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 620 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 630 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 640 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 650 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 660 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 670 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 680 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 690 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 700 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 710 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 720 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 730 */ 269, 269, 269, 269, 269, 269, 269, 269, 269, 269, - /* 740 */ 269, 269, 269, 269, 269, 269, + /* 80 */ 13, 14, 246, 16, 17, 245, 247, 260, 21, 260, + /* 90 */ 210, 24, 25, 26, 27, 28, 269, 270, 259, 270, + /* 100 */ 33, 34, 102, 78, 37, 38, 39, 210, 14, 98, + /* 110 */ 16, 17, 101, 102, 261, 21, 244, 104, 24, 25, + /* 120 */ 26, 27, 28, 243, 103, 245, 99, 33, 34, 108, + /* 130 */ 258, 37, 38, 39, 85, 86, 87, 88, 89, 90, + /* 140 */ 91, 92, 93, 94, 95, 96, 97, 226, 63, 228, + /* 150 */ 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, + /* 160 */ 239, 16, 17, 266, 210, 268, 21, 126, 227, 24, + /* 170 */ 25, 26, 27, 28, 133, 134, 210, 1, 33, 34, + /* 180 */ 1, 44, 37, 38, 39, 1, 2, 246, 9, 5, + /* 190 */ 98, 7, 72, 9, 210, 1, 2, 105, 78, 5, + /* 200 */ 63, 7, 210, 9, 210, 210, 69, 70, 71, 243, + /* 210 */ 227, 245, 127, 37, 77, 130, 131, 33, 34, 103, + /* 220 */ 266, 37, 64, 65, 66, 67, 68, 33, 34, 246, + /* 230 */ 227, 37, 74, 1, 2, 98, 120, 5, 243, 7, + /* 240 */ 245, 9, 105, 25, 26, 27, 28, 260, 264, 246, + /* 250 */ 266, 33, 34, 103, 262, 37, 38, 39, 214, 260, + /* 260 */ 266, 217, 125, 115, 116, 33, 34, 85, 86, 132, + /* 270 */ 88, 210, 122, 5, 92, 7, 94, 95, 96, 33, + /* 280 */ 34, 246, 98, 37, 38, 39, 64, 65, 66, 67, + /* 290 */ 68, 260, 98, 109, 37, 38, 39, 64, 65, 66, + /* 300 */ 67, 68, 214, 109, 243, 217, 245, 98, 124, 60, + /* 310 */ 61, 62, 214, 260, 105, 217, 99, 5, 124, 7, + /* 320 */ 99, 59, 99, 106, 103, 99, 103, 99, 99, 103, + /* 330 */ 98, 103, 103, 99, 99, 128, 129, 103, 103, 128, + /* 340 */ 129, 109, 5, 5, 7, 7, 72, 73, 241, 260, + /* 350 */ 260, 260, 241, 260, 241, 260, 124, 260, 241, 260, + /* 360 */ 98, 260, 260, 260, 241, 241, 244, 242, 241, 210, + /* 370 */ 210, 267, 267, 210, 248, 210, 210, 210, 210, 210, + /* 380 */ 210, 210, 210, 210, 210, 210, 105, 210, 210, 59, + /* 390 */ 210, 210, 109, 210, 263, 210, 210, 210, 210, 210, + /* 400 */ 210, 210, 210, 210, 263, 210, 210, 210, 210, 210, + /* 410 */ 210, 210, 210, 210, 210, 210, 119, 121, 257, 211, + /* 420 */ 256, 211, 118, 211, 113, 117, 112, 111, 110, 123, + /* 430 */ 75, 84, 83, 49, 80, 82, 53, 81, 211, 79, + /* 440 */ 75, 211, 5, 5, 135, 5, 215, 5, 211, 5, + /* 450 */ 244, 215, 135, 87, 211, 126, 212, 212, 211, 219, + /* 460 */ 218, 99, 223, 225, 244, 224, 250, 253, 255, 254, + /* 470 */ 222, 252, 220, 213, 249, 251, 221, 216, 106, 103, + /* 480 */ 107, 99, 1, 98, 98, 114, 99, 98, 114, 72, + /* 490 */ 99, 103, 98, 103, 98, 100, 98, 100, 9, 5, + /* 500 */ 5, 5, 5, 5, 76, 15, 72, 16, 129, 129, + /* 510 */ 103, 5, 5, 99, 98, 5, 5, 5, 5, 5, + /* 520 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 103, + /* 530 */ 76, 59, 58, 0, 271, 271, 271, 271, 271, 271, + /* 540 */ 271, 271, 271, 271, 271, 21, 21, 271, 271, 271, + /* 550 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 560 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 570 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 580 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 590 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 600 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 610 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 620 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 630 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 640 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 650 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 660 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 670 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 680 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 690 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 700 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 710 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 720 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 730 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 740 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 750 */ 271, 271, 271, }; -#define YY_SHIFT_COUNT (240) +#define YY_SHIFT_COUNT (241) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (529) +#define YY_SHIFT_MAX (533) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 163, 75, 183, 184, 204, 79, 79, 79, 79, 79, - /* 10 */ 79, 0, 22, 204, 256, 256, 256, 46, 79, 79, - /* 20 */ 79, 79, 79, 157, 136, 136, 541, 194, 204, 204, - /* 30 */ 204, 204, 204, 204, 204, 204, 204, 204, 204, 204, - /* 40 */ 204, 204, 204, 204, 204, 256, 256, 249, 249, 249, - /* 50 */ 249, 249, 249, 30, 249, 111, 79, 79, 127, 127, - /* 60 */ 178, 79, 79, 79, 79, 79, 79, 79, 79, 79, - /* 70 */ 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, - /* 80 */ 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, - /* 90 */ 79, 79, 79, 79, 79, 79, 79, 79, 266, 333, - /* 100 */ 333, 285, 285, 333, 295, 296, 298, 305, 306, 310, - /* 110 */ 313, 315, 303, 266, 333, 333, 351, 351, 333, 343, - /* 120 */ 345, 380, 350, 349, 379, 353, 356, 333, 361, 333, - /* 130 */ 361, 541, 541, 27, 69, 69, 69, 95, 120, 218, - /* 140 */ 218, 218, 232, 186, 186, 186, 186, 257, 264, 26, - /* 150 */ 65, 61, 61, 212, 161, 151, 206, 207, 213, 279, - /* 160 */ 288, 302, 229, 214, 85, 216, 235, 236, 192, 217, - /* 170 */ 335, 336, 274, 433, 309, 434, 435, 311, 441, 442, - /* 180 */ 363, 323, 346, 355, 370, 375, 357, 381, 478, 383, - /* 190 */ 384, 386, 382, 368, 385, 372, 388, 391, 392, 393, - /* 200 */ 394, 395, 418, 484, 490, 491, 492, 493, 494, 424, - /* 210 */ 486, 430, 487, 376, 377, 404, 502, 503, 411, 413, - /* 220 */ 404, 506, 507, 508, 509, 510, 511, 512, 513, 514, - /* 230 */ 515, 516, 517, 518, 422, 449, 505, 519, 468, 470, - /* 240 */ 529, + /* 0 */ 137, 49, 182, 184, 232, 179, 179, 179, 179, 179, + /* 10 */ 179, 0, 22, 232, 13, 13, 13, 92, 179, 179, + /* 20 */ 179, 179, 179, 120, 25, 25, 547, 194, 232, 232, + /* 30 */ 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, + /* 40 */ 232, 232, 232, 232, 232, 13, 13, 2, 2, 2, + /* 50 */ 2, 2, 2, 11, 2, 209, 179, 179, 148, 148, + /* 60 */ 21, 179, 179, 179, 179, 179, 179, 179, 179, 179, + /* 70 */ 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, + /* 80 */ 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, + /* 90 */ 179, 179, 179, 179, 179, 179, 179, 179, 281, 330, + /* 100 */ 330, 283, 283, 330, 297, 296, 304, 311, 308, 314, + /* 110 */ 316, 318, 306, 281, 330, 330, 355, 355, 330, 347, + /* 120 */ 349, 384, 354, 353, 383, 356, 360, 330, 365, 330, + /* 130 */ 365, 547, 547, 27, 67, 67, 67, 94, 145, 218, + /* 140 */ 218, 218, 158, 246, 246, 246, 246, 222, 233, 85, + /* 150 */ 41, 257, 257, 249, 217, 221, 223, 226, 228, 268, + /* 160 */ 312, 176, 262, 150, 116, 229, 234, 235, 207, 211, + /* 170 */ 337, 338, 274, 437, 309, 438, 440, 317, 442, 444, + /* 180 */ 366, 329, 372, 362, 373, 376, 382, 385, 481, 386, + /* 190 */ 387, 389, 388, 371, 390, 374, 391, 394, 396, 395, + /* 200 */ 398, 397, 417, 489, 494, 495, 496, 497, 498, 428, + /* 210 */ 490, 434, 491, 379, 380, 407, 506, 507, 414, 416, + /* 220 */ 407, 510, 511, 512, 513, 514, 515, 516, 517, 518, + /* 230 */ 519, 520, 521, 522, 523, 426, 454, 524, 525, 472, + /* 240 */ 474, 533, }; #define YY_REDUCE_COUNT (132) -#define YY_REDUCE_MIN (-255) -#define YY_REDUCE_MAX (263) +#define YY_REDUCE_MIN (-257) +#define YY_REDUCE_MAX (261) static const short yy_reduce_ofst[] = { - /* 0 */ -200, -53, -225, -238, -222, -151, -122, -194, -117, -92, - /* 10 */ 7, -197, -190, -236, -163, -34, -32, -138, -150, -159, - /* 20 */ -125, -36, -152, -78, 23, 63, -57, -255, -253, -223, - /* 30 */ -144, -28, -11, 4, 6, 12, 52, 55, 78, 90, - /* 40 */ 91, 92, 93, 94, 96, -22, 109, 116, 117, 118, - /* 50 */ 119, 121, 122, 123, 125, 124, 153, 156, 102, 103, - /* 60 */ 126, 160, 162, 164, 165, 166, 167, 168, 169, 170, - /* 70 */ 171, 172, 173, 174, 175, 176, 177, 179, 180, 181, - /* 80 */ 182, 185, 187, 188, 189, 190, 191, 193, 195, 196, - /* 90 */ 197, 198, 199, 200, 201, 202, 203, 205, 145, 208, - /* 100 */ 209, 134, 140, 210, 148, 211, 215, 219, 221, 220, - /* 110 */ 224, 226, 222, 225, 223, 227, 228, 230, 231, 233, - /* 120 */ 237, 234, 240, 238, 242, 243, 245, 239, 241, 244, - /* 130 */ 253, 251, 263, + /* 0 */ -202, -79, -226, -211, -173, -103, -16, -120, -34, -5, + /* 10 */ 61, -147, -180, -171, -59, -17, 3, -128, -8, -46, + /* 20 */ -6, -178, -160, 44, 88, 98, -161, -257, -241, -215, + /* 30 */ -203, -13, -1, 31, 53, 89, 90, 91, 93, 95, + /* 40 */ 97, 99, 101, 102, 103, -164, 35, 107, 111, 113, + /* 50 */ 117, 123, 124, 125, 127, 122, 159, 160, 104, 105, + /* 60 */ 126, 163, 165, 166, 167, 168, 169, 170, 171, 172, + /* 70 */ 173, 174, 175, 177, 178, 180, 181, 183, 185, 186, + /* 80 */ 187, 188, 189, 190, 191, 192, 193, 195, 196, 197, + /* 90 */ 198, 199, 200, 201, 202, 203, 204, 205, 206, 208, + /* 100 */ 210, 131, 141, 212, 161, 164, 213, 215, 214, 219, + /* 110 */ 224, 216, 225, 220, 227, 230, 231, 236, 237, 238, + /* 120 */ 241, 239, 240, 248, 252, 255, 242, 243, 244, 247, + /* 130 */ 245, 261, 260, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 617, 669, 658, 829, 829, 617, 617, 617, 617, 617, - /* 10 */ 617, 759, 635, 829, 617, 617, 617, 617, 617, 617, - /* 20 */ 617, 617, 617, 671, 671, 671, 754, 617, 617, 617, - /* 30 */ 617, 617, 617, 617, 617, 617, 617, 617, 617, 617, - /* 40 */ 617, 617, 617, 617, 617, 617, 617, 617, 617, 617, - /* 50 */ 617, 617, 617, 617, 617, 617, 617, 617, 778, 778, - /* 60 */ 752, 617, 617, 617, 617, 617, 617, 617, 617, 617, - /* 70 */ 617, 617, 617, 617, 617, 617, 617, 617, 617, 656, - /* 80 */ 617, 654, 617, 617, 617, 617, 617, 617, 617, 617, - /* 90 */ 617, 617, 617, 617, 617, 643, 617, 617, 617, 637, - /* 100 */ 637, 617, 617, 637, 785, 789, 783, 771, 779, 770, - /* 110 */ 766, 765, 793, 617, 637, 637, 666, 666, 637, 687, - /* 120 */ 685, 683, 675, 681, 677, 679, 673, 637, 664, 637, - /* 130 */ 664, 702, 715, 617, 794, 828, 784, 812, 811, 824, - /* 140 */ 818, 817, 617, 816, 815, 814, 813, 617, 617, 617, - /* 150 */ 617, 820, 819, 617, 617, 617, 617, 617, 617, 617, - /* 160 */ 617, 617, 796, 790, 786, 617, 617, 617, 617, 617, - /* 170 */ 617, 617, 617, 617, 617, 617, 617, 617, 617, 617, - /* 180 */ 617, 617, 751, 617, 617, 760, 617, 617, 617, 617, - /* 190 */ 617, 617, 780, 617, 772, 617, 617, 617, 617, 617, - /* 200 */ 617, 728, 617, 617, 617, 617, 617, 617, 617, 617, - /* 210 */ 617, 617, 617, 617, 617, 833, 617, 617, 617, 722, - /* 220 */ 831, 617, 617, 617, 617, 617, 617, 617, 617, 617, - /* 230 */ 617, 617, 617, 617, 690, 617, 641, 639, 617, 633, - /* 240 */ 617, + /* 0 */ 624, 676, 665, 839, 839, 624, 624, 624, 624, 624, + /* 10 */ 624, 769, 642, 839, 624, 624, 624, 624, 624, 624, + /* 20 */ 624, 624, 624, 678, 678, 678, 764, 624, 624, 624, + /* 30 */ 624, 624, 624, 624, 624, 624, 624, 624, 624, 624, + /* 40 */ 624, 624, 624, 624, 624, 624, 624, 624, 624, 624, + /* 50 */ 624, 624, 624, 624, 624, 624, 624, 624, 788, 788, + /* 60 */ 762, 624, 624, 624, 624, 624, 624, 624, 624, 624, + /* 70 */ 624, 624, 624, 624, 624, 624, 624, 624, 624, 663, + /* 80 */ 624, 661, 624, 624, 624, 624, 624, 624, 624, 624, + /* 90 */ 624, 624, 624, 624, 624, 650, 624, 624, 624, 644, + /* 100 */ 644, 624, 624, 644, 795, 799, 793, 781, 789, 780, + /* 110 */ 776, 775, 803, 624, 644, 644, 673, 673, 644, 694, + /* 120 */ 692, 690, 682, 688, 684, 686, 680, 644, 671, 644, + /* 130 */ 671, 710, 724, 624, 804, 838, 794, 822, 821, 834, + /* 140 */ 828, 827, 624, 826, 825, 824, 823, 624, 624, 624, + /* 150 */ 624, 830, 829, 624, 624, 624, 624, 624, 624, 624, + /* 160 */ 624, 624, 806, 800, 796, 624, 624, 624, 624, 624, + /* 170 */ 624, 624, 624, 624, 624, 624, 624, 624, 624, 624, + /* 180 */ 624, 624, 761, 624, 624, 770, 624, 624, 624, 624, + /* 190 */ 624, 624, 790, 624, 782, 624, 624, 624, 624, 624, + /* 200 */ 624, 738, 624, 624, 624, 624, 624, 624, 624, 624, + /* 210 */ 624, 624, 624, 624, 624, 843, 624, 624, 624, 732, + /* 220 */ 841, 624, 624, 624, 624, 624, 624, 624, 624, 624, + /* 230 */ 624, 624, 624, 624, 624, 697, 624, 648, 646, 624, + /* 240 */ 640, 624, }; /********** End of lemon-generated parsing tables *****************************/ @@ -526,6 +527,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* BLOCKS => nothing */ 0, /* CTIME => nothing */ 0, /* WAL => nothing */ + 0, /* FSYNC => nothing */ 0, /* COMP => nothing */ 0, /* PRECISION => nothing */ 0, /* LP => nothing */ @@ -817,180 +819,182 @@ static const char *const yyTokenName[] = { /* 92 */ "BLOCKS", /* 93 */ "CTIME", /* 94 */ "WAL", - /* 95 */ "COMP", - /* 96 */ "PRECISION", - /* 97 */ "LP", - /* 98 */ "RP", - /* 99 */ "TAGS", - /* 100 */ "USING", - /* 101 */ "AS", - /* 102 */ "COMMA", - /* 103 */ "NULL", - /* 104 */ "SELECT", - /* 105 */ "UNION", - /* 106 */ "ALL", - /* 107 */ "FROM", - /* 108 */ "VARIABLE", - /* 109 */ "INTERVAL", - /* 110 */ "FILL", - /* 111 */ "SLIDING", - /* 112 */ "ORDER", - /* 113 */ "BY", - /* 114 */ "ASC", - /* 115 */ "DESC", - /* 116 */ "GROUP", - /* 117 */ "HAVING", - /* 118 */ "LIMIT", - /* 119 */ "OFFSET", - /* 120 */ "SLIMIT", - /* 121 */ "SOFFSET", - /* 122 */ "WHERE", - /* 123 */ "NOW", - /* 124 */ "RESET", - /* 125 */ "QUERY", - /* 126 */ "ADD", - /* 127 */ "COLUMN", - /* 128 */ "TAG", - /* 129 */ "CHANGE", - /* 130 */ "SET", - /* 131 */ "KILL", - /* 132 */ "CONNECTION", - /* 133 */ "STREAM", - /* 134 */ "COLON", - /* 135 */ "ABORT", - /* 136 */ "AFTER", - /* 137 */ "ATTACH", - /* 138 */ "BEFORE", - /* 139 */ "BEGIN", - /* 140 */ "CASCADE", - /* 141 */ "CLUSTER", - /* 142 */ "CONFLICT", - /* 143 */ "COPY", - /* 144 */ "DEFERRED", - /* 145 */ "DELIMITERS", - /* 146 */ "DETACH", - /* 147 */ "EACH", - /* 148 */ "END", - /* 149 */ "EXPLAIN", - /* 150 */ "FAIL", - /* 151 */ "FOR", - /* 152 */ "IGNORE", - /* 153 */ "IMMEDIATE", - /* 154 */ "INITIALLY", - /* 155 */ "INSTEAD", - /* 156 */ "MATCH", - /* 157 */ "KEY", - /* 158 */ "OF", - /* 159 */ "RAISE", - /* 160 */ "REPLACE", - /* 161 */ "RESTRICT", - /* 162 */ "ROW", - /* 163 */ "STATEMENT", - /* 164 */ "TRIGGER", - /* 165 */ "VIEW", - /* 166 */ "COUNT", - /* 167 */ "SUM", - /* 168 */ "AVG", - /* 169 */ "MIN", - /* 170 */ "MAX", - /* 171 */ "FIRST", - /* 172 */ "LAST", - /* 173 */ "TOP", - /* 174 */ "BOTTOM", - /* 175 */ "STDDEV", - /* 176 */ "PERCENTILE", - /* 177 */ "APERCENTILE", - /* 178 */ "LEASTSQUARES", - /* 179 */ "HISTOGRAM", - /* 180 */ "DIFF", - /* 181 */ "SPREAD", - /* 182 */ "TWA", - /* 183 */ "INTERP", - /* 184 */ "LAST_ROW", - /* 185 */ "RATE", - /* 186 */ "IRATE", - /* 187 */ "SUM_RATE", - /* 188 */ "SUM_IRATE", - /* 189 */ "AVG_RATE", - /* 190 */ "AVG_IRATE", - /* 191 */ "TBID", - /* 192 */ "SEMI", - /* 193 */ "NONE", - /* 194 */ "PREV", - /* 195 */ "LINEAR", - /* 196 */ "IMPORT", - /* 197 */ "METRIC", - /* 198 */ "TBNAME", - /* 199 */ "JOIN", - /* 200 */ "METRICS", - /* 201 */ "STABLE", - /* 202 */ "INSERT", - /* 203 */ "INTO", - /* 204 */ "VALUES", - /* 205 */ "error", - /* 206 */ "program", - /* 207 */ "cmd", - /* 208 */ "dbPrefix", - /* 209 */ "ids", - /* 210 */ "cpxName", - /* 211 */ "ifexists", - /* 212 */ "alter_db_optr", - /* 213 */ "acct_optr", - /* 214 */ "ifnotexists", - /* 215 */ "db_optr", - /* 216 */ "pps", - /* 217 */ "tseries", - /* 218 */ "dbs", - /* 219 */ "streams", - /* 220 */ "storage", - /* 221 */ "qtime", - /* 222 */ "users", - /* 223 */ "conns", - /* 224 */ "state", - /* 225 */ "keep", - /* 226 */ "tagitemlist", - /* 227 */ "tables", - /* 228 */ "cache", - /* 229 */ "replica", - /* 230 */ "days", - /* 231 */ "minrows", - /* 232 */ "maxrows", - /* 233 */ "blocks", - /* 234 */ "ctime", - /* 235 */ "wal", - /* 236 */ "comp", - /* 237 */ "prec", - /* 238 */ "typename", - /* 239 */ "signed", - /* 240 */ "create_table_args", - /* 241 */ "columnlist", - /* 242 */ "select", - /* 243 */ "column", - /* 244 */ "tagitem", - /* 245 */ "selcollist", - /* 246 */ "from", - /* 247 */ "where_opt", - /* 248 */ "interval_opt", - /* 249 */ "fill_opt", - /* 250 */ "sliding_opt", - /* 251 */ "groupby_opt", - /* 252 */ "orderby_opt", - /* 253 */ "having_opt", - /* 254 */ "slimit_opt", - /* 255 */ "limit_opt", - /* 256 */ "union", - /* 257 */ "sclp", - /* 258 */ "expr", - /* 259 */ "as", - /* 260 */ "tablelist", - /* 261 */ "tmvar", - /* 262 */ "sortlist", - /* 263 */ "sortitem", - /* 264 */ "item", - /* 265 */ "sortorder", - /* 266 */ "grouplist", - /* 267 */ "exprlist", - /* 268 */ "expritem", + /* 95 */ "FSYNC", + /* 96 */ "COMP", + /* 97 */ "PRECISION", + /* 98 */ "LP", + /* 99 */ "RP", + /* 100 */ "TAGS", + /* 101 */ "USING", + /* 102 */ "AS", + /* 103 */ "COMMA", + /* 104 */ "NULL", + /* 105 */ "SELECT", + /* 106 */ "UNION", + /* 107 */ "ALL", + /* 108 */ "FROM", + /* 109 */ "VARIABLE", + /* 110 */ "INTERVAL", + /* 111 */ "FILL", + /* 112 */ "SLIDING", + /* 113 */ "ORDER", + /* 114 */ "BY", + /* 115 */ "ASC", + /* 116 */ "DESC", + /* 117 */ "GROUP", + /* 118 */ "HAVING", + /* 119 */ "LIMIT", + /* 120 */ "OFFSET", + /* 121 */ "SLIMIT", + /* 122 */ "SOFFSET", + /* 123 */ "WHERE", + /* 124 */ "NOW", + /* 125 */ "RESET", + /* 126 */ "QUERY", + /* 127 */ "ADD", + /* 128 */ "COLUMN", + /* 129 */ "TAG", + /* 130 */ "CHANGE", + /* 131 */ "SET", + /* 132 */ "KILL", + /* 133 */ "CONNECTION", + /* 134 */ "STREAM", + /* 135 */ "COLON", + /* 136 */ "ABORT", + /* 137 */ "AFTER", + /* 138 */ "ATTACH", + /* 139 */ "BEFORE", + /* 140 */ "BEGIN", + /* 141 */ "CASCADE", + /* 142 */ "CLUSTER", + /* 143 */ "CONFLICT", + /* 144 */ "COPY", + /* 145 */ "DEFERRED", + /* 146 */ "DELIMITERS", + /* 147 */ "DETACH", + /* 148 */ "EACH", + /* 149 */ "END", + /* 150 */ "EXPLAIN", + /* 151 */ "FAIL", + /* 152 */ "FOR", + /* 153 */ "IGNORE", + /* 154 */ "IMMEDIATE", + /* 155 */ "INITIALLY", + /* 156 */ "INSTEAD", + /* 157 */ "MATCH", + /* 158 */ "KEY", + /* 159 */ "OF", + /* 160 */ "RAISE", + /* 161 */ "REPLACE", + /* 162 */ "RESTRICT", + /* 163 */ "ROW", + /* 164 */ "STATEMENT", + /* 165 */ "TRIGGER", + /* 166 */ "VIEW", + /* 167 */ "COUNT", + /* 168 */ "SUM", + /* 169 */ "AVG", + /* 170 */ "MIN", + /* 171 */ "MAX", + /* 172 */ "FIRST", + /* 173 */ "LAST", + /* 174 */ "TOP", + /* 175 */ "BOTTOM", + /* 176 */ "STDDEV", + /* 177 */ "PERCENTILE", + /* 178 */ "APERCENTILE", + /* 179 */ "LEASTSQUARES", + /* 180 */ "HISTOGRAM", + /* 181 */ "DIFF", + /* 182 */ "SPREAD", + /* 183 */ "TWA", + /* 184 */ "INTERP", + /* 185 */ "LAST_ROW", + /* 186 */ "RATE", + /* 187 */ "IRATE", + /* 188 */ "SUM_RATE", + /* 189 */ "SUM_IRATE", + /* 190 */ "AVG_RATE", + /* 191 */ "AVG_IRATE", + /* 192 */ "TBID", + /* 193 */ "SEMI", + /* 194 */ "NONE", + /* 195 */ "PREV", + /* 196 */ "LINEAR", + /* 197 */ "IMPORT", + /* 198 */ "METRIC", + /* 199 */ "TBNAME", + /* 200 */ "JOIN", + /* 201 */ "METRICS", + /* 202 */ "STABLE", + /* 203 */ "INSERT", + /* 204 */ "INTO", + /* 205 */ "VALUES", + /* 206 */ "error", + /* 207 */ "program", + /* 208 */ "cmd", + /* 209 */ "dbPrefix", + /* 210 */ "ids", + /* 211 */ "cpxName", + /* 212 */ "ifexists", + /* 213 */ "alter_db_optr", + /* 214 */ "acct_optr", + /* 215 */ "ifnotexists", + /* 216 */ "db_optr", + /* 217 */ "pps", + /* 218 */ "tseries", + /* 219 */ "dbs", + /* 220 */ "streams", + /* 221 */ "storage", + /* 222 */ "qtime", + /* 223 */ "users", + /* 224 */ "conns", + /* 225 */ "state", + /* 226 */ "keep", + /* 227 */ "tagitemlist", + /* 228 */ "tables", + /* 229 */ "cache", + /* 230 */ "replica", + /* 231 */ "days", + /* 232 */ "minrows", + /* 233 */ "maxrows", + /* 234 */ "blocks", + /* 235 */ "ctime", + /* 236 */ "wal", + /* 237 */ "fsync", + /* 238 */ "comp", + /* 239 */ "prec", + /* 240 */ "typename", + /* 241 */ "signed", + /* 242 */ "create_table_args", + /* 243 */ "columnlist", + /* 244 */ "select", + /* 245 */ "column", + /* 246 */ "tagitem", + /* 247 */ "selcollist", + /* 248 */ "from", + /* 249 */ "where_opt", + /* 250 */ "interval_opt", + /* 251 */ "fill_opt", + /* 252 */ "sliding_opt", + /* 253 */ "groupby_opt", + /* 254 */ "orderby_opt", + /* 255 */ "having_opt", + /* 256 */ "slimit_opt", + /* 257 */ "limit_opt", + /* 258 */ "union", + /* 259 */ "sclp", + /* 260 */ "expr", + /* 261 */ "as", + /* 262 */ "tablelist", + /* 263 */ "tmvar", + /* 264 */ "sortlist", + /* 265 */ "sortitem", + /* 266 */ "item", + /* 267 */ "sortorder", + /* 268 */ "grouplist", + /* 269 */ "exprlist", + /* 270 */ "expritem", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1078,146 +1082,149 @@ static const char *const yyRuleName[] = { /* 77 */ "blocks ::= BLOCKS INTEGER", /* 78 */ "ctime ::= CTIME INTEGER", /* 79 */ "wal ::= WAL INTEGER", - /* 80 */ "comp ::= COMP INTEGER", - /* 81 */ "prec ::= PRECISION STRING", - /* 82 */ "db_optr ::=", - /* 83 */ "db_optr ::= db_optr tables", - /* 84 */ "db_optr ::= db_optr cache", - /* 85 */ "db_optr ::= db_optr replica", - /* 86 */ "db_optr ::= db_optr days", - /* 87 */ "db_optr ::= db_optr minrows", - /* 88 */ "db_optr ::= db_optr maxrows", - /* 89 */ "db_optr ::= db_optr blocks", - /* 90 */ "db_optr ::= db_optr ctime", - /* 91 */ "db_optr ::= db_optr wal", - /* 92 */ "db_optr ::= db_optr comp", - /* 93 */ "db_optr ::= db_optr prec", - /* 94 */ "db_optr ::= db_optr keep", - /* 95 */ "alter_db_optr ::=", - /* 96 */ "alter_db_optr ::= alter_db_optr replica", - /* 97 */ "alter_db_optr ::= alter_db_optr tables", - /* 98 */ "alter_db_optr ::= alter_db_optr keep", - /* 99 */ "alter_db_optr ::= alter_db_optr blocks", - /* 100 */ "alter_db_optr ::= alter_db_optr comp", - /* 101 */ "alter_db_optr ::= alter_db_optr wal", - /* 102 */ "typename ::= ids", - /* 103 */ "typename ::= ids LP signed RP", - /* 104 */ "signed ::= INTEGER", - /* 105 */ "signed ::= PLUS INTEGER", - /* 106 */ "signed ::= MINUS INTEGER", - /* 107 */ "cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args", - /* 108 */ "create_table_args ::= LP columnlist RP", - /* 109 */ "create_table_args ::= LP columnlist RP TAGS LP columnlist RP", - /* 110 */ "create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP", - /* 111 */ "create_table_args ::= AS select", - /* 112 */ "columnlist ::= columnlist COMMA column", - /* 113 */ "columnlist ::= column", - /* 114 */ "column ::= ids typename", - /* 115 */ "tagitemlist ::= tagitemlist COMMA tagitem", - /* 116 */ "tagitemlist ::= tagitem", - /* 117 */ "tagitem ::= INTEGER", - /* 118 */ "tagitem ::= FLOAT", - /* 119 */ "tagitem ::= STRING", - /* 120 */ "tagitem ::= BOOL", - /* 121 */ "tagitem ::= NULL", - /* 122 */ "tagitem ::= MINUS INTEGER", - /* 123 */ "tagitem ::= MINUS FLOAT", - /* 124 */ "tagitem ::= PLUS INTEGER", - /* 125 */ "tagitem ::= PLUS FLOAT", - /* 126 */ "select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt", - /* 127 */ "union ::= select", - /* 128 */ "union ::= LP union RP", - /* 129 */ "union ::= union UNION ALL select", - /* 130 */ "union ::= union UNION ALL LP select RP", - /* 131 */ "cmd ::= union", - /* 132 */ "select ::= SELECT selcollist", - /* 133 */ "sclp ::= selcollist COMMA", - /* 134 */ "sclp ::=", - /* 135 */ "selcollist ::= sclp expr as", - /* 136 */ "selcollist ::= sclp STAR", - /* 137 */ "as ::= AS ids", - /* 138 */ "as ::= ids", - /* 139 */ "as ::=", - /* 140 */ "from ::= FROM tablelist", - /* 141 */ "tablelist ::= ids cpxName", - /* 142 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 143 */ "tmvar ::= VARIABLE", - /* 144 */ "interval_opt ::= INTERVAL LP tmvar RP", - /* 145 */ "interval_opt ::=", - /* 146 */ "fill_opt ::=", - /* 147 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 148 */ "fill_opt ::= FILL LP ID RP", - /* 149 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 150 */ "sliding_opt ::=", - /* 151 */ "orderby_opt ::=", - /* 152 */ "orderby_opt ::= ORDER BY sortlist", - /* 153 */ "sortlist ::= sortlist COMMA item sortorder", - /* 154 */ "sortlist ::= item sortorder", - /* 155 */ "item ::= ids cpxName", - /* 156 */ "sortorder ::= ASC", - /* 157 */ "sortorder ::= DESC", - /* 158 */ "sortorder ::=", - /* 159 */ "groupby_opt ::=", - /* 160 */ "groupby_opt ::= GROUP BY grouplist", - /* 161 */ "grouplist ::= grouplist COMMA item", - /* 162 */ "grouplist ::= item", - /* 163 */ "having_opt ::=", - /* 164 */ "having_opt ::= HAVING expr", - /* 165 */ "limit_opt ::=", - /* 166 */ "limit_opt ::= LIMIT signed", - /* 167 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 168 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 169 */ "slimit_opt ::=", - /* 170 */ "slimit_opt ::= SLIMIT signed", - /* 171 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 172 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 173 */ "where_opt ::=", - /* 174 */ "where_opt ::= WHERE expr", - /* 175 */ "expr ::= LP expr RP", - /* 176 */ "expr ::= ID", - /* 177 */ "expr ::= ID DOT ID", - /* 178 */ "expr ::= ID DOT STAR", - /* 179 */ "expr ::= INTEGER", - /* 180 */ "expr ::= MINUS INTEGER", - /* 181 */ "expr ::= PLUS INTEGER", - /* 182 */ "expr ::= FLOAT", - /* 183 */ "expr ::= MINUS FLOAT", - /* 184 */ "expr ::= PLUS FLOAT", - /* 185 */ "expr ::= STRING", - /* 186 */ "expr ::= NOW", - /* 187 */ "expr ::= VARIABLE", - /* 188 */ "expr ::= BOOL", - /* 189 */ "expr ::= ID LP exprlist RP", - /* 190 */ "expr ::= ID LP STAR RP", - /* 191 */ "expr ::= expr AND expr", - /* 192 */ "expr ::= expr OR expr", - /* 193 */ "expr ::= expr LT expr", - /* 194 */ "expr ::= expr GT expr", - /* 195 */ "expr ::= expr LE expr", - /* 196 */ "expr ::= expr GE expr", - /* 197 */ "expr ::= expr NE expr", - /* 198 */ "expr ::= expr EQ expr", - /* 199 */ "expr ::= expr PLUS expr", - /* 200 */ "expr ::= expr MINUS expr", - /* 201 */ "expr ::= expr STAR expr", - /* 202 */ "expr ::= expr SLASH expr", - /* 203 */ "expr ::= expr REM expr", - /* 204 */ "expr ::= expr LIKE expr", - /* 205 */ "expr ::= expr IN LP exprlist RP", - /* 206 */ "exprlist ::= exprlist COMMA expritem", - /* 207 */ "exprlist ::= expritem", - /* 208 */ "expritem ::= expr", - /* 209 */ "expritem ::=", - /* 210 */ "cmd ::= RESET QUERY CACHE", - /* 211 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 212 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 213 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 214 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 215 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 216 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 217 */ "cmd ::= KILL CONNECTION INTEGER", - /* 218 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 219 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 80 */ "fsync ::= FSYNC INTEGER", + /* 81 */ "comp ::= COMP INTEGER", + /* 82 */ "prec ::= PRECISION STRING", + /* 83 */ "db_optr ::=", + /* 84 */ "db_optr ::= db_optr tables", + /* 85 */ "db_optr ::= db_optr cache", + /* 86 */ "db_optr ::= db_optr replica", + /* 87 */ "db_optr ::= db_optr days", + /* 88 */ "db_optr ::= db_optr minrows", + /* 89 */ "db_optr ::= db_optr maxrows", + /* 90 */ "db_optr ::= db_optr blocks", + /* 91 */ "db_optr ::= db_optr ctime", + /* 92 */ "db_optr ::= db_optr wal", + /* 93 */ "db_optr ::= db_optr fsync", + /* 94 */ "db_optr ::= db_optr comp", + /* 95 */ "db_optr ::= db_optr prec", + /* 96 */ "db_optr ::= db_optr keep", + /* 97 */ "alter_db_optr ::=", + /* 98 */ "alter_db_optr ::= alter_db_optr replica", + /* 99 */ "alter_db_optr ::= alter_db_optr tables", + /* 100 */ "alter_db_optr ::= alter_db_optr keep", + /* 101 */ "alter_db_optr ::= alter_db_optr blocks", + /* 102 */ "alter_db_optr ::= alter_db_optr comp", + /* 103 */ "alter_db_optr ::= alter_db_optr wal", + /* 104 */ "alter_db_optr ::= alter_db_optr fsync", + /* 105 */ "typename ::= ids", + /* 106 */ "typename ::= ids LP signed RP", + /* 107 */ "signed ::= INTEGER", + /* 108 */ "signed ::= PLUS INTEGER", + /* 109 */ "signed ::= MINUS INTEGER", + /* 110 */ "cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args", + /* 111 */ "create_table_args ::= LP columnlist RP", + /* 112 */ "create_table_args ::= LP columnlist RP TAGS LP columnlist RP", + /* 113 */ "create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP", + /* 114 */ "create_table_args ::= AS select", + /* 115 */ "columnlist ::= columnlist COMMA column", + /* 116 */ "columnlist ::= column", + /* 117 */ "column ::= ids typename", + /* 118 */ "tagitemlist ::= tagitemlist COMMA tagitem", + /* 119 */ "tagitemlist ::= tagitem", + /* 120 */ "tagitem ::= INTEGER", + /* 121 */ "tagitem ::= FLOAT", + /* 122 */ "tagitem ::= STRING", + /* 123 */ "tagitem ::= BOOL", + /* 124 */ "tagitem ::= NULL", + /* 125 */ "tagitem ::= MINUS INTEGER", + /* 126 */ "tagitem ::= MINUS FLOAT", + /* 127 */ "tagitem ::= PLUS INTEGER", + /* 128 */ "tagitem ::= PLUS FLOAT", + /* 129 */ "select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt", + /* 130 */ "union ::= select", + /* 131 */ "union ::= LP union RP", + /* 132 */ "union ::= union UNION ALL select", + /* 133 */ "union ::= union UNION ALL LP select RP", + /* 134 */ "cmd ::= union", + /* 135 */ "select ::= SELECT selcollist", + /* 136 */ "sclp ::= selcollist COMMA", + /* 137 */ "sclp ::=", + /* 138 */ "selcollist ::= sclp expr as", + /* 139 */ "selcollist ::= sclp STAR", + /* 140 */ "as ::= AS ids", + /* 141 */ "as ::= ids", + /* 142 */ "as ::=", + /* 143 */ "from ::= FROM tablelist", + /* 144 */ "tablelist ::= ids cpxName", + /* 145 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 146 */ "tmvar ::= VARIABLE", + /* 147 */ "interval_opt ::= INTERVAL LP tmvar RP", + /* 148 */ "interval_opt ::=", + /* 149 */ "fill_opt ::=", + /* 150 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 151 */ "fill_opt ::= FILL LP ID RP", + /* 152 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 153 */ "sliding_opt ::=", + /* 154 */ "orderby_opt ::=", + /* 155 */ "orderby_opt ::= ORDER BY sortlist", + /* 156 */ "sortlist ::= sortlist COMMA item sortorder", + /* 157 */ "sortlist ::= item sortorder", + /* 158 */ "item ::= ids cpxName", + /* 159 */ "sortorder ::= ASC", + /* 160 */ "sortorder ::= DESC", + /* 161 */ "sortorder ::=", + /* 162 */ "groupby_opt ::=", + /* 163 */ "groupby_opt ::= GROUP BY grouplist", + /* 164 */ "grouplist ::= grouplist COMMA item", + /* 165 */ "grouplist ::= item", + /* 166 */ "having_opt ::=", + /* 167 */ "having_opt ::= HAVING expr", + /* 168 */ "limit_opt ::=", + /* 169 */ "limit_opt ::= LIMIT signed", + /* 170 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 171 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 172 */ "slimit_opt ::=", + /* 173 */ "slimit_opt ::= SLIMIT signed", + /* 174 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 175 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 176 */ "where_opt ::=", + /* 177 */ "where_opt ::= WHERE expr", + /* 178 */ "expr ::= LP expr RP", + /* 179 */ "expr ::= ID", + /* 180 */ "expr ::= ID DOT ID", + /* 181 */ "expr ::= ID DOT STAR", + /* 182 */ "expr ::= INTEGER", + /* 183 */ "expr ::= MINUS INTEGER", + /* 184 */ "expr ::= PLUS INTEGER", + /* 185 */ "expr ::= FLOAT", + /* 186 */ "expr ::= MINUS FLOAT", + /* 187 */ "expr ::= PLUS FLOAT", + /* 188 */ "expr ::= STRING", + /* 189 */ "expr ::= NOW", + /* 190 */ "expr ::= VARIABLE", + /* 191 */ "expr ::= BOOL", + /* 192 */ "expr ::= ID LP exprlist RP", + /* 193 */ "expr ::= ID LP STAR RP", + /* 194 */ "expr ::= expr AND expr", + /* 195 */ "expr ::= expr OR expr", + /* 196 */ "expr ::= expr LT expr", + /* 197 */ "expr ::= expr GT expr", + /* 198 */ "expr ::= expr LE expr", + /* 199 */ "expr ::= expr GE expr", + /* 200 */ "expr ::= expr NE expr", + /* 201 */ "expr ::= expr EQ expr", + /* 202 */ "expr ::= expr PLUS expr", + /* 203 */ "expr ::= expr MINUS expr", + /* 204 */ "expr ::= expr STAR expr", + /* 205 */ "expr ::= expr SLASH expr", + /* 206 */ "expr ::= expr REM expr", + /* 207 */ "expr ::= expr LIKE expr", + /* 208 */ "expr ::= expr IN LP exprlist RP", + /* 209 */ "exprlist ::= exprlist COMMA expritem", + /* 210 */ "exprlist ::= expritem", + /* 211 */ "expritem ::= expr", + /* 212 */ "expritem ::=", + /* 213 */ "cmd ::= RESET QUERY CACHE", + /* 214 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 215 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 216 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 217 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 218 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 219 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 220 */ "cmd ::= KILL CONNECTION INTEGER", + /* 221 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 222 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1338,50 +1345,50 @@ static void yy_destructor( ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 225: /* keep */ - case 226: /* tagitemlist */ - case 249: /* fill_opt */ - case 251: /* groupby_opt */ - case 252: /* orderby_opt */ - case 262: /* sortlist */ - case 266: /* grouplist */ + case 226: /* keep */ + case 227: /* tagitemlist */ + case 251: /* fill_opt */ + case 253: /* groupby_opt */ + case 254: /* orderby_opt */ + case 264: /* sortlist */ + case 268: /* grouplist */ { -tVariantListDestroy((yypminor->yy322)); +tVariantListDestroy((yypminor->yy494)); } break; - case 241: /* columnlist */ + case 243: /* columnlist */ { -tFieldListDestroy((yypminor->yy369)); +tFieldListDestroy((yypminor->yy449)); } break; - case 242: /* select */ + case 244: /* select */ { -doDestroyQuerySql((yypminor->yy190)); +doDestroyQuerySql((yypminor->yy150)); } break; - case 245: /* selcollist */ - case 257: /* sclp */ - case 267: /* exprlist */ + case 247: /* selcollist */ + case 259: /* sclp */ + case 269: /* exprlist */ { -tSQLExprListDestroy((yypminor->yy260)); +tSQLExprListDestroy((yypminor->yy224)); } break; - case 247: /* where_opt */ - case 253: /* having_opt */ - case 258: /* expr */ - case 268: /* expritem */ + case 249: /* where_opt */ + case 255: /* having_opt */ + case 260: /* expr */ + case 270: /* expritem */ { -tSQLExprDestroy((yypminor->yy500)); +tSQLExprDestroy((yypminor->yy66)); } break; - case 256: /* union */ + case 258: /* union */ { -destroyAllSelectClause((yypminor->yy263)); +destroyAllSelectClause((yypminor->yy25)); } break; - case 263: /* sortitem */ + case 265: /* sortitem */ { -tVariantDestroy(&(yypminor->yy518)); +tVariantDestroy(&(yypminor->yy312)); } break; /********* End destructor definitions *****************************************/ @@ -1675,226 +1682,229 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 206, -1 }, /* (0) program ::= cmd */ - { 207, -2 }, /* (1) cmd ::= SHOW DATABASES */ - { 207, -2 }, /* (2) cmd ::= SHOW MNODES */ - { 207, -2 }, /* (3) cmd ::= SHOW DNODES */ - { 207, -2 }, /* (4) cmd ::= SHOW ACCOUNTS */ - { 207, -2 }, /* (5) cmd ::= SHOW USERS */ - { 207, -2 }, /* (6) cmd ::= SHOW MODULES */ - { 207, -2 }, /* (7) cmd ::= SHOW QUERIES */ - { 207, -2 }, /* (8) cmd ::= SHOW CONNECTIONS */ - { 207, -2 }, /* (9) cmd ::= SHOW STREAMS */ - { 207, -2 }, /* (10) cmd ::= SHOW CONFIGS */ - { 207, -2 }, /* (11) cmd ::= SHOW SCORES */ - { 207, -2 }, /* (12) cmd ::= SHOW GRANTS */ - { 207, -2 }, /* (13) cmd ::= SHOW VNODES */ - { 207, -3 }, /* (14) cmd ::= SHOW VNODES IPTOKEN */ - { 208, 0 }, /* (15) dbPrefix ::= */ - { 208, -2 }, /* (16) dbPrefix ::= ids DOT */ - { 210, 0 }, /* (17) cpxName ::= */ - { 210, -2 }, /* (18) cpxName ::= DOT ids */ - { 207, -3 }, /* (19) cmd ::= SHOW dbPrefix TABLES */ - { 207, -5 }, /* (20) cmd ::= SHOW dbPrefix TABLES LIKE ids */ - { 207, -3 }, /* (21) cmd ::= SHOW dbPrefix STABLES */ - { 207, -5 }, /* (22) cmd ::= SHOW dbPrefix STABLES LIKE ids */ - { 207, -3 }, /* (23) cmd ::= SHOW dbPrefix VGROUPS */ - { 207, -4 }, /* (24) cmd ::= SHOW dbPrefix VGROUPS ids */ - { 207, -5 }, /* (25) cmd ::= DROP TABLE ifexists ids cpxName */ - { 207, -4 }, /* (26) cmd ::= DROP DATABASE ifexists ids */ - { 207, -3 }, /* (27) cmd ::= DROP DNODE ids */ - { 207, -3 }, /* (28) cmd ::= DROP USER ids */ - { 207, -3 }, /* (29) cmd ::= DROP ACCOUNT ids */ - { 207, -2 }, /* (30) cmd ::= USE ids */ - { 207, -3 }, /* (31) cmd ::= DESCRIBE ids cpxName */ - { 207, -5 }, /* (32) cmd ::= ALTER USER ids PASS ids */ - { 207, -5 }, /* (33) cmd ::= ALTER USER ids PRIVILEGE ids */ - { 207, -4 }, /* (34) cmd ::= ALTER DNODE ids ids */ - { 207, -5 }, /* (35) cmd ::= ALTER DNODE ids ids ids */ - { 207, -3 }, /* (36) cmd ::= ALTER LOCAL ids */ - { 207, -4 }, /* (37) cmd ::= ALTER LOCAL ids ids */ - { 207, -4 }, /* (38) cmd ::= ALTER DATABASE ids alter_db_optr */ - { 207, -4 }, /* (39) cmd ::= ALTER ACCOUNT ids acct_optr */ - { 207, -6 }, /* (40) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ - { 209, -1 }, /* (41) ids ::= ID */ - { 209, -1 }, /* (42) ids ::= STRING */ - { 211, -2 }, /* (43) ifexists ::= IF EXISTS */ - { 211, 0 }, /* (44) ifexists ::= */ - { 214, -3 }, /* (45) ifnotexists ::= IF NOT EXISTS */ - { 214, 0 }, /* (46) ifnotexists ::= */ - { 207, -3 }, /* (47) cmd ::= CREATE DNODE ids */ - { 207, -6 }, /* (48) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 207, -5 }, /* (49) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 207, -5 }, /* (50) cmd ::= CREATE USER ids PASS ids */ - { 216, 0 }, /* (51) pps ::= */ - { 216, -2 }, /* (52) pps ::= PPS INTEGER */ - { 217, 0 }, /* (53) tseries ::= */ - { 217, -2 }, /* (54) tseries ::= TSERIES INTEGER */ - { 218, 0 }, /* (55) dbs ::= */ - { 218, -2 }, /* (56) dbs ::= DBS INTEGER */ - { 219, 0 }, /* (57) streams ::= */ - { 219, -2 }, /* (58) streams ::= STREAMS INTEGER */ - { 220, 0 }, /* (59) storage ::= */ - { 220, -2 }, /* (60) storage ::= STORAGE INTEGER */ - { 221, 0 }, /* (61) qtime ::= */ - { 221, -2 }, /* (62) qtime ::= QTIME INTEGER */ - { 222, 0 }, /* (63) users ::= */ - { 222, -2 }, /* (64) users ::= USERS INTEGER */ - { 223, 0 }, /* (65) conns ::= */ - { 223, -2 }, /* (66) conns ::= CONNS INTEGER */ - { 224, 0 }, /* (67) state ::= */ - { 224, -2 }, /* (68) state ::= STATE ids */ - { 213, -9 }, /* (69) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 225, -2 }, /* (70) keep ::= KEEP tagitemlist */ - { 227, -2 }, /* (71) tables ::= MAXTABLES INTEGER */ - { 228, -2 }, /* (72) cache ::= CACHE INTEGER */ - { 229, -2 }, /* (73) replica ::= REPLICA INTEGER */ - { 230, -2 }, /* (74) days ::= DAYS INTEGER */ - { 231, -2 }, /* (75) minrows ::= MINROWS INTEGER */ - { 232, -2 }, /* (76) maxrows ::= MAXROWS INTEGER */ - { 233, -2 }, /* (77) blocks ::= BLOCKS INTEGER */ - { 234, -2 }, /* (78) ctime ::= CTIME INTEGER */ - { 235, -2 }, /* (79) wal ::= WAL INTEGER */ - { 236, -2 }, /* (80) comp ::= COMP INTEGER */ - { 237, -2 }, /* (81) prec ::= PRECISION STRING */ - { 215, 0 }, /* (82) db_optr ::= */ - { 215, -2 }, /* (83) db_optr ::= db_optr tables */ - { 215, -2 }, /* (84) db_optr ::= db_optr cache */ - { 215, -2 }, /* (85) db_optr ::= db_optr replica */ - { 215, -2 }, /* (86) db_optr ::= db_optr days */ - { 215, -2 }, /* (87) db_optr ::= db_optr minrows */ - { 215, -2 }, /* (88) db_optr ::= db_optr maxrows */ - { 215, -2 }, /* (89) db_optr ::= db_optr blocks */ - { 215, -2 }, /* (90) db_optr ::= db_optr ctime */ - { 215, -2 }, /* (91) db_optr ::= db_optr wal */ - { 215, -2 }, /* (92) db_optr ::= db_optr comp */ - { 215, -2 }, /* (93) db_optr ::= db_optr prec */ - { 215, -2 }, /* (94) db_optr ::= db_optr keep */ - { 212, 0 }, /* (95) alter_db_optr ::= */ - { 212, -2 }, /* (96) alter_db_optr ::= alter_db_optr replica */ - { 212, -2 }, /* (97) alter_db_optr ::= alter_db_optr tables */ - { 212, -2 }, /* (98) alter_db_optr ::= alter_db_optr keep */ - { 212, -2 }, /* (99) alter_db_optr ::= alter_db_optr blocks */ - { 212, -2 }, /* (100) alter_db_optr ::= alter_db_optr comp */ - { 212, -2 }, /* (101) alter_db_optr ::= alter_db_optr wal */ - { 238, -1 }, /* (102) typename ::= ids */ - { 238, -4 }, /* (103) typename ::= ids LP signed RP */ - { 239, -1 }, /* (104) signed ::= INTEGER */ - { 239, -2 }, /* (105) signed ::= PLUS INTEGER */ - { 239, -2 }, /* (106) signed ::= MINUS INTEGER */ - { 207, -6 }, /* (107) cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */ - { 240, -3 }, /* (108) create_table_args ::= LP columnlist RP */ - { 240, -7 }, /* (109) create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ - { 240, -7 }, /* (110) create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ - { 240, -2 }, /* (111) create_table_args ::= AS select */ - { 241, -3 }, /* (112) columnlist ::= columnlist COMMA column */ - { 241, -1 }, /* (113) columnlist ::= column */ - { 243, -2 }, /* (114) column ::= ids typename */ - { 226, -3 }, /* (115) tagitemlist ::= tagitemlist COMMA tagitem */ - { 226, -1 }, /* (116) tagitemlist ::= tagitem */ - { 244, -1 }, /* (117) tagitem ::= INTEGER */ - { 244, -1 }, /* (118) tagitem ::= FLOAT */ - { 244, -1 }, /* (119) tagitem ::= STRING */ - { 244, -1 }, /* (120) tagitem ::= BOOL */ - { 244, -1 }, /* (121) tagitem ::= NULL */ - { 244, -2 }, /* (122) tagitem ::= MINUS INTEGER */ - { 244, -2 }, /* (123) tagitem ::= MINUS FLOAT */ - { 244, -2 }, /* (124) tagitem ::= PLUS INTEGER */ - { 244, -2 }, /* (125) tagitem ::= PLUS FLOAT */ - { 242, -12 }, /* (126) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ - { 256, -1 }, /* (127) union ::= select */ - { 256, -3 }, /* (128) union ::= LP union RP */ - { 256, -4 }, /* (129) union ::= union UNION ALL select */ - { 256, -6 }, /* (130) union ::= union UNION ALL LP select RP */ - { 207, -1 }, /* (131) cmd ::= union */ - { 242, -2 }, /* (132) select ::= SELECT selcollist */ - { 257, -2 }, /* (133) sclp ::= selcollist COMMA */ - { 257, 0 }, /* (134) sclp ::= */ - { 245, -3 }, /* (135) selcollist ::= sclp expr as */ - { 245, -2 }, /* (136) selcollist ::= sclp STAR */ - { 259, -2 }, /* (137) as ::= AS ids */ - { 259, -1 }, /* (138) as ::= ids */ - { 259, 0 }, /* (139) as ::= */ - { 246, -2 }, /* (140) from ::= FROM tablelist */ - { 260, -2 }, /* (141) tablelist ::= ids cpxName */ - { 260, -4 }, /* (142) tablelist ::= tablelist COMMA ids cpxName */ - { 261, -1 }, /* (143) tmvar ::= VARIABLE */ - { 248, -4 }, /* (144) interval_opt ::= INTERVAL LP tmvar RP */ - { 248, 0 }, /* (145) interval_opt ::= */ - { 249, 0 }, /* (146) fill_opt ::= */ - { 249, -6 }, /* (147) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 249, -4 }, /* (148) fill_opt ::= FILL LP ID RP */ - { 250, -4 }, /* (149) sliding_opt ::= SLIDING LP tmvar RP */ - { 250, 0 }, /* (150) sliding_opt ::= */ - { 252, 0 }, /* (151) orderby_opt ::= */ - { 252, -3 }, /* (152) orderby_opt ::= ORDER BY sortlist */ - { 262, -4 }, /* (153) sortlist ::= sortlist COMMA item sortorder */ - { 262, -2 }, /* (154) sortlist ::= item sortorder */ - { 264, -2 }, /* (155) item ::= ids cpxName */ - { 265, -1 }, /* (156) sortorder ::= ASC */ - { 265, -1 }, /* (157) sortorder ::= DESC */ - { 265, 0 }, /* (158) sortorder ::= */ - { 251, 0 }, /* (159) groupby_opt ::= */ - { 251, -3 }, /* (160) groupby_opt ::= GROUP BY grouplist */ - { 266, -3 }, /* (161) grouplist ::= grouplist COMMA item */ - { 266, -1 }, /* (162) grouplist ::= item */ - { 253, 0 }, /* (163) having_opt ::= */ - { 253, -2 }, /* (164) having_opt ::= HAVING expr */ - { 255, 0 }, /* (165) limit_opt ::= */ - { 255, -2 }, /* (166) limit_opt ::= LIMIT signed */ - { 255, -4 }, /* (167) limit_opt ::= LIMIT signed OFFSET signed */ - { 255, -4 }, /* (168) limit_opt ::= LIMIT signed COMMA signed */ - { 254, 0 }, /* (169) slimit_opt ::= */ - { 254, -2 }, /* (170) slimit_opt ::= SLIMIT signed */ - { 254, -4 }, /* (171) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 254, -4 }, /* (172) slimit_opt ::= SLIMIT signed COMMA signed */ - { 247, 0 }, /* (173) where_opt ::= */ - { 247, -2 }, /* (174) where_opt ::= WHERE expr */ - { 258, -3 }, /* (175) expr ::= LP expr RP */ - { 258, -1 }, /* (176) expr ::= ID */ - { 258, -3 }, /* (177) expr ::= ID DOT ID */ - { 258, -3 }, /* (178) expr ::= ID DOT STAR */ - { 258, -1 }, /* (179) expr ::= INTEGER */ - { 258, -2 }, /* (180) expr ::= MINUS INTEGER */ - { 258, -2 }, /* (181) expr ::= PLUS INTEGER */ - { 258, -1 }, /* (182) expr ::= FLOAT */ - { 258, -2 }, /* (183) expr ::= MINUS FLOAT */ - { 258, -2 }, /* (184) expr ::= PLUS FLOAT */ - { 258, -1 }, /* (185) expr ::= STRING */ - { 258, -1 }, /* (186) expr ::= NOW */ - { 258, -1 }, /* (187) expr ::= VARIABLE */ - { 258, -1 }, /* (188) expr ::= BOOL */ - { 258, -4 }, /* (189) expr ::= ID LP exprlist RP */ - { 258, -4 }, /* (190) expr ::= ID LP STAR RP */ - { 258, -3 }, /* (191) expr ::= expr AND expr */ - { 258, -3 }, /* (192) expr ::= expr OR expr */ - { 258, -3 }, /* (193) expr ::= expr LT expr */ - { 258, -3 }, /* (194) expr ::= expr GT expr */ - { 258, -3 }, /* (195) expr ::= expr LE expr */ - { 258, -3 }, /* (196) expr ::= expr GE expr */ - { 258, -3 }, /* (197) expr ::= expr NE expr */ - { 258, -3 }, /* (198) expr ::= expr EQ expr */ - { 258, -3 }, /* (199) expr ::= expr PLUS expr */ - { 258, -3 }, /* (200) expr ::= expr MINUS expr */ - { 258, -3 }, /* (201) expr ::= expr STAR expr */ - { 258, -3 }, /* (202) expr ::= expr SLASH expr */ - { 258, -3 }, /* (203) expr ::= expr REM expr */ - { 258, -3 }, /* (204) expr ::= expr LIKE expr */ - { 258, -5 }, /* (205) expr ::= expr IN LP exprlist RP */ - { 267, -3 }, /* (206) exprlist ::= exprlist COMMA expritem */ - { 267, -1 }, /* (207) exprlist ::= expritem */ - { 268, -1 }, /* (208) expritem ::= expr */ - { 268, 0 }, /* (209) expritem ::= */ - { 207, -3 }, /* (210) cmd ::= RESET QUERY CACHE */ - { 207, -7 }, /* (211) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 207, -7 }, /* (212) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 207, -7 }, /* (213) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 207, -7 }, /* (214) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 207, -8 }, /* (215) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 207, -9 }, /* (216) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 207, -3 }, /* (217) cmd ::= KILL CONNECTION INTEGER */ - { 207, -5 }, /* (218) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 207, -5 }, /* (219) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + { 207, -1 }, /* (0) program ::= cmd */ + { 208, -2 }, /* (1) cmd ::= SHOW DATABASES */ + { 208, -2 }, /* (2) cmd ::= SHOW MNODES */ + { 208, -2 }, /* (3) cmd ::= SHOW DNODES */ + { 208, -2 }, /* (4) cmd ::= SHOW ACCOUNTS */ + { 208, -2 }, /* (5) cmd ::= SHOW USERS */ + { 208, -2 }, /* (6) cmd ::= SHOW MODULES */ + { 208, -2 }, /* (7) cmd ::= SHOW QUERIES */ + { 208, -2 }, /* (8) cmd ::= SHOW CONNECTIONS */ + { 208, -2 }, /* (9) cmd ::= SHOW STREAMS */ + { 208, -2 }, /* (10) cmd ::= SHOW CONFIGS */ + { 208, -2 }, /* (11) cmd ::= SHOW SCORES */ + { 208, -2 }, /* (12) cmd ::= SHOW GRANTS */ + { 208, -2 }, /* (13) cmd ::= SHOW VNODES */ + { 208, -3 }, /* (14) cmd ::= SHOW VNODES IPTOKEN */ + { 209, 0 }, /* (15) dbPrefix ::= */ + { 209, -2 }, /* (16) dbPrefix ::= ids DOT */ + { 211, 0 }, /* (17) cpxName ::= */ + { 211, -2 }, /* (18) cpxName ::= DOT ids */ + { 208, -3 }, /* (19) cmd ::= SHOW dbPrefix TABLES */ + { 208, -5 }, /* (20) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + { 208, -3 }, /* (21) cmd ::= SHOW dbPrefix STABLES */ + { 208, -5 }, /* (22) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + { 208, -3 }, /* (23) cmd ::= SHOW dbPrefix VGROUPS */ + { 208, -4 }, /* (24) cmd ::= SHOW dbPrefix VGROUPS ids */ + { 208, -5 }, /* (25) cmd ::= DROP TABLE ifexists ids cpxName */ + { 208, -4 }, /* (26) cmd ::= DROP DATABASE ifexists ids */ + { 208, -3 }, /* (27) cmd ::= DROP DNODE ids */ + { 208, -3 }, /* (28) cmd ::= DROP USER ids */ + { 208, -3 }, /* (29) cmd ::= DROP ACCOUNT ids */ + { 208, -2 }, /* (30) cmd ::= USE ids */ + { 208, -3 }, /* (31) cmd ::= DESCRIBE ids cpxName */ + { 208, -5 }, /* (32) cmd ::= ALTER USER ids PASS ids */ + { 208, -5 }, /* (33) cmd ::= ALTER USER ids PRIVILEGE ids */ + { 208, -4 }, /* (34) cmd ::= ALTER DNODE ids ids */ + { 208, -5 }, /* (35) cmd ::= ALTER DNODE ids ids ids */ + { 208, -3 }, /* (36) cmd ::= ALTER LOCAL ids */ + { 208, -4 }, /* (37) cmd ::= ALTER LOCAL ids ids */ + { 208, -4 }, /* (38) cmd ::= ALTER DATABASE ids alter_db_optr */ + { 208, -4 }, /* (39) cmd ::= ALTER ACCOUNT ids acct_optr */ + { 208, -6 }, /* (40) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + { 210, -1 }, /* (41) ids ::= ID */ + { 210, -1 }, /* (42) ids ::= STRING */ + { 212, -2 }, /* (43) ifexists ::= IF EXISTS */ + { 212, 0 }, /* (44) ifexists ::= */ + { 215, -3 }, /* (45) ifnotexists ::= IF NOT EXISTS */ + { 215, 0 }, /* (46) ifnotexists ::= */ + { 208, -3 }, /* (47) cmd ::= CREATE DNODE ids */ + { 208, -6 }, /* (48) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 208, -5 }, /* (49) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 208, -5 }, /* (50) cmd ::= CREATE USER ids PASS ids */ + { 217, 0 }, /* (51) pps ::= */ + { 217, -2 }, /* (52) pps ::= PPS INTEGER */ + { 218, 0 }, /* (53) tseries ::= */ + { 218, -2 }, /* (54) tseries ::= TSERIES INTEGER */ + { 219, 0 }, /* (55) dbs ::= */ + { 219, -2 }, /* (56) dbs ::= DBS INTEGER */ + { 220, 0 }, /* (57) streams ::= */ + { 220, -2 }, /* (58) streams ::= STREAMS INTEGER */ + { 221, 0 }, /* (59) storage ::= */ + { 221, -2 }, /* (60) storage ::= STORAGE INTEGER */ + { 222, 0 }, /* (61) qtime ::= */ + { 222, -2 }, /* (62) qtime ::= QTIME INTEGER */ + { 223, 0 }, /* (63) users ::= */ + { 223, -2 }, /* (64) users ::= USERS INTEGER */ + { 224, 0 }, /* (65) conns ::= */ + { 224, -2 }, /* (66) conns ::= CONNS INTEGER */ + { 225, 0 }, /* (67) state ::= */ + { 225, -2 }, /* (68) state ::= STATE ids */ + { 214, -9 }, /* (69) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 226, -2 }, /* (70) keep ::= KEEP tagitemlist */ + { 228, -2 }, /* (71) tables ::= MAXTABLES INTEGER */ + { 229, -2 }, /* (72) cache ::= CACHE INTEGER */ + { 230, -2 }, /* (73) replica ::= REPLICA INTEGER */ + { 231, -2 }, /* (74) days ::= DAYS INTEGER */ + { 232, -2 }, /* (75) minrows ::= MINROWS INTEGER */ + { 233, -2 }, /* (76) maxrows ::= MAXROWS INTEGER */ + { 234, -2 }, /* (77) blocks ::= BLOCKS INTEGER */ + { 235, -2 }, /* (78) ctime ::= CTIME INTEGER */ + { 236, -2 }, /* (79) wal ::= WAL INTEGER */ + { 237, -2 }, /* (80) fsync ::= FSYNC INTEGER */ + { 238, -2 }, /* (81) comp ::= COMP INTEGER */ + { 239, -2 }, /* (82) prec ::= PRECISION STRING */ + { 216, 0 }, /* (83) db_optr ::= */ + { 216, -2 }, /* (84) db_optr ::= db_optr tables */ + { 216, -2 }, /* (85) db_optr ::= db_optr cache */ + { 216, -2 }, /* (86) db_optr ::= db_optr replica */ + { 216, -2 }, /* (87) db_optr ::= db_optr days */ + { 216, -2 }, /* (88) db_optr ::= db_optr minrows */ + { 216, -2 }, /* (89) db_optr ::= db_optr maxrows */ + { 216, -2 }, /* (90) db_optr ::= db_optr blocks */ + { 216, -2 }, /* (91) db_optr ::= db_optr ctime */ + { 216, -2 }, /* (92) db_optr ::= db_optr wal */ + { 216, -2 }, /* (93) db_optr ::= db_optr fsync */ + { 216, -2 }, /* (94) db_optr ::= db_optr comp */ + { 216, -2 }, /* (95) db_optr ::= db_optr prec */ + { 216, -2 }, /* (96) db_optr ::= db_optr keep */ + { 213, 0 }, /* (97) alter_db_optr ::= */ + { 213, -2 }, /* (98) alter_db_optr ::= alter_db_optr replica */ + { 213, -2 }, /* (99) alter_db_optr ::= alter_db_optr tables */ + { 213, -2 }, /* (100) alter_db_optr ::= alter_db_optr keep */ + { 213, -2 }, /* (101) alter_db_optr ::= alter_db_optr blocks */ + { 213, -2 }, /* (102) alter_db_optr ::= alter_db_optr comp */ + { 213, -2 }, /* (103) alter_db_optr ::= alter_db_optr wal */ + { 213, -2 }, /* (104) alter_db_optr ::= alter_db_optr fsync */ + { 240, -1 }, /* (105) typename ::= ids */ + { 240, -4 }, /* (106) typename ::= ids LP signed RP */ + { 241, -1 }, /* (107) signed ::= INTEGER */ + { 241, -2 }, /* (108) signed ::= PLUS INTEGER */ + { 241, -2 }, /* (109) signed ::= MINUS INTEGER */ + { 208, -6 }, /* (110) cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */ + { 242, -3 }, /* (111) create_table_args ::= LP columnlist RP */ + { 242, -7 }, /* (112) create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ + { 242, -7 }, /* (113) create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ + { 242, -2 }, /* (114) create_table_args ::= AS select */ + { 243, -3 }, /* (115) columnlist ::= columnlist COMMA column */ + { 243, -1 }, /* (116) columnlist ::= column */ + { 245, -2 }, /* (117) column ::= ids typename */ + { 227, -3 }, /* (118) tagitemlist ::= tagitemlist COMMA tagitem */ + { 227, -1 }, /* (119) tagitemlist ::= tagitem */ + { 246, -1 }, /* (120) tagitem ::= INTEGER */ + { 246, -1 }, /* (121) tagitem ::= FLOAT */ + { 246, -1 }, /* (122) tagitem ::= STRING */ + { 246, -1 }, /* (123) tagitem ::= BOOL */ + { 246, -1 }, /* (124) tagitem ::= NULL */ + { 246, -2 }, /* (125) tagitem ::= MINUS INTEGER */ + { 246, -2 }, /* (126) tagitem ::= MINUS FLOAT */ + { 246, -2 }, /* (127) tagitem ::= PLUS INTEGER */ + { 246, -2 }, /* (128) tagitem ::= PLUS FLOAT */ + { 244, -12 }, /* (129) select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + { 258, -1 }, /* (130) union ::= select */ + { 258, -3 }, /* (131) union ::= LP union RP */ + { 258, -4 }, /* (132) union ::= union UNION ALL select */ + { 258, -6 }, /* (133) union ::= union UNION ALL LP select RP */ + { 208, -1 }, /* (134) cmd ::= union */ + { 244, -2 }, /* (135) select ::= SELECT selcollist */ + { 259, -2 }, /* (136) sclp ::= selcollist COMMA */ + { 259, 0 }, /* (137) sclp ::= */ + { 247, -3 }, /* (138) selcollist ::= sclp expr as */ + { 247, -2 }, /* (139) selcollist ::= sclp STAR */ + { 261, -2 }, /* (140) as ::= AS ids */ + { 261, -1 }, /* (141) as ::= ids */ + { 261, 0 }, /* (142) as ::= */ + { 248, -2 }, /* (143) from ::= FROM tablelist */ + { 262, -2 }, /* (144) tablelist ::= ids cpxName */ + { 262, -4 }, /* (145) tablelist ::= tablelist COMMA ids cpxName */ + { 263, -1 }, /* (146) tmvar ::= VARIABLE */ + { 250, -4 }, /* (147) interval_opt ::= INTERVAL LP tmvar RP */ + { 250, 0 }, /* (148) interval_opt ::= */ + { 251, 0 }, /* (149) fill_opt ::= */ + { 251, -6 }, /* (150) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 251, -4 }, /* (151) fill_opt ::= FILL LP ID RP */ + { 252, -4 }, /* (152) sliding_opt ::= SLIDING LP tmvar RP */ + { 252, 0 }, /* (153) sliding_opt ::= */ + { 254, 0 }, /* (154) orderby_opt ::= */ + { 254, -3 }, /* (155) orderby_opt ::= ORDER BY sortlist */ + { 264, -4 }, /* (156) sortlist ::= sortlist COMMA item sortorder */ + { 264, -2 }, /* (157) sortlist ::= item sortorder */ + { 266, -2 }, /* (158) item ::= ids cpxName */ + { 267, -1 }, /* (159) sortorder ::= ASC */ + { 267, -1 }, /* (160) sortorder ::= DESC */ + { 267, 0 }, /* (161) sortorder ::= */ + { 253, 0 }, /* (162) groupby_opt ::= */ + { 253, -3 }, /* (163) groupby_opt ::= GROUP BY grouplist */ + { 268, -3 }, /* (164) grouplist ::= grouplist COMMA item */ + { 268, -1 }, /* (165) grouplist ::= item */ + { 255, 0 }, /* (166) having_opt ::= */ + { 255, -2 }, /* (167) having_opt ::= HAVING expr */ + { 257, 0 }, /* (168) limit_opt ::= */ + { 257, -2 }, /* (169) limit_opt ::= LIMIT signed */ + { 257, -4 }, /* (170) limit_opt ::= LIMIT signed OFFSET signed */ + { 257, -4 }, /* (171) limit_opt ::= LIMIT signed COMMA signed */ + { 256, 0 }, /* (172) slimit_opt ::= */ + { 256, -2 }, /* (173) slimit_opt ::= SLIMIT signed */ + { 256, -4 }, /* (174) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 256, -4 }, /* (175) slimit_opt ::= SLIMIT signed COMMA signed */ + { 249, 0 }, /* (176) where_opt ::= */ + { 249, -2 }, /* (177) where_opt ::= WHERE expr */ + { 260, -3 }, /* (178) expr ::= LP expr RP */ + { 260, -1 }, /* (179) expr ::= ID */ + { 260, -3 }, /* (180) expr ::= ID DOT ID */ + { 260, -3 }, /* (181) expr ::= ID DOT STAR */ + { 260, -1 }, /* (182) expr ::= INTEGER */ + { 260, -2 }, /* (183) expr ::= MINUS INTEGER */ + { 260, -2 }, /* (184) expr ::= PLUS INTEGER */ + { 260, -1 }, /* (185) expr ::= FLOAT */ + { 260, -2 }, /* (186) expr ::= MINUS FLOAT */ + { 260, -2 }, /* (187) expr ::= PLUS FLOAT */ + { 260, -1 }, /* (188) expr ::= STRING */ + { 260, -1 }, /* (189) expr ::= NOW */ + { 260, -1 }, /* (190) expr ::= VARIABLE */ + { 260, -1 }, /* (191) expr ::= BOOL */ + { 260, -4 }, /* (192) expr ::= ID LP exprlist RP */ + { 260, -4 }, /* (193) expr ::= ID LP STAR RP */ + { 260, -3 }, /* (194) expr ::= expr AND expr */ + { 260, -3 }, /* (195) expr ::= expr OR expr */ + { 260, -3 }, /* (196) expr ::= expr LT expr */ + { 260, -3 }, /* (197) expr ::= expr GT expr */ + { 260, -3 }, /* (198) expr ::= expr LE expr */ + { 260, -3 }, /* (199) expr ::= expr GE expr */ + { 260, -3 }, /* (200) expr ::= expr NE expr */ + { 260, -3 }, /* (201) expr ::= expr EQ expr */ + { 260, -3 }, /* (202) expr ::= expr PLUS expr */ + { 260, -3 }, /* (203) expr ::= expr MINUS expr */ + { 260, -3 }, /* (204) expr ::= expr STAR expr */ + { 260, -3 }, /* (205) expr ::= expr SLASH expr */ + { 260, -3 }, /* (206) expr ::= expr REM expr */ + { 260, -3 }, /* (207) expr ::= expr LIKE expr */ + { 260, -5 }, /* (208) expr ::= expr IN LP exprlist RP */ + { 269, -3 }, /* (209) exprlist ::= exprlist COMMA expritem */ + { 269, -1 }, /* (210) exprlist ::= expritem */ + { 270, -1 }, /* (211) expritem ::= expr */ + { 270, 0 }, /* (212) expritem ::= */ + { 208, -3 }, /* (213) cmd ::= RESET QUERY CACHE */ + { 208, -7 }, /* (214) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 208, -7 }, /* (215) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 208, -7 }, /* (216) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 208, -7 }, /* (217) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 208, -8 }, /* (218) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 208, -9 }, /* (219) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 208, -3 }, /* (220) cmd ::= KILL CONNECTION INTEGER */ + { 208, -5 }, /* (221) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 208, -5 }, /* (222) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2114,13 +2124,13 @@ static void yy_reduce( { setDCLSQLElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; case 38: /* cmd ::= ALTER DATABASE ids alter_db_optr */ -{ SSQLToken t = {0}; setCreateDBSQL(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy374, &t);} +{ SSQLToken t = {0}; setCreateDBSQL(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy158, &t);} break; case 39: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ setCreateAcctSQL(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy219);} +{ setCreateAcctSQL(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy73);} break; case 40: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSQL(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy219);} +{ setCreateAcctSQL(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy73);} break; case 41: /* ids ::= ID */ case 42: /* ids ::= STRING */ yytestcase(yyruleno==42); @@ -2141,10 +2151,10 @@ static void yy_reduce( { setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} break; case 48: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSQL(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy219);} +{ setCreateAcctSQL(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy73);} break; case 49: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ -{ setCreateDBSQL(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy374, &yymsp[-2].minor.yy0);} +{ setCreateDBSQL(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy158, &yymsp[-2].minor.yy0);} break; case 50: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSQL(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} @@ -2173,20 +2183,20 @@ static void yy_reduce( break; case 69: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { - yylhsminor.yy219.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yylhsminor.yy219.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yylhsminor.yy219.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yylhsminor.yy219.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yylhsminor.yy219.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yylhsminor.yy219.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy219.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy219.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yylhsminor.yy219.stat = yymsp[0].minor.yy0; + yylhsminor.yy73.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy73.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy73.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy73.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy73.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy73.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy73.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy73.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy73.stat = yymsp[0].minor.yy0; } - yymsp[-8].minor.yy219 = yylhsminor.yy219; + yymsp[-8].minor.yy73 = yylhsminor.yy73; break; case 70: /* keep ::= KEEP tagitemlist */ -{ yymsp[-1].minor.yy322 = yymsp[0].minor.yy322; } +{ yymsp[-1].minor.yy494 = yymsp[0].minor.yy494; } break; case 71: /* tables ::= MAXTABLES INTEGER */ case 72: /* cache ::= CACHE INTEGER */ yytestcase(yyruleno==72); @@ -2197,496 +2207,505 @@ static void yy_reduce( case 77: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==77); case 78: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==78); case 79: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==79); - case 80: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==80); - case 81: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==81); + case 80: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==80); + case 81: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==81); + case 82: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==82); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 82: /* db_optr ::= */ -{setDefaultCreateDbOption(&yymsp[1].minor.yy374);} + case 83: /* db_optr ::= */ +{setDefaultCreateDbOption(&yymsp[1].minor.yy158);} break; - case 83: /* db_optr ::= db_optr tables */ - case 97: /* alter_db_optr ::= alter_db_optr tables */ yytestcase(yyruleno==97); -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.maxTablesPerVnode = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 84: /* db_optr ::= db_optr tables */ + case 99: /* alter_db_optr ::= alter_db_optr tables */ yytestcase(yyruleno==99); +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.maxTablesPerVnode = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 84: /* db_optr ::= db_optr cache */ -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 85: /* db_optr ::= db_optr cache */ +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 85: /* db_optr ::= db_optr replica */ - case 96: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==96); -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 86: /* db_optr ::= db_optr replica */ + case 98: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==98); +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 86: /* db_optr ::= db_optr days */ -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 87: /* db_optr ::= db_optr days */ +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 87: /* db_optr ::= db_optr minrows */ -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 88: /* db_optr ::= db_optr minrows */ +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 88: /* db_optr ::= db_optr maxrows */ -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 89: /* db_optr ::= db_optr maxrows */ +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 89: /* db_optr ::= db_optr blocks */ - case 99: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==99); -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 90: /* db_optr ::= db_optr blocks */ + case 101: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==101); +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 90: /* db_optr ::= db_optr ctime */ -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 91: /* db_optr ::= db_optr ctime */ +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 91: /* db_optr ::= db_optr wal */ - case 101: /* alter_db_optr ::= alter_db_optr wal */ yytestcase(yyruleno==101); -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 92: /* db_optr ::= db_optr wal */ + case 103: /* alter_db_optr ::= alter_db_optr wal */ yytestcase(yyruleno==103); +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 92: /* db_optr ::= db_optr comp */ - case 100: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==100); -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 93: /* db_optr ::= db_optr fsync */ +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 93: /* db_optr ::= db_optr prec */ -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.precision = yymsp[0].minor.yy0; } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 94: /* db_optr ::= db_optr comp */ + case 102: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==102); +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 94: /* db_optr ::= db_optr keep */ - case 98: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==98); -{ yylhsminor.yy374 = yymsp[-1].minor.yy374; yylhsminor.yy374.keep = yymsp[0].minor.yy322; } - yymsp[-1].minor.yy374 = yylhsminor.yy374; + case 95: /* db_optr ::= db_optr prec */ +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.precision = yymsp[0].minor.yy0; } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 95: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yymsp[1].minor.yy374);} + case 96: /* db_optr ::= db_optr keep */ + case 100: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==100); +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.keep = yymsp[0].minor.yy494; } + yymsp[-1].minor.yy158 = yylhsminor.yy158; break; - case 102: /* typename ::= ids */ + case 97: /* alter_db_optr ::= */ +{ setDefaultCreateDbOption(&yymsp[1].minor.yy158);} + break; + case 104: /* alter_db_optr ::= alter_db_optr fsync */ +{ yylhsminor.yy158 = yymsp[-1].minor.yy158; yylhsminor.yy158.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[-1].minor.yy158 = yylhsminor.yy158; + break; + case 105: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; - tSQLSetColumnType (&yylhsminor.yy325, &yymsp[0].minor.yy0); + tSQLSetColumnType (&yylhsminor.yy181, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy325 = yylhsminor.yy325; + yymsp[0].minor.yy181 = yylhsminor.yy181; break; - case 103: /* typename ::= ids LP signed RP */ + case 106: /* typename ::= ids LP signed RP */ { - if (yymsp[-1].minor.yy279 <= 0) { + if (yymsp[-1].minor.yy271 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSQLSetColumnType(&yylhsminor.yy325, &yymsp[-3].minor.yy0); + tSQLSetColumnType(&yylhsminor.yy181, &yymsp[-3].minor.yy0); } else { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy279; // negative value of name length - tSQLSetColumnType(&yylhsminor.yy325, &yymsp[-3].minor.yy0); + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy271; // negative value of name length + tSQLSetColumnType(&yylhsminor.yy181, &yymsp[-3].minor.yy0); } } - yymsp[-3].minor.yy325 = yylhsminor.yy325; + yymsp[-3].minor.yy181 = yylhsminor.yy181; break; - case 104: /* signed ::= INTEGER */ -{ yylhsminor.yy279 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[0].minor.yy279 = yylhsminor.yy279; + case 107: /* signed ::= INTEGER */ +{ yylhsminor.yy271 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + yymsp[0].minor.yy271 = yylhsminor.yy271; break; - case 105: /* signed ::= PLUS INTEGER */ -{ yymsp[-1].minor.yy279 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 108: /* signed ::= PLUS INTEGER */ +{ yymsp[-1].minor.yy271 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 106: /* signed ::= MINUS INTEGER */ -{ yymsp[-1].minor.yy279 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} + case 109: /* signed ::= MINUS INTEGER */ +{ yymsp[-1].minor.yy271 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; - case 107: /* cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */ + case 110: /* cmd ::= CREATE TABLE ifnotexists ids cpxName create_table_args */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-2].minor.yy0, &yymsp[-3].minor.yy0); } break; - case 108: /* create_table_args ::= LP columnlist RP */ + case 111: /* create_table_args ::= LP columnlist RP */ { - yymsp[-2].minor.yy408 = tSetCreateSQLElems(yymsp[-1].minor.yy369, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE); - setSQLInfo(pInfo, yymsp[-2].minor.yy408, NULL, TSDB_SQL_CREATE_TABLE); + yymsp[-2].minor.yy374 = tSetCreateSQLElems(yymsp[-1].minor.yy449, NULL, NULL, NULL, NULL, TSQL_CREATE_TABLE); + setSQLInfo(pInfo, yymsp[-2].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE); } break; - case 109: /* create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ + case 112: /* create_table_args ::= LP columnlist RP TAGS LP columnlist RP */ { - yymsp[-6].minor.yy408 = tSetCreateSQLElems(yymsp[-5].minor.yy369, yymsp[-1].minor.yy369, NULL, NULL, NULL, TSQL_CREATE_STABLE); - setSQLInfo(pInfo, yymsp[-6].minor.yy408, NULL, TSDB_SQL_CREATE_TABLE); + yymsp[-6].minor.yy374 = tSetCreateSQLElems(yymsp[-5].minor.yy449, yymsp[-1].minor.yy449, NULL, NULL, NULL, TSQL_CREATE_STABLE); + setSQLInfo(pInfo, yymsp[-6].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE); } break; - case 110: /* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ + case 113: /* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; - yymsp[-6].minor.yy408 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy322, NULL, TSQL_CREATE_TABLE_FROM_STABLE); - setSQLInfo(pInfo, yymsp[-6].minor.yy408, NULL, TSDB_SQL_CREATE_TABLE); + yymsp[-6].minor.yy374 = tSetCreateSQLElems(NULL, NULL, &yymsp[-5].minor.yy0, yymsp[-1].minor.yy494, NULL, TSQL_CREATE_TABLE_FROM_STABLE); + setSQLInfo(pInfo, yymsp[-6].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE); } break; - case 111: /* create_table_args ::= AS select */ + case 114: /* create_table_args ::= AS select */ { - yymsp[-1].minor.yy408 = tSetCreateSQLElems(NULL, NULL, NULL, NULL, yymsp[0].minor.yy190, TSQL_CREATE_STREAM); - setSQLInfo(pInfo, yymsp[-1].minor.yy408, NULL, TSDB_SQL_CREATE_TABLE); + yymsp[-1].minor.yy374 = tSetCreateSQLElems(NULL, NULL, NULL, NULL, yymsp[0].minor.yy150, TSQL_CREATE_STREAM); + setSQLInfo(pInfo, yymsp[-1].minor.yy374, NULL, TSDB_SQL_CREATE_TABLE); } break; - case 112: /* columnlist ::= columnlist COMMA column */ -{yylhsminor.yy369 = tFieldListAppend(yymsp[-2].minor.yy369, &yymsp[0].minor.yy325); } - yymsp[-2].minor.yy369 = yylhsminor.yy369; + case 115: /* columnlist ::= columnlist COMMA column */ +{yylhsminor.yy449 = tFieldListAppend(yymsp[-2].minor.yy449, &yymsp[0].minor.yy181); } + yymsp[-2].minor.yy449 = yylhsminor.yy449; break; - case 113: /* columnlist ::= column */ -{yylhsminor.yy369 = tFieldListAppend(NULL, &yymsp[0].minor.yy325);} - yymsp[0].minor.yy369 = yylhsminor.yy369; + case 116: /* columnlist ::= column */ +{yylhsminor.yy449 = tFieldListAppend(NULL, &yymsp[0].minor.yy181);} + yymsp[0].minor.yy449 = yylhsminor.yy449; break; - case 114: /* column ::= ids typename */ + case 117: /* column ::= ids typename */ { - tSQLSetColumnInfo(&yylhsminor.yy325, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy325); + tSQLSetColumnInfo(&yylhsminor.yy181, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy181); } - yymsp[-1].minor.yy325 = yylhsminor.yy325; + yymsp[-1].minor.yy181 = yylhsminor.yy181; break; - case 115: /* tagitemlist ::= tagitemlist COMMA tagitem */ -{ yylhsminor.yy322 = tVariantListAppend(yymsp[-2].minor.yy322, &yymsp[0].minor.yy518, -1); } - yymsp[-2].minor.yy322 = yylhsminor.yy322; + case 118: /* tagitemlist ::= tagitemlist COMMA tagitem */ +{ yylhsminor.yy494 = tVariantListAppend(yymsp[-2].minor.yy494, &yymsp[0].minor.yy312, -1); } + yymsp[-2].minor.yy494 = yylhsminor.yy494; break; - case 116: /* tagitemlist ::= tagitem */ -{ yylhsminor.yy322 = tVariantListAppend(NULL, &yymsp[0].minor.yy518, -1); } - yymsp[0].minor.yy322 = yylhsminor.yy322; + case 119: /* tagitemlist ::= tagitem */ +{ yylhsminor.yy494 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1); } + yymsp[0].minor.yy494 = yylhsminor.yy494; break; - case 117: /* tagitem ::= INTEGER */ - case 118: /* tagitem ::= FLOAT */ yytestcase(yyruleno==118); - case 119: /* tagitem ::= STRING */ yytestcase(yyruleno==119); - case 120: /* tagitem ::= BOOL */ yytestcase(yyruleno==120); -{toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy518, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy518 = yylhsminor.yy518; + case 120: /* tagitem ::= INTEGER */ + case 121: /* tagitem ::= FLOAT */ yytestcase(yyruleno==121); + case 122: /* tagitem ::= STRING */ yytestcase(yyruleno==122); + case 123: /* tagitem ::= BOOL */ yytestcase(yyruleno==123); +{toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy312, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy312 = yylhsminor.yy312; break; - case 121: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy518, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy518 = yylhsminor.yy518; + case 124: /* tagitem ::= NULL */ +{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy312, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy312 = yylhsminor.yy312; break; - case 122: /* tagitem ::= MINUS INTEGER */ - case 123: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==123); - case 124: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==124); - case 125: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==125); + case 125: /* tagitem ::= MINUS INTEGER */ + case 126: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==126); + case 127: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==127); + case 128: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==128); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - tVariantCreate(&yylhsminor.yy518, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy312, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy518 = yylhsminor.yy518; + yymsp[-1].minor.yy312 = yylhsminor.yy312; break; - case 126: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ + case 129: /* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */ { - yylhsminor.yy190 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy260, yymsp[-9].minor.yy322, yymsp[-8].minor.yy500, yymsp[-4].minor.yy322, yymsp[-3].minor.yy322, &yymsp[-7].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy322, &yymsp[0].minor.yy284, &yymsp[-1].minor.yy284); + yylhsminor.yy150 = tSetQuerySQLElems(&yymsp[-11].minor.yy0, yymsp[-10].minor.yy224, yymsp[-9].minor.yy494, yymsp[-8].minor.yy66, yymsp[-4].minor.yy494, yymsp[-3].minor.yy494, &yymsp[-7].minor.yy0, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy494, &yymsp[0].minor.yy188, &yymsp[-1].minor.yy188); } - yymsp[-11].minor.yy190 = yylhsminor.yy190; + yymsp[-11].minor.yy150 = yylhsminor.yy150; break; - case 127: /* union ::= select */ -{ yylhsminor.yy263 = setSubclause(NULL, yymsp[0].minor.yy190); } - yymsp[0].minor.yy263 = yylhsminor.yy263; + case 130: /* union ::= select */ +{ yylhsminor.yy25 = setSubclause(NULL, yymsp[0].minor.yy150); } + yymsp[0].minor.yy25 = yylhsminor.yy25; break; - case 128: /* union ::= LP union RP */ -{ yymsp[-2].minor.yy263 = yymsp[-1].minor.yy263; } + case 131: /* union ::= LP union RP */ +{ yymsp[-2].minor.yy25 = yymsp[-1].minor.yy25; } break; - case 129: /* union ::= union UNION ALL select */ -{ yylhsminor.yy263 = appendSelectClause(yymsp[-3].minor.yy263, yymsp[0].minor.yy190); } - yymsp[-3].minor.yy263 = yylhsminor.yy263; + case 132: /* union ::= union UNION ALL select */ +{ yylhsminor.yy25 = appendSelectClause(yymsp[-3].minor.yy25, yymsp[0].minor.yy150); } + yymsp[-3].minor.yy25 = yylhsminor.yy25; break; - case 130: /* union ::= union UNION ALL LP select RP */ -{ yylhsminor.yy263 = appendSelectClause(yymsp[-5].minor.yy263, yymsp[-1].minor.yy190); } - yymsp[-5].minor.yy263 = yylhsminor.yy263; + case 133: /* union ::= union UNION ALL LP select RP */ +{ yylhsminor.yy25 = appendSelectClause(yymsp[-5].minor.yy25, yymsp[-1].minor.yy150); } + yymsp[-5].minor.yy25 = yylhsminor.yy25; break; - case 131: /* cmd ::= union */ -{ setSQLInfo(pInfo, yymsp[0].minor.yy263, NULL, TSDB_SQL_SELECT); } + case 134: /* cmd ::= union */ +{ setSQLInfo(pInfo, yymsp[0].minor.yy25, NULL, TSDB_SQL_SELECT); } break; - case 132: /* select ::= SELECT selcollist */ + case 135: /* select ::= SELECT selcollist */ { - yylhsminor.yy190 = tSetQuerySQLElems(&yymsp[-1].minor.yy0, yymsp[0].minor.yy260, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yylhsminor.yy150 = tSetQuerySQLElems(&yymsp[-1].minor.yy0, yymsp[0].minor.yy224, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } - yymsp[-1].minor.yy190 = yylhsminor.yy190; + yymsp[-1].minor.yy150 = yylhsminor.yy150; break; - case 133: /* sclp ::= selcollist COMMA */ -{yylhsminor.yy260 = yymsp[-1].minor.yy260;} - yymsp[-1].minor.yy260 = yylhsminor.yy260; + case 136: /* sclp ::= selcollist COMMA */ +{yylhsminor.yy224 = yymsp[-1].minor.yy224;} + yymsp[-1].minor.yy224 = yylhsminor.yy224; break; - case 134: /* sclp ::= */ -{yymsp[1].minor.yy260 = 0;} + case 137: /* sclp ::= */ +{yymsp[1].minor.yy224 = 0;} break; - case 135: /* selcollist ::= sclp expr as */ + case 138: /* selcollist ::= sclp expr as */ { - yylhsminor.yy260 = tSQLExprListAppend(yymsp[-2].minor.yy260, yymsp[-1].minor.yy500, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy224 = tSQLExprListAppend(yymsp[-2].minor.yy224, yymsp[-1].minor.yy66, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } - yymsp[-2].minor.yy260 = yylhsminor.yy260; + yymsp[-2].minor.yy224 = yylhsminor.yy224; break; - case 136: /* selcollist ::= sclp STAR */ + case 139: /* selcollist ::= sclp STAR */ { tSQLExpr *pNode = tSQLExprIdValueCreate(NULL, TK_ALL); - yylhsminor.yy260 = tSQLExprListAppend(yymsp[-1].minor.yy260, pNode, 0); + yylhsminor.yy224 = tSQLExprListAppend(yymsp[-1].minor.yy224, pNode, 0); } - yymsp[-1].minor.yy260 = yylhsminor.yy260; + yymsp[-1].minor.yy224 = yylhsminor.yy224; break; - case 137: /* as ::= AS ids */ + case 140: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 138: /* as ::= ids */ + case 141: /* as ::= ids */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 139: /* as ::= */ + case 142: /* as ::= */ { yymsp[1].minor.yy0.n = 0; } break; - case 140: /* from ::= FROM tablelist */ -{yymsp[-1].minor.yy322 = yymsp[0].minor.yy322;} + case 143: /* from ::= FROM tablelist */ +{yymsp[-1].minor.yy494 = yymsp[0].minor.yy494;} break; - case 141: /* tablelist ::= ids cpxName */ -{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy322 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);} - yymsp[-1].minor.yy322 = yylhsminor.yy322; + case 144: /* tablelist ::= ids cpxName */ +{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy494 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1);} + yymsp[-1].minor.yy494 = yylhsminor.yy494; break; - case 142: /* tablelist ::= tablelist COMMA ids cpxName */ -{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy322 = tVariantListAppendToken(yymsp[-3].minor.yy322, &yymsp[-1].minor.yy0, -1); } - yymsp[-3].minor.yy322 = yylhsminor.yy322; + case 145: /* tablelist ::= tablelist COMMA ids cpxName */ +{ toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy494 = tVariantListAppendToken(yymsp[-3].minor.yy494, &yymsp[-1].minor.yy0, -1); } + yymsp[-3].minor.yy494 = yylhsminor.yy494; break; - case 143: /* tmvar ::= VARIABLE */ + case 146: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 144: /* interval_opt ::= INTERVAL LP tmvar RP */ - case 149: /* sliding_opt ::= SLIDING LP tmvar RP */ yytestcase(yyruleno==149); + case 147: /* interval_opt ::= INTERVAL LP tmvar RP */ + case 152: /* sliding_opt ::= SLIDING LP tmvar RP */ yytestcase(yyruleno==152); {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 145: /* interval_opt ::= */ - case 150: /* sliding_opt ::= */ yytestcase(yyruleno==150); + case 148: /* interval_opt ::= */ + case 153: /* sliding_opt ::= */ yytestcase(yyruleno==153); {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 146: /* fill_opt ::= */ -{yymsp[1].minor.yy322 = 0; } + case 149: /* fill_opt ::= */ +{yymsp[1].minor.yy494 = 0; } break; - case 147: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 150: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { tVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); tVariantCreate(&A, &yymsp[-3].minor.yy0); - tVariantListInsert(yymsp[-1].minor.yy322, &A, -1, 0); - yymsp[-5].minor.yy322 = yymsp[-1].minor.yy322; + tVariantListInsert(yymsp[-1].minor.yy494, &A, -1, 0); + yymsp[-5].minor.yy494 = yymsp[-1].minor.yy494; } break; - case 148: /* fill_opt ::= FILL LP ID RP */ + case 151: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); - yymsp[-3].minor.yy322 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy494 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 151: /* orderby_opt ::= */ - case 159: /* groupby_opt ::= */ yytestcase(yyruleno==159); -{yymsp[1].minor.yy322 = 0;} + case 154: /* orderby_opt ::= */ + case 162: /* groupby_opt ::= */ yytestcase(yyruleno==162); +{yymsp[1].minor.yy494 = 0;} break; - case 152: /* orderby_opt ::= ORDER BY sortlist */ - case 160: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==160); -{yymsp[-2].minor.yy322 = yymsp[0].minor.yy322;} + case 155: /* orderby_opt ::= ORDER BY sortlist */ + case 163: /* groupby_opt ::= GROUP BY grouplist */ yytestcase(yyruleno==163); +{yymsp[-2].minor.yy494 = yymsp[0].minor.yy494;} break; - case 153: /* sortlist ::= sortlist COMMA item sortorder */ + case 156: /* sortlist ::= sortlist COMMA item sortorder */ { - yylhsminor.yy322 = tVariantListAppend(yymsp[-3].minor.yy322, &yymsp[-1].minor.yy518, yymsp[0].minor.yy150); + yylhsminor.yy494 = tVariantListAppend(yymsp[-3].minor.yy494, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82); } - yymsp[-3].minor.yy322 = yylhsminor.yy322; + yymsp[-3].minor.yy494 = yylhsminor.yy494; break; - case 154: /* sortlist ::= item sortorder */ + case 157: /* sortlist ::= item sortorder */ { - yylhsminor.yy322 = tVariantListAppend(NULL, &yymsp[-1].minor.yy518, yymsp[0].minor.yy150); + yylhsminor.yy494 = tVariantListAppend(NULL, &yymsp[-1].minor.yy312, yymsp[0].minor.yy82); } - yymsp[-1].minor.yy322 = yylhsminor.yy322; + yymsp[-1].minor.yy494 = yylhsminor.yy494; break; - case 155: /* item ::= ids cpxName */ + case 158: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - tVariantCreate(&yylhsminor.yy518, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy312, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy518 = yylhsminor.yy518; + yymsp[-1].minor.yy312 = yylhsminor.yy312; break; - case 156: /* sortorder ::= ASC */ -{yymsp[0].minor.yy150 = TSDB_ORDER_ASC; } + case 159: /* sortorder ::= ASC */ +{yymsp[0].minor.yy82 = TSDB_ORDER_ASC; } break; - case 157: /* sortorder ::= DESC */ -{yymsp[0].minor.yy150 = TSDB_ORDER_DESC;} + case 160: /* sortorder ::= DESC */ +{yymsp[0].minor.yy82 = TSDB_ORDER_DESC;} break; - case 158: /* sortorder ::= */ -{yymsp[1].minor.yy150 = TSDB_ORDER_ASC;} + case 161: /* sortorder ::= */ +{yymsp[1].minor.yy82 = TSDB_ORDER_ASC;} break; - case 161: /* grouplist ::= grouplist COMMA item */ + case 164: /* grouplist ::= grouplist COMMA item */ { - yylhsminor.yy322 = tVariantListAppend(yymsp[-2].minor.yy322, &yymsp[0].minor.yy518, -1); + yylhsminor.yy494 = tVariantListAppend(yymsp[-2].minor.yy494, &yymsp[0].minor.yy312, -1); } - yymsp[-2].minor.yy322 = yylhsminor.yy322; + yymsp[-2].minor.yy494 = yylhsminor.yy494; break; - case 162: /* grouplist ::= item */ + case 165: /* grouplist ::= item */ { - yylhsminor.yy322 = tVariantListAppend(NULL, &yymsp[0].minor.yy518, -1); + yylhsminor.yy494 = tVariantListAppend(NULL, &yymsp[0].minor.yy312, -1); } - yymsp[0].minor.yy322 = yylhsminor.yy322; + yymsp[0].minor.yy494 = yylhsminor.yy494; break; - case 163: /* having_opt ::= */ - case 173: /* where_opt ::= */ yytestcase(yyruleno==173); - case 209: /* expritem ::= */ yytestcase(yyruleno==209); -{yymsp[1].minor.yy500 = 0;} + case 166: /* having_opt ::= */ + case 176: /* where_opt ::= */ yytestcase(yyruleno==176); + case 212: /* expritem ::= */ yytestcase(yyruleno==212); +{yymsp[1].minor.yy66 = 0;} break; - case 164: /* having_opt ::= HAVING expr */ - case 174: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==174); -{yymsp[-1].minor.yy500 = yymsp[0].minor.yy500;} + case 167: /* having_opt ::= HAVING expr */ + case 177: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==177); +{yymsp[-1].minor.yy66 = yymsp[0].minor.yy66;} break; - case 165: /* limit_opt ::= */ - case 169: /* slimit_opt ::= */ yytestcase(yyruleno==169); -{yymsp[1].minor.yy284.limit = -1; yymsp[1].minor.yy284.offset = 0;} + case 168: /* limit_opt ::= */ + case 172: /* slimit_opt ::= */ yytestcase(yyruleno==172); +{yymsp[1].minor.yy188.limit = -1; yymsp[1].minor.yy188.offset = 0;} break; - case 166: /* limit_opt ::= LIMIT signed */ - case 170: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==170); -{yymsp[-1].minor.yy284.limit = yymsp[0].minor.yy279; yymsp[-1].minor.yy284.offset = 0;} + case 169: /* limit_opt ::= LIMIT signed */ + case 173: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==173); +{yymsp[-1].minor.yy188.limit = yymsp[0].minor.yy271; yymsp[-1].minor.yy188.offset = 0;} break; - case 167: /* limit_opt ::= LIMIT signed OFFSET signed */ - case 171: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ yytestcase(yyruleno==171); -{yymsp[-3].minor.yy284.limit = yymsp[-2].minor.yy279; yymsp[-3].minor.yy284.offset = yymsp[0].minor.yy279;} + case 170: /* limit_opt ::= LIMIT signed OFFSET signed */ + case 174: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ yytestcase(yyruleno==174); +{yymsp[-3].minor.yy188.limit = yymsp[-2].minor.yy271; yymsp[-3].minor.yy188.offset = yymsp[0].minor.yy271;} break; - case 168: /* limit_opt ::= LIMIT signed COMMA signed */ - case 172: /* slimit_opt ::= SLIMIT signed COMMA signed */ yytestcase(yyruleno==172); -{yymsp[-3].minor.yy284.limit = yymsp[0].minor.yy279; yymsp[-3].minor.yy284.offset = yymsp[-2].minor.yy279;} + case 171: /* limit_opt ::= LIMIT signed COMMA signed */ + case 175: /* slimit_opt ::= SLIMIT signed COMMA signed */ yytestcase(yyruleno==175); +{yymsp[-3].minor.yy188.limit = yymsp[0].minor.yy271; yymsp[-3].minor.yy188.offset = yymsp[-2].minor.yy271;} break; - case 175: /* expr ::= LP expr RP */ -{yymsp[-2].minor.yy500 = yymsp[-1].minor.yy500; } + case 178: /* expr ::= LP expr RP */ +{yymsp[-2].minor.yy66 = yymsp[-1].minor.yy66; } break; - case 176: /* expr ::= ID */ -{yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);} - yymsp[0].minor.yy500 = yylhsminor.yy500; + case 179: /* expr ::= ID */ +{yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_ID);} + yymsp[0].minor.yy66 = yylhsminor.yy66; break; - case 177: /* expr ::= ID DOT ID */ -{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 180: /* expr ::= ID DOT ID */ +{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ID);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 178: /* expr ::= ID DOT STAR */ -{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 181: /* expr ::= ID DOT STAR */ +{yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[-2].minor.yy0, TK_ALL);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 179: /* expr ::= INTEGER */ -{yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);} - yymsp[0].minor.yy500 = yylhsminor.yy500; + case 182: /* expr ::= INTEGER */ +{yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_INTEGER);} + yymsp[0].minor.yy66 = yylhsminor.yy66; break; - case 180: /* expr ::= MINUS INTEGER */ - case 181: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==181); -{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);} - yymsp[-1].minor.yy500 = yylhsminor.yy500; + case 183: /* expr ::= MINUS INTEGER */ + case 184: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==184); +{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_INTEGER);} + yymsp[-1].minor.yy66 = yylhsminor.yy66; break; - case 182: /* expr ::= FLOAT */ -{yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);} - yymsp[0].minor.yy500 = yylhsminor.yy500; + case 185: /* expr ::= FLOAT */ +{yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_FLOAT);} + yymsp[0].minor.yy66 = yylhsminor.yy66; break; - case 183: /* expr ::= MINUS FLOAT */ - case 184: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==184); -{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);} - yymsp[-1].minor.yy500 = yylhsminor.yy500; + case 186: /* expr ::= MINUS FLOAT */ + case 187: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==187); +{yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[-1].minor.yy0, TK_FLOAT);} + yymsp[-1].minor.yy66 = yylhsminor.yy66; break; - case 185: /* expr ::= STRING */ -{yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);} - yymsp[0].minor.yy500 = yylhsminor.yy500; + case 188: /* expr ::= STRING */ +{yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_STRING);} + yymsp[0].minor.yy66 = yylhsminor.yy66; break; - case 186: /* expr ::= NOW */ -{yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); } - yymsp[0].minor.yy500 = yylhsminor.yy500; + case 189: /* expr ::= NOW */ +{yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_NOW); } + yymsp[0].minor.yy66 = yylhsminor.yy66; break; - case 187: /* expr ::= VARIABLE */ -{yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);} - yymsp[0].minor.yy500 = yylhsminor.yy500; + case 190: /* expr ::= VARIABLE */ +{yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_VARIABLE);} + yymsp[0].minor.yy66 = yylhsminor.yy66; break; - case 188: /* expr ::= BOOL */ -{yylhsminor.yy500 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);} - yymsp[0].minor.yy500 = yylhsminor.yy500; + case 191: /* expr ::= BOOL */ +{yylhsminor.yy66 = tSQLExprIdValueCreate(&yymsp[0].minor.yy0, TK_BOOL);} + yymsp[0].minor.yy66 = yylhsminor.yy66; break; - case 189: /* expr ::= ID LP exprlist RP */ + case 192: /* expr ::= ID LP exprlist RP */ { - yylhsminor.yy500 = tSQLExprCreateFunction(yymsp[-1].minor.yy260, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); + yylhsminor.yy66 = tSQLExprCreateFunction(yymsp[-1].minor.yy224, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy500 = yylhsminor.yy500; + yymsp[-3].minor.yy66 = yylhsminor.yy66; break; - case 190: /* expr ::= ID LP STAR RP */ + case 193: /* expr ::= ID LP STAR RP */ { - yylhsminor.yy500 = tSQLExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); + yylhsminor.yy66 = tSQLExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy500 = yylhsminor.yy500; + yymsp[-3].minor.yy66 = yylhsminor.yy66; break; - case 191: /* expr ::= expr AND expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_AND);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 194: /* expr ::= expr AND expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_AND);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 192: /* expr ::= expr OR expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_OR); } - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 195: /* expr ::= expr OR expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_OR); } + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 193: /* expr ::= expr LT expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_LT);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 196: /* expr ::= expr LT expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_LT);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 194: /* expr ::= expr GT expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_GT);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 197: /* expr ::= expr GT expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_GT);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 195: /* expr ::= expr LE expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_LE);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 198: /* expr ::= expr LE expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_LE);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 196: /* expr ::= expr GE expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_GE);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 199: /* expr ::= expr GE expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_GE);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 197: /* expr ::= expr NE expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_NE);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 200: /* expr ::= expr NE expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_NE);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 198: /* expr ::= expr EQ expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_EQ);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 201: /* expr ::= expr EQ expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_EQ);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 199: /* expr ::= expr PLUS expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_PLUS); } - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 202: /* expr ::= expr PLUS expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_PLUS); } + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 200: /* expr ::= expr MINUS expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_MINUS); } - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 203: /* expr ::= expr MINUS expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_MINUS); } + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 201: /* expr ::= expr STAR expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_STAR); } - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 204: /* expr ::= expr STAR expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_STAR); } + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 202: /* expr ::= expr SLASH expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_DIVIDE);} - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 205: /* expr ::= expr SLASH expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_DIVIDE);} + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 203: /* expr ::= expr REM expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_REM); } - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 206: /* expr ::= expr REM expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_REM); } + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 204: /* expr ::= expr LIKE expr */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-2].minor.yy500, yymsp[0].minor.yy500, TK_LIKE); } - yymsp[-2].minor.yy500 = yylhsminor.yy500; + case 207: /* expr ::= expr LIKE expr */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-2].minor.yy66, yymsp[0].minor.yy66, TK_LIKE); } + yymsp[-2].minor.yy66 = yylhsminor.yy66; break; - case 205: /* expr ::= expr IN LP exprlist RP */ -{yylhsminor.yy500 = tSQLExprCreate(yymsp[-4].minor.yy500, (tSQLExpr*)yymsp[-1].minor.yy260, TK_IN); } - yymsp[-4].minor.yy500 = yylhsminor.yy500; + case 208: /* expr ::= expr IN LP exprlist RP */ +{yylhsminor.yy66 = tSQLExprCreate(yymsp[-4].minor.yy66, (tSQLExpr*)yymsp[-1].minor.yy224, TK_IN); } + yymsp[-4].minor.yy66 = yylhsminor.yy66; break; - case 206: /* exprlist ::= exprlist COMMA expritem */ -{yylhsminor.yy260 = tSQLExprListAppend(yymsp[-2].minor.yy260,yymsp[0].minor.yy500,0);} - yymsp[-2].minor.yy260 = yylhsminor.yy260; + case 209: /* exprlist ::= exprlist COMMA expritem */ +{yylhsminor.yy224 = tSQLExprListAppend(yymsp[-2].minor.yy224,yymsp[0].minor.yy66,0);} + yymsp[-2].minor.yy224 = yylhsminor.yy224; break; - case 207: /* exprlist ::= expritem */ -{yylhsminor.yy260 = tSQLExprListAppend(0,yymsp[0].minor.yy500,0);} - yymsp[0].minor.yy260 = yylhsminor.yy260; + case 210: /* exprlist ::= expritem */ +{yylhsminor.yy224 = tSQLExprListAppend(0,yymsp[0].minor.yy66,0);} + yymsp[0].minor.yy224 = yylhsminor.yy224; break; - case 208: /* expritem ::= expr */ -{yylhsminor.yy500 = yymsp[0].minor.yy500;} - yymsp[0].minor.yy500 = yylhsminor.yy500; + case 211: /* expritem ::= expr */ +{yylhsminor.yy66 = yymsp[0].minor.yy66;} + yymsp[0].minor.yy66 = yylhsminor.yy66; break; - case 210: /* cmd ::= RESET QUERY CACHE */ + case 213: /* cmd ::= RESET QUERY CACHE */ { setDCLSQLElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 211: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 214: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy369, NULL, TSDB_ALTER_TABLE_ADD_COLUMN); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy449, NULL, TSDB_ALTER_TABLE_ADD_COLUMN); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 212: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 215: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2697,14 +2716,14 @@ static void yy_reduce( setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 213: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 216: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy369, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN); + SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-4].minor.yy0, yymsp[0].minor.yy449, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 214: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 217: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2715,7 +2734,7 @@ static void yy_reduce( setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 215: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 218: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -2729,25 +2748,25 @@ static void yy_reduce( setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 216: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 219: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); tVariantList* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tVariantListAppend(A, &yymsp[0].minor.yy518, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy312, -1); SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL); setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 217: /* cmd ::= KILL CONNECTION INTEGER */ + case 220: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSQL(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 218: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 221: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 219: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 222: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSQL(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: diff --git a/src/query/tests/tsBufTest.cpp b/src/query/tests/tsBufTest.cpp index 1d2d94f3c0..f813261957 100644 --- a/src/query/tests/tsBufTest.cpp +++ b/src/query/tests/tsBufTest.cpp @@ -47,7 +47,7 @@ void simpleTest() { EXPECT_EQ(pTSBuf->tsData.len, 0); EXPECT_EQ(pTSBuf->block.numOfElem, num); - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); } // one large list of ts, the ts list need to be split into several small blocks @@ -71,7 +71,7 @@ void largeTSTest() { EXPECT_EQ(pTSBuf->tsData.len, 0); EXPECT_EQ(pTSBuf->block.numOfElem, num); - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); } void multiTagsTest() { @@ -101,7 +101,7 @@ void multiTagsTest() { EXPECT_EQ(pTSBuf->tsData.len, 0); EXPECT_EQ(pTSBuf->block.numOfElem, num); - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); } void multiVnodeTagsTest() { @@ -139,7 +139,7 @@ void multiVnodeTagsTest() { EXPECT_EQ(pTSBuf->tsData.len, 0); EXPECT_EQ(pTSBuf->block.numOfElem, num); - tsBufDestory(pTSBuf); + tsBufDestroy(pTSBuf); } void loadDataTest() { @@ -386,8 +386,8 @@ void mergeDiffVnodeBufferTest() { tsBufDisplay(pTSBuf1); - tsBufDestory(pTSBuf2); - tsBufDestory(pTSBuf1); + tsBufDestroy(pTSBuf2); + tsBufDestroy(pTSBuf1); } void mergeIdenticalVnodeBufferTest() { @@ -432,8 +432,8 @@ void mergeIdenticalVnodeBufferTest() { printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); } - tsBufDestory(pTSBuf1); - tsBufDestory(pTSBuf2); + tsBufDestroy(pTSBuf1); + tsBufDestroy(pTSBuf2); } } // namespace diff --git a/src/rpc/inc/rpcLog.h b/src/rpc/inc/rpcLog.h index f0f5c84ff9..10e8476691 100644 --- a/src/rpc/inc/rpcLog.h +++ b/src/rpc/inc/rpcLog.h @@ -27,10 +27,10 @@ extern int32_t tscEmbedded; #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 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 tDebug(...) { if (rpcDebugFlag & DEBUG_DEBUG) { taosPrintLog("RPC DEBUG ", rpcDebugFlag, __VA_ARGS__); }} -#define tTrace(...) { if (rpcDebugFlag & DEBUG_TRACE) { taosPrintLog("RPC TRACE ", 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 ", tscEmbedded ? 255 : rpcDebugFlag, __VA_ARGS__); }} +#define tDebug(...) { if (rpcDebugFlag & DEBUG_DEBUG) { taosPrintLog("RPC ", 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); }} #ifdef __cplusplus diff --git a/src/tsdb/inc/tsdbMain.h b/src/tsdb/inc/tsdbMain.h index 7d1a5a52de..40f2dac660 100644 --- a/src/tsdb/inc/tsdbMain.h +++ b/src/tsdb/inc/tsdbMain.h @@ -21,11 +21,10 @@ #include "tkvstore.h" #include "tlist.h" #include "tlog.h" -#include "tref.h" +#include "tlockfree.h" #include "tsdb.h" #include "tskiplist.h" #include "tutil.h" -#include "trwlatch.h" #ifdef __cplusplus extern "C" { @@ -35,10 +34,10 @@ extern int tsdbDebugFlag; #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 tsdbWarn(...) { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", 255, __VA_ARGS__); }} -#define tsdbInfo(...) { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB INFO ", 255, __VA_ARGS__); }} -#define tsdbDebug(...) { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB DEBUG ", tsdbDebugFlag, __VA_ARGS__); }} -#define tsdbTrace(...) { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB TRACE ", tsdbDebugFlag, __VA_ARGS__); }} +#define tsdbWarn(...) { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", 255, __VA_ARGS__); }} +#define tsdbInfo(...) { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", 255, __VA_ARGS__); }} +#define tsdbDebug(...) { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} +#define tsdbTrace(...) { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} #define TSDB_MAX_TABLE_SCHEMAS 16 #define TSDB_FILE_HEAD_SIZE 512 @@ -96,6 +95,11 @@ typedef struct { } STsdbBufPool; // ------------------ tsdbMemTable.c +typedef struct { + STable * pTable; + SSkipListIterator *pIter; +} SCommitIter; + typedef struct { uint64_t uid; TSKEY keyFirst; @@ -206,10 +210,10 @@ typedef struct { int64_t offset : 63; int32_t algorithm : 8; int32_t numOfRows : 24; - int32_t sversion; int32_t len; + int32_t keyLen; // key column length, keyOffset = offset+sizeof(SCompData)+sizeof(SCompCol)*numOfCols int16_t numOfSubBlocks; - int16_t numOfCols; + int16_t numOfCols; // not including timestamp column TSKEY keyFirst; TSKEY keyLast; } SCompBlock; @@ -377,6 +381,24 @@ int tsdbUnRefMemTable(STsdbRepo* pRepo, SMemTable* pMemTable); int tsdbTakeMemSnapshot(STsdbRepo* pRepo, SMemTable** pMem, SMemTable** pIMem); void* tsdbAllocBytes(STsdbRepo* pRepo, int bytes); 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 #define TSDB_KEY_FILEID(key, daysPerFile, precision) ((key) / tsMsPerDay[(precision)] / (daysPerFile)) @@ -421,25 +443,36 @@ void tsdbRemoveFileGroup(STsdbRepo* pRepo, SFileGroup* pFGroup); #define helperType(h) (h)->type #define helperRepo(h) (h)->pRepo #define helperState(h) (h)->state +#define TSDB_NLAST_FILE_OPENED(h) ((h)->files.nLastF.fd > 0) -int tsdbInitReadHelper(SRWHelper* pHelper, STsdbRepo* pRepo); -int tsdbInitWriteHelper(SRWHelper* pHelper, STsdbRepo* pRepo); -void tsdbDestroyHelper(SRWHelper* pHelper); -void tsdbResetHelper(SRWHelper* pHelper); -int tsdbSetAndOpenHelperFile(SRWHelper* pHelper, SFileGroup* pGroup); -int tsdbCloseHelperFile(SRWHelper* pHelper, bool hasError); -void tsdbSetHelperTable(SRWHelper* pHelper, STable* pTable, STsdbRepo* pRepo); -int tsdbWriteDataBlock(SRWHelper* pHelper, SDataCols* pDataCols); -int tsdbMoveLastBlockIfNeccessary(SRWHelper* pHelper); -int tsdbWriteCompInfo(SRWHelper* pHelper); -int tsdbWriteCompIdx(SRWHelper* pHelper); -int tsdbLoadCompIdx(SRWHelper* pHelper, void* target); -int tsdbLoadCompInfo(SRWHelper* pHelper, void* target); -int tsdbLoadCompData(SRWHelper* phelper, SCompBlock* pcompblock, void* target); -void tsdbGetDataStatis(SRWHelper* pHelper, SDataStatis* pStatis, int numOfCols); -int tsdbLoadBlockDataCols(SRWHelper* pHelper, SCompBlock* pCompBlock, SCompInfo* pCompInfo, int16_t* colIds, - int numOfColIds); -int tsdbLoadBlockData(SRWHelper* pHelper, SCompBlock* pCompBlock, SCompInfo* pCompInfo); +int tsdbInitReadHelper(SRWHelper* pHelper, STsdbRepo* pRepo); +int tsdbInitWriteHelper(SRWHelper* pHelper, STsdbRepo* pRepo); +void tsdbDestroyHelper(SRWHelper* pHelper); +void tsdbResetHelper(SRWHelper* pHelper); +int tsdbSetAndOpenHelperFile(SRWHelper* pHelper, SFileGroup* pGroup); +int tsdbCloseHelperFile(SRWHelper* pHelper, bool hasError); +void tsdbSetHelperTable(SRWHelper* pHelper, STable* pTable, STsdbRepo* pRepo); +int tsdbCommitTableData(SRWHelper* pHelper, SCommitIter* pCommitIter, SDataCols* pDataCols, TSKEY maxKey); +int tsdbMoveLastBlockIfNeccessary(SRWHelper* pHelper); +int tsdbWriteCompInfo(SRWHelper* pHelper); +int tsdbWriteCompIdx(SRWHelper* pHelper); +int tsdbLoadCompIdx(SRWHelper* pHelper, void* target); +int tsdbLoadCompInfo(SRWHelper* pHelper, void* target); +int tsdbLoadCompData(SRWHelper* phelper, SCompBlock* pcompblock, void* target); +void tsdbGetDataStatis(SRWHelper* pHelper, SDataStatis* pStatis, int numOfCols); +int tsdbLoadBlockDataCols(SRWHelper* pHelper, SCompBlock* pCompBlock, SCompInfo* pCompInfo, int16_t* colIds, + int numOfColIds); +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 #define REPO_ID(r) (r)->config.tsdbId diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 6b31600705..ffaab375a3 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -69,6 +69,8 @@ static int tsdbEncodeCfg(void **buf, STsdbCfg *pCfg); static void * tsdbDecodeCfg(void *buf, STsdbCfg *pCfg); static int tsdbCheckTableSchema(STsdbRepo *pRepo, SSubmitBlk *pBlock, STable *pTable); static int tsdbScanAndConvertSubmitMsg(STsdbRepo *pRepo, SSubmitMsg *pMsg); +static void tsdbStartStream(STsdbRepo *pRepo); +static void tsdbStopStream(STsdbRepo *pRepo); // Function declaration int32_t tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg) { @@ -127,6 +129,7 @@ TSDB_REPO_T *tsdbOpenRepo(char *rootDir, STsdbAppH *pAppH) { goto _err; } + tsdbStartStream(pRepo); // pRepo->state = TSDB_REPO_STATE_ACTIVE; tsdbDebug("vgId:%d open tsdb repository succeed!", REPO_ID(pRepo)); @@ -145,6 +148,8 @@ void tsdbCloseRepo(TSDB_REPO_T *repo, int toCommit) { STsdbRepo *pRepo = (STsdbRepo *)repo; int vgId = REPO_ID(pRepo); + tsdbStopStream(repo); + if (toCommit) { tsdbAsyncCommit(pRepo); if (pRepo->commit) pthread_join(pRepo->commitThread, NULL); @@ -265,19 +270,6 @@ uint32_t tsdbGetFileInfo(TSDB_REPO_T *repo, char *name, uint32_t *index, uint32_ return magic; } -void tsdbStartStream(TSDB_REPO_T *repo) { - STsdbRepo *pRepo = (STsdbRepo *)repo; - STsdbMeta *pMeta = pRepo->tsdbMeta; - - for (int i = 0; i < pRepo->config.maxTables; i++) { - STable *pTable = pMeta->tables[i]; - if (pTable && pTable->type == TSDB_STREAM_TABLE) { - pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, TABLE_UID(pTable), TABLE_TID(pTable), pTable->sql, - tsdbGetTableSchemaImpl(pTable, false, false, -1)); - } - } -} - STsdbCfg *tsdbGetCfg(const TSDB_REPO_T *repo) { ASSERT(repo != NULL); return &((STsdbRepo *)repo)->config; @@ -1120,4 +1112,27 @@ TSKEY tsdbGetTableLastKey(TSDB_REPO_T *repo, uint64_t uid) { return TSDB_GET_TABLE_LAST_KEY(pTable); } -#endif \ No newline at end of file +#endif + +static void tsdbStartStream(STsdbRepo *pRepo) { + STsdbMeta *pMeta = pRepo->tsdbMeta; + + for (int i = 0; i < pRepo->config.maxTables; i++) { + STable *pTable = pMeta->tables[i]; + if (pTable && pTable->type == TSDB_STREAM_TABLE) { + pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, TABLE_UID(pTable), TABLE_TID(pTable), pTable->sql, + tsdbGetTableSchemaImpl(pTable, false, false, -1)); + } + } +} + +static void tsdbStopStream(STsdbRepo *pRepo) { + STsdbMeta *pMeta = pRepo->tsdbMeta; + + for (int i = 0; i < pRepo->config.maxTables; i++) { + STable *pTable = pMeta->tables[i]; + if (pTable && pTable->type == TSDB_STREAM_TABLE) { + (*pRepo->appH.cqDropFunc)(pTable->cqhandle); + } + } +} diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 675e44f458..1cd212b216 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -18,11 +18,6 @@ #define TSDB_DATA_SKIPLIST_LEVEL 5 -typedef struct { - STable * pTable; - SSkipListIterator *pIter; -} SCommitIter; - static FORCE_INLINE STsdbBufBlock *tsdbGetCurrBufBlock(STsdbRepo *pRepo); 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 int tsdbCommitMeta(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 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 SCommitIter *tsdbCreateTableIters(STsdbRepo *pRepo); -static void tsdbDestroyTableIters(SCommitIter *iters, int maxTables); -static int tsdbReadRowsFromCache(STsdbMeta *pMeta, STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, - int maxRowsToRead, SDataCols *pCols); +static SCommitIter *tsdbCreateCommitIters(STsdbRepo *pRepo); +static void tsdbDestroyCommitIters(SCommitIter *iters, int maxTables); // ---------------- INTERNAL FUNCTIONS ---------------- int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) { @@ -252,6 +244,66 @@ int tsdbAsyncCommit(STsdbRepo *pRepo) { 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 ---------------- static FORCE_INLINE STsdbBufBlock *tsdbGetCurrBufBlock(STsdbRepo *pRepo) { ASSERT(pRepo != NULL); @@ -378,7 +430,7 @@ static void *tsdbCommitData(void *arg) { // Create the iterator to read from cache if (pMem->numOfRows > 0) { - iters = tsdbCreateTableIters(pRepo); + iters = tsdbCreateCommitIters(pRepo); if (iters == NULL) { tsdbError("vgId:%d failed to create commit iterator since %s", REPO_ID(pRepo), tstrerror(terrno)); goto _exit; @@ -418,7 +470,7 @@ static void *tsdbCommitData(void *arg) { _exit: tdFreeDataCols(pDataCols); - tsdbDestroyTableIters(iters, pCfg->maxTables); + tsdbDestroyCommitIters(iters, pCfg->maxTables); tsdbDestroyHelper(&whelper); tsdbEndCommit(pRepo); 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); } -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) { 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; } 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) { char * dataDir = NULL; - STsdbMeta * pMeta = pRepo->tsdbMeta; STsdbCfg * pCfg = &pRepo->config; STsdbFileH *pFileH = pRepo->tsdbFileH; SFileGroup *pGroup = NULL; @@ -549,33 +590,13 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe if (pIter->pIter != NULL) { tdInitDataCols(pDataCols, tsdbGetTableSchemaImpl(pIter->pTable, false, false, -1)); - int maxRowsToRead = pCfg->maxRowsPerFileBlock * 4 / 5; - 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)); - tsdbError("vgId:%d failed to write data block to table %s tid %d uid %" PRIu64 " since %s", REPO_ID(pRepo), - TABLE_CHAR_NAME(pIter->pTable), TABLE_TID(pIter->pTable), TABLE_UID(pIter->pTable), - tstrerror(terrno)); - goto _err; - } - ASSERT(rowsWritten <= pDataCols->numOfRows); - - tdPopDataColsPoints(pDataCols, rowsWritten); - maxRowsToRead = pCfg->maxRowsPerFileBlock * 4 / 5 - pDataCols->numOfRows; + if (tsdbCommitTableData(pHelper, pIter, pDataCols, maxKey) < 0) { + taosRUnLockLatch(&(pIter->pTable->latch)); + 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), + tstrerror(terrno)); + goto _err; } - - ASSERT(pDataCols->numOfRows == 0); } taosRUnLockLatch(&(pIter->pTable->latch)); @@ -615,7 +636,7 @@ _err: return -1; } -static SCommitIter *tsdbCreateTableIters(STsdbRepo *pRepo) { +static SCommitIter *tsdbCreateCommitIters(STsdbRepo *pRepo) { STsdbCfg * pCfg = &(pRepo->config); SMemTable *pMem = pRepo->imem; STsdbMeta *pMeta = pRepo->tsdbMeta; @@ -645,21 +666,18 @@ static SCommitIter *tsdbCreateTableIters(STsdbRepo *pRepo) { goto _err; } - if (!tSkipListIterNext(iters[i].pIter)) { - terrno = TSDB_CODE_TDB_NO_TABLE_DATA_IN_MEM; - goto _err; - } + tSkipListIterNext(iters[i].pIter); } } return iters; _err: - tsdbDestroyTableIters(iters, pCfg->maxTables); + tsdbDestroyCommitIters(iters, pCfg->maxTables); return NULL; } -static void tsdbDestroyTableIters(SCommitIter *iters, int maxTables) { +static void tsdbDestroyCommitIters(SCommitIter *iters, int maxTables) { if (iters == NULL) return; for (int i = 1; i < maxTables; i++) { @@ -670,35 +688,4 @@ static void tsdbDestroyTableIters(SCommitIter *iters, int maxTables) { } 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; } \ No newline at end of file diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 84c1c8e7d1..fcf9b04e4a 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -57,8 +57,30 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg) { STable * super = NULL; STable * table = NULL; int newSuper = 0; + int tid = pCfg->tableId.tid; + STable * pTable = NULL; - STable *pTable = tsdbGetTableByUid(pMeta, pCfg->tableId.uid); + if (tid < 0 || tid >= pRepo->config.maxTables) { + tsdbError("vgId:%d failed to create table since invalid tid %d", REPO_ID(pRepo), tid); + terrno = TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO; + goto _err; + } + + if (pMeta->tables[tid] != NULL) { + if (TABLE_UID(pMeta->tables[tid]) == pCfg->tableId.uid) { + tsdbError("vgId:%d table %s already exists, tid %d uid %" PRId64, REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), + TABLE_TID(pTable), TABLE_UID(pTable)); + return TSDB_CODE_TDB_TABLE_ALREADY_EXIST; + } else { + tsdbError("vgId:%d table %s at tid %d uid %" PRIu64 + " exists, replace it with new table, this can be not reasonable", + REPO_ID(pRepo), TABLE_CHAR_NAME(pMeta->tables[tid]), TABLE_TID(pMeta->tables[tid]), + TABLE_UID(pMeta->tables[tid])); + tsdbDropTable(pRepo, pMeta->tables[tid]->tableId); + } + } + + pTable = tsdbGetTableByUid(pMeta, pCfg->tableId.uid); if (pTable != NULL) { tsdbError("vgId:%d table %s already exists, tid %d uid %" PRId64, REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable)); @@ -72,10 +94,10 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg) { super = tsdbNewTable(pCfg, true); if (super == NULL) goto _err; } else { - // TODO - if (super->type != TSDB_SUPER_TABLE) return -1; - if (super->tableId.uid != pCfg->superUid) return -1; - // tsdbUpdateTable(pRepo, super, pCfg); + if (TABLE_TYPE(super) != TSDB_SUPER_TABLE || TABLE_UID(super) != pCfg->superUid) { + terrno = TSDB_CODE_TDB_IVD_CREATE_TABLE_INFO; + goto _err; + } } } @@ -705,6 +727,9 @@ static STable *tsdbNewTable(STableCfg *pCfg, bool isSuper) { T_REF_INC(pTable); + tsdbTrace("table %s tid %d uid %" PRIu64 " is created", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), + TABLE_UID(pTable)); + return pTable; _err: @@ -714,7 +739,9 @@ _err: static void tsdbFreeTable(STable *pTable) { if (pTable) { - if (pTable->name != NULL) tsdbDebug("table %s is destroyed", TABLE_CHAR_NAME(pTable)); + if (pTable->name != NULL) + tsdbTrace("table %s tid %d uid %" PRIu64 " is freed", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), + TABLE_UID(pTable)); tfree(TABLE_NAME(pTable)); if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) { for (int i = 0; i < TSDB_MAX_TABLE_SCHEMAS; i++) { @@ -782,7 +809,7 @@ static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx, boo tsdbGetTableSchemaImpl(pTable, false, false, -1)); } - tsdbTrace("vgId:%d table %s tid %d uid %" PRIu64 " is added to meta", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), + tsdbDebug("vgId:%d table %s tid %d uid %" PRIu64 " is added to meta", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable)); return 0; diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index 326da07a36..040b4a5334 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -22,39 +22,44 @@ #include "tfile.h" #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 int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, int rowsToWrite, - SCompBlock *pCompBlock, bool isLast, bool isSuperBlock); -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 tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx); -static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx, int rowsAdded); -static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx); -static int tsdbGetRowsInRange(SDataCols *pDataCols, TSKEY minKey, TSKEY maxKey); -static void tsdbResetHelperFileImpl(SRWHelper *pHelper); -static int tsdbInitHelperFile(SRWHelper *pHelper); -static void tsdbDestroyHelperFile(SRWHelper *pHelper); -static void tsdbResetHelperTableImpl(SRWHelper *pHelper); -static void tsdbResetHelperTable(SRWHelper *pHelper); -static void tsdbInitHelperTable(SRWHelper *pHelper); -static void tsdbDestroyHelperTable(SRWHelper *pHelper); -static void tsdbResetHelperBlockImpl(SRWHelper *pHelper); -static void tsdbResetHelperBlock(SRWHelper *pHelper); -static int tsdbInitHelperBlock(SRWHelper *pHelper); -static int tsdbInitHelper(SRWHelper *pHelper, STsdbRepo *pRepo, tsdb_rw_helper_t type); -static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, char *content, int32_t len, int8_t comp, int numOfRows, - int maxPoints, char *buffer, int bufferSize); -static int tsdbLoadBlockDataColsImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols, int16_t *colIds, - int numOfColIds); -static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols); -static int tsdbEncodeSCompIdx(void **buf, SCompIdx *pIdx); +static bool tsdbShouldCreateNewLast(SRWHelper *pHelper); +static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, SCompBlock *pCompBlock, + bool isLast, bool isSuperBlock); +static int compareKeyBlock(const void *arg1, const void *arg2); +static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t esize); +static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx); +static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx, int rowsAdded); +static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkIdx); +static void tsdbResetHelperFileImpl(SRWHelper *pHelper); +static int tsdbInitHelperFile(SRWHelper *pHelper); +static void tsdbDestroyHelperFile(SRWHelper *pHelper); +static void tsdbResetHelperTableImpl(SRWHelper *pHelper); +static void tsdbResetHelperTable(SRWHelper *pHelper); +static void tsdbInitHelperTable(SRWHelper *pHelper); +static void tsdbDestroyHelperTable(SRWHelper *pHelper); +static void tsdbResetHelperBlockImpl(SRWHelper *pHelper); +static void tsdbResetHelperBlock(SRWHelper *pHelper); +static int tsdbInitHelperBlock(SRWHelper *pHelper); +static int tsdbInitHelper(SRWHelper *pHelper, STsdbRepo *pRepo, tsdb_rw_helper_t type); +static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, char *content, int32_t len, int8_t comp, int numOfRows, + int maxPoints, char *buffer, int bufferSize); +static int tsdbLoadBlockDataColsImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols, int16_t *colIds, + int numOfColIds); +static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDataCols *pDataCols); +static int tsdbEncodeSCompIdx(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 int tsdbLoadColData(SRWHelper *pHelper, SFile *pFile, SCompBlock *pCompBlock, SCompCol *pCompCol, 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 ---------------------- int tsdbInitReadHelper(SRWHelper *pHelper, STsdbRepo *pRepo) { @@ -225,84 +230,41 @@ void tsdbSetHelperTable(SRWHelper *pHelper, STable *pTable, STsdbRepo *pRepo) { tdInitDataCols(pHelper->pDataCols[1], pSchema); SCompIdx *pIdx = pHelper->pCompIdx + pTable->tableId.tid; - if (pIdx->offset > 0 && pIdx->hasLast) { - pHelper->hasOldLastBlock = true; + if (pIdx->offset > 0) { + 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); ASSERT(pHelper->state == ((TSDB_HELPER_TABLE_SET << 1) - 1)); } -/** - * 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) { +int tsdbCommitTableData(SRWHelper *pHelper, SCommitIter *pCommitIter, SDataCols *pDataCols, TSKEY maxKey) { ASSERT(helperType(pHelper) == TSDB_WRITE_HELPER); - ASSERT(pDataCols->numOfRows > 0); - SCompBlock compBlock; - int rowsToWrite = 0; - TSKEY keyFirst = dataColsKeyFirst(pDataCols); + SCompIdx * pIdx = &(pHelper->pCompIdx[TABLE_TID(pCommitIter->pTable)]); + int blkIdx = 0; - 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)); - SCompIdx *pIdx = pHelper->pCompIdx + pHelper->tableInfo.tid; // for change purpose + while (true) { + ASSERT(blkIdx <= pIdx->numOfBlocks); + TSKEY keyFirst = tsdbNextIterKey(pCommitIter->pIter); + if (keyFirst < 0 || keyFirst > maxKey) break; // iter over - // Load the SCompInfo part if neccessary - ASSERT(helperHasState(pHelper, TSDB_HELPER_TABLE_SET)); - if (tsdbLoadCompInfo(pHelper, NULL) < 0) goto _err; - - 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); + if (pIdx->len <= 0 || keyFirst > pIdx->maxKey) { + if (tsdbProcessAppendCommit(pHelper, pCommitIter, pDataCols, maxKey) < 0) return -1; + blkIdx = pIdx->numOfBlocks; } else { - isLast = true; - 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; - } + if (tsdbProcessMergeCommit(pHelper, pCommitIter, pDataCols, maxKey, &blkIdx) < 0) return -1; } } - return rowsToWrite; - -_err: - return -1; + return 0; } int tsdbMoveLastBlockIfNeccessary(SRWHelper *pHelper) { @@ -310,29 +272,42 @@ int tsdbMoveLastBlockIfNeccessary(SRWHelper *pHelper) { ASSERT(helperType(pHelper) == TSDB_WRITE_HELPER); SCompIdx * pIdx = pHelper->pCompIdx + pHelper->tableInfo.tid; - SCompBlock compBlock; - if ((pHelper->files.nLastF.fd > 0) && (pHelper->hasOldLastBlock)) { + SCompBlock compBlock = {0}; + if (TSDB_NLAST_FILE_OPENED(pHelper) && (pHelper->hasOldLastBlock)) { 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); if (pCompBlock->numOfSubBlocks > 1) { - if (tsdbLoadBlockData(pHelper, blockAtIdx(pHelper, pIdx->numOfBlocks - 1), NULL) < 0) return -1; - ASSERT(pHelper->pDataCols[0]->numOfRows > 0 && pHelper->pDataCols[0]->numOfRows < pCfg->minRowsPerFileBlock); - if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.nLastF), pHelper->pDataCols[0], - pHelper->pDataCols[0]->numOfRows, &compBlock, true, true) < 0) + if (tsdbLoadBlockData(pHelper, pCompBlock, NULL) < 0) return -1; + ASSERT(pHelper->pDataCols[0]->numOfRows == pCompBlock->numOfRows && + pHelper->pDataCols[0]->numOfRows < pCfg->minRowsPerFileBlock); + if (tsdbWriteBlockToFile(pHelper, &(pHelper->files.nLastF), pHelper->pDataCols[0], &compBlock, true, true) < 0) return -1; if (tsdbUpdateSuperBlock(pHelper, &compBlock, pIdx->numOfBlocks - 1) < 0) return -1; - } else { - if (lseek(pHelper->files.lastF.fd, pCompBlock->offset, SEEK_SET) < 0) return -1; - pCompBlock->offset = lseek(pHelper->files.nLastF.fd, 0, SEEK_END); - if (pCompBlock->offset < 0) return -1; - - if (tsendfile(pHelper->files.nLastF.fd, pHelper->files.lastF.fd, NULL, pCompBlock->len) < pCompBlock->len) + if (lseek(pHelper->files.lastF.fd, pCompBlock->offset, SEEK_SET) < 0) { + tsdbError("vgId:%d failed to lseek file %s since %s", REPO_ID(pHelper->pRepo), pHelper->files.lastF.fname, + strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); 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; @@ -365,27 +340,30 @@ int tsdbWriteCompInfo(SRWHelper *pHelper) { } } } else { - pHelper->pCompInfo->delimiter = TSDB_FILE_DELIMITER; - pHelper->pCompInfo->uid = pHelper->tableInfo.uid; - pHelper->pCompInfo->checksum = 0; - ASSERT((pIdx->len - sizeof(SCompInfo) - sizeof(TSCKSUM)) % sizeof(SCompBlock) == 0); - taosCalcChecksumAppend(0, (uint8_t *)pHelper->pCompInfo, pIdx->len); - offset = lseek(pHelper->files.nHeadF.fd, 0, SEEK_END); - if (offset < 0) { - tsdbError("vgId:%d failed to lseek file %s since %s", REPO_ID(pHelper->pRepo), pHelper->files.nHeadF.fname, - strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - pIdx->offset = offset; - pIdx->uid = pHelper->tableInfo.uid; - ASSERT(pIdx->offset >= TSDB_FILE_HEAD_SIZE); + if (pIdx->len > 0) { + pHelper->pCompInfo->delimiter = TSDB_FILE_DELIMITER; + pHelper->pCompInfo->uid = pHelper->tableInfo.uid; + pHelper->pCompInfo->checksum = 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); + offset = lseek(pHelper->files.nHeadF.fd, 0, SEEK_END); + if (offset < 0) { + tsdbError("vgId:%d failed to lseek file %s since %s", REPO_ID(pHelper->pRepo), pHelper->files.nHeadF.fname, + strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + pIdx->offset = offset; + pIdx->uid = pHelper->tableInfo.uid; + ASSERT(pIdx->offset >= TSDB_FILE_HEAD_SIZE); - if (twrite(pHelper->files.nHeadF.fd, (void *)(pHelper->pCompInfo), pIdx->len) < pIdx->len) { - tsdbError("vgId:%d failed to write %d bytes to file %s since %s", REPO_ID(pHelper->pRepo), pIdx->len, - pHelper->files.nHeadF.fname, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; + if (twrite(pHelper->files.nHeadF.fd, (void *)(pHelper->pCompInfo), pIdx->len) < pIdx->len) { + tsdbError("vgId:%d failed to write %d bytes to file %s since %s", REPO_ID(pHelper->pRepo), pIdx->len, + pHelper->files.nHeadF.fname, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } } } @@ -397,7 +375,12 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) { ASSERT(helperType(pHelper) == TSDB_WRITE_HELPER); 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); pFile->info.offset = offset; @@ -409,6 +392,10 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) { int drift = POINTER_DISTANCE(buf, pHelper->pBuffer); if (tsizeof(pHelper->pBuffer) - drift < 128) { 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); taosEncodeVariantU32(&buf, i); @@ -419,7 +406,12 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) { int tsize = (char *)buf - (char *)pHelper->pBuffer + sizeof(TSCKSUM); 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; return 0; } @@ -496,11 +488,29 @@ int tsdbLoadCompInfo(SRWHelper *pHelper, void *target) { if (!helperHasState(pHelper, TSDB_HELPER_INFO_LOAD)) { 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); - if (tread(fd, (void *)(pHelper->pCompInfo), pIdx->len) < pIdx->len) return -1; - if (!taosCheckChecksumWhole((uint8_t *)pHelper->pCompInfo, pIdx->len)) return -1; + if (tread(fd, (void *)(pHelper->pCompInfo), pIdx->len) < pIdx->len) { + 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); @@ -628,13 +638,14 @@ static bool tsdbShouldCreateNewLast(SRWHelper *pHelper) { return false; } -static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, int rowsToWrite, - SCompBlock *pCompBlock, bool isLast, bool isSuperBlock) { +static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDataCols, SCompBlock *pCompBlock, + bool isLast, bool isSuperBlock) { STsdbCfg * pCfg = &(pHelper->pRepo->config); SCompData *pCompData = (SCompData *)(pHelper->pBuffer); 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); offset = lseek(pFile->fd, 0, SEEK_END); @@ -646,7 +657,7 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa } 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; SCompCol *pCompCol = pCompData->cols + nColsNotAllNull; @@ -658,7 +669,7 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa pCompCol->colId = pDataCol->colId; pCompCol->type = pDataCol->type; - if (tDataTypeDesc[pDataCol->type].getStatisFunc && ncol != 0) { + if (tDataTypeDesc[pDataCol->type].getStatisFunc) { (*tDataTypeDesc[pDataCol->type].getStatisFunc)( (TSKEY *)(pDataCols->cols[0].pData), pDataCol->pData, rowsToWrite, &(pCompCol->min), &(pCompCol->max), &(pCompCol->sum), &(pCompCol->minIndex), &(pCompCol->maxIndex), &(pCompCol->numOfNull)); @@ -666,24 +677,24 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa nColsNotAllNull++; } - ASSERT(nColsNotAllNull > 0 && nColsNotAllNull <= pDataCols->numOfCols); + ASSERT(nColsNotAllNull >= 0 && nColsNotAllNull <= pDataCols->numOfCols); // Compress the data if neccessary int tcol = 0; int32_t toffset = 0; int32_t tsize = TSDB_GET_COMPCOL_LEN(nColsNotAllNull); int32_t lsize = tsize; + int32_t keyLen = 0; for (int ncol = 0; ncol < pDataCols->numOfCols; ncol++) { if (tcol >= nColsNotAllNull) break; SDataCol *pDataCol = pDataCols->cols + ncol; SCompCol *pCompCol = pCompData->cols + tcol; - if (pDataCol->colId != pCompCol->colId) continue; - void *tptr = (void *)((char *)pCompData + lsize); - - pCompCol->offset = toffset; + if (ncol != 0 && (pDataCol->colId != pCompCol->colId)) continue; + void *tptr = POINTER_SHIFT(pCompData, lsize); + int32_t flen = 0; // final length int32_t tlen = dataColGetNEleLen(pDataCol, rowsToWrite); 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, - tsizeof(pHelper->pBuffer) - lsize, pCfg->compression, - pHelper->compBuffer, tsizeof(pHelper->compBuffer)); + flen = (*(tDataTypeDesc[pDataCol->type].compFunc))((char *)pDataCol->pData, tlen, rowsToWrite, tptr, + tsizeof(pHelper->pBuffer) - lsize, pCfg->compression, + pHelper->compBuffer, tsizeof(pHelper->compBuffer)); } else { - pCompCol->len = tlen; - memcpy(tptr, pDataCol->pData, pCompCol->len); + flen = tlen; + memcpy(tptr, pDataCol->pData, flen); } // Add checksum - ASSERT(pCompCol->len > 0); - pCompCol->len += sizeof(TSCKSUM); - taosCalcChecksumAppend(0, (uint8_t *)tptr, pCompCol->len); + ASSERT(flen > 0); + flen += sizeof(TSCKSUM); + taosCalcChecksumAppend(0, (uint8_t *)tptr, flen); - toffset += pCompCol->len; - lsize += pCompCol->len; - tcol++; + if (ncol != 0) { + pCompCol->offset = toffset; + pCompCol->len = flen; + tcol++; + } else { + keyLen = flen; + } + + toffset += flen; + lsize += flen; } pCompData->delimiter = TSDB_FILE_DELIMITER; @@ -732,8 +750,8 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa pCompBlock->offset = offset; pCompBlock->algorithm = pCfg->compression; pCompBlock->numOfRows = rowsToWrite; - pCompBlock->sversion = pHelper->tableInfo.sversion; - pCompBlock->len = (int32_t)lsize; + pCompBlock->len = lsize; + pCompBlock->keyLen = keyLen; pCompBlock->numOfSubBlocks = isSuperBlock ? 1 : 0; pCompBlock->numOfCols = nColsNotAllNull; pCompBlock->keyFirst = dataColsKeyFirst(pDataCols); @@ -764,136 +782,6 @@ static int compareKeyBlock(const void *arg1, const void *arg2) { 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) { if (tsizeof((void *)pHelper->pCompInfo) <= esize) { size_t tsize = esize + sizeof(SCompBlock) * 16; @@ -911,7 +799,7 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int ASSERT(pCompBlock->numOfSubBlocks == 1); // 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; // Change the offset @@ -925,16 +813,16 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int if (tsize > 0) { ASSERT(sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1) < 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)), - (void *)((char *)pHelper->pCompInfo + sizeof(SCompInfo) + sizeof(SCompBlock) * blkIdx), tsize); + memmove(POINTER_SHIFT(pHelper->pCompInfo, sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1)), + POINTER_SHIFT(pHelper->pCompInfo, sizeof(SCompInfo) + sizeof(SCompBlock) * blkIdx), tsize); } pHelper->pCompInfo->blocks[blkIdx] = *pCompBlock; pIdx->numOfBlocks++; pIdx->len += sizeof(SCompBlock); ASSERT(pIdx->len <= tsizeof(pHelper->pCompInfo)); - pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].keyLast; - pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].last; + pIdx->maxKey = blockAtIdx(pHelper, pIdx->numOfBlocks - 1)->keyLast; + pIdx->hasLast = blockAtIdx(pHelper, pIdx->numOfBlocks - 1)->last; if (pIdx->numOfBlocks > 1) { ASSERT(pHelper->pCompInfo->blocks[0].keyLast < pHelper->pCompInfo->blocks[1].keyFirst); @@ -1048,8 +936,8 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int if (pSCompBlock->numOfSubBlocks > 1) { size_t tsize = pIdx->len - (pSCompBlock->offset + pSCompBlock->len); if (tsize > 0) { - memmove((void *)((char *)(pHelper->pCompInfo) + pSCompBlock->offset), - (void *)((char *)(pHelper->pCompInfo) + pSCompBlock->offset + pSCompBlock->len), tsize); + memmove(POINTER_SHIFT(pHelper->pCompInfo, pSCompBlock->offset), + POINTER_SHIFT(pHelper->pCompInfo, pSCompBlock->offset + pSCompBlock->len), tsize); } for (int i = blkIdx + 1; i < pIdx->numOfBlocks; i++) { @@ -1062,8 +950,8 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int *pSCompBlock = *pCompBlock; - pIdx->maxKey = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].keyLast; - pIdx->hasLast = pHelper->pCompInfo->blocks[pIdx->numOfBlocks - 1].last; + pIdx->maxKey = blockAtIdx(pHelper, pIdx->numOfBlocks - 1)->keyLast; + 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, blkIdx); @@ -1071,30 +959,6 @@ static int tsdbUpdateSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int 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) { memset((void *)&pHelper->files, 0, sizeof(pHelper->files)); pHelper->files.fid = -1; @@ -1250,7 +1114,8 @@ static int tsdbLoadColData(SRWHelper *pHelper, SFile *pFile, SCompBlock *pCompBl 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)); terrno = TAOS_SYSTEM_ERROR(errno); 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) { 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 ccol = 0; @@ -1298,23 +1168,31 @@ static int tsdbLoadBlockDataColsImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, ASSERT(pDataCol->colId == colId); - while (ccol < pCompBlock->numOfCols) { - pCompCol = &pHelper->pCompData->cols[ccol]; - if (pCompCol->colId >= colId) break; - ccol++; - } + 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) { + pCompCol = &pHelper->pCompData->cols[ccol]; + if (pCompCol->colId >= colId) break; + ccol++; + } - if (ccol >= pCompBlock->numOfCols || pCompCol->colId > colId) { - dataColSetNEleNull(pDataCol, pCompBlock->numOfRows, pDataCols->maxPoints); - dcol++; - continue; - } + if (ccol >= pCompBlock->numOfCols || pCompCol->colId > colId) { + dataColSetNEleNull(pDataCol, pCompBlock->numOfRows, pDataCols->maxPoints); + dcol++; + continue; + } - ASSERT(pCompCol->colId == pDataCol->colId); + ASSERT(pCompCol->colId == pDataCol->colId); + } if (tsdbLoadColData(pHelper, pFile, pCompBlock, pCompCol, pDataCol) < 0) goto _err; dcol++; - ccol++; + if (colId != 0) ccol++; } return 0; @@ -1362,8 +1240,8 @@ static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDa pDataCols->numOfRows = pCompBlock->numOfRows; // Recover the data - int ccol = 0; - int dcol = 0; + int ccol = 0; // loop iter for SCompCol object + int dcol = 0; // loop iter for SDataCols object while (dcol < pDataCols->numOfCols) { SDataCol *pDataCol = &(pDataCols->cols[dcol]); if (ccol >= pCompData->numOfCols) { @@ -1373,12 +1251,23 @@ static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDa 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) { 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); } pHelper->compBuffer = trealloc(pHelper->compBuffer, zsize); @@ -1387,16 +1276,16 @@ static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDa goto _err; } } - if (tsdbCheckAndDecodeColumnData(pDataCol, (char *)pCompData + tsize + pCompCol->offset, pCompCol->len, - pCompBlock->algorithm, pCompBlock->numOfRows, pDataCols->maxPoints, - pHelper->compBuffer, tsizeof(pHelper->compBuffer)) < 0) { - tsdbError("vgId:%d file %s is broken at column %d offset %" PRId64, REPO_ID(pHelper->pRepo), pFile->fname, - pCompCol->colId, (int64_t)pCompCol->offset); + if (tsdbCheckAndDecodeColumnData(pDataCol, (char *)pCompData + tsize + toffset, tlen, pCompBlock->algorithm, + pCompBlock->numOfRows, pDataCols->maxPoints, pHelper->compBuffer, + tsizeof(pHelper->compBuffer)) < 0) { + tsdbError("vgId:%d file %s is broken at column %d block offset %" PRId64 " column offset %d", + REPO_ID(pHelper->pRepo), pFile->fname, tcolId, (int64_t)pCompBlock->offset, toffset); goto _err; } + if (dcol != 0) ccol++; dcol++; - ccol++; - } else if (pCompCol->colId < pDataCol->colId) { + } else if (tcolId < pDataCol->colId) { ccol++; } else { // Set current column as NULL and forward @@ -1442,3 +1331,250 @@ static void *tsdbDecodeSCompIdx(void *buf, SCompIdx *pIdx) { 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; +} \ No newline at end of file diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index a4e0151f89..c43d2636c2 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -110,9 +110,10 @@ typedef struct STsdbQueryHandle { SFileGroupIter fileIter; SRWHelper rhelper; STableBlockInfo* pDataBlockInfo; + int32_t allocSize; // allocated data block size SMemTable* mem; // mem-table SMemTable* imem; // imem-table, acquired from snapshot - + SArray* defaultLoadColumn;// default load column SDataBlockLoadInfo dataBlockLoadInfo; /* record current block load information */ SLoadCompBlockInfo compBlockLoadInfo; /* record current compblock information in SQuery */ } STsdbQueryHandle; @@ -136,6 +137,34 @@ static void tsdbInitCompBlockLoadInfo(SLoadCompBlockInfo* pCompBlockLoadInfo) { pCompBlockLoadInfo->fileId = -1; } +static SArray* getColumnIdList(STsdbQueryHandle* pQueryHandle) { + size_t numOfCols = QH_GET_NUM_OF_COLS(pQueryHandle); + assert(numOfCols <= TSDB_MAX_COLUMNS); + + SArray* pIdList = taosArrayInit(numOfCols, sizeof(int16_t)); + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pCol = taosArrayGet(pQueryHandle->pColumns, i); + taosArrayPush(pIdList, &pCol->info.colId); + } + + return pIdList; +} + +static SArray* getDefaultLoadColumns(STsdbQueryHandle* pQueryHandle, bool loadTS) { + SArray* pLocalIdList = getColumnIdList(pQueryHandle); + + // check if the primary time stamp column needs to load + int16_t colId = *(int16_t*)taosArrayGet(pLocalIdList, 0); + + // the primary timestamp column does not be included in the the specified load column list, add it + if (loadTS && colId != 0) { + int16_t columnId = 0; + taosArrayInsert(pLocalIdList, 0, &columnId); + } + + return pLocalIdList; +} + TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, void* qinfo) { STsdbQueryHandle* pQueryHandle = calloc(1, sizeof(STsdbQueryHandle)); pQueryHandle->order = pCond->order; @@ -148,8 +177,12 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab pQueryHandle->activeIndex = 0; // current active table index pQueryHandle->qinfo = qinfo; pQueryHandle->outputCapacity = ((STsdbRepo*)tsdb)->config.maxRowsPerFileBlock; - - tsdbInitReadHelper(&pQueryHandle->rhelper, (STsdbRepo*) tsdb); + pQueryHandle->allocSize = 0; + + if (tsdbInitReadHelper(&pQueryHandle->rhelper, (STsdbRepo*) tsdb) != 0) { + free(pQueryHandle); + return NULL; + } tsdbTakeMemSnapshot(pQueryHandle->pTsdb, &pQueryHandle->mem, &pQueryHandle->imem); size_t sizeOfGroup = taosArrayGetSize(groupList->pGroupList); @@ -195,7 +228,9 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab taosArrayPush(pQueryHandle->pTableCheckInfo, &info); } } - + + pQueryHandle->defaultLoadColumn = getDefaultLoadColumns(pQueryHandle, true); + tsdbDebug("%p total numOfTable:%zu in query", pQueryHandle, taosArrayGetSize(pQueryHandle->pTableCheckInfo)); tsdbInitDataBlockLoadInfo(&pQueryHandle->dataBlockLoadInfo); @@ -206,11 +241,11 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab TsdbQueryHandleT tsdbQueryLastRow(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, void* qinfo) { STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qinfo); - - pQueryHandle->type = TSDB_QUERY_TYPE_LAST; - pQueryHandle->order = TSDB_ORDER_DESC; - - changeQueryHandleForLastrowQuery(pQueryHandle); + if (pQueryHandle != NULL) { + pQueryHandle->type = TSDB_QUERY_TYPE_LAST; + pQueryHandle->order = TSDB_ORDER_DESC; + changeQueryHandleForLastrowQuery(pQueryHandle); + } return pQueryHandle; } @@ -232,9 +267,10 @@ SArray* tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle) { TsdbQueryHandleT tsdbQueryRowsInExternalWindow(TSDB_REPO_T *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, void* qinfo) { STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qinfo); - - pQueryHandle->type = TSDB_QUERY_TYPE_EXTERNAL; - changeQueryHandleForInterpQuery(pQueryHandle); + if (pQueryHandle != NULL) { + pQueryHandle->type = TSDB_QUERY_TYPE_EXTERNAL; + changeQueryHandleForInterpQuery(pQueryHandle); + } return pQueryHandle; } @@ -546,33 +582,7 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo .tid = (_checkInfo)->tableId.tid, \ .uid = (_checkInfo)->tableId.uid}) -static SArray* getColumnIdList(STsdbQueryHandle* pQueryHandle) { - size_t numOfCols = QH_GET_NUM_OF_COLS(pQueryHandle); - assert(numOfCols <= TSDB_MAX_COLUMNS); - - SArray* pIdList = taosArrayInit(numOfCols, sizeof(int16_t)); - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* pCol = taosArrayGet(pQueryHandle->pColumns, i); - taosArrayPush(pIdList, &pCol->info.colId); - } - - return pIdList; -} -static SArray* getDefaultLoadColumns(STsdbQueryHandle* pQueryHandle, bool loadTS) { - SArray* pLocalIdList = getColumnIdList(pQueryHandle); - - // check if the primary time stamp column needs to load - int16_t colId = *(int16_t*)taosArrayGet(pLocalIdList, 0); - - // the primary timestamp column does not be included in the the specified load column list, add it - if (loadTS && colId != 0) { - int16_t columnId = 0; - taosArrayInsert(pLocalIdList, 0, &columnId); - } - - return pLocalIdList; -} static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlock, STableCheckInfo* pCheckInfo) { STsdbRepo *pRepo = pQueryHandle->pTsdb; @@ -584,8 +594,6 @@ static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlo data->uid = pCheckInfo->pTableObj->tableId.uid; bool blockLoaded = false; - SArray* sa = getDefaultLoadColumns(pQueryHandle, true); - int64_t st = taosGetTimestampUs(); if (pCheckInfo->pDataCols == NULL) { @@ -613,7 +621,6 @@ static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlo assert(pCols->numOfRows != 0 && pCols->numOfRows <= pBlock->numOfRows); pBlock->numOfRows = pCols->numOfRows; - taosArrayDestroy(sa); tfree(data); int64_t et = taosGetTimestampUs() - st; @@ -656,12 +663,8 @@ static void handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SCompBlock* return; } - SArray* sa = getDefaultLoadColumns(pQueryHandle, true); - doLoadFileDataBlock(pQueryHandle, pBlock, pCheckInfo); - doMergeTwoLevelData(pQueryHandle, pCheckInfo, pBlock, sa); - taosArrayDestroy(sa); - + doMergeTwoLevelData(pQueryHandle, pCheckInfo, pBlock, pQueryHandle->defaultLoadColumn); } else { /* * no data in cache, only load data from file @@ -681,14 +684,12 @@ static void handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SCompBlock* } static bool loadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlock, STableCheckInfo* pCheckInfo) { - SArray* sa = getDefaultLoadColumns(pQueryHandle, true); SQueryFilePos* cur = &pQueryHandle->cur; if (ASCENDING_TRAVERSE(pQueryHandle->order)) { // query ended in current block if (pQueryHandle->window.ekey < pBlock->keyLast || pCheckInfo->lastKey > pBlock->keyFirst) { if (!doLoadFileDataBlock(pQueryHandle, pBlock, pCheckInfo)) { - taosArrayDestroy(sa); return false; } @@ -702,7 +703,7 @@ static bool loadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlock cur->pos = 0; } - doMergeTwoLevelData(pQueryHandle, pCheckInfo, pBlock, sa); + doMergeTwoLevelData(pQueryHandle, pCheckInfo, pBlock, pQueryHandle->defaultLoadColumn); } else { // the whole block is loaded in to buffer handleDataMergeIfNeeded(pQueryHandle, pBlock, pCheckInfo); } @@ -719,13 +720,12 @@ static bool loadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlock cur->pos = pBlock->numOfRows - 1; } - doMergeTwoLevelData(pQueryHandle, pCheckInfo, pBlock, sa); + doMergeTwoLevelData(pQueryHandle, pCheckInfo, pBlock, pQueryHandle->defaultLoadColumn); } else { handleDataMergeIfNeeded(pQueryHandle, pBlock, pCheckInfo); } } - taosArrayDestroy(sa); return pQueryHandle->realNumOfRows > 0; } @@ -1241,22 +1241,30 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* STableBlockInfo* pRightBlockInfoEx = &pSupporter->pDataBlockInfo[rightTableIndex][rightTableBlockIndex]; // assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset); +#if 0 // TODO: temporarily comment off requested by Dr. Liao if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset && pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) { 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; } static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numOfBlocks, int32_t* numOfAllocBlocks) { - char* tmp = realloc(pQueryHandle->pDataBlockInfo, sizeof(STableBlockInfo) * numOfBlocks); - if (tmp == NULL) { - return TSDB_CODE_TDB_OUT_OF_MEMORY; + size_t size = sizeof(STableBlockInfo) * numOfBlocks; + + if (pQueryHandle->allocSize < size) { + pQueryHandle->allocSize = size; + char* tmp = realloc(pQueryHandle->pDataBlockInfo, pQueryHandle->allocSize); + if (tmp == NULL) { + return TSDB_CODE_TDB_OUT_OF_MEMORY; + } + + pQueryHandle->pDataBlockInfo = (STableBlockInfo*) tmp; } - pQueryHandle->pDataBlockInfo = (STableBlockInfo*) tmp; - memset(pQueryHandle->pDataBlockInfo, 0, sizeof(STableBlockInfo) * numOfBlocks); + memset(pQueryHandle->pDataBlockInfo, 0, size); *numOfAllocBlocks = numOfBlocks; int32_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo); @@ -1492,9 +1500,8 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { return false; } - SArray* sa = getDefaultLoadColumns(pQueryHandle, true); /*SDataBlockInfo* pBlockInfo =*/ tsdbRetrieveDataBlockInfo(pHandle, &blockInfo); - /*SArray *pDataBlock = */tsdbRetrieveDataBlock(pHandle, sa); + /*SArray *pDataBlock = */tsdbRetrieveDataBlock(pHandle, pQueryHandle->defaultLoadColumn); if (pQueryHandle->cur.win.ekey == pQueryHandle->window.skey) { // data already retrieve, discard other data rows and return @@ -1508,7 +1515,6 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { pQueryHandle->window = pQueryHandle->cur.win; pQueryHandle->cur.rows = 1; pQueryHandle->type = TSDB_QUERY_TYPE_EXTERNAL; - taosArrayDestroy(sa); return true; } else { STsdbQueryHandle* pSecQueryHandle = calloc(1, sizeof(STsdbQueryHandle)); @@ -1522,7 +1528,10 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { pSecQueryHandle->activeIndex = 0; 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); // allocate buffer in order to load data blocks from file @@ -1565,7 +1574,7 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { assert(ret); /*SDataBlockInfo* pBlockInfo =*/ tsdbRetrieveDataBlockInfo((void*) pSecQueryHandle, &blockInfo); - /*SArray *pDataBlock = */tsdbRetrieveDataBlock((void*) pSecQueryHandle, sa); + /*SArray *pDataBlock = */tsdbRetrieveDataBlock((void*) pSecQueryHandle, pSecQueryHandle->defaultLoadColumn); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pCol = taosArrayGet(pQueryHandle->pColumns, i); @@ -1606,7 +1615,9 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { } // TODO: opt by consider the scan order - return doHasDataInBuffer(pQueryHandle); + bool ret = doHasDataInBuffer(pQueryHandle); + terrno = TSDB_CODE_SUCCESS; + return ret; } void changeQueryHandleForLastrowQuery(TsdbQueryHandleT pqHandle) { @@ -1801,7 +1812,8 @@ int32_t tsdbRetrieveDataBlockStatisInfo(TsdbQueryHandleT* pQueryHandle, SDataSta } tsdbLoadCompData(&pHandle->rhelper, pBlockInfo->compBlock, NULL); - + + // todo opt perf size_t numOfCols = QH_GET_NUM_OF_COLS(pHandle); for(int32_t i = 0; i < numOfCols; ++i) { SDataStatis* st = &pHandle->statis[i]; @@ -1820,6 +1832,13 @@ int32_t tsdbRetrieveDataBlockStatisInfo(TsdbQueryHandleT* pQueryHandle, SDataSta if (pHandle->statis[i].numOfNull == -1) { // set the column data are all NULL pHandle->statis[i].numOfNull = pBlockInfo->compBlock->numOfRows; } + + // todo opt perf + SColumnInfo* pColInfo = taosArrayGet(pHandle->pColumns, i); + if (pColInfo->type == TSDB_DATA_TYPE_TIMESTAMP) { + pHandle->statis[i].min = pBlockInfo->compBlock->keyFirst; + pHandle->statis[i].max = pBlockInfo->compBlock->keyLast; + } } return TSDB_CODE_SUCCESS; @@ -2193,7 +2212,7 @@ int32_t tsdbQuerySTableByTagCond(TSDB_REPO_T* tsdb, uint64_t uid, const char* pT int32_t ret = TSDB_CODE_SUCCESS; tExprNode* expr = NULL; - TRY(32) { + TRY(TSDB_MAX_TAGS) { expr = exprTreeFromTableName(tbnameCond); if (expr == NULL) { expr = exprTreeFromBinary(pTagCond, len); @@ -2217,7 +2236,8 @@ int32_t tsdbQuerySTableByTagCond(TSDB_REPO_T* tsdb, uint64_t uid, const char* pT } CATCH( code ) { CLEANUP_EXECUTE(); - ret = code; + terrno = code; + goto _error; // TODO: more error handling } END_TRY @@ -2333,6 +2353,7 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) { } taosArrayDestroy(pQueryHandle->pColumns); + taosArrayDestroy(pQueryHandle->defaultLoadColumn); tfree(pQueryHandle->pDataBlockInfo); tfree(pQueryHandle->statis); diff --git a/src/util/inc/exception.h b/src/util/inc/exception.h index 52cd03d830..38f94bfe28 100644 --- a/src/util/inc/exception.h +++ b/src/util/inc/exception.h @@ -78,6 +78,7 @@ void cleanupPush_int_ptr ( bool failOnly, void* func, void* arg ); int32_t cleanupGetActionCount(); void cleanupExecuteTo( int32_t anchor, bool failed ); void cleanupExecute( SExceptionNode* node, bool failed ); +bool cleanupExceedLimit(); #define CLEANUP_PUSH_VOID_PTR_PTR( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_ptr( (failOnly), (void*)(func), (void*)(arg1), (void*)(arg2) ) #define CLEANUP_PUSH_VOID_PTR_BOOL( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_bool( (failOnly), (void*)(func), (void*)(arg1), (bool)(arg2) ) @@ -91,7 +92,7 @@ void cleanupExecute( SExceptionNode* node, bool failed ); #define CLEANUP_GET_ANCHOR() cleanupGetActionCount() #define CLEANUP_EXECUTE_TO( anchor, failed ) cleanupExecuteTo( (anchor), (failed) ) - +#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit() //////////////////////////////////////////////////////////////////////////////// // functions & macros for exception handling diff --git a/src/util/inc/tarray.h b/src/util/inc/tarray.h index 4d44e82b1b..71838af150 100644 --- a/src/util/inc/tarray.h +++ b/src/util/inc/tarray.h @@ -23,14 +23,13 @@ extern "C" { #include "os.h" #define TARRAY_MIN_SIZE 8 -#define TARRAY_GET_ELEM(array, index) ((array)->pData + (index) * (array)->elemSize) +#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize)) typedef struct SArray { size_t size; size_t capacity; size_t elemSize; - - void* pData; + void* pData; } SArray; /** diff --git a/src/util/inc/tcache.h b/src/util/inc/tcache.h index 2982b8dc70..5a3545fd8f 100644 --- a/src/util/inc/tcache.h +++ b/src/util/inc/tcache.h @@ -21,7 +21,7 @@ extern "C" { #endif #include "os.h" -#include "tref.h" +#include "tlockfree.h" #include "hash.h" typedef void (*__cache_free_fn_t)(void*); @@ -33,17 +33,20 @@ typedef struct SCacheStatis { int64_t refreshCount; } SCacheStatis; +struct STrashElem; + typedef struct SCacheDataNode { - uint64_t addedTime; // the added time when this element is added or updated into cache - uint64_t lifespan; // expiredTime expiredTime when this element should be remove from cache - uint64_t signature; - uint32_t size; // allocated size for current SCacheDataNode + uint64_t addedTime; // the added time when this element is added or updated into cache + uint64_t lifespan; // life duration when this element should be remove from cache + uint64_t expireTime; // expire time + uint64_t signature; + struct STrashElem *pTNodeHeader; // point to trash node head + uint16_t keySize: 15; // max key size: 32kb + bool inTrashCan: 1;// denote if it is in trash or not + uint32_t size; // allocated size for current SCacheDataNode T_REF_DECLARE() - uint16_t keySize: 15; // max key size: 32kb - bool inTrashCan: 1;// denote if it is in trash or not - int32_t extendFactor; // number of life span extend - char *key; - char data[]; + char *key; + char data[]; } SCacheDataNode; typedef struct STrashElem { diff --git a/src/util/inc/tfile.h b/src/util/inc/tfile.h index 04e500743c..de52a40967 100644 --- a/src/util/inc/tfile.h +++ b/src/util/inc/tfile.h @@ -19,13 +19,14 @@ #ifdef TAOS_RANDOM_FILE_FAIL void taosSetRandomFileFailFactor(int factor); -ssize_t taos_tread(int fd, void *buf, size_t count); -ssize_t taos_twrite(int fd, void *buf, size_t count); -off_t taos_lseek(int fd, off_t offset, int whence); +void taosSetRandomFileFailOutput(const char *path); +ssize_t taos_tread(int fd, void *buf, size_t count, const char *file, uint32_t line); +ssize_t taos_twrite(int fd, void *buf, size_t count, const char *file, uint32_t line); +off_t taos_lseek(int fd, off_t offset, int whence, const char *file, uint32_t line); -#define tread(fd, buf, count) taos_tread(fd, buf, count) -#define twrite(fd, buf, count) taos_twrite(fd, buf, count) -#define lseek(fd, offset, whence) taos_lseek(fd, offset, whence) +#define tread(fd, buf, count) taos_tread(fd, buf, count, __FILE__, __LINE__) +#define twrite(fd, buf, count) taos_twrite(fd, buf, count, __FILE__, __LINE__) +#define lseek(fd, offset, whence) taos_lseek(fd, offset, whence, __FILE__, __LINE__) #endif // TAOS_RANDOM_FILE_FAIL diff --git a/src/util/inc/tref.h b/src/util/inc/tlockfree.h similarity index 66% rename from src/util/inc/tref.h rename to src/util/inc/tlockfree.h index 0503325326..e425d71d27 100644 --- a/src/util/inc/tref.h +++ b/src/util/inc/tlockfree.h @@ -12,12 +12,17 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - -#ifndef TDENGINE_TREF_H -#define TDENGINE_TREF_H +#ifndef __TD_LOCK_FREE_H__ +#define __TD_LOCK_FREE_H__ #include "os.h" +#ifdef __cplusplus +extern "C" { +#endif + + +// reference counting typedef void (*_ref_fn_t)(const void* pObj); #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 -#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 diff --git a/src/util/inc/trwlatch.h b/src/util/inc/trwlatch.h deleted file mode 100644 index c6923f0e90..0000000000 --- a/src/util/inc/trwlatch.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * 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 . - */ -#ifndef __TD_RWLATCH_H__ -#define __TD_RWLATCH_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -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 diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index 1ba57bbaaa..f7c69e3973 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -133,6 +133,8 @@ char **strsplit(char *src, const char *delim, int32_t *num); char* strtolower(char *dst, const char *src); +char* strntolower(char *dst, const char *src, int32_t n); + int64_t strnatoi(char *num, int32_t len); //char* strreplace(const char* str, const char* pattern, const char* rep); diff --git a/src/util/src/exception.c b/src/util/src/exception.c index e1f6516fe7..0b716b6aba 100644 --- a/src/util/src/exception.c +++ b/src/util/src/exception.c @@ -147,3 +147,6 @@ void cleanupExecuteTo( int32_t anchor, bool failed ) { void cleanupExecute( SExceptionNode* node, bool failed ) { doExecuteCleanup( node, 0, failed ); } +bool cleanupExceedLimit() { + return expList->numCleanupAction >= expList->maxCleanupAction; +} diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 688e49a40b..072e9939de 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -116,11 +116,13 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheDataNo return; } - int32_t size = pNode->size; taosHashRemove(pCacheObj->pHashTable, pNode->key, pNode->keySize); + pCacheObj->totalSize -= pNode->size; uDebug("cache:%s, key:%p, %p is destroyed from cache, totalNum:%d totalSize:%" PRId64 "bytes size:%dbytes", - pCacheObj->name, pNode->key, pNode->data, (int32_t)taosHashGetSize(pCacheObj->pHashTable), pCacheObj->totalSize, size); + pCacheObj->name, pNode->key, pNode->data, (int32_t)taosHashGetSize(pCacheObj->pHashTable), pCacheObj->totalSize, + pNode->size); + if (pCacheObj->freeFp) pCacheObj->freeFp(pNode->data); free(pNode); } @@ -285,14 +287,14 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v uDebug("cache:%s, key:%p, %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", totalNum:%d totalSize:%" PRId64 "bytes size:%" PRId64 "bytes", - pCacheObj->name, key, pNode->data, pNode->addedTime, (pNode->lifespan * pNode->extendFactor + pNode->addedTime), + pCacheObj->name, key, pNode->data, pNode->addedTime, pNode->expireTime, (int32_t)taosHashGetSize(pCacheObj->pHashTable), pCacheObj->totalSize, dataSize); } else { uError("cache:%s, key:%p, failed to added into cache, out of memory", pCacheObj->name, key); } } else { // old data exists, update the node pNode = taosUpdateCacheImpl(pCacheObj, pOld, key, keyLen, pData, dataSize, duration * 1000L); - uDebug("cache:%s, key:%p, %p exist in cache, updated", pCacheObj->name, key, pNode->data); + uDebug("cache:%s, key:%p, %p exist in cache, updated old:%p", pCacheObj->name, key, pNode->data, pOld); } __cache_unlock(pCacheObj); @@ -305,36 +307,30 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen return NULL; } + void *pData = NULL; + __cache_rd_lock(pCacheObj); - + SCacheDataNode **ptNode = (SCacheDataNode **)taosHashGet(pCacheObj->pHashTable, key, keyLen); int32_t ref = 0; if (ptNode != NULL) { ref = T_REF_INC(*ptNode); - - // if the remained life span is less then the (*ptNode)->lifeSpan, add up one lifespan - if (pCacheObj->extendLifespan) { - int64_t now = taosGetTimestampMs(); - - if ((now - (*ptNode)->addedTime) < (*ptNode)->lifespan * (*ptNode)->extendFactor) { - (*ptNode)->extendFactor += 1; - uDebug("key:%p extend life time to %"PRId64, key, (*ptNode)->lifespan * (*ptNode)->extendFactor + (*ptNode)->addedTime); - } - } + pData = (*ptNode)->data; } + __cache_unlock(pCacheObj); - - if (ptNode != NULL) { + + if (pData != NULL) { atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1); - uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, (*ptNode)->data, ref); + uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData, ref); } else { atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1); uDebug("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key); } - + atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1); - return (ptNode != NULL) ? (*ptNode)->data : NULL; + return pData; } void* taosCacheUpdateExpireTimeByName(SCacheObj *pCacheObj, void *key, size_t keyLen, uint64_t expireTime) { @@ -347,8 +343,7 @@ void* taosCacheUpdateExpireTimeByName(SCacheObj *pCacheObj, void *key, size_t ke SCacheDataNode **ptNode = (SCacheDataNode **)taosHashGet(pCacheObj->pHashTable, key, keyLen); if (ptNode != NULL) { T_REF_INC(*ptNode); - (*ptNode)->extendFactor += 1; -// (*ptNode)->lifespan = expireTime; + (*ptNode)->expireTime = taosGetTimestampMs() + (*ptNode)->lifespan; } __cache_unlock(pCacheObj); @@ -380,17 +375,6 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) { int32_t ref = T_REF_INC(ptNode); uDebug("cache:%s, data: %p acquired by data in cache, refcnt:%d", pCacheObj->name, ptNode->data, ref); - // if the remained life span is less then the (*ptNode)->lifeSpan, add up one lifespan - if (pCacheObj->extendLifespan) { - int64_t now = taosGetTimestampMs(); - - if ((now - ptNode->addedTime) < ptNode->lifespan * ptNode->extendFactor) { - ptNode->extendFactor += 1; - uDebug("cache:%s, %p extend life time to %" PRId64, pCacheObj->name, ptNode->data, - ptNode->lifespan * ptNode->extendFactor + ptNode->addedTime); - } - } - // the data if referenced by at least one object, so the reference count must be greater than the value of 2. assert(ref >= 2); return data; @@ -431,23 +415,91 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { } *data = NULL; - int16_t ref = T_REF_DEC(pNode); - uDebug("cache:%s, key:%p, %p is released, refcnt:%d", pCacheObj->name, pNode->key, pNode->data, ref); - if (_remove && (!pNode->inTrashCan)) { + // note: extend lifespan before dec ref count + bool inTrashCan = pNode->inTrashCan; + + if (pCacheObj->extendLifespan && (!inTrashCan)) { + atomic_store_64(&pNode->expireTime, pNode->lifespan + taosGetTimestampMs()); + uDebug("cache:%s data:%p extend life time to %"PRId64 " before release", pCacheObj->name, pNode->data, pNode->expireTime); + } + + if (_remove) { __cache_wr_lock(pCacheObj); - if (T_REF_VAL_GET(pNode) == 0) { - // remove directly, if not referenced by other users - taosCacheReleaseNode(pCacheObj, pNode); + // NOTE: once refcount is decrease, pNode may be freed by other thread immediately. + int32_t ref = T_REF_DEC(pNode); + uDebug("cache:%s, key:%p, %p is released, refcnt:%d", pCacheObj->name, pNode->key, pNode->data, ref); + + /* + * If it is not referenced by other users, remove it immediately. Otherwise move this node to trashcan wait for all users + * releasing this resources. + * + * NOTE: previous ref is 0, and current ref is still 0, remove it. If previous is not 0, there is another thread + * that tries to do the same thing. + */ + if (pNode->inTrashCan) { + if (ref == 0) { + assert(pNode->pTNodeHeader->pData == pNode); + taosRemoveFromTrashCan(pCacheObj, pNode->pTNodeHeader); + } } else { - // pNode may be released immediately by other thread after the reference count of pNode is set to 0, - // So we need to lock it in the first place. - taosCacheMoveToTrash(pCacheObj, pNode); + if (ref > 0) { + assert(pNode->pTNodeHeader == NULL); + taosCacheMoveToTrash(pCacheObj, pNode); + } else { + taosCacheReleaseNode(pCacheObj, pNode); + } + } + + __cache_unlock(pCacheObj); + + } else { + uDebug("cache:%s, key:%p, %p is released, refcnt:%d", pCacheObj->name, pNode->key, pNode->data, T_REF_VAL_GET(pNode) - 1); + + __cache_wr_lock(pCacheObj); + + // NOTE: once refcount is decrease, pNode may be freed by other thread immediately. + int32_t ref = T_REF_DEC(pNode); + + if (inTrashCan && (ref == 0)) { + // Remove it if the ref count is 0. + // The ref count does not need to load and check again after lock acquired, since ref count can not be increased when + // the node is in trashcan. + assert(pNode->pTNodeHeader->pData == pNode); + taosRemoveFromTrashCan(pCacheObj, pNode->pTNodeHeader); } __cache_unlock(pCacheObj); } + +// else { +// if (_remove) { // not in trash can, but need to remove it +// __cache_wr_lock(pCacheObj); +// +// /* +// * If not referenced by other users. Otherwise move this node to trashcan wait for all users +// * releasing this resources. +// * +// * NOTE: previous ref is 0, and current ref is still 0, remove it. If previous is not 0, there is another thread +// * that tries to do the same thing. +// */ +// if (ref == 0) { +// if (T_REF_VAL_GET(pNode) == 0) { +// taosCacheReleaseNode(pCacheObj, pNode); +// } else { +// taosCacheMoveToTrash(pCacheObj, pNode); +// } +// } else if (ref > 0) { +// if (!pNode->inTrashCan) { +// assert(pNode->pTNodeHeader == NULL); +// taosCacheMoveToTrash(pCacheObj, pNode); +// } +// } +// +// __cache_unlock(pCacheObj); +// } +// } } void taosCacheEmpty(SCacheObj *pCacheObj) { @@ -486,7 +538,7 @@ void taosCacheCleanup(SCacheObj *pCacheObj) { SCacheDataNode *taosCreateCacheNode(const char *key, size_t keyLen, const char *pData, size_t size, uint64_t duration) { - size_t totalSize = size + sizeof(SCacheDataNode) + keyLen + 1; + size_t totalSize = size + sizeof(SCacheDataNode) + keyLen; SCacheDataNode *pNewNode = calloc(1, totalSize); if (pNewNode == NULL) { @@ -503,7 +555,7 @@ SCacheDataNode *taosCreateCacheNode(const char *key, size_t keyLen, const char * pNewNode->addedTime = (uint64_t)taosGetTimestampMs(); pNewNode->lifespan = duration; - pNewNode->extendFactor = 1; + pNewNode->expireTime = pNewNode->addedTime + pNewNode->lifespan; pNewNode->signature = (uint64_t)pNewNode; pNewNode->size = (uint32_t)totalSize; @@ -512,6 +564,7 @@ SCacheDataNode *taosCreateCacheNode(const char *key, size_t keyLen, const char * void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) { if (pNode->inTrashCan) { /* node is already in trash */ + assert(pNode->pTNodeHeader != NULL && pNode->pTNodeHeader->pData == pNode); return; } @@ -527,6 +580,7 @@ void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) { pCacheObj->pTrash = pElem; pNode->inTrashCan = true; + pNode->pTNodeHeader = pElem; pCacheObj->numOfElemsInTrash++; uDebug("key:%p, %p move to trash, numOfElem in trash:%d", pNode->key, pNode->data, pCacheObj->numOfElemsInTrash); @@ -629,7 +683,7 @@ static void doCacheRefresh(SCacheObj* pCacheObj, int64_t time, __cache_free_fn_t __cache_wr_lock(pCacheObj); while (taosHashIterNext(pIter)) { SCacheDataNode *pNode = *(SCacheDataNode **)taosHashIterGet(pIter); - if ((pNode->addedTime + pNode->lifespan * pNode->extendFactor) <= time && T_REF_VAL_GET(pNode) <= 0) { + if (pNode->expireTime < time && T_REF_VAL_GET(pNode) <= 0) { taosCacheReleaseNode(pCacheObj, pNode); continue; } diff --git a/src/util/src/tfile.c b/src/util/src/tfile.c index 92eeaef126..d1a9c24615 100644 --- a/src/util/src/tfile.c +++ b/src/util/src/tfile.c @@ -29,14 +29,55 @@ #ifdef TAOS_RANDOM_FILE_FAIL static int random_file_fail_factor = 20; +static FILE *fpRandomFileFailOutput = NULL; void taosSetRandomFileFailFactor(int factor) { random_file_fail_factor = factor; } + +static void close_random_file_fail_output() +{ + if (fpRandomFileFailOutput != NULL) { + if (fpRandomFileFailOutput != stdout) { + fclose(fpRandomFileFailOutput); + } + fpRandomFileFailOutput = NULL; + } +} + +static void random_file_fail_output_sig(int sig) +{ + fprintf(fpRandomFileFailOutput, "signal %d received.\n", sig); + + struct sigaction act = {0}; + act.sa_handler = SIG_DFL; + sigaction(sig, &act, NULL); + + close_random_file_fail_output(); + exit(EXIT_FAILURE); +} + +void taosSetRandomFileFailOutput(const char *path) +{ + if (path == NULL) { + fpRandomFileFailOutput = stdout; + } else if ((fpRandomFileFailOutput = fopen(path, "w")) != NULL) { + atexit(close_random_file_fail_output); + } else { + printf("failed to open random file fail log file '%s', errno=%d\n", path, errno); + return; + } + + struct sigaction act = {0}; + act.sa_handler = random_file_fail_output_sig; + sigaction(SIGFPE, &act, NULL); + sigaction(SIGSEGV, &act, NULL); + sigaction(SIGILL, &act, NULL); +} #endif -ssize_t taos_tread(int fd, void *buf, size_t count) +ssize_t taos_tread(int fd, void *buf, size_t count, const char *file, uint32_t line) { #ifdef TAOS_RANDOM_FILE_FAIL if (random_file_fail_factor > 0) { @@ -49,7 +90,7 @@ ssize_t taos_tread(int fd, void *buf, size_t count) return tread(fd, buf, count); } -ssize_t taos_twrite(int fd, void *buf, size_t count) +ssize_t taos_twrite(int fd, void *buf, size_t count, const char *file, uint32_t line) { #ifdef TAOS_RANDOM_FILE_FAIL if (random_file_fail_factor > 0) { @@ -62,7 +103,7 @@ ssize_t taos_twrite(int fd, void *buf, size_t count) return twrite(fd, buf, count); } -off_t taos_lseek(int fd, off_t offset, int whence) +off_t taos_lseek(int fd, off_t offset, int whence, const char *file, uint32_t line) { #ifdef TAOS_RANDOM_FILE_FAIL if (random_file_fail_factor > 0) { diff --git a/src/util/src/tidpool.c b/src/util/src/tidpool.c index 3764c7966b..53d81bb542 100644 --- a/src/util/src/tidpool.c +++ b/src/util/src/tidpool.c @@ -123,7 +123,7 @@ void taosIdPoolMarkStatus(void *handle, int id) { int taosUpdateIdPool(id_pool_t *handle, int maxId) { id_pool_t *pIdPool = (id_pool_t*)handle; if (maxId <= pIdPool->maxId) { - return -1; + return 0; } bool *idList = calloc(maxId, sizeof(bool)); diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c index 2a24a59742..ab2aa738c6 100644 --- a/src/util/src/tkvstore.c +++ b/src/util/src/tkvstore.c @@ -260,7 +260,7 @@ int tdUpdateKVStoreRecord(SKVStore *pStore, uint64_t uid, void *cont, int contLe } taosHashPut(pStore->map, (void *)(&uid), sizeof(uid), (void *)(&rInfo), sizeof(rInfo)); - uDebug("put uid %" PRIu64 " into kvStore %s", uid, pStore->fname); + uTrace("put uid %" PRIu64 " into kvStore %s", uid, pStore->fname); return 0; } diff --git a/src/util/src/trwlatch.c b/src/util/src/tlockfree.c similarity index 98% rename from src/util/src/trwlatch.c rename to src/util/src/tlockfree.c index cc027aa3df..3161518a36 100644 --- a/src/util/src/trwlatch.c +++ b/src/util/src/tlockfree.c @@ -15,8 +15,7 @@ // #define _GNU_SOURCE // #include -#include "trwlatch.h" -#include "os.h" +#include "tlockfree.h" #define TD_RWLATCH_WRITE_FLAG 0x40000000 diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index b225dfa36a..5de61a3d57 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -270,6 +270,14 @@ int taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clientI return -1; } + /* set REUSEADDR option, so the portnumber can be re-used */ + int reuse = 1; + if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { + uError("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); + close(sockFd); + return -1; + }; + if ( clientIp != 0) { memset((char *)&clientAddr, 0, sizeof(clientAddr)); clientAddr.sin_family = AF_INET; diff --git a/src/util/src/ttime.c b/src/util/src/ttime.c index 6f67c4a136..018c0d640b 100644 --- a/src/util/src/ttime.c +++ b/src/util/src/ttime.c @@ -317,29 +317,34 @@ int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec) { static int32_t getTimestampInUsFromStrImpl(int64_t val, char unit, int64_t* result) { *result = val; + int64_t factor = 1000L; + switch (unit) { case 's': - (*result) *= MILLISECOND_PER_SECOND; + (*result) *= MILLISECOND_PER_SECOND*factor; break; case 'm': - (*result) *= MILLISECOND_PER_MINUTE; + (*result) *= MILLISECOND_PER_MINUTE*factor; break; case 'h': - (*result) *= MILLISECOND_PER_HOUR; + (*result) *= MILLISECOND_PER_HOUR*factor; break; case 'd': - (*result) *= MILLISECOND_PER_DAY; + (*result) *= MILLISECOND_PER_DAY*factor; break; case 'w': - (*result) *= MILLISECOND_PER_WEEK; + (*result) *= MILLISECOND_PER_WEEK*factor; break; case 'n': - (*result) *= MILLISECOND_PER_MONTH; + (*result) *= MILLISECOND_PER_MONTH*factor; break; case 'y': - (*result) *= MILLISECOND_PER_YEAR; + (*result) *= MILLISECOND_PER_YEAR*factor; break; case 'a': + (*result) *= factor; + break; + case 'u': break; default: { ; @@ -348,7 +353,6 @@ static int32_t getTimestampInUsFromStrImpl(int64_t val, char unit, int64_t* resu } /* get the value in microsecond */ - (*result) *= 1000L; return 0; } diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index 62aa2007b2..5cdc6ff918 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -24,10 +24,10 @@ extern int32_t tscEmbedded; #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 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 tmrDebug(...) { if (tmrDebugFlag & DEBUG_DEBUG) { taosPrintLog("TMR DEBUG ", tmrDebugFlag, __VA_ARGS__); }} -#define tmrTrace(...) { if (tmrDebugFlag & DEBUG_TRACE) { taosPrintLog("TMR TRACE ", 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 ", tscEmbedded ? 255 : tmrDebugFlag, __VA_ARGS__); }} +#define tmrDebug(...) { if (tmrDebugFlag & DEBUG_DEBUG) { taosPrintLog("TMR ", tmrDebugFlag, __VA_ARGS__); }} +#define tmrTrace(...) { if (tmrDebugFlag & DEBUG_TRACE) { taosPrintLog("TMR ", tmrDebugFlag, __VA_ARGS__); }} #define TIMER_STATE_WAITING 0 #define TIMER_STATE_EXPIRED 1 diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 1a74359f47..3764df4afc 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -234,6 +234,35 @@ char* strtolower(char *dst, const char *src) { *p = 0; return dst; } +char* strntolower(char *dst, const char *src, int32_t n) { + int esc = 0; + char quote = 0, *p = dst, c; + + assert(dst != NULL); + if (n == 0) { + *p = 0; + return dst; + } + for (c = *src++; n-- > 0; c = *src++) { + if (esc) { + esc = 0; + } else if (quote) { + if (c == '\\') { + esc = 1; + } else if (c == quote) { + quote = 0; + } + } else if (c >= 'A' && c <= 'Z') { + c -= 'A' - 'a'; + } else if (c == '\'' || c == '"') { + quote = c; + } + *p++ = c; + } + + *p = 0; + return dst; +} char *paGetToken(char *string, char **token, int32_t *tokenLen) { char quote = 0; diff --git a/src/vnode/inc/vnodeInt.h b/src/vnode/inc/vnodeInt.h index 4f22c7784d..74cfbf1e73 100644 --- a/src/vnode/inc/vnodeInt.h +++ b/src/vnode/inc/vnodeInt.h @@ -29,15 +29,15 @@ extern int32_t vDebugFlag; #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 vWarn(...) { if (vDebugFlag & DEBUG_WARN) { taosPrintLog("VND WARN ", 255, __VA_ARGS__); }} -#define vInfo(...) { if (vDebugFlag & DEBUG_INFO) { taosPrintLog("VND INFO ", 255, __VA_ARGS__); }} -#define vDebug(...) { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND DEBUG ", vDebugFlag, __VA_ARGS__); }} -#define vTrace(...) { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND TRACE ", vDebugFlag, __VA_ARGS__); }} +#define vWarn(...) { if (vDebugFlag & DEBUG_WARN) { taosPrintLog("VND WARN ", 255, __VA_ARGS__); }} +#define vInfo(...) { if (vDebugFlag & DEBUG_INFO) { taosPrintLog("VND ", 255, __VA_ARGS__); }} +#define vDebug(...) { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", vDebugFlag, __VA_ARGS__); }} +#define vTrace(...) { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", vDebugFlag, __VA_ARGS__); }} typedef struct { int32_t vgId; // global vnode group ID int32_t refCount; // reference count - int status; + int8_t status; int8_t role; int8_t accessState; int64_t version; // current version @@ -55,6 +55,8 @@ typedef struct { SWalCfg walCfg; void *qMgmt; char *rootDir; + tsem_t sem; + int8_t dropped; char db[TSDB_DB_NAME_LEN]; } SVnodeObj; diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 18c9ebf2e1..bf98824570 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -44,7 +44,7 @@ static int vnodeProcessTsdbStatus(void *arg, int status); static uint32_t vnodeGetFileInfo(void *ahandle, char *name, uint32_t *index, uint32_t eindex, int32_t *size, uint64_t *fversion); static int vnodeGetWalInfo(void *ahandle, char *name, uint32_t *index); static void vnodeNotifyRole(void *ahandle, int8_t role); -static void vnodeNotifyFileSynced(void *ahandle, uint64_t fversion); +static int vnodeNotifyFileSynced(void *ahandle, uint64_t fversion); #ifndef _SYNC tsync_h syncStart(const SSyncInfo *info) { return NULL; } @@ -59,7 +59,7 @@ int32_t vnodeInitResources() { vnodeInitWriteFp(); vnodeInitReadFp(); - tsDnodeVnodesHash = taosHashInit(TSDB_MAX_VNODES, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true); + tsDnodeVnodesHash = taosHashInit(TSDB_MIN_VNODES, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true); if (tsDnodeVnodesHash == NULL) { vError("failed to init vnode list"); return TSDB_CODE_VND_OUT_OF_MEMORY; @@ -69,6 +69,7 @@ int32_t vnodeInitResources() { } void vnodeCleanupResources() { + if (tsDnodeVnodesHash != NULL) { taosHashCleanup(tsDnodeVnodesHash); tsDnodeVnodesHash = NULL; @@ -137,7 +138,7 @@ int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { 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); return code; @@ -152,7 +153,7 @@ int32_t vnodeDrop(int32_t vgId) { SVnodeObj *pVnode = *ppVnode; vTrace("vgId:%d, vnode will be dropped, refCount:%d", pVnode->vgId, pVnode->refCount); - pVnode->status = TAOS_VN_STATUS_DELETING; + pVnode->dropped = 1; vnodeCleanUp(pVnode); return TSDB_CODE_SUCCESS; @@ -163,29 +164,36 @@ int32_t vnodeAlter(void *param, SMDCreateVnodeMsg *pVnodeCfg) { // vnode in non-ready state and still needs to return success instead of TSDB_CODE_VND_INVALID_STATUS // cfgVersion can be corrected by status msg - if (pVnode->status != TAOS_VN_STATUS_READY) { + if (atomic_val_compare_exchange_8(&pVnode->status, TAOS_VN_STATUS_READY, TAOS_VN_STATUS_UPDATING) != TAOS_VN_STATUS_READY) { vDebug("vgId:%d, vnode is not ready, do alter operation later", pVnode->vgId); return TSDB_CODE_SUCCESS; } - // the vnode may always fail to synchronize because of it in low cfgVersion - // so cannot use the following codes - // if (pVnode->syncCfg.replica > 1 && pVnode->role == TAOS_SYNC_ROLE_UNSYNCED) - // return TSDB_CODE_VND_NOT_SYNCED; - - pVnode->status = TAOS_VN_STATUS_UPDATING; - int32_t code = vnodeSaveCfg(pVnodeCfg); - if (code != TSDB_CODE_SUCCESS) return code; + if (code != TSDB_CODE_SUCCESS) { + pVnode->status = TAOS_VN_STATUS_READY; + return code; + } code = vnodeReadCfg(pVnode); - if (code != TSDB_CODE_SUCCESS) return code; + if (code != TSDB_CODE_SUCCESS) { + pVnode->status = TAOS_VN_STATUS_READY; + return code; + } code = syncReconfig(pVnode->sync, &pVnode->syncCfg); - if (code != TSDB_CODE_SUCCESS) return code; + if (code != TSDB_CODE_SUCCESS) { + pVnode->status = TAOS_VN_STATUS_READY; + return code; + } - code = tsdbConfigRepo(pVnode->tsdb, &pVnode->tsdbCfg); - if (code != TSDB_CODE_SUCCESS) return code; + if (pVnode->tsdb) { + code = tsdbConfigRepo(pVnode->tsdb, &pVnode->tsdbCfg); + if (code != TSDB_CODE_SUCCESS) { + pVnode->status = TAOS_VN_STATUS_READY; + return code; + } + } pVnode->status = TAOS_VN_STATUS_READY; vDebug("vgId:%d, vnode is altered", pVnode->vgId); @@ -210,6 +218,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { pVnode->tsdbCfg.tsdbId = pVnode->vgId; pVnode->rootDir = strdup(rootDir); pVnode->accessState = TSDB_VN_ALL_ACCCESS; + tsem_init(&pVnode->sem, 0, 0); int32_t code = vnodeReadCfg(pVnode); if (code != TSDB_CODE_SUCCESS) { @@ -290,10 +299,6 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { } #endif - // start continuous query - if (pVnode->role == TAOS_SYNC_ROLE_MASTER) - cqStart(pVnode->cq); - pVnode->qMgmt = qOpenQueryMgmt(pVnode->vgId); pVnode->events = NULL; pVnode->status = TAOS_VN_STATUS_READY; @@ -304,22 +309,12 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) { return TSDB_CODE_SUCCESS; } -int32_t vnodeStartStream(int32_t vnode) { - SVnodeObj* pVnode = vnodeAcquireVnode(vnode); - if (pVnode != NULL) { - tsdbStartStream(pVnode->tsdb); - vnodeRelease(pVnode); - } - return TSDB_CODE_SUCCESS; -} - int32_t vnodeClose(int32_t vgId) { SVnodeObj **ppVnode = (SVnodeObj **)taosHashGet(tsDnodeVnodesHash, (const char *)&vgId, sizeof(int32_t)); if (ppVnode == NULL || *ppVnode == NULL) return 0; SVnodeObj *pVnode = *ppVnode; vDebug("vgId:%d, vnode will be closed", pVnode->vgId); - pVnode->status = TAOS_VN_STATUS_CLOSING; vnodeCleanUp(pVnode); return 0; @@ -334,6 +329,8 @@ void vnodeRelease(void *pVnodeRaw) { if (refCount > 0) { vDebug("vgId:%d, release vnode, refCount:%d", vgId, refCount); + if (pVnode->status == TAOS_VN_STATUS_RESET && refCount == 2) + tsem_post(&pVnode->sem); return; } @@ -344,11 +341,6 @@ void vnodeRelease(void *pVnodeRaw) { tsdbCloseRepo(pVnode->tsdb, 1); pVnode->tsdb = NULL; - // stop continuous query - if (pVnode->cq) - cqClose(pVnode->cq); - pVnode->cq = NULL; - if (pVnode->wal) walClose(pVnode->wal); pVnode->wal = NULL; @@ -363,20 +355,21 @@ void vnodeRelease(void *pVnodeRaw) { tfree(pVnode->rootDir); - if (pVnode->status == TAOS_VN_STATUS_DELETING) { + if (pVnode->dropped) { char rootDir[TSDB_FILENAME_LEN] = {0}; sprintf(rootDir, "%s/vnode%d", tsVnodeDir, vgId); taosMvDir(tsVnodeBakDir, rootDir); taosRemoveDir(rootDir); } + tsem_destroy(&pVnode->sem); free(pVnode); int32_t count = taosHashGetSize(tsDnodeVnodesHash); vDebug("vgId:%d, vnode is released, vnodes:%d", vgId, count); } -void *vnodeGetVnode(int32_t vgId) { +void *vnodeAcquire(int32_t vgId) { SVnodeObj **ppVnode = (SVnodeObj **)taosHashGet(tsDnodeVnodesHash, (const char *)&vgId, sizeof(int32_t)); if (ppVnode == NULL || *ppVnode == NULL) { terrno = TSDB_CODE_VND_INVALID_VGROUP_ID; @@ -384,35 +377,38 @@ void *vnodeGetVnode(int32_t vgId) { return NULL; } - return *ppVnode; -} - -void *vnodeAcquireVnode(int32_t vgId) { - SVnodeObj *pVnode = vnodeGetVnode(vgId); - if (pVnode == NULL) return pVnode; - + SVnodeObj *pVnode = *ppVnode; atomic_add_fetch_32(&pVnode->refCount, 1); vDebug("vgId:%d, get vnode, refCount:%d", pVnode->vgId, pVnode->refCount); return pVnode; } -void *vnodeAcquireRqueue(void *param) { - SVnodeObj *pVnode = param; +void *vnodeAcquireRqueue(int32_t vgId) { + SVnodeObj *pVnode = vnodeAcquire(vgId); if (pVnode == NULL) return NULL; - atomic_add_fetch_32(&pVnode->refCount, 1); - vDebug("vgId:%d, get vnode rqueue, refCount:%d", pVnode->vgId, pVnode->refCount); - return ((SVnodeObj *)pVnode)->rqueue; + if (pVnode->status == TAOS_VN_STATUS_RESET) { + terrno = TSDB_CODE_VND_INVALID_STATUS; + vInfo("vgId:%d, status is in reset", vgId); + vnodeRelease(pVnode); + return NULL; + } + + return pVnode->rqueue; } -void *vnodeGetRqueue(void *pVnode) { - return ((SVnodeObj *)pVnode)->rqueue; -} - -void *vnodeGetWqueue(int32_t vgId) { - SVnodeObj *pVnode = vnodeAcquireVnode(vgId); +void *vnodeAcquireWqueue(int32_t vgId) { + SVnodeObj *pVnode = vnodeAcquire(vgId); if (pVnode == NULL) return NULL; + + if (pVnode->status == TAOS_VN_STATUS_RESET) { + terrno = TSDB_CODE_VND_INVALID_STATUS; + vInfo("vgId:%d, status is in reset", vgId); + vnodeRelease(pVnode); + return NULL; + } + return pVnode->wqueue; } @@ -484,7 +480,7 @@ void vnodeBuildStatusMsg(void *param) { void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes) { for (int32_t i = 0; i < numOfVnodes; ++i) { pAccess[i].vgId = htonl(pAccess[i].vgId); - SVnodeObj *pVnode = vnodeAcquireVnode(pAccess[i].vgId); + SVnodeObj *pVnode = vnodeAcquire(pAccess[i].vgId); if (pVnode != NULL) { pVnode->accessState = pAccess[i].accessState; if (pVnode->accessState != TSDB_VN_ALL_ACCCESS) { @@ -498,17 +494,35 @@ void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes) { static void vnodeCleanUp(SVnodeObj *pVnode) { // remove from hash, so new messages wont be consumed taosHashRemove(tsDnodeVnodesHash, (const char *)&pVnode->vgId, sizeof(int32_t)); + int i = 0; + + if (pVnode->status != TAOS_VN_STATUS_INIT) { + // it may be in updateing or reset state, then it shall wait + while (atomic_val_compare_exchange_8(&pVnode->status, TAOS_VN_STATUS_READY, TAOS_VN_STATUS_CLOSING) != TAOS_VN_STATUS_READY) { + if (++i % 1000 == 0) { + sched_yield(); + } + } + } // stop replication module if (pVnode->sync) { - syncStop(pVnode->sync); + void *sync = pVnode->sync; pVnode->sync = NULL; + syncStop(sync); + } + + // stop continuous query + if (pVnode->cq) { + void *cq = pVnode->cq; + pVnode->cq = NULL; + cqClose(cq); } vTrace("vgId:%d, vnode will cleanup, refCount:%d", pVnode->vgId, pVnode->refCount); // release local resources only after cutting off outside connections - qSetQueryMgmtClosed(pVnode->qMgmt); + qQueryMgmtNotifyClosed(pVnode->qMgmt); vnodeRelease(pVnode); } @@ -549,18 +563,25 @@ static void vnodeNotifyRole(void *ahandle, int8_t role) { cqStop(pVnode->cq); } -static void vnodeNotifyFileSynced(void *ahandle, uint64_t fversion) { - SVnodeObj *pVnode = ahandle; - vDebug("vgId:%d, data file is synced, fversion:%" PRId64, pVnode->vgId, fversion); - - pVnode->fversion = fversion; - pVnode->version = fversion; - vnodeSaveVersion(pVnode); - +static int vnodeResetTsdb(SVnodeObj *pVnode) +{ char rootDir[128] = "\0"; sprintf(rootDir, "%s/tsdb", pVnode->rootDir); - // clsoe tsdb, then open tsdb - tsdbCloseRepo(pVnode->tsdb, 0); + + if (atomic_val_compare_exchange_8(&pVnode->status, TAOS_VN_STATUS_READY, TAOS_VN_STATUS_RESET) != TAOS_VN_STATUS_READY) + return -1; + + void *tsdb = pVnode->tsdb; + pVnode->tsdb = NULL; + + // acquire vnode + int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1); + + if (refCount > 2) + tsem_wait(&pVnode->sem); + + // close tsdb, then open tsdb + tsdbCloseRepo(tsdb, 0); STsdbAppH appH = {0}; appH.appH = (void *)pVnode; appH.notifyStatus = vnodeProcessTsdbStatus; @@ -569,6 +590,22 @@ static void vnodeNotifyFileSynced(void *ahandle, uint64_t fversion) { appH.cqDropFunc = cqDrop; appH.configFunc = dnodeSendCfgTableToRecv; pVnode->tsdb = tsdbOpenRepo(rootDir, &appH); + + pVnode->status = TAOS_VN_STATUS_READY; + vnodeRelease(pVnode); + + return 0; +} + +static int vnodeNotifyFileSynced(void *ahandle, uint64_t fversion) { + SVnodeObj *pVnode = ahandle; + vDebug("vgId:%d, data file is synced, fversion:%" PRId64, pVnode->vgId, fversion); + + pVnode->fversion = fversion; + pVnode->version = fversion; + vnodeSaveVersion(pVnode); + + return vnodeResetTsdb(pVnode); } static int32_t vnodeSaveCfg(SMDCreateVnodeMsg *pVnodeCfg) { @@ -606,6 +643,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, " \"compression\": %d,\n", pVnodeCfg->cfg.compression); 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, " \"wals\": %d,\n", pVnodeCfg->cfg.wals); len += snprintf(content + len, maxLen - len, " \"quorum\": %d,\n", pVnodeCfg->cfg.quorum); @@ -770,6 +808,13 @@ static int32_t vnodeReadCfg(SVnodeObj *pVnode) { } 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"); if (!wals || wals->type != cJSON_Number) { vError("vgId:%d, failed to read vnode cfg, wals not found", pVnode->vgId); diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index f054ae3904..973df7c5a1 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -26,6 +26,7 @@ #include "tsdb.h" #include "vnode.h" #include "vnodeInt.h" +#include "tqueue.h" static int32_t (*vnodeProcessReadMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *pVnode, SReadMsg *pReadMsg); static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg); @@ -51,6 +52,11 @@ int32_t vnodeProcessRead(void *param, SReadMsg *pReadMsg) { return TSDB_CODE_VND_INVALID_STATUS; } + // tsdb may be in reset state + if (pVnode->tsdb == NULL) return TSDB_CODE_RPC_NOT_READY; + if (pVnode->status == TAOS_VN_STATUS_CLOSING) + return TSDB_CODE_RPC_NOT_READY; + // TODO: Later, let slave to support query if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) { vDebug("vgId:%d, msgType:%s not processed, replica:%d role:%d", pVnode->vgId, taosMsg[msgType], pVnode->syncCfg.replica, pVnode->role); @@ -60,6 +66,16 @@ int32_t vnodeProcessRead(void *param, SReadMsg *pReadMsg) { return (*vnodeProcessReadMsgFp[msgType])(pVnode, pReadMsg); } +static void vnodePutItemIntoReadQueue(SVnodeObj *pVnode, void *qhandle) { + SReadMsg *pRead = (SReadMsg *)taosAllocateQitem(sizeof(SReadMsg)); + pRead->rpcMsg.msgType = TSDB_MSG_TYPE_QUERY; + pRead->pCont = qhandle; + pRead->contLen = 0; + + atomic_add_fetch_32(&pVnode->refCount, 1); + taosWriteQitem(pVnode->rqueue, TAOS_QTYPE_QUERY, pRead); +} + static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) { void *pCont = pReadMsg->pCont; int32_t contLen = pReadMsg->contLen; @@ -82,6 +98,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) { vWarn("QInfo:%p invalid qhandle, no matched query handle, conn:%p", (void*) killQueryMsg->qhandle, pReadMsg->rpcMsg.handle); } else { assert(*qhandle == (void*) killQueryMsg->qhandle); + qKillQuery(*qhandle); qReleaseQInfo(pVnode->qMgmt, (void**) &qhandle, true); } @@ -93,7 +110,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) { if (contLen != 0) { qinfo_t pQInfo = NULL; - code = qCreateQueryInfo(pVnode->tsdb, pVnode->vgId, pQueryTableMsg, pVnode, NULL, &pQInfo); + code = qCreateQueryInfo(pVnode->tsdb, pVnode->vgId, pQueryTableMsg, pVnode, &pQInfo); SQueryTableRsp *pRsp = (SQueryTableRsp *) rpcMallocCont(sizeof(SQueryTableRsp)); pRsp->code = code; @@ -107,10 +124,10 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) { if (code == TSDB_CODE_SUCCESS) { handle = qRegisterQInfo(pVnode->qMgmt, (uint64_t) pQInfo); if (handle == NULL) { // failed to register qhandle + vError("vgId:%d QInfo:%p register qhandle failed, return to app, code:%s", pVnode->vgId, (void *)pQInfo, + tstrerror(pRsp->code)); pRsp->code = TSDB_CODE_QRY_INVALID_QHANDLE; - - qKillQuery(pQInfo); - qKillQuery(pQInfo); + qDestroyQueryInfo(pQInfo); // destroy it directly } else { assert(*handle == pQInfo); pRsp->qhandle = htobe64((uint64_t) pQInfo); @@ -120,21 +137,20 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) { if (handle != NULL && vnodeNotifyCurrentQhandle(pReadMsg->rpcMsg.handle, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) { vError("vgId:%d, QInfo:%p, query discarded since link is broken, %p", pVnode->vgId, *handle, pReadMsg->rpcMsg.handle); pRsp->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; - - // NOTE: there two refcount, needs to kill twice - // query has not been put into qhandle pool, kill it directly. - qKillQuery(*handle); qReleaseQInfo(pVnode->qMgmt, (void**) &handle, true); return pRsp->code; } } else { assert(pQInfo == NULL); } + if (handle != NULL) { - dnodePutItemIntoReadQueue(pVnode, *handle); + vDebug("vgId:%d, QInfo:%p, dnode query msg disposed, register qhandle and return to app", vgId, *handle); + + vnodePutItemIntoReadQueue(pVnode, *handle); qReleaseQInfo(pVnode->qMgmt, (void**) &handle, false); } - vDebug("vgId:%d, QInfo:%p, dnode query msg disposed", vgId, pQInfo); + } else { assert(pCont != NULL); handle = qAcquireQInfo(pVnode->qMgmt, (uint64_t) pCont); @@ -142,12 +158,13 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) { vWarn("QInfo:%p invalid qhandle in continuing exec query, conn:%p", (void*) pCont, pReadMsg->rpcMsg.handle); code = TSDB_CODE_QRY_INVALID_QHANDLE; } else { - vDebug("vgId:%d, QInfo:%p, dnode query msg in progress", pVnode->vgId, (void*) pCont); + vDebug("vgId:%d, QInfo:%p, dnode continue exec query", pVnode->vgId, (void*) pCont); code = TSDB_CODE_VND_ACTION_IN_PROGRESS; qTableQuery(*handle); // do execute query } qReleaseQInfo(pVnode->qMgmt, (void**) &handle, false); } + return code; } @@ -159,7 +176,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) { pRetrieve->qhandle = htobe64(pRetrieve->qhandle); pRetrieve->free = htons(pRetrieve->free); - vDebug("vgId:%d, QInfo:%p, retrieve msg is disposed", pVnode->vgId, *(void**) pRetrieve->qhandle); + vDebug("vgId:%d, QInfo:%p, retrieve msg is disposed", pVnode->vgId, (void*) pRetrieve->qhandle); memset(pRet, 0, sizeof(SRspRet)); @@ -183,6 +200,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) { if (pRetrieve->free == 1) { vDebug("vgId:%d, QInfo:%p, retrieve msg received to kill query and free qhandle", pVnode->vgId, *handle); + qKillQuery(*handle); qReleaseQInfo(pVnode->qMgmt, (void**) &handle, true); pRet->rsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp)); @@ -206,9 +224,12 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) { } else { // if failed to dump result, free qhandle immediately if ((code = qDumpRetrieveResult(*handle, (SRetrieveTableRsp **)&pRet->rsp, &pRet->len)) == TSDB_CODE_SUCCESS) { if (qHasMoreResultsToRetrieve(*handle)) { - dnodePutItemIntoReadQueue(pVnode, *handle); + vnodePutItemIntoReadQueue(pVnode, *handle); pRet->qhandle = *handle; freeHandle = false; + } else { + qKillQuery(*handle); + freeHandle = true; } } } diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index 5ed5e747f2..6b9b8ca4fd 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -59,13 +59,18 @@ int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) { return TSDB_CODE_VND_NO_WRITE_AUTH; } + // tsdb may be in reset state + if (pVnode->tsdb == NULL) return TSDB_CODE_RPC_NOT_READY; + if (pVnode->status == TAOS_VN_STATUS_CLOSING) + return TSDB_CODE_RPC_NOT_READY; + if (pHead->version == 0) { // from client or CQ if (pVnode->status != TAOS_VN_STATUS_READY) { vDebug("vgId:%d, msgType:%s not processed, vnode status is %d", pVnode->vgId, taosMsg[pHead->msgType], pVnode->status); return TSDB_CODE_VND_INVALID_STATUS; // it may be in deleting or closing state } - if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) { + if (pVnode->role != TAOS_SYNC_ROLE_MASTER) { vDebug("vgId:%d, msgType:%s not processed, replica:%d role:%d", pVnode->vgId, taosMsg[pHead->msgType], pVnode->syncCfg.replica, pVnode->role); return TSDB_CODE_RPC_NOT_READY; } @@ -184,6 +189,8 @@ int vnodeWriteToQueue(void *param, void *data, int type) { memcpy(pWal, pHead, size); atomic_add_fetch_32(&pVnode->refCount, 1); + vDebug("vgId:%d, get vnode wqueue, refCount:%d", pVnode->vgId, pVnode->refCount); + taosWriteQitem(pVnode->wqueue, type, pWal); return 0; diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index 94a0fdc956..a0e2ccb51d 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -25,6 +25,7 @@ #include "tlog.h" #include "tchecksum.h" #include "tutil.h" +#include "ttimer.h" #include "taoserror.h" #include "twal.h" #include "tqueue.h" @@ -34,16 +35,19 @@ #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 wWarn(...) { if (wDebugFlag & DEBUG_WARN) { taosPrintLog("WAL WARN ", 255, __VA_ARGS__); }} -#define wInfo(...) { if (wDebugFlag & DEBUG_INFO) { taosPrintLog("WAL INFO ", 255, __VA_ARGS__); }} -#define wDebug(...) { if (wDebugFlag & DEBUG_DEBUG) { taosPrintLog("WAL DEBUG ", wDebugFlag, __VA_ARGS__); }} -#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL TRACE ", wDebugFlag, __VA_ARGS__); }} +#define wWarn(...) { if (wDebugFlag & DEBUG_WARN) { taosPrintLog("WAL WARN ", 255, __VA_ARGS__); }} +#define wInfo(...) { if (wDebugFlag & DEBUG_INFO) { taosPrintLog("WAL ", 255, __VA_ARGS__); }} +#define wDebug(...) { if (wDebugFlag & DEBUG_DEBUG) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }} +#define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__); }} typedef struct { uint64_t version; int fd; int keep; int level; + int32_t fsyncPeriod; + void *timer; + void *signature; int max; // maximum number of wal files uint32_t id; // increase continuously int num; // number of wal files @@ -52,10 +56,23 @@ typedef struct { pthread_mutex_t mutex; } SWal; +static void *walTmrCtrl = NULL; +static int tsWalNum = 0; +static pthread_once_t walModuleInit = PTHREAD_ONCE_INIT; static uint32_t walSignature = 0xFAFBFDFE; -static int walHandleExistingFiles(const char *path); -static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp); -static int walRemoveWalFiles(const char *path); +static int walHandleExistingFiles(const char *path); +static int walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp); +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) { SWal *pWal = calloc(sizeof(SWal), 1); @@ -64,20 +81,38 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { 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->max = pCfg->wals; pWal->id = 0; pWal->num = 0; pWal->level = pCfg->walLevel; pWal->keep = pCfg->keep; + pWal->fsyncPeriod = pCfg->fsyncPeriod; + pWal->signature = pWal; tstrncpy(pWal->path, path, sizeof(pWal->path)); 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) { terrno = TAOS_SYSTEM_ERROR(errno); wError("wal:%s, failed to create directory(%s)", path, strerror(errno)); - pthread_mutex_destroy(&pWal->mutex); - free(pWal); + walRelease(pWal); pWal = NULL; } @@ -89,12 +124,11 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { if (pWal && pWal->fd <0) { terrno = TAOS_SYSTEM_ERROR(errno); wError("wal:%s, failed to open(%s)", path, strerror(errno)); - pthread_mutex_destroy(&pWal->mutex); - free(pWal); + walRelease(pWal); 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; } @@ -102,7 +136,8 @@ void walClose(void *handle) { if (handle == NULL) return; SWal *pWal = handle; - close(pWal->fd); + tclose(pWal->fd); + if (pWal->timer) taosTmrStopA(&pWal->timer); if (pWal->keep == 0) { // remove all files in the directory @@ -118,9 +153,7 @@ void walClose(void *handle) { wDebug("wal:%s, it is closed and kept", pWal->name); } - pthread_mutex_destroy(&pWal->mutex); - - free(pWal); + walRelease(pWal); } int walRenew(void *handle) { @@ -194,9 +227,9 @@ int walWrite(void *handle, SWalHead *pHead) { void walFsync(void *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) { 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; } +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) { char *name = pWal->name; @@ -433,3 +480,15 @@ static int walRemoveWalFiles(const char *path) { 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); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a6070a2fc1..4e7e9a87ea 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,3 +12,4 @@ SET(CMAKE_VERBOSE_MAKEFILE ON) ADD_SUBDIRECTORY(examples/c) ADD_SUBDIRECTORY(tsim) ADD_SUBDIRECTORY(test/c) +ADD_SUBDIRECTORY(comparisonTest/tdengine) diff --git a/tests/comparisonTest/tdengine/CMakeLists.txt b/tests/comparisonTest/tdengine/CMakeLists.txt new file mode 100644 index 0000000000..ccdeefcdaf --- /dev/null +++ b/tests/comparisonTest/tdengine/CMakeLists.txt @@ -0,0 +1,12 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(TDengine) + +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) +INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) + +IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) + add_executable(tdengineTest tdengineTest.c) + target_link_libraries(tdengineTest taos_static tutil common pthread) +ENDIF() diff --git a/tests/comparisonTest/tdengine/tdengineTest.c b/tests/comparisonTest/tdengine/tdengineTest.c index a2b048214f..de92526337 100644 --- a/tests/comparisonTest/tdengine/tdengineTest.c +++ b/tests/comparisonTest/tdengine/tdengineTest.c @@ -7,6 +7,7 @@ #include #include #include +#include typedef struct { char sql[256]; @@ -123,19 +124,21 @@ void writeDataImp(void *param) { if (taos == NULL) taos_error(taos); - int code = taos_query(taos, "use db"); + TAOS_RES* result = taos_query(taos, "use db"); + int32_t code = taos_errno(result); if (code != 0) { taos_error(taos); } + taos_free_result(result); - char sql[65000]; + char *sql = calloc(1, 8*1024*1024); int sqlLen = 0; int lastMachineid = 0; int counter = 0; int totalRecords = 0; for (int j = pThread->sID; j <= pThread->eID; j++) { - char fileName[256]; + char fileName[300]; sprintf(fileName, "%s/testdata%d.csv", arguments.dataDir, j); FILE *fp = fopen(fileName, "r"); @@ -162,7 +165,7 @@ void writeDataImp(void *param) { int64_t timestamp; int temperature; float humidity; - sscanf(line, "%d%s%d%lld%d%f", &machineid, machinename, &machinegroup, ×tamp, &temperature, &humidity); + sscanf(line, "%d%s%d%" PRId64 "%d%f", &machineid, machinename, &machinegroup, ×tamp, &temperature, &humidity); if (counter == 0) { sqlLen = sprintf(sql, "insert into"); @@ -174,14 +177,16 @@ void writeDataImp(void *param) { machineid, machineid, machinename, machinegroup); } - sqlLen += sprintf(sql + sqlLen, "(%lld,%d,%f)", timestamp, temperature, humidity); + sqlLen += sprintf(sql + sqlLen, "(%" PRId64 ",%d,%f)", timestamp, temperature, humidity); counter++; if (counter >= arguments.rowsPerRequest) { - int code = taos_query(taos, sql); + TAOS_RES *result = taos_query(taos, sql); + int32_t code = taos_errno(result); if (code != 0) { - printf("thread:%d error:%d reason:%s\n", pThread->pid, code, taos_errstr(taos)); + printf("thread:%d error:%d reason:%s\n", pThread->threadId, code, taos_errstr(taos)); } + taos_free_result(result); totalRecords += counter; counter = 0; @@ -194,15 +199,18 @@ void writeDataImp(void *param) { } if (counter > 0) { - int code = taos_query(taos, sql); + TAOS_RES *result = taos_query(taos, sql); + int32_t code = taos_errno(result); if (code != 0) { - printf("thread:%d error:%d reason:%s\n", pThread->pid, code, taos_errstr(taos)); + printf("thread:%d error:%d reason:%s\n", pThread->threadId, code, taos_errstr(taos)); } + taos_free_result(result); totalRecords += counter; } __sync_fetch_and_add(&statis.totalRows, totalRecords); + free(sql); } void writeData() { @@ -215,19 +223,23 @@ void writeData() { taos_init(); void *taos = taos_connect("127.0.0.1", "root", "taosdata", NULL, 0); - if (taos == NULL) - taos_error(taos); + if (taos == NULL) taos_error(taos); - int code = taos_query(taos, "create database if not exists db"); + TAOS_RES *result = taos_query(taos, "create database if not exists db"); + int32_t code = taos_errno(result); if (code != 0) { taos_error(taos); } + taos_free_result(result); - code = taos_query(taos, "create table if not exists db.devices(ts timestamp, temperature int, humidity float) " - "tags(devid int, devname binary(16), devgroup int)"); + result = taos_query(taos, + "create table if not exists db.devices(ts timestamp, temperature int, humidity float) " + "tags(devid int, devname binary(16), devgroup int)"); + code = taos_errno(result); if (code != 0) { taos_error(taos); } + taos_free_result(result); int64_t st = getTimeStampMs(); @@ -292,17 +304,12 @@ void readData() { int64_t st = getTimeStampMs(); - int code = taos_query(taos, line); + TAOS_RES *result = taos_query(taos, line); + int32_t code = taos_errno(result); if (code != 0) { taos_error(taos); } - void *result = taos_use_result(taos); - if (result == NULL) { - printf("failed to get result, reason:%s\n", taos_errstr(taos)); - exit(1); - } - TAOS_ROW row; int rows = 0; //int num_fields = taos_field_count(taos); diff --git a/tests/pytest/crash_gen.py b/tests/pytest/crash_gen.py index 9af72af471..9e38e04b63 100755 --- a/tests/pytest/crash_gen.py +++ b/tests/pytest/crash_gen.py @@ -84,8 +84,17 @@ class WorkerThread: # Let us have a DB connection of our own if (gConfig.per_thread_db_connection): # type: ignore # print("connector_type = {}".format(gConfig.connector_type)) - self._dbConn = DbConn.createNative() if ( - gConfig.connector_type == 'native') else DbConn.createRest() + if gConfig.connector_type == 'native': + 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 @@ -130,22 +139,15 @@ class WorkerThread: while True: tc = self._tc # Thread Coordinator, the overall master tc.crossStepBarrier() # shared barrier first, INCLUDING the last one - logger.debug( - "[TRD] Worker thread [{}] exited barrier...".format( - self._tid)) + logger.debug("[TRD] Worker thread [{}] exited barrier...".format(self._tid)) self.crossStepGate() # then per-thread gate, after being tapped - logger.debug( - "[TRD] Worker thread [{}] exited step gate...".format( - self._tid)) + logger.debug("[TRD] Worker thread [{}] exited step gate...".format(self._tid)) if not self._tc.isRunning(): - logger.debug( - "[TRD] Thread Coordinator not running any more, worker thread now stopping...") + logger.debug("[TRD] Thread Coordinator not running any more, worker thread now stopping...") break # Fetch a task from the Thread Coordinator - logger.debug( - "[TRD] Worker thread [{}] about to fetch task".format( - self._tid)) + logger.debug( "[TRD] Worker thread [{}] about to fetch task".format(self._tid)) task = tc.fetchTask() # Execute such a task @@ -154,9 +156,7 @@ class WorkerThread: self._tid, task.__class__.__name__)) task.execute(self) tc.saveExecutedTask(task) - logger.debug( - "[TRD] Worker thread [{}] finished executing task".format( - self._tid)) + logger.debug("[TRD] Worker thread [{}] finished executing task".format(self._tid)) self._dbInUse = False # there may be changes between steps @@ -255,101 +255,124 @@ class ThreadCoordinator: self._runStatus = MainExec.STATUS_STOPPING self._execStats.registerFailure("User Interruption") + def _runShouldEnd(self, transitionFailed, hasAbortedTask): + maxSteps = gConfig.max_steps # type: ignore + if self._curStep >= (maxSteps - 1): # maxStep==10, last curStep should be 9 + return True + if self._runStatus != MainExec.STATUS_RUNNING: + return True + if transitionFailed: + return True + if hasAbortedTask: + return True + return False + + def _hasAbortedTask(self): # from execution of previous step + for task in self._executedTasks: + if task.isAborted(): + # 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 + # let other threads go past the pool barrier, but wait at the + # thread gate + logger.debug("[TRD] Main thread about to cross the barrier") + self.crossStepBarrier() + self._stepBarrier.reset() # Other worker threads should now be at the "gate" + logger.debug("[TRD] Main thread finished crossing the barrier") + + def _doTransition(self): + transitionFailed = False + try: + sm = self._dbManager.getStateMachine() + logger.debug("[STT] starting transitions") + # at end of step, transiton the DB state + sm.transition(self._executedTasks) + logger.debug("[STT] transition ended") + # Due to limitation (or maybe not) of the Python library, + # we cannot share connections across threads + if sm.hasDatabase(): + for t in self._pool.threadList: + logger.debug("[DB] use db for all worker threads") + t.useDb() + # t.execSql("use db") # main thread executing "use + # db" on behalf of every worker thread + except taos.error.ProgrammingError as err: + if (err.msg == 'network unavailable'): # broken DB connection + logger.info("DB connection broken, execution failed") + traceback.print_stack() + transitionFailed = True + self._te = None # Not running any more + self._execStats.registerFailure("Broken DB Connection") + # continue # don't do that, need to tap all threads at + # end, and maybe signal them to stop + else: + raise + + self.resetExecutedTasks() # clear the tasks after we are done + # Get ready for next step + logger.debug("<-- Step {} finished, trasition failed = {}".format(self._curStep, transitionFailed)) + return transitionFailed + def run(self): self._pool.createAndStartThreads(self) # Coordinate all threads step by step self._curStep = -1 # not started yet - maxSteps = gConfig.max_steps # type: ignore + self._execStats.startExec() # start the stop watch transitionFailed = False hasAbortedTask = False - while(self._curStep < maxSteps - 1 and - (not transitionFailed) and - (self._runStatus == MainExec.STATUS_RUNNING) and - (not hasAbortedTask)): # maxStep==10, last curStep should be 9 - - if not gConfig.debug: - # print this only if we are not in debug mode + while not self._runShouldEnd(transitionFailed, hasAbortedTask): + if not gConfig.debug: # print this only if we are not in debug mode print(".", end="", flush=True) - logger.debug("[TRD] Main thread going to sleep") - - # Now main thread (that's us) is ready to enter a step - # let other threads go past the pool barrier, but wait at the - # thread gate - self.crossStepBarrier() - self._stepBarrier.reset() # Other worker threads should now be at the "gate" + + 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 = 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 + hasAbortedTask = self._hasAbortedTask() # from previous step + if hasAbortedTask: + logger.info("Aborted task encountered, exiting test program") self._execStats.registerFailure("Aborted Task Encountered") - else: - try: - sm = self._dbManager.getStateMachine() - logger.debug("[STT] starting transitions") - # at end of step, transiton the DB state - sm.transition(self._executedTasks) - logger.debug("[STT] transition ended") - # Due to limitation (or maybe not) of the Python library, - # we cannot share connections across threads - if sm.hasDatabase(): - for t in self._pool.threadList: - logger.debug("[DB] use db for all worker threads") - t.useDb() - # t.execSql("use db") # main thread executing "use - # db" on behalf of every worker thread - except taos.error.ProgrammingError as err: - if (err.msg == 'network unavailable'): # broken DB connection - logger.info("DB connection broken, execution failed") - traceback.print_stack() - transitionFailed = True - self._te = None # Not running any more - self._execStats.registerFailure("Broken DB Connection") - # continue # don't do that, need to tap all threads at - # end, and maybe signal them to stop - else: - raise - # finally: - # pass + break # do transition only if tasks are error free - self.resetExecutedTasks() # clear the tasks after we are done + # Ending previous step + transitionFailed = self._doTransition() # To start, we end step -1 first + # Then we move on to the next step + self._releaseAllWorkerThreads(transitionFailed) - # Get ready for next step - logger.debug("<-- Step {} finished".format(self._curStep)) - 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)) + 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() - # A new TE for the new step - 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() - - 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 - logger.debug("Main thread tapping all threads one last time...") - self.tapAllThreads() # Let the threads run one last time + self._te = None # No more executor, time to end + logger.debug("Main thread tapping all threads 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") self._pool.joinAll() # Get all threads to finish logger.info("\nAll worker threads finished") @@ -514,7 +537,7 @@ class LinearQueue(): class DbConn: TYPE_NATIVE = "native-c" - TYPE_REST = "rest-api" + TYPE_REST = "rest-api" TYPE_INVALID = "invalid" @classmethod @@ -620,9 +643,13 @@ class DbConnRest(DbConn): self.isOpen = False def _doSql(self, sql): - r = requests.post(self._url, - data=sql, - auth=HTTPBasicAuth('root', 'taosdata')) + try: + r = requests.post(self._url, + data = sql, + auth = HTTPBasicAuth('root', 'taosdata')) + except: + print("REST API Failure (TODO: more info here)") + raise rj = r.json() # Sanity check for the "Json Result" if ('status' not in rj): @@ -717,7 +744,7 @@ class MyTDSql: class DbConnNative(DbConn): def __init__(self): super().__init__() - self._type = self.TYPE_REST + self._type = self.TYPE_NATIVE self._conn = None self._cursor = None @@ -736,10 +763,16 @@ class DbConnNative(DbConn): break return buildPath + connInfoDisplayed = False def openByType(self): # Open connection 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( - host="127.0.0.1", + host=hostAddr, config=cfgPath) # TODO: make configurable self._cursor = self._conn.cursor() @@ -2254,8 +2287,9 @@ class ClientManager: def sigIntHandler(self, signalNumber, frame): if self._status != MainExec.STATUS_RUNNING: - print("Ignoring repeated SIGINT...") - return # do nothing if it's already not running + print("Repeated SIGINT received, forced exit...") + # return # do nothing if it's already not running + sys.exit(-1) self._status = MainExec.STATUS_STOPPING # immediately set our status 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( '-a', '--auto-start-service', diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 5ee33c421e..9d1aef0dc5 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -143,6 +143,7 @@ python3 ./test.py -f query/filterOtherTypes.py python3 ./test.py -f query/querySort.py python3 ./test.py -f query/queryJoin.py python3 ./test.py -f query/select_last_crash.py +python3 ./test.py -f query/queryNullValueTest.py #stream python3 ./test.py -f stream/metric_1.py diff --git a/tests/pytest/query/queryInsertValue.py b/tests/pytest/query/queryInsertValue.py new file mode 100644 index 0000000000..856801b4ee --- /dev/null +++ b/tests/pytest/query/queryInsertValue.py @@ -0,0 +1,65 @@ +################################################################### +# 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 taos +from util.log import * +from util.cases import * +from util.sql import * +import numpy as np +from util.dnodes import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.numOfRecords = 10 + self.ts = 1537146000000 + + def restartTaosd(self): + tdDnodes.stop(1) + tdDnodes.start(1) + tdSql.execute("use db") + + def run(self): + tdSql.prepare() + + print("==============step1") + + tdSql.execute( + "create table st (ts timestamp, speed int) tags(areaid int, loc nchar(20))") + tdSql.execute("create table t1 using st tags(1, 'beijing')") + tdSql.execute("insert into t1 values(now, 1)") + tdSql.query("select * from st") + tdSql.checkRows(1) + + tdSql.execute("alter table st add column length int") + tdSql.execute("insert into t1 values(now, 1, 2)") + tdSql.query("select last(*) from st") + tdSql.checkData(0, 2, 2); + + self.restartTaosd(); + + tdSql.query("select last(*) from st") + tdSql.checkData(0, 2, 2); + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/query/queryNullValueTest.py b/tests/pytest/query/queryNullValueTest.py new file mode 100644 index 0000000000..2ad1979e0b --- /dev/null +++ b/tests/pytest/query/queryNullValueTest.py @@ -0,0 +1,181 @@ +################################################################### +# 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 taos +from util.log import * +from util.cases import * +from util.sql import * +import numpy as np +from util.dnodes import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.numOfRecords = 10 + self.ts = 1537146000000 + + def checkNullValue(self, result): + mx = np.array(result) + [rows, cols] = mx.shape + for i in range(rows): + for j in range(cols): + if j + 1 < cols and mx[i, j + 1] is not None: + print(mx[i, j + 1]) + return False + return True + + def restartTaosd(self): + tdDnodes.stop(1) + tdDnodes.start(1) + tdSql.execute("use db") + + def run(self): + tdSql.prepare() + + print("==============step1") + + tdSql.execute( + "create table meters (ts timestamp, col1 int) tags(tgcol1 int)") + tdSql.execute("create table t0 using meters tags(NULL)") + + for i in range (self.numOfRecords): + tdSql.execute("insert into t0 values (%d, %d)" % (self.ts + i, i)); + + tdSql.query("select * from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add column col2 tinyint") + tdSql.execute("alter table meters drop column col1") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select col2 from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add column col1 int") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select col1 from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add column col3 smallint") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select col3 from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add column col4 bigint") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select col4 from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add column col5 float") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select col5 from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add column col6 double") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select col6 from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add column col7 bool") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select col7 from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add column col8 binary(20)") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select col8 from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add column col9 nchar(20)") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select col9 from meters") + tdSql.checkRows(10) + + tdSql.execute("alter table meters add tag tgcol2 tinyint") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select tgcol2 from meters") + tdSql.checkRows(1) + + + tdSql.execute("alter table meters add tag tgcol3 smallint") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select tgcol3 from meters") + tdSql.checkRows(1) + + + tdSql.execute("alter table meters add tag tgcol4 bigint") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select tgcol4 from meters") + tdSql.checkRows(1) + + tdSql.execute("alter table meters add tag tgcol5 float") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select tgcol5 from meters") + tdSql.checkRows(1) + + tdSql.execute("alter table meters add tag tgcol6 double") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select tgcol6 from meters") + tdSql.checkRows(1) + + tdSql.execute("alter table meters add tag tgcol7 bool") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select tgcol7 from meters") + tdSql.checkRows(1) + + tdSql.execute("alter table meters add tag tgcol8 binary(20)") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select tgcol8 from meters") + tdSql.checkRows(1) + + tdSql.execute("alter table meters add tag tgcol9 nchar(20)") + tdSql.query("select * from meters") + tdSql.checkRows(10) + tdSql.query("select tgcol9 from meters") + tdSql.checkRows(1) + + self.restartTaosd() + tdSql.query("select * from meters") + tdSql.checkRows(10) + if self.checkNullValue(tdSql.queryResult) is False: + tdLog.exit("non None value is detected") + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/regressiontest.sh b/tests/pytest/regressiontest.sh index ccc6635ced..24cd93f0fc 100755 --- a/tests/pytest/regressiontest.sh +++ b/tests/pytest/regressiontest.sh @@ -140,6 +140,7 @@ python3 ./test.py -f query/queryJoin.py python3 ./test.py -f query/filterCombo.py python3 ./test.py -f query/queryNormal.py python3 ./test.py -f query/select_last_crash.py +python3 ./test.py -f query/queryNullValueTest.py #stream python3 ./test.py -f stream/stream1.py diff --git a/tests/pytest/table/del_stable.py b/tests/pytest/table/del_stable.py index e458b6679f..1b078ac519 100644 --- a/tests/pytest/table/del_stable.py +++ b/tests/pytest/table/del_stable.py @@ -37,17 +37,8 @@ class TDTestCase: except Exception as e: tdLog.exit(e) - try: - tdSql.execute("select * from db.st") - except Exception as e: - if e.args[0] != 'mnode invalid table name': - tdLog.exit(e) - - try: - tdSql.execute("select * from db.tb") - except Exception as e: - if e.args[0] != 'mnode invalid table name': - tdLog.exit(e) + tdSql.error("select * from db.st") + tdSql.error("select * from db.tb") def stop(self): tdSql.close() diff --git a/tests/pytest/tag_lite/add.py b/tests/pytest/tag_lite/add.py index b23ff350c3..49e2f8ab69 100644 --- a/tests/pytest/tag_lite/add.py +++ b/tests/pytest/tag_lite/add.py @@ -100,6 +100,8 @@ class TDTestCase: # TSIM: sql alter table $mt add tag tgcol4 int tdLog.info('alter table %s add tag tgcol4 int' % (mt)) tdSql.execute('alter table %s add tag tgcol4 int' % (mt)) + tdLog.info('select * from %s where tgcol4=6' % (mt)) + tdSql.query('select * from %s where tgcol4=6' % (mt)) # TSIM: sql reset query cache tdLog.info('reset query cache') tdSql.execute('reset query cache') diff --git a/tests/pytest/util/dnodes-no-random-fail.py b/tests/pytest/util/dnodes-no-random-fail.py new file mode 100644 index 0000000000..88b2049464 --- /dev/null +++ b/tests/pytest/util/dnodes-no-random-fail.py @@ -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() diff --git a/tests/pytest/util/dnodes-random-fail.py b/tests/pytest/util/dnodes-random-fail.py index db3a5fea93..df4af0c58b 100644 --- a/tests/pytest/util/dnodes-random-fail.py +++ b/tests/pytest/util/dnodes-random-fail.py @@ -175,7 +175,8 @@ class TDDnode: self.cfg("logDir", self.logDir) self.cfg("numOfLogLines", "100000000") self.cfg("mnodeEqualVnodeNum", "0") - self.cfg("walLevel", "1") + self.cfg("walLevel", "2") + self.cfg("fsync", "1000") self.cfg("statusInterval", "1") self.cfg("numOfTotalVnodes", "64") self.cfg("numOfMnodes", "3") @@ -235,12 +236,12 @@ class TDDnode: tdLog.exit("dnode:%d is not deployed" % (self.index)) 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) 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 --random-file-fail-factor 5 2>&1 & " % ( + cmd = "nohup %s %s -c %s 2>&1 & " % ( valgrindCmdline, binPath, self.cfgDir) print(cmd) diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 226682ff92..56e63bae11 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -28,8 +28,11 @@ class TDSimClient: "locale": "en_US.UTF-8", "charset": "UTF-8", "asyncLog": "0", - "anyIp": "0", - "sdbDebugFlag": "135", + "minTablesPerVnode": "4", + "maxTablesPerVnode": "1000", + "tableIncStepPerVnode": "10000", + "maxVgroupsPerDb": "1000", + "sdbDebugFlag": "143", "rpcDebugFlag": "135", "tmrDebugFlag": "131", "cDebugFlag": "135", @@ -37,7 +40,6 @@ class TDSimClient: "jnidebugFlag": "135", "qdebugFlag": "135", } - def init(self, path): self.__init__() self.path = path @@ -175,7 +177,8 @@ class TDDnode: self.cfg("logDir", self.logDir) self.cfg("numOfLogLines", "100000000") self.cfg("mnodeEqualVnodeNum", "0") - self.cfg("walLevel", "1") + self.cfg("walLevel", "2") + self.cfg("fsync", "1000") self.cfg("statusInterval", "1") self.cfg("numOfTotalVnodes", "64") self.cfg("numOfMnodes", "3") diff --git a/tests/script/general/db/alter_option.sim b/tests/script/general/db/alter_option.sim index f871ead11d..076f7364ee 100644 --- a/tests/script/general/db/alter_option.sim +++ b/tests/script/general/db/alter_option.sim @@ -2,7 +2,7 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c wallevel -v 0 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 1000 system sh/exec.sh -n dnode1 -s start @@ -10,7 +10,7 @@ sleep 3000 sql connect print ============================ dnode1 start -sql create database db maxTables 500 cache 2 blocks 4 days 10 keep 20 minRows 300 maxRows 400 ctime 120 precision 'ms' comp 2 wal 1 replica 1 +sql create database db cache 2 blocks 4 days 10 keep 20 minRows 300 maxRows 400 ctime 120 precision 'ms' comp 2 wal 1 replica 1 sql show databases print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 if $data00 != db then @@ -31,13 +31,10 @@ endi if $data06 != 20,20,20 then return -1 endi -if $data07 != 500 then +if $data07 != 2 then return -1 endi -if $data08 != 2 then - return -1 -endi -if $data09 != 4 then +if $data08 != 4 then return -1 endi @@ -46,7 +43,6 @@ system sh/exec.sh -n dnode1 -s stop -x SIGINT return sql_error alter database db cache 256 sql_error alter database db blocks 1 -sql_error alter database db maxTables 10 sql_error alter database db days 10 sql_error alter database db keep 10 sql_error alter database db minRows 350 @@ -59,7 +55,6 @@ sql_error alter database db replica 2 print ============== step3 -sql alter database db maxTables 1000 sql alter database db comp 1 sql alter database db blocks 40 sql alter database db keep 30 diff --git a/tests/script/general/db/alter_tables_d2.sim b/tests/script/general/db/alter_tables_d2.sim index bf950a5e49..9ef39fb556 100644 --- a/tests/script/general/db/alter_tables_d2.sim +++ b/tests/script/general/db/alter_tables_d2.sim @@ -1,11 +1,13 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c wallevel -v 2 -system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 2 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 5 system sh/deploy.sh -n dnode2 -i 2 system sh/cfg.sh -n dnode2 -c wallevel -v 2 -system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 2 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 5 system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode2 -s start @@ -17,7 +19,7 @@ sleep 1000 print ============================ step1 -sql create database db maxTables 5 +sql create database db sql create table db.st (ts timestamp, i int) tags(t int) sql create table db.t000 using db.st tags(0) sql create table db.t001 using db.st tags(1) @@ -74,9 +76,14 @@ if $rows != 20 then endi print ============================ step3 - -sql alter database db maxTables 10 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 10 +system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 10 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sleep 5000 sql create table db.t100 using db.st tags(0) sql create table db.t101 using db.st tags(1) @@ -133,9 +140,14 @@ if $rows != 40 then endi print ============================ step5 - -sql alter database db maxTables 15 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 15 +system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 15 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sleep 5000 sql create table db.t200 using db.st tags(0) sql create table db.t201 using db.st tags(1) @@ -252,9 +264,14 @@ if $rows != 60 then endi print ============================ step9 - -sql alter database db maxTables 20 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 20 +system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 20 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sleep 5000 sql create table db.t300 using db.st tags(0) sql create table db.t301 using db.st tags(1) @@ -380,9 +397,14 @@ if $rows != 80 then endi print ============================ step9 - -sql alter database db maxTables 25 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 25 +system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 25 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sleep 5000 sql create table db.t400 using db.st tags(0) sql create table db.t401 using db.st tags(1) diff --git a/tests/script/general/db/alter_tables_v1.sim b/tests/script/general/db/alter_tables_v1.sim index ccddb8f959..dde5eb6d9e 100644 --- a/tests/script/general/db/alter_tables_v1.sim +++ b/tests/script/general/db/alter_tables_v1.sim @@ -1,8 +1,8 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c wallevel -v 0 -system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 1 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 10 system sh/exec.sh -n dnode1 -s start @@ -11,7 +11,7 @@ sql connect print ============================ step1 -sql create database db maxTables 10 +sql create database db sql create table db.st (ts timestamp, i int) tags(t int) sql create table db.t0 using db.st tags(0) sql create table db.t1 using db.st tags(1) @@ -49,8 +49,11 @@ endi print ============================ step3 -sql alter database db maxTables 20 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 20 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +sleep 5000 sql create table db.t10 using db.st tags(0) sql create table db.t11 using db.st tags(1) @@ -86,9 +89,11 @@ if $rows != 20 then endi print ============================ step5 - -sql alter database db maxTables 30 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 30 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +sleep 5000 sql create table db.t20 using db.st tags(0) sql create table db.t21 using db.st tags(1) @@ -183,9 +188,11 @@ if $rows != 30 then endi print ============================ step9 - -sql alter database db maxTables 40 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 40 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +sleep 5000 sql create table db.t30 using db.st tags(0) sql create table db.t31 using db.st tags(1) @@ -285,9 +292,11 @@ if $rows != 40 then endi print ============================ step12 - -sql alter database db maxTables 50 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 50 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +sleep 5000 sql create table db.t40 using db.st tags(0) sql create table db.t41 using db.st tags(1) diff --git a/tests/script/general/db/alter_tables_v4.sim b/tests/script/general/db/alter_tables_v4.sim index 75687b417e..7c9262874d 100644 --- a/tests/script/general/db/alter_tables_v4.sim +++ b/tests/script/general/db/alter_tables_v4.sim @@ -1,8 +1,8 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c wallevel -v 0 -system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 5 system sh/exec.sh -n dnode1 -s start @@ -11,7 +11,7 @@ sql connect print ============================ step1 -sql create database db maxTables 5 +sql create database db sql create table db.st (ts timestamp, i int) tags(t int) sql create table db.t000 using db.st tags(0) sql create table db.t001 using db.st tags(1) @@ -68,9 +68,11 @@ if $rows != 20 then endi print ============================ step3 - -sql alter database db maxTables 10 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 10 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +sleep 5000 sql create table db.t100 using db.st tags(0) sql create table db.t101 using db.st tags(1) @@ -127,9 +129,11 @@ if $rows != 40 then endi print ============================ step5 - -sql alter database db maxTables 15 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 15 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +sleep 5000 sql create table db.t200 using db.st tags(0) sql create table db.t201 using db.st tags(1) @@ -244,9 +248,11 @@ if $rows != 60 then endi print ============================ step9 - -sql alter database db maxTables 20 -sleep 1000 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 20 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +sleep 5000 sql create table db.t300 using db.st tags(0) sql create table db.t301 using db.st tags(1) @@ -370,10 +376,11 @@ if $rows != 80 then endi print ============================ step12 - -sql alter database db maxTables 25 -sleep 1000 - +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 25 +sleep 5000 +system sh/exec.sh -n dnode1 -s start +sleep 5000 sql create table db.t400 using db.st tags(0) sql create table db.t401 using db.st tags(1) sql create table db.t402 using db.st tags(2) diff --git a/tests/script/general/db/alter_vgroups.sim b/tests/script/general/db/alter_vgroups.sim index 93f3b1c0e5..13928cf033 100644 --- a/tests/script/general/db/alter_vgroups.sim +++ b/tests/script/general/db/alter_vgroups.sim @@ -1,8 +1,8 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c wallevel -v 0 -system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 1 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 20 system sh/exec.sh -n dnode1 -s start @@ -11,7 +11,7 @@ sql connect print ============================ step1 -sql create database db maxTables 20 +sql create database db sql create table db.st (ts timestamp, i int) tags(t int) sql create table db.t000 using db.st tags(0) sql create table db.t001 using db.st tags(1) @@ -69,7 +69,7 @@ endi print ============================ step3 system sh/exec.sh -n dnode1 -s stop -x SIGINT -system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 2 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 2 sleep 5000 system sh/exec.sh -n dnode1 -s start sleep 5000 @@ -131,7 +131,7 @@ endi print ============================ step5 system sh/exec.sh -n dnode1 -s stop -x SIGINT -system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 3 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 3 sleep 5000 system sh/exec.sh -n dnode1 -s start sleep 5000 diff --git a/tests/script/general/db/basic.sim b/tests/script/general/db/basic.sim index 43b18abd32..9983df378e 100644 --- a/tests/script/general/db/basic.sim +++ b/tests/script/general/db/basic.sim @@ -1,8 +1,8 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c wallevel -v 0 -system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 1000 system sh/exec.sh -n dnode1 -s start @@ -17,7 +17,7 @@ $db = $dbPrefix . $i $tb = $tbPrefix . $i print =============== step1 -sql create database $db replica 1 days 20 keep 2000 +sql create database $db replica 1 days 20 keep 2000 cache 16 sql show databases print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 if $data00 != $db then @@ -35,7 +35,7 @@ endi if $data05 != 20 then return -1 endi -if $data07 != 1000 then +if $data07 != 16 then return -1 endi @@ -76,13 +76,6 @@ if $data05 != 15 then return -1 endi -#if $data06 != 1500,15000,1500 then -# return -1 -#endi -if $data07 != 1000 then - return -1 -endi - print =============== step6 sql use $db sql create table $tb (ts timestamp, speed int) diff --git a/tests/script/general/db/delete.sim b/tests/script/general/db/delete.sim index 6d0090a78d..477962a32d 100644 --- a/tests/script/general/db/delete.sim +++ b/tests/script/general/db/delete.sim @@ -2,6 +2,8 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c wallevel -v 2 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 10 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 10 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 1000 print ========= start dnodes system sh/exec.sh -n dnode1 -s start @@ -9,7 +11,7 @@ sleep 3000 sql connect print ======== step1 -sql create database db blocks 2 maxtables 1000 +sql create database db blocks 2 sql create table db.mt (ts timestamp, tbcol int) TAGS(tgcol int) $tbPrefix = db.t @@ -21,7 +23,7 @@ while $i < 2000 endw sql show db.vgroups -if $rows != 2 then +if $rows != 10 then return -1 endi diff --git a/tests/script/general/db/tables.sim b/tests/script/general/db/tables.sim index bf714dbf56..d700bf8068 100644 --- a/tests/script/general/db/tables.sim +++ b/tests/script/general/db/tables.sim @@ -2,15 +2,15 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 0 -system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 2000 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4 system sh/exec.sh -n dnode1 -s start sleep 3000 sql connect print =============== step2 -sql create database db maxtables 4 +sql create database db sql show databases print $rows $data07 @@ -18,10 +18,6 @@ if $rows != 1 then return -1 endi -if $data07 != 4 then - return -1 -endi - print =============== step3 sql use db sql create table t1 (ts timestamp, i int) @@ -78,7 +74,7 @@ sql reset query cache sleep 4000 print =============== step7 -sql create database db maxtables 4 +sql create database db sql show databases print $rows $data07 @@ -86,10 +82,6 @@ if $rows != 1 then return -1 endi -if $data07 != 4 then - return -1 -endi - print =============== step8 sql use db sql create table t1 (ts timestamp, i int) diff --git a/tests/script/general/db/vnodes.sim b/tests/script/general/db/vnodes.sim index 54d8aa77c3..769eec3241 100644 --- a/tests/script/general/db/vnodes.sim +++ b/tests/script/general/db/vnodes.sim @@ -6,7 +6,8 @@ $totalRows = $totalVnodes * $maxTables system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 0 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $maxTables +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v $maxTables +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v $totalVnodes system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v $totalVnodes system sh/cfg.sh -n dnode1 -c maxVnodeConnections -v 100000 system sh/cfg.sh -n dnode1 -c maxMeterConnections -v 100000 @@ -17,7 +18,7 @@ print ========== prepare data system sh/exec.sh -n dnode1 -s start sleep 3000 sql connect -sql create database db blocks 2 cache 1 maxTables $maxTables +sql create database db blocks 2 cache 1 sql use db print ========== step1 diff --git a/tests/script/general/http/restful_full.sim b/tests/script/general/http/restful_full.sim index 60ffa4cb28..8545b8d2cd 100644 --- a/tests/script/general/http/restful_full.sim +++ b/tests/script/general/http/restful_full.sim @@ -81,7 +81,7 @@ print =============== step2 - no db #11 system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'show databases' 127.0.0.1:6020/rest/sql print 11-> $system_content -if $system_content != @{"status":"succ","head":["name","created_time","ntables","vgroups","replica","days","keep1,keep2,keep(D)","maxtables","cache(MB)","blocks","minrows","maxrows","ctime(Sec.)","wallevel","comp","precision","status"],"data":[],"rows":0}@ then +if $system_content != @{"status":"succ","head":["name","created_time","ntables","vgroups","replica","days","keep1,keep2,keep(D)","cache(MB)","blocks","minrows","maxrows","wallevel","fsync","comp","precision","status"],"data":[],"rows":0}@ then return -1 endi diff --git a/tests/script/general/parser/create_db.sim b/tests/script/general/parser/create_db.sim index 2fbe03c093..be8587f2ae 100644 --- a/tests/script/general/parser/create_db.sim +++ b/tests/script/general/parser/create_db.sim @@ -128,12 +128,12 @@ endi if $data06 != 365,365,365 then return -1 endi -print data08 = $data08 -if $data08 != $cache then - print expect $cache, actual:$data08 +print data07 = $data07 +if $data07 != $cache then + print expect $cache, actual:$data07 return -1 endi -if $data09 != 4 then +if $data08 != 4 then return -1 endi diff --git a/tests/script/general/parser/fill_us.sim b/tests/script/general/parser/fill_us.sim index a66629c90b..b597d378a2 100644 --- a/tests/script/general/parser/fill_us.sim +++ b/tests/script/general/parser/fill_us.sim @@ -652,25 +652,25 @@ endi if $data01 != 1 then return -1 endi -if $data11 != null then +if $data11 != NULL then return -1 endi if $data21 != 1 then return -1 endi -if $data31 != null then +if $data31 != NULL then return -1 endi if $data41 != 1 then return -1 endi -if $data51 != null then +if $data51 != NULL then return -1 endi if $data61 != 1 then return -1 endi -if $data71 != null then +if $data71 != NULL then return -1 endi if $data81 != 1 then @@ -689,25 +689,25 @@ endi if $data01 != 0.000000000 then return -1 endi -if $data11 != null then +if $data11 != NULL then return -1 endi if $data21 != 1.000000000 then return -1 endi -if $data31 != null then +if $data31 != NULL then return -1 endi if $data41 != 2.000000000 then return -1 endi -if $data51 != null then +if $data51 != NULL then return -1 endi if $data61 != 3.000000000 then return -1 endi -if $data71 != null then +if $data71 != NULL then return -1 endi if $data81 != 4.000000000 then @@ -722,25 +722,25 @@ endi if $data01 != 0 then return -1 endi -if $data11 != null then +if $data11 != NULL then return -1 endi if $data21 != 1 then return -1 endi -if $data31 != null then +if $data31 != NULL then return -1 endi if $data41 != 2 then return -1 endi -if $data51 != null then +if $data51 != NULL then return -1 endi if $data61 != 3 then return -1 endi -if $data71 != null then +if $data71 != NULL then return -1 endi if $data81 != 4 then @@ -755,25 +755,25 @@ endi if $data01 != 0 then return -1 endi -if $data11 != null then +if $data11 != NULL then return -1 endi if $data21 != 1 then return -1 endi -if $data31 != null then +if $data31 != NULL then return -1 endi if $data41 != 2 then return -1 endi -if $data51 != null then +if $data51 != NULL then return -1 endi if $data61 != 3 then return -1 endi -if $data71 != null then +if $data71 != NULL then return -1 endi if $data81 != 4 then @@ -788,25 +788,25 @@ endi if $data01 != 0 then return -1 endi -if $data11 != null then +if $data11 != NULL then return -1 endi if $data21 != 1 then return -1 endi -if $data31 != null then +if $data31 != NULL then return -1 endi if $data41 != 2 then return -1 endi -if $data51 != null then +if $data51 != NULL then return -1 endi if $data61 != 3 then return -1 endi -if $data71 != null then +if $data71 != NULL then return -1 endi if $data81 != 4 then @@ -821,25 +821,25 @@ endi if $data01 != 0 then return -1 endi -if $data11 != null then +if $data11 != NULL then return -1 endi if $data21 != 1 then return -1 endi -if $data31 != null then +if $data31 != NULL then return -1 endi if $data41 != 2 then return -1 endi -if $data51 != null then +if $data51 != NULL then return -1 endi if $data61 != 3 then return -1 endi -if $data71 != null then +if $data71 != NULL then return -1 endi if $data81 != 4 then diff --git a/tests/script/general/parser/limit.sim b/tests/script/general/parser/limit.sim index 2129c6b82a..d8c72349db 100644 --- a/tests/script/general/parser/limit.sim +++ b/tests/script/general/parser/limit.sim @@ -2,6 +2,7 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 0 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 system sh/exec.sh -n dnode1 -s start sleep 3000 sql connect diff --git a/tests/script/general/parser/limit1.sim b/tests/script/general/parser/limit1.sim index 84b760ced9..8b927b2a7f 100644 --- a/tests/script/general/parser/limit1.sim +++ b/tests/script/general/parser/limit1.sim @@ -2,6 +2,7 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 0 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 system sh/exec.sh -n dnode1 -s start sleep 3000 sql connect diff --git a/tests/script/general/parser/limit1_tblocks100.sim b/tests/script/general/parser/limit1_tblocks100.sim index 29b48bdd43..f1702924aa 100644 --- a/tests/script/general/parser/limit1_tblocks100.sim +++ b/tests/script/general/parser/limit1_tblocks100.sim @@ -2,6 +2,7 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 0 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 system sh/exec.sh -n dnode1 -s start sleep 3000 sql connect diff --git a/tests/script/general/parser/limit_stb.sim b/tests/script/general/parser/limit_stb.sim index 9983424dbf..c9df03ab2e 100644 --- a/tests/script/general/parser/limit_stb.sim +++ b/tests/script/general/parser/limit_stb.sim @@ -63,6 +63,11 @@ if $data41 != 9 then endi sql select * from $stb order by ts asc limit 5 +print select * from $stb order by ts asc limit 5 +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 + if $rows != 5 then return -1 endi diff --git a/tests/script/general/parser/limit_tb.sim b/tests/script/general/parser/limit_tb.sim index 9e62d652e2..970c7b75c5 100644 --- a/tests/script/general/parser/limit_tb.sim +++ b/tests/script/general/parser/limit_tb.sim @@ -356,6 +356,11 @@ if $rows != 0 then return -1 endi sql select top(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1 +print select top(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1 +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 + if $rows != 3 then return -1 endi diff --git a/tests/script/general/parser/set_tag_vals.sim b/tests/script/general/parser/set_tag_vals.sim index 9d7ac9678d..38af57c73d 100644 --- a/tests/script/general/parser/set_tag_vals.sim +++ b/tests/script/general/parser/set_tag_vals.sim @@ -2,6 +2,7 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 0 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 system sh/exec.sh -n dnode1 -s start sleep 3000 sql connect diff --git a/tests/script/general/stream/metrics_replica1_vnoden.sim b/tests/script/general/stream/metrics_replica1_vnoden.sim index ee071fd681..abe3e2ffdf 100644 --- a/tests/script/general/stream/metrics_replica1_vnoden.sim +++ b/tests/script/general/stream/metrics_replica1_vnoden.sim @@ -4,7 +4,8 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 0 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 8 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 3 system sh/exec.sh -n dnode1 -s start sleep 3000 diff --git a/tests/script/general/stream/table_replica1_vnoden.sim b/tests/script/general/stream/table_replica1_vnoden.sim index e1d5a9babf..ee0c871d98 100644 --- a/tests/script/general/stream/table_replica1_vnoden.sim +++ b/tests/script/general/stream/table_replica1_vnoden.sim @@ -4,7 +4,8 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 0 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 8 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 3 system sh/exec.sh -n dnode1 -s start sleep 3000 diff --git a/tests/script/general/table/limit.sim b/tests/script/general/table/limit.sim index 46fc5103c1..067182e1c8 100644 --- a/tests/script/general/table/limit.sim +++ b/tests/script/general/table/limit.sim @@ -3,6 +3,7 @@ system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 0 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 8 system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 129 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 8 system sh/exec.sh -n dnode1 -s start sleep 3000 @@ -36,7 +37,7 @@ while $x > $y endw sql show vgroups -if $rows != 2 then +if $rows != 8 then return -1 endi @@ -51,7 +52,7 @@ while $x > $y endw sql show vgroups -if $rows != 4 then +if $rows != 8 then return -1 endi @@ -66,7 +67,7 @@ while $x > $y endw sql show vgroups -if $rows != 6 then +if $rows != 8 then return -1 endi diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index bead4bd095..3b9806558e 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -312,9 +312,9 @@ cd ../../../debug; make #./test.sh -f general/parser/stream_on_sys.sim #./test.sh -f general/parser/repeatStream.sim -./test.sh -f general/stream/metrics_del.sim +#./test.sh -f general/stream/metrics_del.sim ./test.sh -f general/stream/metrics_n.sim -./test.sh -f general/stream/metrics_replica1_vnoden.sim +#./test.sh -f general/stream/metrics_replica1_vnoden.sim ./test.sh -f general/stream/restart_stream.sim ./test.sh -f general/stream/stream_3.sim ./test.sh -f general/stream/stream_restart.sim @@ -324,7 +324,7 @@ cd ../../../debug; make ./test.sh -f general/stream/table_replica1_vnoden.sim ./test.sh -f unique/arbitrator/check_cluster_cfg_para.sim -./test.sh -f unique/arbitrator/dn2_mn1_cache_file_sync.sim +#./test.sh -f unique/arbitrator/dn2_mn1_cache_file_sync.sim ./test.sh -f unique/arbitrator/dn3_mn1_full_createTableFail.sim ./test.sh -f unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim ./test.sh -f unique/arbitrator/dn3_mn1_multiCreateDropTable.sim @@ -358,6 +358,7 @@ cd ../../../debug; make ./test.sh -f unique/arbitrator/replica_changeWithArbitrator.sim ./test.sh -f unique/arbitrator/sync_replica2_alterTable_add.sim ./test.sh -f unique/arbitrator/sync_replica2_alterTable_drop.sim + ./test.sh -f unique/arbitrator/sync_replica2_dropDb.sim ./test.sh -f unique/arbitrator/sync_replica2_dropTable.sim ./test.sh -f unique/arbitrator/sync_replica3_alterTable_add.sim diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 37be89f8d6..b9a9e4f024 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -110,7 +110,7 @@ echo "second ${HOSTNAME}:7200" >> $TAOS_CFG echo "serverPort ${NODE}" >> $TAOS_CFG echo "dataDir $DATA_DIR" >> $TAOS_CFG echo "logDir $LOG_DIR" >> $TAOS_CFG -echo "debugFlag 135" >> $TAOS_CFG +echo "debugFlag 0" >> $TAOS_CFG echo "mDebugFlag 135" >> $TAOS_CFG echo "sdbDebugFlag 135" >> $TAOS_CFG echo "dDebugFlag 135" >> $TAOS_CFG @@ -119,13 +119,13 @@ echo "tsdbDebugFlag 135" >> $TAOS_CFG echo "cDebugFlag 135" >> $TAOS_CFG echo "jnidebugFlag 135" >> $TAOS_CFG echo "odbcdebugFlag 135" >> $TAOS_CFG -echo "httpDebugFlag 135" >> $TAOS_CFG -echo "monitorDebugFlag 131" >> $TAOS_CFG -echo "mqttDebugFlag 131" >> $TAOS_CFG +echo "httpDebugFlag 143" >> $TAOS_CFG +echo "monitorDebugFlag 135" >> $TAOS_CFG +echo "mqttDebugFlag 135" >> $TAOS_CFG echo "qdebugFlag 135" >> $TAOS_CFG echo "rpcDebugFlag 135" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG -echo "udebugFlag 135" >> $TAOS_CFG +echo "udebugFlag 143" >> $TAOS_CFG echo "sdebugFlag 135" >> $TAOS_CFG echo "wdebugFlag 135" >> $TAOS_CFG echo "monitor 0" >> $TAOS_CFG @@ -133,14 +133,20 @@ echo "monitorInterval 1" >> $TAOS_CFG echo "http 0" >> $TAOS_CFG echo "numOfThreadsPerCore 2.0" >> $TAOS_CFG echo "defaultPass taosdata" >> $TAOS_CFG -echo "numOfLogLines 10000000" >> $TAOS_CFG -echo "mnodeEqualVnodeNum 0" >> $TAOS_CFG +echo "numOfLogLines 20000000" >> $TAOS_CFG +echo "mnodeEqualVnodeNum 0" >> $TAOS_CFG echo "clog 2" >> $TAOS_CFG +#echo "cache 1" >> $TAOS_CFG +#echo "block 2" >> $TAOS_CFG echo "statusInterval 1" >> $TAOS_CFG echo "numOfTotalVnodes 4" >> $TAOS_CFG +echo "maxVgroupsPerDb 4" >> $TAOS_CFG +echo "minTablesPerVnode 4" >> $TAOS_CFG +echo "maxTablesPerVnode 1000" >> $TAOS_CFG +echo "tableIncStepPerVnode 10000" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG echo "numOfMnodes 1" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG -echo "anyIp 0" >> $TAOS_CFG +echo "fsync 0" >> $TAOS_CFG diff --git a/tests/script/sh/exec-no-random-fail.sh b/tests/script/sh/exec-no-random-fail.sh new file mode 100755 index 0000000000..04a663bc5a --- /dev/null +++ b/tests/script/sh/exec-no-random-fail.sh @@ -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 + diff --git a/tests/script/sh/exec-random-fail.sh b/tests/script/sh/exec-random-fail.sh index 7ba301617c..a354021684 100755 --- a/tests/script/sh/exec-random-fail.sh +++ b/tests/script/sh/exec-random-fail.sh @@ -90,7 +90,7 @@ if [ "$EXEC_OPTON" = "start" ]; 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 & 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 else diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index 6928039be1..2f294075a1 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -88,7 +88,9 @@ 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 & + TT=`date +%s` + mkdir ${LOG_DIR}/${TT} + nohup valgrind --log-file=${LOG_DIR}/${TT}/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 > /dev/null 2>&1 & fi diff --git a/tests/script/tmp/mnodes.sim b/tests/script/tmp/mnodes.sim index afc068b3f1..b4e176f221 100644 --- a/tests/script/tmp/mnodes.sim +++ b/tests/script/tmp/mnodes.sim @@ -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 dnode3 -c qdebugFlag -v 131 -system sh/cfg.sh -n dnode1 -c cDebugFlag -v 131 -system sh/cfg.sh -n dnode2 -c cDebugFlag -v 131 -system sh/cfg.sh -n dnode3 -c cDebugFlag -v 131 +system sh/cfg.sh -n dnode1 -c cDebugFlag -v 135 +system sh/cfg.sh -n dnode2 -c cDebugFlag -v 135 +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 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 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 system sh/exec.sh -n dnode1 -s start diff --git a/tests/script/tmp/prepare.sim b/tests/script/tmp/prepare.sim index 2480c20709..0a0c512b26 100644 --- a/tests/script/tmp/prepare.sim +++ b/tests/script/tmp/prepare.sim @@ -15,16 +15,19 @@ 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 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 dnode2 -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 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 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 dnode4 -c maxTablesPerVnode -v 100000 system sh/cfg.sh -n dnode1 -c http -v 1 system sh/cfg.sh -n dnode2 -c http -v 1 -system sh/cfg.sh -n dnode3 -c http -v 1 \ No newline at end of file +system sh/cfg.sh -n dnode3 -c http -v 1 +system sh/cfg.sh -n dnode4 -c http -v 1 \ No newline at end of file diff --git a/tests/script/unique/arbitrator/check_cluster_cfg_para.sim b/tests/script/unique/arbitrator/check_cluster_cfg_para.sim index af2b47d1ea..1b22db9d82 100644 --- a/tests/script/unique/arbitrator/check_cluster_cfg_para.sim +++ b/tests/script/unique/arbitrator/check_cluster_cfg_para.sim @@ -161,7 +161,7 @@ sleep 10000 $loopCnt = 0 wait_dnode_offline_overtime_dropped: $loopCnt = $loopCnt + 1 -if $loopCnt == 10 then +if $loopCnt == 20 then return -1 endi sql show dnodes diff --git a/tests/script/unique/arbitrator/dn3_mn1_multiCreateDropTable.sim b/tests/script/unique/arbitrator/dn3_mn1_multiCreateDropTable.sim index c3bae9005a..5827b25ff4 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_multiCreateDropTable.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_multiCreateDropTable.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -56,11 +62,10 @@ sql create dnode $hostname3 sql create dnode $hostname4 sleep 3000 -$totalTableNum = 10 $sleepTimer = 3000 $db = db -sql create database $db replica 3 maxTables $totalTableNum +sql create database $db replica 3 sql use $db # create table , insert data diff --git a/tests/script/unique/arbitrator/dn3_mn1_r2_vnode_delDir.sim b/tests/script/unique/arbitrator/dn3_mn1_r2_vnode_delDir.sim index 807709b675..dd101bc97c 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_r2_vnode_delDir.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_r2_vnode_delDir.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -54,11 +60,10 @@ sql create dnode $hostname2 sql create dnode $hostname3 sleep 3000 -$totalTableNum = 10 $sleepTimer = 3000 $db = db -sql create database $db replica 2 maxTables $totalTableNum +sql create database $db replica 2 sql use $db # create table , insert data @@ -137,8 +142,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode3Vtatus = $data4_2 -$dnode2Vtatus = $data7_2 +$dnode3Vtatus = $data6_2 +$dnode2Vtatus = $data9_2 if $dnode3Vtatus != offline then sleep 2000 @@ -204,8 +209,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode3Vtatus = $data4_2 -$dnode2Vtatus = $data7_2 +$dnode3Vtatus = $data6_2 +$dnode2Vtatus = $data9_2 print dnode2Vtatus: $dnode3Vtatus print dnode3Vtatus: $dnode3Vtatus @@ -319,8 +324,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode3Vtatus = $data4_2 -$dnode2Vtatus = $data7_2 +$dnode3Vtatus = $data6_2 +$dnode2Vtatus = $data9_2 print dnode4Vtatus: $dnode4Vtatus print dnode3Vtatus: $dnode3Vtatus diff --git a/tests/script/unique/arbitrator/dn3_mn1_r3_vnode_delDir.sim b/tests/script/unique/arbitrator/dn3_mn1_r3_vnode_delDir.sim index a05681ece2..6cd2e0cca3 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_r3_vnode_delDir.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_r3_vnode_delDir.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -56,11 +62,10 @@ sql create dnode $hostname3 sql create dnode $hostname4 sleep 3000 -$totalTableNum = 10 $sleepTimer = 3000 $db = db -sql create database $db replica 3 maxTables $totalTableNum +sql create database $db replica 3 sql use $db # create table , insert data @@ -139,8 +144,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 @@ -206,8 +211,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 print dnode4Vtatus: $dnode4Vtatus print dnode3Vtatus: $dnode3Vtatus @@ -325,8 +330,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 print dnode4Vtatus: $dnode4Vtatus print dnode3Vtatus: $dnode3Vtatus @@ -386,8 +391,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 print dnode4Vtatus: $dnode4Vtatus print dnode3Vtatus: $dnode3Vtatus diff --git a/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim b/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim index cacbcbb132..26f45cf645 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_replica2_wal1_AddDelDnode.sim @@ -23,6 +23,12 @@ system sh/cfg.sh -n dnode3 -c balanceInterval -v 10 system sh/cfg.sh -n dnode4 -c balanceInterval -v 10 system sh/cfg.sh -n dnode5 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 16 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 16 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 16 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 16 +system sh/cfg.sh -n dnode5 -c maxVgroupsPerDb -v 16 + system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 @@ -215,6 +221,7 @@ system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c offlineThreshold -v 10 system sh/cfg.sh -n dnode3 -c enableCoreFile -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 16 system sh/exec.sh -n dnode3 -s start sql create dnode $hostname3 @@ -322,7 +329,7 @@ $totalRows = 0 $tsStart = 1420041600000 $db = db1 -sql create database $db replica 2 maxTables 4 +sql create database $db replica 2 sql use $db $stb = stb sql create table $stb (ts timestamp, c1 int) tags(t1 int) diff --git a/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim b/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim index 9b01b2fae3..8abd4460c5 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_replica_change.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -52,11 +58,10 @@ system sh/exec.sh -n dnode2 -s start sql create dnode $hostname2 sleep 3000 -$totalTableNum = 10 $sleepTimer = 10000 $db = db -sql create database $db replica 1 maxTables $totalTableNum +sql create database $db replica 1 sql use $db # create table , insert data @@ -352,16 +357,16 @@ if $loopCnt == 10 then endi sql show vgroups -print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 -print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 -print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 -print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 $data5_4 $data6_4 $data7_4 $data8_4 +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 $data10_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 $data10_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 $data10_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 $data5_4 $data6_4 $data7_4 $data8_4 $data9_4 $data10_4 #print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 #print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 -$thirdDnode_2 = $data8_1 -$thirdDnode_3 = $data8_2 -$thirdDnode_4 = $data8_3 -$thirdDnode_5 = $data8_4 +$thirdDnode_2 = $data10_1 +$thirdDnode_3 = $data10_2 +$thirdDnode_4 = $data10_3 +$thirdDnode_5 = $data10_4 if $thirdDnode_2 != null then sleep 2000 @@ -405,10 +410,10 @@ print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $dat print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 $data5_4 $data6_4 $data7_4 $data8_4 #print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 #print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 -$sencodDnode_2 = $data5_1 -$sencodDnode_3 = $data5_2 -$sencodDnode_4 = $data5_3 -$sencodDnode_5 = $data5_4 +$sencodDnode_2 = $data7_1 +$sencodDnode_3 = $data7_2 +$sencodDnode_4 = $data7_3 +$sencodDnode_5 = $data7_4 if $sencodDnode_2 != null then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim b/tests/script/unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim index 9b001820f6..654983bb0f 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_replica_change_dropDnod.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,7 +66,7 @@ $totalTableNum = 10 $sleepTimer = 10000 $db = db -sql create database $db replica 2 maxTables $totalTableNum +sql create database $db replica 2 sql use $db # create table , insert data diff --git a/tests/script/unique/arbitrator/dn3_mn1_stopDnode_timeout.sim b/tests/script/unique/arbitrator/dn3_mn1_stopDnode_timeout.sim index 152a65a75a..32674acade 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_stopDnode_timeout.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_stopDnode_timeout.sim @@ -39,10 +39,10 @@ system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator -system sh/cfg.sh -n dnode1 -c offlineThreshold -v 10 -system sh/cfg.sh -n dnode2 -c offlineThreshold -v 10 -system sh/cfg.sh -n dnode3 -c offlineThreshold -v 10 -system sh/cfg.sh -n dnode4 -c offlineThreshold -v 10 +system sh/cfg.sh -n dnode1 -c offlineThreshold -v 5 +system sh/cfg.sh -n dnode2 -c offlineThreshold -v 5 +system sh/cfg.sh -n dnode3 -c offlineThreshold -v 5 +system sh/cfg.sh -n dnode4 -c offlineThreshold -v 5 system sh/cfg.sh -n dnode1 -c enableCoreFile -v 1 system sh/cfg.sh -n dnode2 -c enableCoreFile -v 1 @@ -182,7 +182,7 @@ system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator -system sh/cfg.sh -n dnode4 -c offlineThreshold -v 10 +system sh/cfg.sh -n dnode4 -c offlineThreshold -v 5 system sh/cfg.sh -n dnode4 -c enableCoreFile -v 1 system sh/exec.sh -n dnode4 -s start diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim index 13c3517e24..3c47fdf93b 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_change.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -137,8 +143,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 @@ -212,8 +218,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 print dnode4Vtatus: $dnode4Vtatus print dnode3Vtatus: $dnode3Vtatus @@ -286,8 +292,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 print dnode4Vtatus: $dnode4Vtatus print dnode3Vtatus: $dnode3Vtatus diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim index 0b4e385785..6b107aed60 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,7 +66,7 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -sql create database $db replica 2 maxTables $totalTableNum +sql create database $db replica 2 sql use $db # create table , insert data @@ -143,8 +149,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode3Vtatus = $data4_2 -$dnode2Vtatus = $data7_2 +$dnode3Vtatus = $data6_2 +$dnode2Vtatus = $data9_2 if $dnode3Vtatus != offline then sleep 2000 @@ -233,8 +239,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != master then sleep 2000 @@ -312,8 +318,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != offline then sleep 2000 @@ -392,8 +398,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus == offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim index c464d4023f..7e71fe3a8d 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -195,8 +201,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != offline then sleep 2000 @@ -268,8 +274,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != offline then sleep 2000 @@ -324,8 +330,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != slave then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_createErrData_online.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_createErrData_online.sim index f2aa000170..8cd31e4de6 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_createErrData_online.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_createErrData_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,7 +66,7 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -sql create database $db replica 2 maxTables $totalTableNum +sql create database $db replica 2 sql use $db # create table , insert data @@ -157,8 +163,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != offline then sleep 2000 @@ -230,8 +236,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != offline then sleep 2000 @@ -286,8 +292,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != slave then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_delDir.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_delDir.sim index cf20122d4c..43538cf95a 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_delDir.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_delDir.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -56,11 +62,10 @@ sql create dnode $hostname3 sql create dnode $hostname4 sleep 3000 -$totalTableNum = 10 $sleepTimer = 3000 $db = db -sql create database $db replica 3 maxTables $totalTableNum +sql create database $db replica 3 sql use $db # create table , insert data @@ -141,8 +146,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 @@ -201,8 +206,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 print dnode4Vtatus: $dnode4Vtatus print dnode3Vtatus: $dnode3Vtatus @@ -301,8 +306,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 print dnode4Vtatus: $dnode4Vtatus print dnode3Vtatus: $dnode3Vtatus @@ -417,8 +422,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 print dnode4Vtatus: $dnode4Vtatus print dnode3Vtatus: $dnode3Vtatus diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_noCorruptFile_offline.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_noCorruptFile_offline.sim index ce05b0b5ff..5b5a9deffa 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_noCorruptFile_offline.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_noCorruptFile_offline.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,7 +66,7 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -sql create database $db replica 2 maxTables $totalTableNum +sql create database $db replica 2 sql use $db # create table , insert data @@ -143,8 +149,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode3Vtatus = $data4_2 -$dnode2Vtatus = $data7_2 +$dnode3Vtatus = $data6_2 +$dnode2Vtatus = $data9_2 if $dnode3Vtatus != offline then sleep 2000 @@ -233,8 +239,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != master then sleep 2000 @@ -312,8 +318,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus != offline then sleep 2000 @@ -391,8 +397,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode2Vtatus = $data7_2 -$dnode3Vtatus = $data4_2 +$dnode2Vtatus = $data9_2 +$dnode3Vtatus = $data6_2 if $dnode2Vtatus == offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim b/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim index f5bcd055a0..7696168bb9 100644 --- a/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim +++ b/tests/script/unique/arbitrator/dn3_mn1_vnode_nomaster.sim @@ -34,6 +34,17 @@ system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 20 + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 + system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator @@ -56,11 +67,10 @@ sql create dnode $hostname3 sql create dnode $hostname4 sleep 3000 -$totalTableNum = 10 $sleepTimer = 3000 $db = db -sql create database $db replica 3 maxTables $totalTableNum +sql create database $db replica 3 sql use $db # create table , insert data @@ -146,8 +156,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 @@ -169,7 +179,7 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db1 -sql create database $db replica 2 maxTables $totalTableNum +sql create database $db replica 2 sql use $db # create table , insert data @@ -254,8 +264,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode3Vtatus = $data4_3 -$dnode2Vtatus = $data7_3 +$dnode3Vtatus = $data6_3 +$dnode2Vtatus = $data9_3 if $dnode3Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_alterTable_online.sim b/tests/script/unique/arbitrator/offline_replica2_alterTable_online.sim index 18ffb32eed..ea5e7608ee 100644 --- a/tests/script/unique/arbitrator/offline_replica2_alterTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_alterTable_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 2 maxTables $totalTableNum -sql create database $db replica 2 maxTables $totalTableNum +print create database $db replica 2 +sql create database $db replica 2 sql use $db # create table , insert data @@ -138,8 +144,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_alterTag_online.sim b/tests/script/unique/arbitrator/offline_replica2_alterTag_online.sim index 6e85429b77..6fa1da4e1d 100644 --- a/tests/script/unique/arbitrator/offline_replica2_alterTag_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_alterTag_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 #system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 #system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -58,11 +64,10 @@ sleep 3000 $totalTableNum = 10 $sleepTimer = 3000 -$maxTables = $totalTableNum * 2 $db = db -print create database $db replica 2 maxTables $maxTables -sql create database $db replica 2 maxTables $maxTables +print create database $db replica 2 +sql create database $db replica 2 sql use $db # create table , insert data @@ -143,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_createTable_online.sim b/tests/script/unique/arbitrator/offline_replica2_createTable_online.sim index 0356f72a97..1d2a83c825 100644 --- a/tests/script/unique/arbitrator/offline_replica2_createTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_createTable_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 20 + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -59,11 +65,9 @@ sleep 3000 $totalTableNum = 10 $sleepTimer = 3000 -$maxTables = $totalTableNum * 2 - $db = db -print create database $db replica 2 maxTables $maxTables -sql create database $db replica 2 maxTables $maxTables +print create database $db replica 2 +sql create database $db replica 2 sql use $db # create table , insert data @@ -144,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_dropDb_online.sim b/tests/script/unique/arbitrator/offline_replica2_dropDb_online.sim index dc2586b43b..630b4eaab8 100644 --- a/tests/script/unique/arbitrator/offline_replica2_dropDb_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_dropDb_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 2 maxTables $totalTableNum -sql create database $db replica 2 maxTables $totalTableNum +print create database $db replica 2 +sql create database $db replica 2 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica2_dropTable_online.sim b/tests/script/unique/arbitrator/offline_replica2_dropTable_online.sim index 721c7d60ba..43dba536c7 100644 --- a/tests/script/unique/arbitrator/offline_replica2_dropTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica2_dropTable_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 2 maxTables $totalTableNum -sql create database $db replica 2 maxTables $totalTableNum +print create database $db replica 2 +sql create database $db replica 2 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_alterTable_online.sim b/tests/script/unique/arbitrator/offline_replica3_alterTable_online.sim index 897c662b51..09a2424c85 100644 --- a/tests/script/unique/arbitrator/offline_replica3_alterTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_alterTable_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 3 maxTables $totalTableNum -sql create database $db replica 3 maxTables $totalTableNum +print create database $db replica 3 +sql create database $db replica 3 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_alterTag_online.sim b/tests/script/unique/arbitrator/offline_replica3_alterTag_online.sim index 95ae8047fa..d94f341236 100644 --- a/tests/script/unique/arbitrator/offline_replica3_alterTag_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_alterTag_online.sim @@ -19,20 +19,21 @@ system sh/cfg.sh -n dnode2 -c balanceInterval -v 10 system sh/cfg.sh -n dnode3 -c balanceInterval -v 10 system sh/cfg.sh -n dnode4 -c balanceInterval -v 10 -system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 - #system sh/cfg.sh -n dnode1 -c alternativeRole -v 1 #system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 #system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 #system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 20 + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -58,11 +59,10 @@ sleep 3000 $totalTableNum = 10 $sleepTimer = 3000 -$maxTables = $totalTableNum * 2 $db = db -print create database $db replica 3 maxTables $maxTables -sql create database $db replica 3 maxTables $maxTables +print create database $db replica 3 +sql create database $db replica 3 sql use $db # create table , insert data @@ -143,8 +143,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_createTable_online.sim b/tests/script/unique/arbitrator/offline_replica3_createTable_online.sim index a60f810eea..fc1c69709a 100644 --- a/tests/script/unique/arbitrator/offline_replica3_createTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_createTable_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 20 +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 20 + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -61,8 +67,8 @@ $sleepTimer = 3000 $maxTables = $totalTableNum * 2 $db = db -print create database $db replica 3 maxTables $maxTables -sql create database $db replica 3 maxTables $maxTables +print create database $db replica 3 +sql create database $db replica 3 sql use $db # create table , insert data @@ -143,8 +149,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_dropDb_online.sim b/tests/script/unique/arbitrator/offline_replica3_dropDb_online.sim index a619cbe826..72727f3df0 100644 --- a/tests/script/unique/arbitrator/offline_replica3_dropDb_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_dropDb_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 3 maxTables $totalTableNum -sql create database $db replica 3 maxTables $totalTableNum +print create database $db replica 3 +sql create database $db replica 3 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/offline_replica3_dropTable_online.sim b/tests/script/unique/arbitrator/offline_replica3_dropTable_online.sim index 3b7ee869ed..7e57b0a971 100644 --- a/tests/script/unique/arbitrator/offline_replica3_dropTable_online.sim +++ b/tests/script/unique/arbitrator/offline_replica3_dropTable_online.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 3 maxTables $totalTableNum -sql create database $db replica 3 maxTables $totalTableNum +print create database $db replica 3 +sql create database $db replica 3 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim b/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim index 1b2c8d1db6..a16e765a30 100644 --- a/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim +++ b/tests/script/unique/arbitrator/replica_changeWithArbitrator.sim @@ -34,10 +34,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 0 system sh/cfg.sh -n dnode3 -c alternativeRole -v 0 system sh/cfg.sh -n dnode4 -c alternativeRole -v 0 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 12 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -65,7 +71,7 @@ sql connect $totalTableNum = 12 $db = db -sql create database $db replica 1 maxTables $totalTableNum +sql create database $db replica 1 sql use $db # create table , insert data diff --git a/tests/script/unique/arbitrator/sync_replica2_alterTable_add.sim b/tests/script/unique/arbitrator/sync_replica2_alterTable_add.sim index 4f66e5c135..8775da607c 100644 --- a/tests/script/unique/arbitrator/sync_replica2_alterTable_add.sim +++ b/tests/script/unique/arbitrator/sync_replica2_alterTable_add.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 2 maxTables $totalTableNum -sql create database $db replica 2 maxTables $totalTableNum +print create database $db replica 2 +sql create database $db replica 2 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica2_alterTable_drop.sim b/tests/script/unique/arbitrator/sync_replica2_alterTable_drop.sim index 7bcd148bc9..84ae9554f3 100644 --- a/tests/script/unique/arbitrator/sync_replica2_alterTable_drop.sim +++ b/tests/script/unique/arbitrator/sync_replica2_alterTable_drop.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 2 maxTables $totalTableNum -sql create database $db replica 2 maxTables $totalTableNum +print create database $db replica 2 +sql create database $db replica 2 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica2_dropDb.sim b/tests/script/unique/arbitrator/sync_replica2_dropDb.sim index f61b1e3cb9..c9dc302d3c 100644 --- a/tests/script/unique/arbitrator/sync_replica2_dropDb.sim +++ b/tests/script/unique/arbitrator/sync_replica2_dropDb.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 2 maxTables $totalTableNum -sql create database $db replica 2 maxTables $totalTableNum +print create database $db replica 2 +sql create database $db replica 2 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica2_dropTable.sim b/tests/script/unique/arbitrator/sync_replica2_dropTable.sim index b27558fdf0..b7392eb960 100644 --- a/tests/script/unique/arbitrator/sync_replica2_dropTable.sim +++ b/tests/script/unique/arbitrator/sync_replica2_dropTable.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 2 maxTables $totalTableNum -sql create database $db replica 2 maxTables $totalTableNum +print create database $db replica 2 +sql create database $db replica 2 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica3_alterTable_add.sim b/tests/script/unique/arbitrator/sync_replica3_alterTable_add.sim index 2a283a6a0c..2fde90f3db 100644 --- a/tests/script/unique/arbitrator/sync_replica3_alterTable_add.sim +++ b/tests/script/unique/arbitrator/sync_replica3_alterTable_add.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 3 maxTables $totalTableNum -sql create database $db replica 3 maxTables $totalTableNum +print create database $db replica 3 +sql create database $db replica 3 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica3_alterTable_drop.sim b/tests/script/unique/arbitrator/sync_replica3_alterTable_drop.sim index 7d321ed381..f31d01b327 100644 --- a/tests/script/unique/arbitrator/sync_replica3_alterTable_drop.sim +++ b/tests/script/unique/arbitrator/sync_replica3_alterTable_drop.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 3 maxTables $totalTableNum -sql create database $db replica 3 maxTables $totalTableNum +print create database $db replica 3 +sql create database $db replica 3 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica3_createTable.sim b/tests/script/unique/arbitrator/sync_replica3_createTable.sim index 1b93cc09f2..a07e6dc93d 100644 --- a/tests/script/unique/arbitrator/sync_replica3_createTable.sim +++ b/tests/script/unique/arbitrator/sync_replica3_createTable.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica3_dnodeChang_DropAddAlterTableDropDb.sim b/tests/script/unique/arbitrator/sync_replica3_dnodeChang_DropAddAlterTableDropDb.sim index f5ceced668..c8663b0009 100644 --- a/tests/script/unique/arbitrator/sync_replica3_dnodeChang_DropAddAlterTableDropDb.sim +++ b/tests/script/unique/arbitrator/sync_replica3_dnodeChang_DropAddAlterTableDropDb.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 40 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -59,9 +65,10 @@ sleep 3000 $totalTableNum = 20 $sleepTimer = 3000 +$maxTables = $totalTableNum * 2 $db = db -print create database $db replica 3 maxTables $totalTableNum -sql create database $db replica 3 maxTables $totalTableNum +print create database $db replica 3 maxTables $maxTables +sql create database $db replica 3 maxTables $maxTables sql use $db # create table , insert data @@ -137,8 +144,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 @@ -205,8 +212,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != slave then sleep 2000 @@ -238,8 +245,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != master then sleep 2000 @@ -312,8 +319,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != slave then sleep 2000 @@ -345,8 +352,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != master then sleep 2000 @@ -435,8 +442,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != slave then sleep 2000 @@ -468,8 +475,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != master then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica3_dropDb.sim b/tests/script/unique/arbitrator/sync_replica3_dropDb.sim index 0f7ee50c39..fd07fda2d4 100644 --- a/tests/script/unique/arbitrator/sync_replica3_dropDb.sim +++ b/tests/script/unique/arbitrator/sync_replica3_dropDb.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 3 maxTables $totalTableNum -sql create database $db replica 3 maxTables $totalTableNum +print create database $db replica 3 +sql create database $db replica 3 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/arbitrator/sync_replica3_dropTable.sim b/tests/script/unique/arbitrator/sync_replica3_dropTable.sim index 9c33dd8bb4..1749477d64 100644 --- a/tests/script/unique/arbitrator/sync_replica3_dropTable.sim +++ b/tests/script/unique/arbitrator/sync_replica3_dropTable.sim @@ -29,10 +29,16 @@ system sh/cfg.sh -n dnode2 -c alternativeRole -v 2 system sh/cfg.sh -n dnode3 -c alternativeRole -v 2 system sh/cfg.sh -n dnode4 -c alternativeRole -v 2 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +$totalTableNum = 10 +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v $totalTableNum +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v $totalTableNum + +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 1 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 1 system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator @@ -60,8 +66,8 @@ $totalTableNum = 10 $sleepTimer = 3000 $db = db -print create database $db replica 3 maxTables $totalTableNum -sql create database $db replica 3 maxTables $totalTableNum +print create database $db replica 3 +sql create database $db replica 3 sql use $db # create table , insert data @@ -142,8 +148,8 @@ print show vgroups: print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 -$dnode4Vtatus = $data4_2 -$dnode3Vtatus = $data7_2 +$dnode4Vtatus = $data6_2 +$dnode3Vtatus = $data9_2 if $dnode4Vtatus != offline then sleep 2000 diff --git a/tests/script/unique/big/balance.sim b/tests/script/unique/big/balance.sim index b2a15b0b96..259951581e 100644 --- a/tests/script/unique/big/balance.sim +++ b/tests/script/unique/big/balance.sim @@ -1,23 +1,28 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 1000 system sh/deploy.sh -n dnode2 -i 2 system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 1000 system sh/deploy.sh -n dnode3 -i 3 system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 1000 system sh/deploy.sh -n dnode4 -i 4 system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode4 -c maxTablesPerVnode -v 1000 system sh/deploy.sh -n dnode5 -i 5 system sh/cfg.sh -n dnode5 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 1000 +system sh/cfg.sh -n dnode5 -c maxVgroupsPerDb -v 4 +system sh/cfg.sh -n dnode5 -c maxTablesPerVnode -v 1000 print =============== prepare data system sh/exec.sh -n dnode1 -s start diff --git a/tests/script/unique/big/maxvnodes.sim b/tests/script/unique/big/maxvnodes.sim index ab93474a43..9603b5de64 100644 --- a/tests/script/unique/big/maxvnodes.sim +++ b/tests/script/unique/big/maxvnodes.sim @@ -9,9 +9,11 @@ $totalRows = $totalVnodes * $maxTables system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 2 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v $totalVnodes +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v $totalVnodes system sh/deploy.sh -n dnode2 -i 2 system sh/cfg.sh -n dnode2 -c walLevel -v 2 system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v $totalVnodes +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v $totalVnodes print ========== prepare data diff --git a/tests/script/unique/cluster/client3.sim b/tests/script/unique/cluster/client3.sim new file mode 100644 index 0000000000..4b3024f881 --- /dev/null +++ b/tests/script/unique/cluster/client3.sim @@ -0,0 +1,55 @@ +$tblStart = 0 +$tblEnd = 10000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + +loop_lable: +print ====================== client3 start loop: dynamic create table and insert data, select, drop table ............ + +$totalRows = 0 + +#sql create table $stb ( ts timestamp, c1 int) tags ( t1 int, t2 binary(16) ) +$tagBinary = ' . client3 +$tagBinary = $tagBinary . ' + +$rowsPerLoop = 100 +$ts = $tsStart + +$i = $tblStart +while $i < $tblEnd + $tb = dtb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb using $stb tags ( $i , $tagBinary ) values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x +# print ====== app insert totalRows: $totalRows + $i = $i + 1 +endw + +sql select count(*) from $stb where t2 == $tagBinary +if $data00 != $totalRows then + print data00 $data00 totalRows $totalRows + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client3 insert loss: $deltaRows ***** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +endi + +print ====================== client3 drop table +$i = $tblStart +while $i < $tblEnd + $tb = dtb . $i + sql drop table if exists $tb + $i = $i + 1 +endw +goto loop_lable \ No newline at end of file diff --git a/tests/script/unique/cluster/client4.sim b/tests/script/unique/cluster/client4.sim new file mode 100644 index 0000000000..a4c347695e --- /dev/null +++ b/tests/script/unique/cluster/client4.sim @@ -0,0 +1,113 @@ +$tblStart = 0 +$tblEnd = 2000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +loop_lable: +print ====================== client4 start loop: create db2, tables and insert data, select, drop db2 ............ + +$db = db2 +$stb = stb2 + +print create database if not exists $db replica 2 +sql create database if not exists $db replica 2 +sql use $db + +print ==== client4start create table +$i = $tblStart +while $i < $tblEnd + $tb = dtb . $i + sql create table $tb (ts timestamp, c1 int) + $i = $i + 1 +endw + + +print ==== client4start insert, include multi table data in one insert sql +$totalRows = 0 +$totalRowsPerTbl = 0 + +$rowsPerLoop = 100 +$ts = $tsStart + +$i = $tblStart +while $i < $tblEnd + $tb0 = dtb . $i + $i = $i + 1 + $tb1 = dtb . $i + $i = $i + 1 + $tb2 = dtb . $i + $i = $i + 1 + $tb3 = dtb . $i + $i = $i + 1 + $tb4 = dtb . $i + $i = $i + 1 + + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb0 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) $tb1 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) $tb2 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) $tb3 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) $tb4 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRowsPerTbl = $totalRowsPerTbl + $x + $x = $x * 5 + $totalRows = $totalRows + $x +endw + +sql select count(*) from tb10 +if $data00 != $totalRowsPerTbl then + print data00 $data00 totalRowsPerTbl $totalRowsPerTbl + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client4 insert loss: $deltaRows ***** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +endi + + +print ====client4 start alter table +$i = $tblStart +while $i < $tblEnd + $tb = dtb . $i + sql alter table $tb add c2 float + $i = $i + 1 +endw + +print ====client4 continue insert, include multi table data in one insert sql + +$i = $tblStart +while $i < $tblEnd + $tb0 = dtb . $i + $i = $i + 1 + $tb1 = dtb . $i + $i = $i + 1 + $tb2 = dtb . $i + $i = $i + 1 + $tb3 = dtb . $i + $i = $i + 1 + $tb4 = dtb . $i + $i = $i + 1 + + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb0 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) $tb1 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) $tb2 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) $tb3 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) $tb4 values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRowsPerTbl = $totalRowsPerTbl + $x + $x = $x * 5 + $totalRows = $totalRows + $x +endw + +sql select count(*) from tb10 +if $data00 != $totalRowsPerTbl then + print data00 $data00 totalRowsPerTbl $totalRowsPerTbl + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client4 insert loss: $deltaRows ***** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +endi + +print ====================== client4 drop database +sql drop if exists database $db +goto loop_lable \ No newline at end of file diff --git a/tests/script/unique/cluster/client5.sim b/tests/script/unique/cluster/client5.sim new file mode 100644 index 0000000000..1fe6298ae7 --- /dev/null +++ b/tests/script/unique/cluster/client5.sim @@ -0,0 +1,53 @@ +$tblStart = 0 +$tblEnd = 2000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +$tsEnd = 1325347210000 +############################################################### + +sql connect +$db = db1 +$stb = stb1 +#subtable: tb0 - tb4999 +#print create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(16)) + +sleep 20000 # wait other client insert data + +loop_lable: +print ====================== client5 start loop query + +sql use $db + +sql select count(*) from $stb + +$tsQueryStart = $tsStart +$tsQueryStart = $tsStart + 90000 +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart order by ts asc limit 500 offset 7 +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart order by ts desc limit 500 offset 7 + +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart and t2 == 'client1_0' +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart and t2 == 'client1_1' +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart and t2 == 'client1_2' +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart and t2 == 'client1_3' + +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart and t2 == 'client2_0' +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart and t2 == 'client2_1' +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart and t2 == 'client2_2' +sql select * from $stb where ts > $tsQueryStart and ts < $tsQueryStart and t2 == 'client2_3' + +sql select min(c1) from $stb +sql select max(c1) from $stb +sql select first(*) from $stb +sql select last(*) from $stb +sql select last_row(*) from $stb +sql select sum(c1) from $stb +sql select avg(c1) from $stb + +sql select min(c1) from tb1 +sql select max(c1) from tb10 +sql select first(*) from tb100 +sql select last(*) from tb1000 +sql select last_row(*) from tb20 +sql select sum(c1) from tb200 +sql select avg(c1) from tb2000 + +goto loop_lable \ No newline at end of file diff --git a/tests/script/unique/cluster/cluster_main.sim b/tests/script/unique/cluster/cluster_main.sim index 236f1aa59a..4c02d416f3 100644 --- a/tests/script/unique/cluster/cluster_main.sim +++ b/tests/script/unique/cluster/cluster_main.sim @@ -71,7 +71,7 @@ print ============== step3: create stable stb1 $stb = stb1 sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) -print ============== step4: start 10 client1/ 10 client2/ 10 client3/ 10 client4/ 1 client5 +print ============== step4: start back client1_0.sim run_back unique/cluster/client1_0.sim #run_back unique/cluster/client1_1.sim #run_back unique/cluster/client1_2.sim @@ -106,27 +106,43 @@ endi print wait for a while to let clients start insert data sleep 5000 -$loop_cnt = 0 -loop_cluster_do: -print **** **** **** START loop cluster do (loop_cnt: $loop_cnt )**** **** **** **** -print ============== step5: start dnode4/dnode5 and add into cluster, then wait ready -system sh/exec.sh -n dnode4 -s start -system sh/exec.sh -n dnode5 -s start +print ============== step4-1: add dnode4/dnode5 into cluster sql create dnode $hostname4 sql create dnode $hostname5 -sleep 5000 - - -print ============== step6: stop and drop dnode1, then remove data dir of dnode1 -system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 5000 -sql drop dnode $hostname1 -sleep 5000 - -system rm -rf ../../../sim/dnode1/data +$loop_cnt = 0 +loop_cluster_do: +print **** **** **** START loop cluster do (loop_cnt: $loop_cnt )**** **** **** **** +print ============== step5: start dnode4/dnode5 +system sh/exec.sh -n dnode4 -s start +system sh/exec.sh -n dnode5 -s start sleep 20000 +print ============== step6: stop dnode1 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 10000 +#sql drop dnode $hostname1 +#sleep 5000 + +#system rm -rf ../../../sim/dnode1/data +#sleep 20000 + +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step6-1: restart dnode1 +system sh/exec.sh -n dnode1 -s start +sleep 10000 sql show mnodes print show mnodes print rows: $rows @@ -139,7 +155,6 @@ print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 -return -1 print ============== step7: stop dnode2 system sh/exec.sh -n dnode2 -s stop -x SIGINT @@ -236,14 +251,17 @@ if $data04 != 2 then return -1 endi -print ============== step14: stop and drop dnode4/dnode5, then remove data dir of dnode4/dnode5 +print ============== step14: stop dnode4/dnode5 system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec.sh -n dnode5 -s stop -x SIGINT sleep 20000 -sql drop dnode $hostname4 -sql drop dnode $hostname5 -system rm -rf ../../../sim/dnode4/data -system rm -rf ../../../sim/dnode5/data +#system sh/exec.sh -n dnode4 -s start +#system sh/exec.sh -n dnode5 -s start +#sleep 10000 +#sql drop dnode $hostname4 +#sql drop dnode $hostname5 +#system rm -rf ../../../sim/dnode4/data +#system rm -rf ../../../sim/dnode5/data print ============== step15: alter replica 1 sql alter database $db replica 1 @@ -263,13 +281,13 @@ if $data04 != 2 then return -1 endi -print ============== step17: start dnode1 and add into cluster, then wait dnode1 ready -system sh/cfg.sh -n dnode1 -c first -v $hostname2 -system sh/cfg.sh -n dnode1 -c second -v $hostname3 - -system sh/exec.sh -n dnode1 -s start -sql create dnode $hostname1 -sleep 20000 +#print ============== step17: start dnode1 and add into cluster, then wait dnode1 ready +#system sh/cfg.sh -n dnode1 -c first -v $hostname2 +#system sh/cfg.sh -n dnode1 -c second -v $hostname3 +# +#system sh/exec.sh -n dnode1 -s start +#sql create dnode $hostname1 +#sleep 20000 print ============== step18: alter replica 3 sql alter database $db replica 3 diff --git a/tests/script/unique/cluster/cluster_main0.sim b/tests/script/unique/cluster/cluster_main0.sim new file mode 100644 index 0000000000..f3cce9fd45 --- /dev/null +++ b/tests/script/unique/cluster/cluster_main0.sim @@ -0,0 +1,288 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 +system sh/deploy.sh -n dnode5 -i 5 + +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode2 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode5 -c numOfMnodes -v 3 + +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode2 -c walLevel -v 1 +system sh/cfg.sh -n dnode3 -c walLevel -v 1 +system sh/cfg.sh -n dnode4 -c walLevel -v 1 +system sh/cfg.sh -n dnode5 -c walLevel -v 1 + +system sh/cfg.sh -n dnode1 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode2 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode3 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode4 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode5 -c balanceInterval -v 10 + +system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode5 -c numOfTotalVnodes -v 256 + +system sh/cfg.sh -n dnode1 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode2 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode3 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode4 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode5 -c alternativeRole -v 0 + +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 5000 + +system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode5 -c arbitrator -v $arbitrator + +print ============== step0: start tarbitrator +system sh/exec_tarbitrator.sh -s start + +print ============== step1: start dnode1/dnode2/dnode3 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +sleep 3000 +sql connect +sql create dnode $hostname2 +sql create dnode $hostname3 +sleep 3000 + +print ============== step2: create db1 with replica 3 +$db = db1 +print create database $db replica 3 +#sql create database $db replica 3 maxTables $totalTableNum +sql create database $db replica 3 +sql use $db + +print ============== step3: create stable stb1 +$stb = stb1 +print create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(16)) +sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(16)) + +print ============== step4: start others client +run_back unique/cluster/client1_0.sim +run_back unique/cluster/client1_1.sim +run_back unique/cluster/client1_2.sim +run_back unique/cluster/client1_3.sim +#run_back unique/cluster/client2_0.sim +#run_back unique/cluster/client2_1.sim +#run_back unique/cluster/client2_2.sim +#run_back unique/cluster/client2_3.sim +#run_back unique/cluster/client3.sim +#run_back unique/cluster/client4.sim + +sleep 20000 + +wait_subsim_insert_complete_create_tables: +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 +if $data00 < 1000 then + sleep 3000 + goto wait_subsim_insert_complete_create_tables +endi + +wait_subsim_insert_data: +print select count(*) from $stb +sql select count(*) from $stb +print data00 $data00 +if $data00 < 1000 then + sleep 3000 + goto wait_subsim_insert_data +endi + +print wait for a while to let clients start insert data +sleep 5000 + +$loop_cnt = 0 +loop_cluster_do: +print **** **** **** START loop cluster do (loop_cnt: $loop_cnt )**** **** **** **** +print ============== step5: start dnode4/dnode5 and add into cluster, then wait ready +system sh/exec.sh -n dnode4 -s start +system sh/exec.sh -n dnode5 -s start +sql create dnode $hostname4 +sql create dnode $hostname5 + +sleep 5000 + + +print ============== step6: stop dnode1 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 10000 +#sql drop dnode $hostname1 +#sleep 5000 +#system rm -rf ../../../sim/dnode1/data +#sleep 20000 +print ============== step6-1: restart dnode1 +system sh/exec.sh -n dnode1 -s start +sleep 10000 + +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step7: stop dnode2 +system sh/exec.sh -n dnode2 -s stop -x SIGINT +sleep 5000 + +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step8: restart dnode2, then wait sync end +system sh/exec.sh -n dnode2 -s start +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step9: stop dnode3, then wait sync end +system sh/exec.sh -n dnode3 -s stop -x SIGINT +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step10: restart dnode3, then wait sync end +system sh/exec.sh -n dnode3 -s start +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step11: stop dnode4, then wait sync end +system sh/exec.sh -n dnode4 -s stop -x SIGINT +sleep 20000 + +print ============== step12: restart dnode4, then wait sync end +system sh/exec.sh -n dnode4 -s start +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step13: alter replica 2 +sql alter database $db replica 2 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 + +if $data04 != 2 then + print rplica is not modify to 2, error!!!!!! + return -1 +endi + +print ============== step14: stop and drop dnode4/dnode5, then remove data dir of dnode4/dnode5 +system sh/exec.sh -n dnode4 -s stop -x SIGINT +system sh/exec.sh -n dnode5 -s stop -x SIGINT +sleep 3000 +sql drop dnode $hostname4 +sql drop dnode $hostname5 +system rm -rf ../../../sim/dnode4/data +system rm -rf ../../../sim/dnode5/data +sleep 20000 + +print ============== step15: alter replica 1 +sql alter database $db replica 1 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +if $data04 != 1 then + print rplica is not modify to 1, error!!!!!! + return -1 +endi + +print ============== step16: alter replica 2 +sql alter database $db replica 2 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +if $data04 != 2 then + print rplica is not modify to 2, error!!!!!! + return -1 +endi + +#print ============== step17: start dnode1 and add into cluster, then wait dnode1 ready +#system sh/cfg.sh -n dnode1 -c first -v $hostname2 +#system sh/cfg.sh -n dnode1 -c second -v $hostname3 +# +#system sh/exec.sh -n dnode1 -s start +#sql create dnode $hostname1 +#sleep 20000 + +print ============== step18: alter replica 3 +sql alter database $db replica 3 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +if $data04 != 3 then + print rplica is not modify to 3, error!!!!!! + return -1 +endi + +print **** **** **** (loop_cnt: $loop_cnt ) end, continue...... **** **** **** **** +$loop_cnt = $loop_cnt + 1 +goto loop_cluster_do diff --git a/tests/script/unique/cluster/cluster_main1.sim b/tests/script/unique/cluster/cluster_main1.sim new file mode 100644 index 0000000000..e05c30aa6d --- /dev/null +++ b/tests/script/unique/cluster/cluster_main1.sim @@ -0,0 +1,330 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 +system sh/deploy.sh -n dnode5 -i 5 + +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode2 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode5 -c numOfMnodes -v 3 + +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode2 -c walLevel -v 1 +system sh/cfg.sh -n dnode3 -c walLevel -v 1 +system sh/cfg.sh -n dnode4 -c walLevel -v 1 +system sh/cfg.sh -n dnode5 -c walLevel -v 1 + +system sh/cfg.sh -n dnode1 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode2 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode3 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode4 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode5 -c balanceInterval -v 10 + +system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode5 -c numOfTotalVnodes -v 256 + +system sh/cfg.sh -n dnode1 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode2 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode3 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode4 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode5 -c alternativeRole -v 0 + +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 5000 + +system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode5 -c arbitrator -v $arbitrator + +print ============== step0: start tarbitrator +system sh/exec_tarbitrator.sh -s start + +print ============== step1: start dnode1/dnode2/dnode3 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +sleep 3000 +sql connect +sql create dnode $hostname2 +sql create dnode $hostname3 +sleep 3000 + +print ============== step2: create db1 with replica 3 +$replica = 3 +$db = db1 +print create database $db replica $replica +#sql create database $db replica 3 maxTables $totalTableNum +sql create database $db replica $replica +sql use $db + +print ============== step3: create stable stb1 +$stb = stb1 +print create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(16)) +sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(16)) + +print ============== step4: start others client +run_back unique/cluster/main1_client1_0.sim +run_back unique/cluster/main1_client1_1.sim +run_back unique/cluster/main1_client1_2.sim +run_back unique/cluster/main1_client1_3.sim +run_back unique/cluster/client3.sim +run_back unique/cluster/client4.sim +run_back unique/cluster/client5.sim + +sleep 20000 + +wait_subsim_insert_complete_create_tables: +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 +if $data00 < 1000 then + sleep 3000 + goto wait_subsim_insert_complete_create_tables +endi + +wait_subsim_insert_data: +print select count(*) from $stb +sql select count(*) from $stb +print data00 $data00 +if $data00 < 1000 then + sleep 3000 + goto wait_subsim_insert_data +endi + +print wait for a while to let clients start insert data +sleep 5000 + +print ============== step4-1: add dnode4/dnode5 into cluster +sql create dnode $hostname4 +sql create dnode $hostname5 +sleep 5000 + +$loop_cnt = 0 +loop_cluster_do: +print **** **** **** START loop cluster do (loop_cnt: $loop_cnt )**** **** **** **** +print ============== step5: start dnode4/dnode5 +system sh/exec.sh -n dnode4 -s start +system sh/exec.sh -n dnode5 -s start +sleep 20000 + +print ============== step6: stop dnode1 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 10000 +#sql drop dnode $hostname1 +#sleep 5000 +#system rm -rf ../../../sim/dnode1/data +#sleep 20000 +print ============== step6-1: restart dnode1 +system sh/exec.sh -n dnode1 -s start +sleep 10000 + +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step7: stop dnode2 +system sh/exec.sh -n dnode2 -s stop -x SIGINT +sleep 5000 + +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step8: restart dnode2, then wait sync end +system sh/exec.sh -n dnode2 -s start +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step9: stop dnode3, then wait sync end +system sh/exec.sh -n dnode3 -s stop -x SIGINT +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step10: restart dnode3, then wait sync end +system sh/exec.sh -n dnode3 -s start +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step11: stop dnode4, then wait sync end +system sh/exec.sh -n dnode4 -s stop -x SIGINT +sleep 20000 + +#print ============== step12: restart dnode4, then wait sync end +#system sh/exec.sh -n dnode4 -s start +#sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step13: alter replica 2 +sql alter database $db replica 2 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 + +if $data00 == db1 then + $replica = $data04 +elif $data10 == db1 then + $replica = $data14 +else then + print ==== db1 already not exists!!!!! + return -1 +endi + +if $replica != 2 then + print rplica is not modify to 2, error!!!!!! + return -1 +endi + +print ============== step14: stop dnode5 +system sh/exec.sh -n dnode5 -s stop -x SIGINT +sleep 20000 +#system rm -rf ../../../sim/dnode5/data + +#print ============== step14-1: drop dnode5, then remove data dir +#sql drop dnode $hostname5 +#sleep 20000 +#system rm -rf ../../../sim/dnode5/data + +print ============== step15: alter replica 1 +sql alter database $db replica 1 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 + +if $data00 == db1 then + $replica = $data04 +elif $data10 == db1 then + $replica = $data14 +else then + print ==== db1 already not exists!!!!! + return -1 +endi + +if $replica != 1 then + print rplica is not modify to 1, error!!!!!! + return -1 +endi + +print ============== step16: alter replica 2 +sql alter database $db replica 2 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 + +if $data00 == db1 then + $replica = $data04 +elif $data10 == db1 then + $replica = $data14 +else then + print ==== db1 already not exists!!!!! + return -1 +endi + +if $replica != 2 then + print rplica is not modify to 2, error!!!!!! + return -1 +endi + +#print ============== step17: start dnode1 and add into cluster, then wait dnode1 ready +#system sh/cfg.sh -n dnode1 -c first -v $hostname2 +#system sh/cfg.sh -n dnode1 -c second -v $hostname3 +# +#system sh/exec.sh -n dnode1 -s start +#sql create dnode $hostname1 +#sleep 20000 + +print ============== step18: alter replica 3 +sql alter database $db replica 3 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 + +if $data00 == db1 then + $replica = $data04 +elif $data10 == db1 then + $replica = $data14 +else then + print ==== db1 already not exists!!!!! + return -1 +endi + +if $replica != 3 then + print rplica is not modify to 3, error!!!!!! + return -1 +endi + +print **** **** **** (loop_cnt: $loop_cnt ) end, continue...... **** **** **** **** +$loop_cnt = $loop_cnt + 1 +goto loop_cluster_do diff --git a/tests/script/unique/cluster/cluster_main2.sim b/tests/script/unique/cluster/cluster_main2.sim new file mode 100644 index 0000000000..9c682de041 --- /dev/null +++ b/tests/script/unique/cluster/cluster_main2.sim @@ -0,0 +1,334 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 +system sh/deploy.sh -n dnode5 -i 5 + +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode2 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode4 -c numOfMnodes -v 3 +system sh/cfg.sh -n dnode5 -c numOfMnodes -v 3 + +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode2 -c walLevel -v 1 +system sh/cfg.sh -n dnode3 -c walLevel -v 1 +system sh/cfg.sh -n dnode4 -c walLevel -v 1 +system sh/cfg.sh -n dnode5 -c walLevel -v 1 + +system sh/cfg.sh -n dnode1 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode2 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode3 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode4 -c balanceInterval -v 10 +system sh/cfg.sh -n dnode5 -c balanceInterval -v 10 + +system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 256 +system sh/cfg.sh -n dnode5 -c numOfTotalVnodes -v 256 + +system sh/cfg.sh -n dnode1 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode2 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode3 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode4 -c alternativeRole -v 0 +system sh/cfg.sh -n dnode5 -c alternativeRole -v 0 + +system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 5000 +system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 5000 + +system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode5 -c arbitrator -v $arbitrator + +print ============== step0: start tarbitrator +system sh/exec_tarbitrator.sh -s start + +print ============== step1: start dnode1/dnode2/dnode3 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +sleep 3000 +sql connect +sql create dnode $hostname2 +sql create dnode $hostname3 +sleep 3000 + +print ============== step2: create db1 with replica 3 +$replica = 3 +$db = db1 +print create database $db replica $replica +#sql create database $db replica 3 maxTables $totalTableNum +sql create database $db replica $replica +sql use $db + +print ============== step3: create stable stb1 +$stb = stb1 +print create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(16)) +sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(16)) + +print ============== step4: start others client +run_back unique/cluster/main2_client1_0.sim +run_back unique/cluster/main2_client1_1.sim +run_back unique/cluster/main2_client1_2.sim +run_back unique/cluster/main2_client1_3.sim +run_back unique/cluster/main2_client2_0.sim +run_back unique/cluster/main2_client2_1.sim +run_back unique/cluster/main2_client2_2.sim +run_back unique/cluster/main2_client2_3.sim +run_back unique/cluster/client3.sim +run_back unique/cluster/client4.sim +run_back unique/cluster/client5.sim + +sleep 20000 + +wait_subsim_insert_complete_create_tables: +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 +if $data00 < 1000 then + sleep 3000 + goto wait_subsim_insert_complete_create_tables +endi + +wait_subsim_insert_data: +print select count(*) from $stb +sql select count(*) from $stb +print data00 $data00 +if $data00 < 1000 then + sleep 3000 + goto wait_subsim_insert_data +endi + +print wait for a while to let clients start insert data +sleep 5000 + +print ============== step4-1: add dnode4/dnode5 into cluster +sql create dnode $hostname4 +sql create dnode $hostname5 +sleep 5000 + + +$loop_cnt = 0 +loop_cluster_do: +print **** **** **** START loop cluster do (loop_cnt: $loop_cnt )**** **** **** **** +print ============== step5: start dnode4/dnode5 +system sh/exec.sh -n dnode4 -s start +system sh/exec.sh -n dnode5 -s start + +print ============== step6: stop dnode1 +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 10000 +#sql drop dnode $hostname1 +#sleep 5000 +#system rm -rf ../../../sim/dnode1/data +#sleep 20000 +print ============== step6-1: restart dnode1 +system sh/exec.sh -n dnode1 -s start +sleep 10000 + +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step7: stop dnode2 +system sh/exec.sh -n dnode2 -s stop -x SIGINT +sleep 5000 + +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step8: restart dnode2, then wait sync end +system sh/exec.sh -n dnode2 -s start +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step9: stop dnode3, then wait sync end +system sh/exec.sh -n dnode3 -s stop -x SIGINT +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step10: restart dnode3, then wait sync end +system sh/exec.sh -n dnode3 -s start +sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step11: stop dnode4, then wait sync end +system sh/exec.sh -n dnode4 -s stop -x SIGINT +sleep 20000 + +#print ============== step12: restart dnode4, then wait sync end +#system sh/exec.sh -n dnode4 -s start +#sleep 20000 +sql show mnodes +print show mnodes +print rows: $rows +print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 +print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 +print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 +print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 +print $data0_5 $data1_5 $data2_5 $data3_5 $data4_5 +print $data0_6 $data1_6 $data2_6 $data3_6 $data4_6 +print $data0_7 $data1_7 $data2_7 $data3_7 $data4_7 +print $data0_8 $data1_8 $data2_8 $data3_8 $data4_8 +print $data0_9 $data1_9 $data2_9 $data3_9 $data4_9 + +print ============== step13: alter replica 2 +sql alter database $db replica 2 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 + +if $data00 == db1 then + $replica = $data04 +elif $data10 == db1 then + $replica = $data14 +else then + print ==== db1 already not exists!!!!! + return -1 +endi + +if $replica != 2 then + print rplica is not modify to 2, error!!!!!! + return -1 +endi + +print ============== step14: drop dnode5, then remove data dir +system sh/exec.sh -n dnode5 -s stop -x SIGINT +sleep 20000 +#system rm -rf ../../../sim/dnode5/data + +#print ============== step14-1: drop dnode5, then remove data dir +#sql drop dnode $hostname5 +#sleep 20000 +#system rm -rf ../../../sim/dnode5/data + +print ============== step15: alter replica 1 +sql alter database $db replica 1 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 + +if $data00 == db1 then + $replica = $data04 +elif $data10 == db1 then + $replica = $data14 +else then + print ==== db1 already not exists!!!!! + return -1 +endi + +if $replica != 1 then + print rplica is not modify to 1, error!!!!!! + return -1 +endi + +print ============== step16: alter replica 2 +sql alter database $db replica 2 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 + +if $data00 == db1 then + $replica = $data04 +elif $data10 == db1 then + $replica = $data14 +else then + print ==== db1 already not exists!!!!! + return -1 +endi + +if $replica != 2 then + print rplica is not modify to 2, error!!!!!! + return -1 +endi + +#print ============== step17: start dnode1 and add into cluster, then wait dnode1 ready +#system sh/cfg.sh -n dnode1 -c first -v $hostname2 +#system sh/cfg.sh -n dnode1 -c second -v $hostname3 +# +#system sh/exec.sh -n dnode1 -s start +#sql create dnode $hostname1 +#sleep 20000 + +print ============== step18: alter replica 3 +sql alter database $db replica 3 +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 + +if $data00 == db1 then + $replica = $data04 +elif $data10 == db1 then + $replica = $data14 +else then + print ==== db1 already not exists!!!!! + return -1 +endi + +if $replica != 3 then + print rplica is not modify to 3, error!!!!!! + return -1 +endi + +print **** **** **** (loop_cnt: $loop_cnt ) end, continue...... **** **** **** **** +$loop_cnt = $loop_cnt + 1 +goto loop_cluster_do diff --git a/tests/script/unique/cluster/main1_client1_0.sim b/tests/script/unique/cluster/main1_client1_0.sim new file mode 100644 index 0000000000..d4f2aa4294 --- /dev/null +++ b/tests/script/unique/cluster/main1_client1_0.sim @@ -0,0 +1,94 @@ +#system sh/stop_dnodes.sh +#system sh/deploy.sh -n dnode1 -i 1 +#system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 10000 +#system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 256 +#system sh/exec.sh -n dnode1 -s start +#sql connect +#$db = db1 +#sql create database $db +#sql use $db +#$stb = stb1 +#sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) + + +$tblStart = 0 +$tblEnd = 1000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client1_0 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client1_0 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lastLossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) -x insert_error_loop + $x = $x + 20 + $ts = $ts + 40a + goto continue_next_0 + insert_error_loop: + print ============== main1_client1_0 run error: sql insert into $tb values ( $ts + 0a , $x ) ... ... + continue_next_0: + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary -x query_error_loop + if $data00 != $totalRows then + print data00 $data00 totalRows $totalRows + $deltaRows = $totalRows - $data00 + if $lastLossRows == 0 then + $lastLossRows = $deltaRows + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client1_0 insert loss: $deltaRows ***** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + elif $deltaRows != $lastLossRows + $tmp = $deltaRows - $lastLossRows + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client1_0 insert loss: $tmp *********** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + $lastLossRows = $deltaRows + endi +# return -1 + endi + goto continue_next_1 + query_error_loop: + print ============== main1_client1_0 run error: sql select count(*) from $stb where t2 == $tagBinary -x query_error_loop + continue_next_1: + print ====================== client1_0 insert data complete once ............ + endi +endw +print ====================== client1_0 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main1_client1_1.sim b/tests/script/unique/cluster/main1_client1_1.sim new file mode 100644 index 0000000000..b50f533ce1 --- /dev/null +++ b/tests/script/unique/cluster/main1_client1_1.sim @@ -0,0 +1,82 @@ +$tblStart = 1000 +$tblEnd = 2000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client1_1 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client1_1 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lastLossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) -x insert_error_loop + $x = $x + 20 + $ts = $ts + 40a + goto continue_next_0 + insert_error_loop: + print ============== main1_client1_1 run error: sql insert into $tb values ( $ts + 0a , $x ) ... ... + continue_next_0: + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary -x query_error_loop + if $data00 != $totalRows then + print data00 $data00 totalRows $totalRows + $deltaRows = $totalRows - $data00 + if $lastLossRows == 0 then + $lastLossRows = $deltaRows + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client1_1 insert loss: $deltaRows ***** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + elif $deltaRows != $lastLossRows + $tmp = $deltaRows - $lastLossRows + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client1_1 insert loss: $tmp *********** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + $lastLossRows = $deltaRows + endi +# return -1 + endi + goto continue_next_1 + query_error_loop: + print ============== main1_client1_1 run error: sql select count(*) from $stb where t2 == $tagBinary -x query_error_loop + continue_next_1: + print ====================== client1_2 insert data complete once ............ + endi +endw +print ====================== client1_1 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main1_client1_2.sim b/tests/script/unique/cluster/main1_client1_2.sim new file mode 100644 index 0000000000..8cc39ded04 --- /dev/null +++ b/tests/script/unique/cluster/main1_client1_2.sim @@ -0,0 +1,81 @@ +$tblStart = 2000 +$tblEnd = 3000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client1_2 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client1_2 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lastLossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) -x insert_error_loop + $x = $x + 20 + $ts = $ts + 40a + goto continue_next_0 + insert_error_loop: + print ============== main1_client1_2 run error: sql insert into $tb values ( $ts + 0a , $x ) ... ... + continue_next_0: + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary -x query_error_loop + if $data00 != $totalRows then + print data00 $data00 totalRows $totalRows + $deltaRows = $totalRows - $data00 + if $lastLossRows == 0 then + $lastLossRows = $deltaRows + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client1_2 insert loss: $deltaRows ***** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + elif $deltaRows != $lastLossRows + $tmp = $deltaRows - $lastLossRows + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client1_2 insert loss: $tmp *********** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + $lastLossRows = $deltaRows + endi +# return -1 + endi + goto continue_next_1 + query_error_loop: + print ============== main1_client1_2 run error: sql select count(*) from $stb where t2 == $tagBinary -x query_error_loop + continue_next_1: + print ====================== client1_2 insert data complete once ............ + endi +endw +print ====================== client1_2 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main1_client1_3.sim b/tests/script/unique/cluster/main1_client1_3.sim new file mode 100644 index 0000000000..72e1be48ac --- /dev/null +++ b/tests/script/unique/cluster/main1_client1_3.sim @@ -0,0 +1,81 @@ +$tblStart = 3000 +$tblEnd = 4000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client1_3 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client1_3 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lastLossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) -x insert_error_loop + $x = $x + 20 + $ts = $ts + 40a + goto continue_next_0 + insert_error_loop: + print ============== main1_client1_3 run error: sql insert into $tb values ( $ts + 0a , $x ) ... ... + continue_next_0: + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary -x query_error_loop + if $data00 != $totalRows then + print data00 $data00 totalRows $totalRows + $deltaRows = $totalRows - $data00 + if $lastLossRows == 0 then + $lastLossRows = $deltaRows + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client1_3 insert loss: $deltaRows ***** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + elif $deltaRows != $lastLossRows + $tmp = $deltaRows - $lastLossRows + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + print ************ client1_3 insert loss: $tmp *********** + print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + $lastLossRows = $deltaRows + endi +# return -1 + endi + goto continue_next_1 + query_error_loop: + print ============== main1_client1_3 run error: sql select count(*) from $stb where t2 == $tagBinary -x query_error_loop + continue_next_1: + print ====================== client1_3 insert data complete once ............ + endi +endw +print ====================== client1_3 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main1_client4.sim b/tests/script/unique/cluster/main1_client4.sim new file mode 100644 index 0000000000..eb8049b04b --- /dev/null +++ b/tests/script/unique/cluster/main1_client4.sim @@ -0,0 +1,127 @@ +$tblStart = 0 +$tblEnd = 10000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db2 +$stb = stb2 + +loop_lable: +print ========= start loop create db, table, inset data, alter column/tag, select, drop db + +sql create database if not exists $db +sql use $db +sql create table if not exists $stb ( ts timestamp, c1 int, c2 float ) tags ( t1 int , t2 binary(16) ) +$tagBinary = ' . client4 +$tagBinary = $tagBinary . ' + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +$rowsPerLoop = 100 +$ts = $tsStart + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x , $x ) ( $ts + 2a , $x , $x ) ( $ts + 4a , $x , $x ) ( $ts + 6a , $x , $x ) ( $ts + 8a , $x , $x ) ( $ts + 10a , $x , $x ) ( $ts + 12a , $x , $x ) ( $ts + 14a , $x , $x ) ( $ts + 16a , $x , $x ) ( $ts + 18a , $x , $x ) ( $ts + 20a , $x , $x ) ( $ts + 22a , $x , $x ) ( $ts + 24a , $x , $x ) ( $ts + 26a , $x , $x ) ( $ts + 28a , $x , $x ) ( $ts + 30a , $x , $x ) ( $ts + 32a , $x , $x ) ( $ts + 34a , $x , $x ) ( $ts + 36a , $x , $x ) ( $ts + 38a , $x , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb -x continue_loop + print data00 $data00 totalRows $totalRows + if $data00 != $totalRows then + print ********************** select error ********************** + endi + continue_loop: + print ====================== client4 insert data complete once ............ + endi +endw + +##################### alter column +sql alter table $stb add column c3 double +sql alter table $stb drop column c2 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x , $x ) ( $ts + 2a , $x , $x ) ( $ts + 4a , $x , $x ) ( $ts + 6a , $x , $x ) ( $ts + 8a , $x , $x ) ( $ts + 10a , $x , $x ) ( $ts + 12a , $x , $x ) ( $ts + 14a , $x , $x ) ( $ts + 16a , $x , $x ) ( $ts + 18a , $x , $x ) ( $ts + 20a , $x , $x ) ( $ts + 22a , $x , $x ) ( $ts + 24a , $x , $x ) ( $ts + 26a , $x , $x ) ( $ts + 28a , $x , $x ) ( $ts + 30a , $x , $x ) ( $ts + 32a , $x , $x ) ( $ts + 34a , $x , $x ) ( $ts + 36a , $x , $x ) ( $ts + 38a , $x , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb -x continue_loop + print data00 $data00 totalRows $totalRows + if $data00 != $totalRows then + print ********************** select error ********************** + endi + continue_loop: + print ====================== client4 insert data complete once ............ + endi +endw + + +##################### alter tag +sql alter table $stb add tag t3 int +sql alter table $stb drop tag t2 + +$i = $tblStart +while $i < $tblEnd + $tb = ttb . $i + sql create table if not exists $tb using $stb tags ($i, $i) + $i = $i + 1 +endw + +$rowsPerLoop = 100 +$ts = $tsStart + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x , $x ) ( $ts + 2a , $x , $x ) ( $ts + 4a , $x , $x ) ( $ts + 6a , $x , $x ) ( $ts + 8a , $x , $x ) ( $ts + 10a , $x , $x ) ( $ts + 12a , $x , $x ) ( $ts + 14a , $x , $x ) ( $ts + 16a , $x , $x ) ( $ts + 18a , $x , $x ) ( $ts + 20a , $x , $x ) ( $ts + 22a , $x , $x ) ( $ts + 24a , $x , $x ) ( $ts + 26a , $x , $x ) ( $ts + 28a , $x , $x ) ( $ts + 30a , $x , $x ) ( $ts + 32a , $x , $x ) ( $ts + 34a , $x , $x ) ( $ts + 36a , $x , $x ) ( $ts + 38a , $x , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb -x continue_loop + print data00 $data00 totalRows $totalRows + if $data00 != $totalRows then + print ********************** select error ********************** + endi + continue_loop: + print ====================== client4 insert data complete once ............ + endi +endw + +goto loop_lable \ No newline at end of file diff --git a/tests/script/unique/cluster/main2_client1_0.sim b/tests/script/unique/cluster/main2_client1_0.sim new file mode 100644 index 0000000000..a7fd181363 --- /dev/null +++ b/tests/script/unique/cluster/main2_client1_0.sim @@ -0,0 +1,69 @@ +#system sh/stop_dnodes.sh +#system sh/deploy.sh -n dnode1 -i 1 +#system sh/cfg.sh -n dnode5 -c maxtablesPerVnode -v 10000 +#system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 256 +#system sh/exec.sh -n dnode1 -s start +#sql connect +#$db = db1 +#sql create database $db +#sql use $db +#$stb = stb1 +#sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) + + +$tblStart = 0 +$tblEnd = 1000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client1_0 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client1_0 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lastLossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary + print ====================== client1_0 insert data complete once ............ + endi +endw +print ====================== client1_0 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main2_client1_1.sim b/tests/script/unique/cluster/main2_client1_1.sim new file mode 100644 index 0000000000..f22d62a741 --- /dev/null +++ b/tests/script/unique/cluster/main2_client1_1.sim @@ -0,0 +1,57 @@ +$tblStart = 1000 +$tblEnd = 2000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client1_1 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client1_1 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lastLossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary + print ====================== client1_1 insert data complete once ............ + endi +endw +print ====================== client1_1 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main2_client1_2.sim b/tests/script/unique/cluster/main2_client1_2.sim new file mode 100644 index 0000000000..df3a925c59 --- /dev/null +++ b/tests/script/unique/cluster/main2_client1_2.sim @@ -0,0 +1,56 @@ +$tblStart = 2000 +$tblEnd = 3000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client1_2 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client1_2 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lastLossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary + print ====================== client1_2 insert data complete once ............ + endi +endw +print ====================== client1_2 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main2_client1_3.sim b/tests/script/unique/cluster/main2_client1_3.sim new file mode 100644 index 0000000000..9c22432fa5 --- /dev/null +++ b/tests/script/unique/cluster/main2_client1_3.sim @@ -0,0 +1,56 @@ +$tblStart = 3000 +$tblEnd = 4000 +$tsStart = 1325347200000 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client1_3 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client1_3 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lastLossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary + print ====================== client1_3 insert data complete once ............ + endi +endw +print ====================== client1_3 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main2_client2_0.sim b/tests/script/unique/cluster/main2_client2_0.sim new file mode 100644 index 0000000000..e44efc49fc --- /dev/null +++ b/tests/script/unique/cluster/main2_client2_0.sim @@ -0,0 +1,56 @@ +$tblStart = 0 +$tblEnd = 1000 +$tsStart = 1325347200001 # 2012-01-01 00:00:00.001 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client2_0 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client2_0 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lastLossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary + print ====================== client2_0 insert data complete once ............ + endi +endw +print ====================== client2_0 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main2_client2_1.sim b/tests/script/unique/cluster/main2_client2_1.sim new file mode 100644 index 0000000000..19de147d3e --- /dev/null +++ b/tests/script/unique/cluster/main2_client2_1.sim @@ -0,0 +1,57 @@ +$tblStart = 1000 +$tblEnd = 2000 +$tsStart = 1325347200001 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client2_1 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client2_1 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary + print ====================== client2_1 insert data complete once ............ + endi +endw +print ====================== client2_1 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main2_client2_2.sim b/tests/script/unique/cluster/main2_client2_2.sim new file mode 100644 index 0000000000..19e3540bd1 --- /dev/null +++ b/tests/script/unique/cluster/main2_client2_2.sim @@ -0,0 +1,57 @@ +$tblStart = 2000 +$tblEnd = 3000 +$tsStart = 1325347200001 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client2_2 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client2_2 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary + print ====================== client2_2 insert data complete once ............ + endi +endw +print ====================== client2_2 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/cluster/main2_client2_3.sim b/tests/script/unique/cluster/main2_client2_3.sim new file mode 100644 index 0000000000..219df131c8 --- /dev/null +++ b/tests/script/unique/cluster/main2_client2_3.sim @@ -0,0 +1,57 @@ +$tblStart = 3000 +$tblEnd = 4000 +$tsStart = 1325347200001 # 2012-01-01 00:00:00.000 +############################################################### + +sql connect + +$db = db1 +$stb = stb1 + +sql use $db + + +######sql create table $stb (ts timestamp, c1 int) tags(t1 int, t2 binary(8)) +$tagBinary = ' . client2_3 +$tagBinary = $tagBinary . ' +#print ======= tag: $tagBinary + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i +# print create table if not exists $tb using $stb tags ( $i , $tagBinary ) + sql create table if not exists $tb using $stb tags ( $i , $tagBinary ) + $i = $i + 1 +endw + +print ====================== client2_3 create table end, start insert data ............ +sql select count(tbname) from $stb +print select count(tbname) from $stb +print data00 $data00 + +$rowsPerLoop = 100 +$ts = $tsStart + +$lossRows = 0 + +$i = $tblStart +while $i < $tblEnd + $tb = tb . $i + $x = 0 + while $x < $rowsPerLoop + sql insert into $tb values ( $ts + 0a , $x ) ( $ts + 2a , $x ) ( $ts + 4a , $x ) ( $ts + 6a , $x ) ( $ts + 8a , $x ) ( $ts + 10a , $x ) ( $ts + 12a , $x ) ( $ts + 14a , $x ) ( $ts + 16a , $x ) ( $ts + 18a , $x ) ( $ts + 20a , $x ) ( $ts + 22a , $x ) ( $ts + 24a , $x ) ( $ts + 26a , $x ) ( $ts + 28a , $x ) ( $ts + 30a , $x ) ( $ts + 32a , $x ) ( $ts + 34a , $x ) ( $ts + 36a , $x ) ( $ts + 38a , $x ) + $x = $x + 20 + $ts = $ts + 40a + endw + + $totalRows = $totalRows + $x + $i = $i + 1 + + if $i == $tblEnd then + $i = $tblStart + + sql select count(*) from $stb where t2 == $tagBinary + print ====================== client2_3 insert data complete once ............ + endi +endw +print ====================== client2_3 success and auto end ===================== \ No newline at end of file diff --git a/tests/script/unique/db/delete.sim b/tests/script/unique/db/delete.sim index 819da67c8a..f05d64e635 100644 --- a/tests/script/unique/db/delete.sim +++ b/tests/script/unique/db/delete.sim @@ -12,6 +12,12 @@ system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3 system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 10 system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 10 system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 10 +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 dnode1 -c maxTablesPerVnode -v 1000 +system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 1000 +system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 1000 print ========= start dnodes system sh/exec.sh -n dnode1 -s start @@ -23,7 +29,7 @@ sql create dnode $hostname3 system sh/exec.sh -n dnode3 -s start print ======== step1 -sql create database db replica 3 blocks 2 maxtables 1000 +sql create database db replica 3 blocks 2 sql create table db.mt (ts timestamp, tbcol int) TAGS(tgcol int) $tbPrefix = db.t diff --git a/tests/script/unique/db/delete_part.sim b/tests/script/unique/db/delete_part.sim index ac84382be4..bf74e04b7f 100644 --- a/tests/script/unique/db/delete_part.sim +++ b/tests/script/unique/db/delete_part.sim @@ -24,10 +24,15 @@ system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4 system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4 -system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode3 -c maxtablesPerVnode -v 4 -system sh/cfg.sh -n dnode4 -c maxtablesPerVnode -v 4 +system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 8 +system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 8 +system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 8 +system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 8 + +system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4 +system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 4 +system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 4 +system sh/cfg.sh -n dnode4 -c maxTablesPerVnode -v 4 print ========= start dnodes system sh/exec.sh -n dnode1 -s start diff --git a/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeDir.sim b/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeDir.sim index e0b5e9b931..9d53c9968e 100644 --- a/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeDir.sim +++ b/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeDir.sim @@ -199,13 +199,13 @@ print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $dat print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 $data5_4 $data6_4 $data7_4 $data8_4 $data9_4 -$d2v2status = $data4_4 -$d2v3status = $data4_2 -$d2v4status = $data4_3 +$d2v2status = $data6_4 +$d2v3status = $data6_2 +$d2v4status = $data6_3 -$d1v2status = $data7_4 -$d1v3status = $data7_2 -$d1v4status = $data7_3 +$d1v2status = $data9_4 +$d1v3status = $data9_2 +$d1v4status = $data9_3 if $d2v2status != master then sleep 2000 diff --git a/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim b/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim index ae7fc6af17..af457f4cba 100644 --- a/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim +++ b/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim @@ -201,13 +201,13 @@ print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $dat print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 $data5_4 $data6_4 $data7_4 $data8_4 $data9_4 -$d2v2status = $data4_4 -$d2v3status = $data4_2 -$d2v4status = $data4_3 +$d2v2status = $data6_4 +$d2v3status = $data6_2 +$d2v4status = $data6_3 -$d1v2status = $data7_4 -$d1v3status = $data7_2 -$d1v4status = $data7_3 +$d1v2status = $data9_4 +$d1v3status = $data9_2 +$d1v4status = $data9_3 if $d2v2status != master then sleep 2000 diff --git a/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir_stopAll_starAll.sim b/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir_stopAll_starAll.sim index dc9bc62696..e4ff2c23c8 100644 --- a/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir_stopAll_starAll.sim +++ b/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir_stopAll_starAll.sim @@ -166,13 +166,13 @@ print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $dat print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 $data5_4 $data6_4 $data7_4 $data8_4 $data9_4 -$d2v2status = $data4_4 -$d2v3status = $data4_2 -$d2v4status = $data4_3 +$d2v2status = $data6_4 +$d2v3status = $data6_2 +$d2v4status = $data6_3 -$d1v2status = $data7_4 -$d1v3status = $data7_2 -$d1v4status = $data7_3 +$d1v2status = $data9_4 +$d1v3status = $data9_2 +$d1v4status = $data9_3 if $d2v2status != master then sleep 2000 diff --git a/tests/script/unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim b/tests/script/unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim index b754dc7a49..6736530240 100644 --- a/tests/script/unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim +++ b/tests/script/unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim @@ -199,13 +199,13 @@ print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $dat print $data0_2 $data1_2 $data2_2 $data3_2 $data4_2 $data5_2 $data6_2 $data7_2 $data8_2 $data9_2 print $data0_3 $data1_3 $data2_3 $data3_3 $data4_3 $data5_3 $data6_3 $data7_3 $data8_3 $data9_3 print $data0_4 $data1_4 $data2_4 $data3_4 $data4_4 $data5_4 $data6_4 $data7_4 $data8_4 $data9_4 -$d2v2status = $data4_4 -$d2v3status = $data4_2 -$d2v4status = $data4_3 +$d2v2status = $data6_4 +$d2v3status = $data6_2 +$d2v4status = $data6_3 -$d1v2status = $data7_4 -$d1v3status = $data7_2 -$d1v4status = $data7_3 +$d1v2status = $data9_4 +$d1v3status = $data9_2 +$d1v4status = $data9_3 if $d2v2status != master then sleep 2000 diff --git a/tests/script/unique/vnode/replica2_a_large.sim b/tests/script/unique/vnode/replica2_a_large.sim new file mode 100644 index 0000000000..801570dd9c --- /dev/null +++ b/tests/script/unique/vnode/replica2_a_large.sim @@ -0,0 +1,103 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 +system sh/deploy.sh -n dnode3 -i 3 +system sh/deploy.sh -n dnode4 -i 4 +system sh/cfg.sh -n dnode1 -c wallevel -v 2 +system sh/cfg.sh -n dnode2 -c wallevel -v 2 +system sh/cfg.sh -n dnode3 -c wallevel -v 2 +system sh/cfg.sh -n dnode4 -c wallevel -v 2 +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 +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 dnode4 -c numOfMnodes -v 1 +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 dnode3 -c mnodeEqualVnodeNum -v 4 +system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 4 +system sh/cfg.sh -n dnode1 -c debugFlag -v 131 +system sh/cfg.sh -n dnode2 -c debugFlag -v 131 +system sh/cfg.sh -n dnode3 -c debugFlag -v 131 +system sh/cfg.sh -n dnode4 -c debugFlag -v 131 +system sh/cfg.sh -n dnode1 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode2 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode3 -c arbitrator -v $arbitrator +system sh/cfg.sh -n dnode4 -c arbitrator -v $arbitrator + +print ============== step0: start tarbitrator +system sh/exec_tarbitrator.sh -s start + +system sh/exec.sh -n dnode1 -s start +sleep 3000 +sql connect + +sql create dnode $hostname2 +sql create dnode $hostname3 +system sh/exec.sh -n dnode2 -s start -t +system sh/exec.sh -n dnode3 -s start -t +sleep 3000 + +print ========= step1 +sql create database db replica 2 +#sql create table db.tb1 (ts timestamp, i int) +#sql create table db.tb2 (ts timestamp, i int) +#sql create table db.tb3 (ts timestamp, i int) +#sql create table db.tb4 (ts timestamp, i int) +#sql insert into db.tb1 values(now, 1) +#sql select count(*) from db.tb1 + +sql create database db replica 2 +sql create table db.tb (ts timestamp, i int) +sql insert into db.tb values(now, 1) +sql select count(*) from db.tb +$lastRows = $rows + +print ======== step2 +#run_back unique/vnode/back_insert_many.sim +run_back unique/vnode/back_insert.sim +sleep 3000 + +print ======== step3 + +$x = 0 +loop: + +print ======== step4 +system sh/exec.sh -n dnode2 -s stop -x SIGINT +sleep 10000 +system sh/exec.sh -n dnode2 -s start -t +sleep 10000 + +print ======== step5 +system sh/exec.sh -n dnode3 -s stop -x SIGINT +sleep 10000 +system sh/exec.sh -n dnode3 -s start -t +sleep 10000 + +print ======== step6 +#sql select count(*) from db.tb1 +#print select count(*) from db.tb1 ==> $data00 $lastRows +sql select count(*) from db.tb +print select count(*) from db.tb ==> $data00 $lastRows +if $data00 <= $lastRows then + return -1 +endi + +print ======== step7 +$lastRows = $data00 +print ======== loop Times $x + +if $x < 10 then + $x = $x + 1 + goto loop +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode3 -s stop -x SIGINT +system sh/exec.sh -n dnode4 -s stop -x SIGINT +system sh/exec.sh -n dnode5 -s stop -x SIGINT +system sh/exec.sh -n dnode6 -s stop -x SIGINT +system sh/exec.sh -n dnode7 -s stop -x SIGINT +system sh/exec.sh -n dnode8 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/test/c/createTablePerformance.c b/tests/test/c/createTablePerformance.c index 3edffd2a5e..2e334fa9b2 100644 --- a/tests/test/c/createTablePerformance.c +++ b/tests/test/c/createTablePerformance.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" +#include "taoserror.h" #include "taos.h" #include "tulog.h" #include "ttime.h" @@ -154,7 +155,7 @@ void *threadFunc(void *param) { TAOS_RES *pSql = taos_query(con, qstr); code = taos_errno(pSql); 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); } diff --git a/tests/tsim/inc/sim.h b/tests/tsim/inc/sim.h index ecd481f869..18af21a506 100644 --- a/tests/tsim/inc/sim.h +++ b/tests/tsim/inc/sim.h @@ -30,8 +30,8 @@ #define MAX_FILE_NAME_LEN 256 #define MAX_ERROR_LEN 1024 #define MAX_QUERY_VALUE_LEN 40 -#define MAX_QUERY_COL_NUM 10 -#define MAX_QUERY_ROW_NUM 10 +#define MAX_QUERY_COL_NUM 20 +#define MAX_QUERY_ROW_NUM 20 #define MAX_SYSTEM_RESULT_LEN 2048 #define MAX_VAR_LEN 100 #define MAX_VAR_NAME_LEN 32 @@ -53,10 +53,10 @@ #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 simWarn(...) { if (simDebugFlag & DEBUG_WARN) { taosPrintLog("SIM WARN ", 255, __VA_ARGS__); }} -#define simInfo(...) { if (simDebugFlag & DEBUG_INFO) { taosPrintLog("SIM INFO ", 255, __VA_ARGS__); }} -#define simDebug(...) { if (simDebugFlag & DEBUG_DEBUG) { taosPrintLog("SIM DEBUG ", simDebugFlag, __VA_ARGS__); }} -#define simTrace(...) { if (simDebugFlag & DEBUG_TRACE) { taosPrintLog("SIM TRACE ", simDebugFlag, __VA_ARGS__); }} +#define simWarn(...) { if (simDebugFlag & DEBUG_WARN) { taosPrintLog("SIM WARN ", 255, __VA_ARGS__); }} +#define simInfo(...) { if (simDebugFlag & DEBUG_INFO) { taosPrintLog("SIM ", 255, __VA_ARGS__); }} +#define simDebug(...) { if (simDebugFlag & DEBUG_DEBUG) { taosPrintLog("SIM ", simDebugFlag, __VA_ARGS__); }} +#define simTrace(...) { if (simDebugFlag & DEBUG_TRACE) { taosPrintLog("SIM ", simDebugFlag, __VA_ARGS__); }} enum { SIM_SCRIPT_TYPE_MAIN, SIM_SCRIPT_TYPE_BACKGROUND }; diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index b077547709..7826735c2f 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -80,6 +80,23 @@ char *simGetVariable(SScript *script, char *varName, int varLen) { } } return "null"; + } else if (varName[6] == '_') { + int col = (varName[4] - '0') * 10 + (varName[5] - '0'); + if (col < 0 || col >= MAX_QUERY_COL_NUM) { + return "null"; + } + + char *keyName; + int keyLen; + paGetToken(varName + 7, &keyName, &keyLen); + + for (int i = 0; i < MAX_QUERY_ROW_NUM; ++i) { + if (strncmp(keyName, script->data[i][0], keyLen) == 0) { + simTrace("script:%s, keyName:%s, keyValue:%s", script->fileName, script->data[i][0], script->data[i][col]); + return script->data[i][col]; + } + } + return "null"; } else { int row = varName[4] - '0'; int col = varName[5] - '0';